File: transform.test

package info (click to toggle)
tcltrf 2.1.4-dfsg3-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 9,628 kB
  • sloc: ansic: 73,134; sh: 3,155; tcl: 1,343; makefile: 176; exp: 22
file content (95 lines) | stat: -rw-r--r-- 2,825 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# -*- tcl -*-
# Commands covered:  transform
#
# This file contains a collection of tests for one or more of the trf
# commands of the TRF extension. Sourcing this file into Tcl runs the
# tests and generates output for errors.  No output means no errors were
# found.
#
# Copyright (c) 1997 Andreas Kupries (andreas_kupries@users.sourceforge.net)
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# $Id: transform.test,v 1.6 2001/08/21 05:51:33 tcl Exp $

if {[string compare test [info procs test]] == 1} then {source defs}


proc 82 {a b} {
    if {[string compare [info tclversion] 8.2] < 0} {
	return $b
    } else {
	return $a
    }
}


proc identity {operation buffer} {
    global  tracevar
    lappend tracevar "${operation}-[string length $buffer]"

    # no changes!
    set     buffer
}

proc pfx {prefix operation buffer} {
    return $prefix$buffer
}


test transform-1.0 {transform behaviour, immediate write} {
    set     tracevar ""
    lappend tracevar [transform -mode write -command identity foobarflabbergast]
    set     tracevar
} {create/write-0 write-17 flush/write-0 delete/write-0 foobarflabbergast}


test transform-1.1 {transform behaviour, immediate read} {
    set     tracevar ""
    lappend tracevar [transform -mode read -command identity foobarflabbergast]
    set     tracevar
} {create/read-0 read-17 flush/read-0 delete/read-0 foobarflabbergast}


test transform-2.0 {transform behaviour, attached write} {
    set tracevar ""
    set                out [memchan]
    transform -attach $out -command identity
    puts -nonewline   $out foobarflabbergast
    close             $out

    set tracevar
} {create/write-0 create/read-0 query/ratio-0 write-17 flush/write-0 flush/read-0 delete/write-0 delete/read-0}


test transform-2.1 {transform behaviour, attached read} {
    set tracevar ""
    set                in [memchan]
    puts -nonewline   $in foobarflabbergast
    seek              $in 0
    transform -attach $in -command identity
    read              $in
    close             $in

    set tracevar
} [82 {create/write-0 create/read-0 query/ratio-0 query/maxRead-0 read-17 query/maxRead-0 flush/read-0 flush/write-0 delete/write-0 delete/read-0} {create/write-0 create/read-0 query/ratio-0 query/maxRead-0 read-17 query/maxRead-0 flush/read-0 query/maxRead-0 flush/write-0 delete/write-0 delete/read-0}]


test transform-3.0 {More than one transform should work too} {
    set tracevar ""
    set                out [memchan]

    transform -attach $out -command [list pfx a]
    transform -attach $out -command [list pfx b]
    puts -nonewline   $out foo

    unstack $out
    unstack $out

    seek $out 0
    set data [read $out]
    close             $out

    set data
} {abfooaba}