File: cdata.test

package info (click to toggle)
tclxml 3.1-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,076 kB
  • ctags: 876
  • sloc: ansic: 6,064; tcl: 5,116; xml: 4,642; sh: 3,112; makefile: 60
file content (252 lines) | stat: -rwxr-xr-x 6,848 bytes parent folder | download | duplicates (5)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# Features covered:  CDATA sections
#
# This file contains a collection of tests for the TclXML parser.
# This file tests the parser's performance on CDATA sections.
# Sourcing this file into Tcl runs the tests and generates output
# for errors.  No output means no errors were found.
#
# Copyright (c) 1998-2003 Zveno Pty Ltd.
#
# $Id: cdata.test,v 1.8 2003/12/03 20:06:36 balls Exp $

package require tcltest
source [file join [tcltest::workingDirectory] tclxmlutils.tcl]

testPackage $::tcltest::parser

namespace eval ::xml::cdataTest {
    namespace import -force ::tcltest::*

    variable SETUP {

	variable element 0
	variable result {}

	proc pcdata data {
	    variable result
	    append result $data
	}
	proc EStart {tagName attrList args} {
	    variable element
	    switch -- $tagName {
		Test {
		}
		default {
		    incr element
		}
	    }
	}

	proc EStop {tagName args} {
	}

	set parser [xml::parser \
		-elementstartcommand [namespace code EStart] \
		-elementendcommand [namespace code EStop] \
		-characterdatacommand [namespace code pcdata]]

    }
    variable CLEANUP {
	catch {unset result}
	catch {unset element}
	rename EStart {}
	rename pcdata {}
	rename EStop {}
	$parser free
    }

