File: namespace.test

package info (click to toggle)
tdom 0.9.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,260 kB
  • sloc: ansic: 56,762; xml: 20,797; tcl: 3,618; sh: 658; makefile: 83; cpp: 30
file content (222 lines) | stat: -rw-r--r-- 6,130 bytes parent folder | download | duplicates (3)
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
# Features covered:  XML Namespaces
#
# This file tests the parser's performance on XML namespaces.
# Sourcing this file into Tcl runs the tests and generates output
# for errors.  No output means no errors were found.
#
# Copyright (c) 2000 Zveno Pty Ltd.
#
# $Id$

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

proc keysort args {
    array set keyvalue $args
    set result {}
    foreach key [lsort [array names keyvalue]] {
	lappend result $key $keyvalue($key)
    }
    return $result
}

catch {unset result}
catch {unset nsdecls}
proc EStart {tag attlist args} {
    global result nsdecls

    array set extra $args

    catch {eval lappend nsdecls $extra(-namespacedecls)}

    if {[info exists extra(-namespace)]} {
	lappend result $extra(-namespace)^$tag
    } else {
	lappend result $tag
    }
}

proc NSDeclStart {prefix uri} {
    global result

    lappend result $prefix
    lappend result $uri
}

test ns-1.1 {Namespace declaration} {
    set ::result {}
    set ::nsdecls {}

    catch {rename xml::ns-1.1 {}}
    set parser [xml::parser ns-1.1 \
            -namespace \
            -startnamespacedeclcommand NSDeclStart \
            -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test xmlns:test="http://www.zveno.com/Schemas"></Test>
}
    list $::result $::nsdecls
} {{test http://www.zveno.com/Schemas Test} {}}

test ns-1.2 {Multiple namespace declarations} {
    set ::result {}
    set ::nsdecls {}

    catch {rename xml::ns-1.2 {}}
    set parser [xml::parser ns-1.2 \
            -namespace \
            -startnamespacedeclcommand NSDeclStart \
            -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test xmlns:test="http://www.zveno.com/Schemas"
xmlns:x='urn:schema'></Test>
}
    list $::result [eval keysort $::nsdecls]
} {{test http://www.zveno.com/Schemas x urn:schema Test} {}}

test ns-1.3 {Default namespace declaration} {
    set ::result {}
    set ::nsdecls {}

    catch {rename xml::ns-1.3 {}}
    set parser [xml::parser ns-1.3 \
            -namespace \
            -startnamespacedeclcommand NSDeclStart \
            -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test xmlns="http://www.zveno.com/Schemas"
xmlns:x='urn:schema'></Test>
}
    list $::result [eval keysort $::nsdecls]
} {{{} http://www.zveno.com/Schemas x urn:schema http://www.zveno.com/Schemas:Test} {}}

test ns-1.4 {Default namespace declaration w/- separate usage} {
    set ::result {}
    set ::nsdecls {}

    catch {rename xml::ns-1.4 {}}
    set parser [xml::parser ns-1.4 \
            -namespace \
            -startnamespacedeclcommand NSDeclStart \
            -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<x:Test xmlns="http://www.zveno.com/Schemas"
xmlns:x='urn:schema'><Test/></x:Test>
}
    list $::result [eval keysort $::nsdecls]
} {{{} http://www.zveno.com/Schemas x urn:schema urn:schema:Test http://www.zveno.com/Schemas:Test} {}}

test ns-1.5 {Place of -namespace option in arg list} {
    set ::result {}
    set ::nsdecls {}

    catch {rename xml::ns-1.5 {}}
    set parser [xml::parser ns-1.4 \
            -startnamespacedeclcommand NSDeclStart \
            -namespace \
            -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<x:Test xmlns="http://tdom.org/Schemas"
xmlns:x='urn:schema'><Test/></x:Test>
}
    list $::result [eval keysort $::nsdecls]
} {{{} http://tdom.org/Schemas x urn:schema urn:schema:Test http://tdom.org/Schemas:Test} {}}

test ns-2.0 {Multiple namespace declarations, same prefix} {
    set ::result {}
    set ::nsdecls {}

    catch {rename xml::ns-2.0 {}}
    set parser [xml::parser ns-2.0 \
            -namespace \
            -startnamespacedeclcommand NSDeclStart \
            -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test>
  <x:Test xmlns:x="http://www.zveno.com/Schemas">
    <x:y/>
  </x:Test>
  <x:Test xmlns:x='urn:schema'>
    <x:z/>
  </x:Test>
</Test>
}
    list $::result [eval keysort $::nsdecls]
} {{Test x http://www.zveno.com/Schemas http://www.zveno.com/Schemas:Test http://www.zveno.com/Schemas:y x urn:schema urn:schema:Test urn:schema:z} {}}

test ns-3.1 {-namespaceseparator} {
    set result ""
    
    catch {rename xml::ns-3.1 {}}
    set parser [xml::parser ns-3.1 \
                    -namespace \
                    -namespaceseparator = \
                    -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test>
  <x:Test xmlns:x="http://tdom.org/Schemas">
    <x:y/>
  </x:Test>
  <x:Test xmlns:x='urn:schema'>
    <x:z/>
  </x:Test>
</Test>
}
    set result
} {Test http://tdom.org/Schemas=Test http://tdom.org/Schemas=y urn:schema=Test urn:schema=z}

test ns-3.2 {-namespaceseparator} {
    set result ""
    
    catch {rename xml::ns-3.2 {}}
    set parser [xml::parser ns-3.2 \
                    -namespace \
                    -namespaceseparator "" \
                    -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test>
  <x:Test xmlns:x="http://tdom.org/Schemas">
    <x:y/>
  </x:Test>
  <x:Test xmlns:x='urn:schema'>
    <x:z/>
  </x:Test>
</Test>
}
    set result
} "Test http://tdom.org/SchemasTest http://tdom.org/Schemasy urn:schemaTest urn:schemaz"

test ns-3.3 {-namespaceseparator} {
    set result ""
    
    catch {rename xml::ns-3.3 {}}
    set parser [xml::parser ns-3.3 \
                    -namespace \
                    -namespaceseparator \x00 \
                    -elementstartcommand EStart]
    $parser parse {<?xml version="1.0"?>
<Test>
  <x:Test xmlns:x="http://tdom.org/Schemas">
    <x:y/>
  </x:Test>
  <x:Test xmlns:x='urn:schema'>
    <x:z/>
  </x:Test>
</Test>
}
    set result
} "Test http://tdom.org/SchemasTest http://tdom.org/Schemasy urn:schemaTest urn:schemaz"

test ns-3.4 {-namespaceseparator} {
    catch {rename xml::ns-3.4 {}}
    set parser [xml::parser ns-3.4 \
                    -namespaceseparator =]
    $parser cget -namespaceseparator
} =

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

# cleanup
::tcltest::cleanupTests
return