1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # This file is free software, which comes along with NIT. This software is
4 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
5 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
6 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
7 # is kept unaltered, and a notification of the changes is added.
8 # You are allowed to redistribute it and sell it, alone or is a part of
11 # Test suite for `attributes_impl`.
12 module test_attributes_impl
is test_suite
15 import sax
::helpers
::attributes_impl
17 class TestAttributesImpl
20 private fun sample
: AttributesImpl do
21 var subject
= new AttributesImpl
23 # The parser may include everything...
24 subject
.add
("http://example.com/", "bar", "foo:bar", "CDATA", "baz")
25 # ... or omit the `qname`...
26 subject
.add
("urn:is:not:often:used", "i-am_ME", "", "ID", "noop")
27 # ... or retrieve an attribute with an empty value (that *must* be kept intact)...
28 subject
.add
("http://www.w3.org/XML/1998/namespace", "lang", "xml:lang",
30 # ... or omit to process the namespace.
31 subject
.add
("", "", "xml:space", "NMTOKEN", "default")
36 var subject
= new AttributesImpl
38 assert 0 == subject
.length
39 subject
.add
("http://example.com/", "bar", "foo:bar", "CDATA", "baz")
40 assert 1 == subject
.length
41 subject
.add
("http://example.com/", "bar", "foo:bar", "CDATA", "baz")
42 assert 2 == subject
.length
44 assert 0 == subject
.length
45 # Clearing twice must not produce erroneous data.
47 assert 0 == subject
.length
53 assert "http://example.com/" == subject
.uri
(0)
54 assert "urn:is:not:often:used" == subject
.uri
(1)
55 assert "http://www.w3.org/XML/1998/namespace" == subject
.uri
(2)
56 assert "" == subject
.uri
(3)
57 assert subject
.uri
(4) == null
58 assert subject
.uri
(-1) == null
60 assert subject
.uri
(0) == null
63 fun test_local_name
do
66 assert "bar" == subject
.local_name
(0)
67 assert "i-am_ME" == subject
.local_name
(1)
68 assert "lang" == subject
.local_name
(2)
69 assert "" == subject
.local_name
(3)
70 assert subject
.local_name
(4) == null
71 assert subject
.local_name
(-1) == null
73 assert subject
.local_name
(0) == null
79 assert "foo:bar" == subject
.qname
(0)
80 assert "" == subject
.qname
(1)
81 assert "xml:lang" == subject
.qname
(2)
82 assert "xml:space" == subject
.qname
(3)
83 assert subject
.qname
(4) == null
84 assert subject
.qname
(-1) == null
86 assert subject
.qname
(0) == null
92 assert "CDATA" == subject
.type_of
(0)
93 assert "ID" == subject
.type_of
(1)
94 assert "NMTOKEN" == subject
.type_of
(2)
95 assert "NMTOKEN" == subject
.type_of
(3)
96 assert subject
.type_of
(4) == null
97 assert subject
.type_of
(-1) == null
99 assert subject
.type_of
(0) == null
102 fun test_type_of_qname
do
105 assert "CDATA" == subject
.type_of
("foo:bar")
106 assert subject
.type_of
("") == null
107 assert "NMTOKEN" == subject
.type_of
("xml:lang")
108 assert "NMTOKEN" == subject
.type_of
("xml:space")
109 assert subject
.type_of
("bob") == null
111 assert subject
.type_of
("xml:lang") == null
117 assert "baz" == subject
.value_of
(0)
118 assert "noop" == subject
.value_of
(1)
119 assert "" == subject
.value_of
(2)
120 assert "default" == subject
.value_of
(3)
121 assert subject
.value_of
(4) == null
122 assert subject
.value_of
(-1) == null
124 assert subject
.value_of
(0) == null
127 fun test_value_of_qname
do
130 assert "baz" == subject
.value_of
("foo:bar")
131 assert subject
.value_of
("") == null
132 assert "" == subject
.value_of
("xml:lang")
133 assert "default" == subject
.value_of
("xml:space")
134 assert subject
.value_of
("bob") == null
136 assert subject
.value_of
("xml:lang") == null
142 assert 0 == subject
.index_ns
("http://example.com/", "bar")
143 assert 1 == subject
.index_ns
("urn:is:not:often:used", "i-am_ME")
144 assert 2 == subject
.index_ns
("http://www.w3.org/XML/1998/namespace", "lang")
145 assert -1 == subject
.index_ns
("", "")
146 assert -1 == subject
.index_ns
("http://www.w3.org/XML/1998/namespace", "space")
148 assert -1 == subject
.index_ns
("http://example.com/", "bar")
154 assert 0 == subject
.index_of
("foo:bar")
155 assert -1 == subject
.index_of
("")
156 assert 2 == subject
.index_of
("xml:lang")
157 assert 3 == subject
.index_of
("xml:space")
158 assert -1 == subject
.index_of
("i-am_ME")
160 assert -1 == subject
.index_of
("foo:bar")
166 assert "CDATA" == subject
.type_ns
("http://example.com/", "bar")
167 assert "ID" == subject
.type_ns
("urn:is:not:often:used", "i-am_ME")
168 assert "NMTOKEN" == subject
.type_ns
("http://www.w3.org/XML/1998/namespace", "lang")
169 assert subject
.type_ns
("", "") == null
170 assert subject
.type_ns
("http://www.w3.org/XML/1998/namespace", "space") == null
172 assert subject
.type_ns
("http://example.com/", "bar") == null
178 assert "baz" == subject
.value_ns
("http://example.com/", "bar")
179 assert "noop" == subject
.value_ns
("urn:is:not:often:used", "i-am_ME")
180 assert "" == subject
.value_ns
("http://www.w3.org/XML/1998/namespace", "lang")
181 assert subject
.value_ns
("", "") == null
182 assert subject
.value_ns
("http://www.w3.org/XML/1998/namespace", "space") == null
184 assert subject
.value_ns
("http://example.com/", "bar") == null
187 fun test_attributes_set
do
189 var subject2
= new AttributesImpl
191 subject
.attributes
= subject2
192 assert subject
.length
== 0
194 subject
.attributes
= subject2
195 assert subject
.length
== 4
201 subject
.set
(1, "urn:is:not:often:used", "i-am_ME", "i-am_ME", "ID",
203 assert "i-am_ME" == subject
.qname
(1)
204 subject
.set
(0, "http://example.com/", "bar", "foo:bar", "NMTOKENS", "baz")
205 assert "NMTOKENS" == subject
.type_of
(0)
208 fun test_remove_at
do
212 assert 3 == subject
.length
213 assert "xml:lang" == subject
.qname
(1)
219 subject
.uri
(0) = "https://example.org/serious"
220 subject
.uri
(1) = "ftp://wat"
221 assert "ftp://wat" == subject
.uri
(1)
222 assert "https://example.org/serious" == subject
.uri
(0)
225 fun test_local_name_set
do
228 subject
.local_name
(0) = "trololol"
229 subject
.local_name
(1) = "ImYou42"
230 assert "trololol" == subject
.local_name
(0)
231 assert "ImYou42" == subject
.local_name
(1)
234 fun test_qname_set
do
237 subject
.qname
(0) = "go-to:bar"
238 subject
.qname
(1) = "yo:i-am_ME"
239 assert "go-to:bar" == subject
.qname
(0)
240 assert "yo:i-am_ME" == subject
.qname
(1)
243 fun test_type_of_set
do
246 subject
.type_of
(0) = "NMTOKENS"
247 subject
.type_of
(1) = "ENTITY"
248 assert "NMTOKENS" == subject
.type_of
(0)
249 assert "ENTITY" == subject
.type_of
(1)
252 fun test_value_of_set
do
255 subject
.value_of
(0) = "buz"
256 subject
.value_of
(1) = "bizzz"
257 assert "buz" == subject
.value_of
(0)
258 assert "bizzz" == subject
.value_of
(1)