    test cdata-1.1 {Simple CDATA section} -setup $SETUP -body {
	$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><![CDATA[This is CDATA]]></Test>
}
	list $result $element
    } -cleanup $CLEANUP -result {{This is CDATA} 0}

    test cdata-1.2 {CDATA test contributed by Richard Emberson (emberson@netintouch.com)} -setup $SETUP -body {
	$parser parse {<?xml version="1.0"?>
  <TOP>
    <![CDATA[928806871035]]>
  </TOP>
}
	list $result $element
    } -cleanup $CLEANUP -result {{
    928806871035
  } 1}

    # Test bug: ']]>' is not valid character data (XML Rec. subsect. 2.4) - 
    # this should produce a warning.
    test cdata-2.0 {CDATA section interpersed with comment} -setup $SETUP -body {
	$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><![CDATA[<!-- This is not a comment -->]]>
<!-- This is a comment <![CDATA[This is not CDATA]]>-->
<![CDATA[<!-- ]]>-->]]&gt;</Test>}
	list $result $element
    } -cleanup $CLEANUP -result {{<!-- This is not a comment -->

<!-- -->]]>} 0}

    test cdata-2.1 {CDATA section with an angle bracket} -setup $SETUP -body {
	$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><![CDATA[This is a > greater than sign]]></Test>
}
	list $result $element
    } -cleanup $CLEANUP -result {{This is a > greater than sign} 0}

    # Test case contributed by Marshall Rose (mrose@dbc.mtview.ca.us)
    test cdata-2.2 {CDATA section with multiple angle brackets} -setup $SETUP -body {
	$parser parse {<?xml version="1.0" ?>
<!DOCTYPE Test>
<Test>
<artwork><![CDATA[
    <?xml version="1.0">
    <!DOCTYPE rfc SYSTEM "rfcXXXX.dtd">
    <rfc>
    ...

    </rfc>
]]></artwork>
</Test>}
	list $result $element
    } -cleanup $CLEANUP -result {{

    <?xml version="1.0">
    <!DOCTYPE rfc SYSTEM "rfcXXXX.dtd">
    <rfc>
    ...

    </rfc>

} 1}

    # Test case contributed by J. Linnenkohl (jlinnen@c-s-k.de)
    test cdata-2.3 {CDATA section with square brackets and curly braces} -setup $SETUP -body {
	$parser parse {<?xml version="1.0" ?>
<Tcl>
<![CDATA[
proc arithmetic_add {groups inputs outputs atts} {
    set ret_val ""
    set t "Hello World"
    set l [string length $t]
    return $ret_val
}
]]>
</Tcl>
}
	list $result $element
    } -cleanup $CLEANUP -result {{

proc arithmetic_add {groups inputs outputs atts} {
    set ret_val ""
    set t "Hello World"
    set l [string length $t]
    return $ret_val
}

} 1}

    test cdata-2.4 {CDATA section with angle brackets and curly braces} -setup $SETUP -body {
	$parser parse {<?xml version="1.0" ?>
<Tcl>
<![CDATA[
proc arithmetic_add {groups inputs outputs atts} {
    set ret_val [expr 1 > 2]
    set t "Hello World"
    set l [string length $t]
    return $ret_val
}
]]>
</Tcl>
}
	list $result $element
    } -cleanup $CLEANUP -result {{

proc arithmetic_add {groups inputs outputs atts} {
    set ret_val [expr 1 > 2]
    set t "Hello World"
    set l [string length $t]
    return $ret_val
}

} 1}

    test cdata-2.5 {CDATA section with angle brackets, Tcl specials trailing CDATA section} -setup $SETUP -body {
	$parser parse {<?xml version="1.0" ?>
<Tcl>
<![CDATA[
proc arithmetic_add {groups inputs outputs atts} {
    set ret_val [expr 1 > 2]
    set t "Hello World"
    set l [string length $t]
    return $ret_val
}
]]> that is {jolly} $good
</Tcl>
}
	list $result $element
    } -cleanup $CLEANUP -result {{

proc arithmetic_add {groups inputs outputs atts} {
    set ret_val [expr 1 > 2]
    set t "Hello World"
    set l [string length $t]
    return $ret_val
}
 that is {jolly} $good
} 1}

    # Test case contributed by Marshall Rose (mrose@dbc.mtview.ca.us)
    # SRB 2001-02-11: Test had to modified (slightly) to due non-well-formedness

    test cdata-3.1 {CDATA section with PI and Tcl special characters} -setup $SETUP -body {
	$parser parse {<?xml version="1.0"?>
<?x_m_l_2rfc toc="yes"?>
<!DOCTYPE Test>
<Test>
<t>this is a \ test</t>
<artwork><![CDATA[
    <date month="December" year="1998"/>
]]></artwork>
</Test>}
	list $result $element
    } -cleanup $CLEANUP -result {{
this is a \ test

    <date month="December" year="1998"/>

} 2}

    # Test case from bug #130127 reported by rnurmi@users.sourceforge.net

    test cdata-3.2 {CDATA with Tcl special character} -setup $SETUP -body {
	$parser parse [format {<?xml version="1.0"?>
<root><![CDATA[%s]]></root>} \\]

	set result
    } -cleanup $CLEANUP -result [format %s \\]

    # Test case from bug #130127 reported by rnurmi@users.sourceforge.net

    test cdata-3.3 {CDATA with Tcl regular expression} -setup $SETUP -body {
	$parser parse [format {<root><![CDATA[NOWRAP
ALIGN=LEFT>([^<]*)[^%sn]*>([^<]*)</A>[^%sn]*>([-+][0-9]*%s.[0-9][0-9]|-)[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]+)[^%sn]*%s>([0-9]*)%s.[0-9][0-9])]]></root>} \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\]

	set result
    } -cleanup $CLEANUP -result [format {NOWRAP
ALIGN=LEFT>([^<]*)[^%sn]*>([^<]*)</A>[^%sn]*>([-+][0-9]*%s.[0-9][0-9]|-)[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]*%s.[0-9][0-9])[^%sn]*>([0-9]+)[^%sn]*%s>([0-9]*)%s.[0-9][0-9])} \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\]

    test cdata-4.1 {CDATA section with entity reference} -setup $SETUP -body {
	$parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><![CDATA[no entity &lt;references&gt;]]></Test>}
	list $result $element
    } -cleanup $CLEANUP -result {{no entity &lt;references&gt;} 0}

    cleanupTests
}

namespace delete ::xml::cdataTest

return