File: test-continue.tcl

package info (click to toggle)
xotcl 1.6.8-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,468 kB
  • sloc: ansic: 22,485; tcl: 2,531; sh: 791; makefile: 141
file content (85 lines) | stat: -rwxr-xr-x 1,981 bytes parent folder | download | duplicates (10)
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
#!/bin/sh
#\
exec tclsh8.1 "$0" "$@"

# This tests the function of the continue facility

lappend auto_path [file dirname [info script]]
package require expat

proc element {tag name {attrs {}}} {
    array set at $attrs
    if {[info exists at(class)]} {
        switch $at(class) {
	    continue {
	        return -code continue
	    }
	    break {
	        return -code break
	    }
	    error {
	        return -code error "error condition in XML"
	    }
        }
    }
}
proc pi {name args} {
    if {[regexp {continue|break|error} $name]} {
	return -code $name
    }
}
proc pcdata pcdata {
    if {[string length [string trim $pcdata]]} {
	puts $pcdata
    }
}

set data(test1) {<?xml version="1.0"?>
<!DOCTYPE Test SYSTEM "test.dtd">
<Test>
<Element>Should see this data</Element>
<Element class="continue">Should not see this data</Element>
<Element>Should see this data</Element>
</Test>}
set data(test2) {<?xml version="1.0"?>
<!DOCTYPE Test SYSTEM "test.dtd">
<Test>
<Element>Should see this data</Element>
<Element>Should see this data
    <Element class="continue">Should not see this data</Element>
Should see this data
</Element>
<Element>Should see this data</Element>
</Test>}
set data(test3) {<?xml version="1.0"?>
<!DOCTYPE Test SYSTEM "test.dtd">
<Test>
<Element>Should see this data</Element>
<Element class="continue">Should not see this data
    <Element>Should not see this data</Element>
    <?break?><!-- Will not have any effect -->
    Should not see this data
    <Empty/>
    Should not see this data
</Element>
<Element>Should see this data</Element>
</Test>}

set parser [expat xmlparser \
	-elementstartcommand {element start}	\
	-elementendcommand {element end}	\
	-characterdatacommand pcdata		\
	-final yes				\
]

foreach {testName testData} [array get data] {
    puts "*** $testName"
    $parser reset
    if {[catch {$parser parse $testData} err]} {
	puts [list test failed due to $err]
    } else {
	puts [list test passed]
    }
}

exit 0