lib/sax: fixes useless type declaration
[nit.git] / lib / sax / helpers / test_attributes_impl.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
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
9 # another product.
10
11 # Test suite for `attributes_impl`.
12 module test_attributes_impl is test_suite
13
14 import test_suite
15 import sax::helpers::attributes_impl
16
17 class TestAttributesImpl
18 super TestSuite
19
20 private fun sample: AttributesImpl do
21 var subject = new AttributesImpl
22
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",
29 "NMTOKEN", "")
30 # ... or omit to process the namespace.
31 subject.add("", "", "xml:space", "NMTOKEN", "default")
32 return subject
33 end
34
35 fun test_length do
36 var subject = new AttributesImpl
37
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
43 subject.clear
44 assert 0 == subject.length
45 # Clearing twice must not produce erroneous data.
46 subject.clear
47 assert 0 == subject.length
48 end
49
50 fun test_uri do
51 var subject = sample
52
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
59 subject.clear
60 assert subject.uri(0) == null
61 end
62
63 fun test_local_name do
64 var subject = sample
65
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
72 subject.clear
73 assert subject.local_name(0) == null
74 end
75
76 fun test_qname do
77 var subject = sample
78
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
85 subject.clear
86 assert subject.qname(0) == null
87 end
88
89 fun test_type_of do
90 var subject = sample
91
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
98 subject.clear
99 assert subject.type_of(0) == null
100 end
101
102 fun test_type_of_qname do
103 var subject = sample
104
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
110 subject.clear
111 assert subject.type_of("xml:lang") == null
112 end
113
114 fun test_value_of do
115 var subject = sample
116
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
123 subject.clear
124 assert subject.value_of(0) == null
125 end
126
127 fun test_value_of_qname do
128 var subject = sample
129
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
135 subject.clear
136 assert subject.value_of("xml:lang") == null
137 end
138
139 fun test_index_ns do
140 var subject = sample
141
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")
147 subject.clear
148 assert -1 == subject.index_ns("http://example.com/", "bar")
149 end
150
151 fun test_index_of do
152 var subject = sample
153
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")
159 subject.clear
160 assert -1 == subject.index_of("foo:bar")
161 end
162
163 fun test_type_ns do
164 var subject = sample
165
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
171 subject.clear
172 assert subject.type_ns("http://example.com/", "bar") == null
173 end
174
175 fun test_value_ns do
176 var subject = sample
177
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
183 subject.clear
184 assert subject.value_ns("http://example.com/", "bar") == null
185 end
186
187 fun test_attributes_set do
188 var subject = sample
189 var subject2 = new AttributesImpl
190
191 subject.attributes = subject2
192 assert subject.length == 0
193 subject2 = sample
194 subject.attributes = subject2
195 assert subject.length == 4
196 end
197
198 fun test_set do
199 var subject = sample
200
201 subject.set(1, "urn:is:not:often:used", "i-am_ME", "i-am_ME", "ID",
202 "noop")
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)
206 end
207
208 fun test_remove_at do
209 var subject = sample
210
211 subject.remove_at(1)
212 assert 3 == subject.length
213 assert "xml:lang" == subject.qname(1)
214 end
215
216 fun test_uri_set do
217 var subject = sample
218
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)
223 end
224
225 fun test_local_name_set do
226 var subject = sample
227
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)
232 end
233
234 fun test_qname_set do
235 var subject = sample
236
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)
241 end
242
243 fun test_type_of_set do
244 var subject = sample
245
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)
250 end
251
252 fun test_value_of_set do
253 var subject = sample
254
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)
259 end
260 end