File: comment.test

package info (click to toggle)
tdom 0.9.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 8,376 kB
  • sloc: ansic: 61,050; xml: 26,497; tcl: 3,704; sh: 1,023; makefile: 117; cpp: 30
file content (209 lines) | stat: -rw-r--r-- 4,905 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
# Features covered:  comments
#
# This file tests the parser's performance on comments.
# Sourcing this file into Tcl runs the tests and generates output
# for errors.  No output means no errors were found.
#
# Copyright (c) 1998-2000 Zveno Pty Ltd.
#
# $Id$

source [file join [file dir [info script]] loadtdom.tcl]

catch {unset result}
proc pcdata data {
    append ::result $data
}
proc comment data {
    append ::comment $data
}
proc Estart {tagName attrList} {
    switch -- $tagName {
	test -
	Test {
	}
	default {
	    incr ::element
	}
    }
}

proc EStop tagname {
}

test comment-1.1 {Simple comment} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-1.1 {}}
    set parser [xml::parser comment-1.1 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- This is a comment --></Test>
}
    list $::comment $::result $::element
} {{ This is a comment } {} 0}

test comment-1.2 {Simple comment, no white space} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-1.2 {}}
    set parser [xml::parser comment-1.2 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!--This is a comment--></Test>
}
    list $::comment $::result $::element
} {{This is a comment} {} 0}

test comment-1.3 {Simple comment, within PCDATA} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-1.3 {}}
    set parser [xml::parser comment-1.3 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test>surrounding <!--This is a comment--> PCDATA</Test>
}
    list $::comment $::result $::element
} {{This is a comment} {surrounding  PCDATA} 0}

test comment-1.4 {Simple comment, no white space} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-1.3 {}}
    set parser [xml::parser comment-1.3 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!--comment--></Test>
}
    list $::comment $::result $::element
} {comment {} 0}

test comment-1.5 {comment, with nested element} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-1.4 {}}
    set parser [xml::parser comment-1.4 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- comment <!blah>--></Test>
}
    list $::comment $::result $::element
} {{ comment <!blah>} {} 0}

test comment-2.1 {comment with an angle bracket} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-2.1 {}}
    set parser [xml::parser comment-2.1 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- This is a > greater than sign --></Test>
}
    list $::comment $::result $::element
} {{ This is a > greater than sign } {} 0}

test comment-2.2 {comment with multiple angle brackets} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-2.2 {}}
    set parser [xml::parser comment-2.2 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse {<?xml version="1.0"?>
<!DOCTYPE Test>
<Test><!-- 
  <Test>
    <Element>
      <Empty/>
    </Element>
  </Test>
 --></Test>
}
    list $::comment $::result $::element
} {{ 
  <Test>
    <Element>
      <Empty/>
    </Element>
  </Test>
 } {} 0}

set comment_2_3 [format {
    <question title="This is &lt;okay&gt;, right?" />
    <question title="Is &lt;this> bogus?" />
    <section title="This is a problem%s" />
  } \}]

test comment-2.3 {comment with entities} {
    set ::result {}
    set ::comment {}
    set ::element 0

    catch {rename xml::comment-2.3 {}}
    set parser [xml::parser comment-2.3 \
	-elementstartcommand Estart \
	-elementendcommand EStop \
	-characterdatacommand pcdata \
	-commentcommand comment]
    $parser parse "<?xml version='1.0'?>
<!DOCTYPE test SYSTEM 'test.dtd'>
<test>

<author>
<organization/>
</author>

<!--${comment_2_3}-->
</test>"

list [string compare $::comment ${comment_2_3}] [string trim $::result] $::element
} [list 0 {} 2]

foreach parser [info commands comment-*] {
    $parser free
}

# cleanup
::tcltest::cleanupTests
return