manual: CI check with nitunit
[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
13
14 import sax::helpers::attributes_impl
15
16 class TestAttributesImpl
17 test
18
19 private fun sample: AttributesImpl do
20 var subject = new AttributesImpl
21
22 # The parser may include everything...
23 subject.add("http://example.com/", "bar", "foo:bar", "CDATA", "baz")
24 # ... or omit the `qname`...
25 subject.add("urn:is:not:often:used", "i-am_ME", "", "ID", "noop")
26 # ... or retrieve an attribute with an empty value (that *must* be kept intact)...
27 subject.add("http://www.w3.org/XML/1998/namespace", "lang", "xml:lang",
28 "NMTOKEN", "")
29 # ... or omit to process the namespace.
30 subject.add("", "", "xml:space", "NMTOKEN", "default")
31 return subject
32 end
33
34 fun test_length is test do
35 var subject = new AttributesImpl
36
37 assert 0 == subject.length
38 subject.add("http://example.com/", "bar", "foo:bar", "CDATA", "baz")
39 assert 1 == subject.length
40 subject.add("http://example.com/", "bar", "foo:bar", "CDATA", "baz")
41 assert 2 == subject.length
42 subject.clear
43 assert 0 == subject.length
44 # Clearing twice must not produce erroneous data.
45 subject.clear
46 assert 0 == subject.length
47 end
48
49 fun test_uri is test do
50 var subject = sample
51
52 assert "http://example.com/" == subject.uri(0)
53 assert "urn:is:not:often:used" == subject.uri(1)
54 assert "http://www.w3.org/XML/1998/namespace" == subject.uri(2)
55 assert "" == subject.uri(3)
56 assert subject.uri(4) == null
57 assert subject.uri(-1) == null
58 subject.clear
59 assert subject.uri(0) == null
60 end
61
62 fun test_local_name is test do
63 var subject = sample
64
65 assert "bar" == subject.local_name(0)
66 assert "i-am_ME" == subject.local_name(1)
67 assert "lang" == subject.local_name(2)
68 assert "" == subject.local_name(3)
69 assert subject.local_name(4) == null
70 assert subject.local_name(-1) == null
71 subject.clear
72 assert subject.local_name(0) == null
73 end
74
75 fun test_qname is test do
76 var subject = sample
77
78 assert "foo:bar" == subject.qname(0)
79 assert "" == subject.qname(1)
80 assert "xml:lang" == subject.qname(2)
81 assert "xml:space" == subject.qname(3)
82 assert subject.qname(4) == null
83 assert subject.qname(-1) == null
84 subject.clear
85 assert subject.qname(0) == null
86 end
87
88 fun test_type_of is test do
89 var subject = sample
90
91 assert "CDATA" == subject.type_of(0)
92 assert "ID" == subject.type_of(1)
93 assert "NMTOKEN" == subject.type_of(2)
94 assert "NMTOKEN" == subject.type_of(3)
95 assert subject.type_of(4) == null
96 assert subject.type_of(-1) == null
97 subject.clear
98 assert subject.type_of(0) == null
99 end
100
101 fun test_type_of_qname is test do
102 var subject = sample
103
104 assert "CDATA" == subject.type_of("foo:bar")
105 assert subject.type_of("") == null
106 assert "NMTOKEN" == subject.type_of("xml:lang")
107 assert "NMTOKEN" == subject.type_of("xml:space")
108 assert subject.type_of("bob") == null
109 subject.clear
110 assert subject.type_of("xml:lang") == null
111 end
112
113 fun test_value_of is test do
114 var subject = sample
115
116 assert "baz" == subject.value_of(0)
117 assert "noop" == subject.value_of(1)
118 assert "" == subject.value_of(2)
119 assert "default" == subject.value_of(3)
120 assert subject.value_of(4) == null
121 assert subject.value_of(-1) == null
122 subject.clear
123 assert subject.value_of(0) == null
124 end
125
126 fun test_value_of_qname is test do
127 var subject = sample
128
129 assert "baz" == subject.value_of("foo:bar")
130 assert subject.value_of("") == null
131 assert "" == subject.value_of("xml:lang")
132 assert "default" == subject.value_of("xml:space")
133 assert subject.value_of("bob") == null
134 subject.clear
135 assert subject.value_of("xml:lang") == null
136 end
137
138 fun test_index_ns is test do
139 var subject = sample
140
141 assert 0 == subject.index_ns("http://example.com/", "bar")
142 assert 1 == subject.index_ns("urn:is:not:often:used", "i-am_ME")
143 assert 2 == subject.index_ns("http://www.w3.org/XML/1998/namespace", "lang")
144 assert -1 == subject.index_ns("", "")
145 assert -1 == subject.index_ns("http://www.w3.org/XML/1998/namespace", "space")
146 subject.clear
147 assert -1 == subject.index_ns("http://example.com/", "bar")
148 end
149
150 fun test_index_of is test do
151 var subject = sample
152
153 assert 0 == subject.index_of("foo:bar")
154 assert -1 == subject.index_of("")
155 assert 2 == subject.index_of("xml:lang")
156 assert 3 == subject.index_of("xml:space")
157 assert -1 == subject.index_of("i-am_ME")
158 subject.clear
159 assert -1 == subject.index_of("foo:bar")
160 end
161
162 fun test_type_ns is test do
163 var subject = sample
164
165 assert "CDATA" == subject.type_ns("http://example.com/", "bar")
166 assert "ID" == subject.type_ns("urn:is:not:often:used", "i-am_ME")
167 assert "NMTOKEN" == subject.type_ns("http://www.w3.org/XML/1998/namespace", "lang")
168 assert subject.type_ns("", "") == null
169 assert subject.type_ns("http://www.w3.org/XML/1998/namespace", "space") == null
170 subject.clear
171 assert subject.type_ns("http://example.com/", "bar") == null
172 end
173
174 fun test_value_ns is test do
175 var subject = sample
176
177 assert "baz" == subject.value_ns("http://example.com/", "bar")
178 assert "noop" == subject.value_ns("urn:is:not:often:used", "i-am_ME")
179 assert "" == subject.value_ns("http://www.w3.org/XML/1998/namespace", "lang")
180 assert subject.value_ns("", "") == null
181 assert subject.value_ns("http://www.w3.org/XML/1998/namespace", "space") == null
182 subject.clear
183 assert subject.value_ns("http://example.com/", "bar") == null
184 end
185
186 fun test_attributes_set is test do
187 var subject = sample
188 var subject2 = new AttributesImpl
189
190 subject.attributes = subject2
191 assert subject.length == 0
192 subject2 = sample
193 subject.attributes = subject2
194 assert subject.length == 4
195 end
196
197 fun test_set is test do
198 var subject = sample
199
200 subject.set(1, "urn:is:not:often:used", "i-am_ME", "i-am_ME", "ID",
201 "noop")
202 assert "i-am_ME" == subject.qname(1)
203 subject.set(0, "http://example.com/", "bar", "foo:bar", "NMTOKENS", "baz")
204 assert "NMTOKENS" == subject.type_of(0)
205 end
206
207 fun test_remove_at is test do
208 var subject = sample
209
210 subject.remove_at(1)
211 assert 3 == subject.length
212 assert "xml:lang" == subject.qname(1)
213 end
214
215 fun test_uri_set is test do
216 var subject = sample
217
218 subject.uri(0) = "https://example.org/serious"
219 subject.uri(1) = "ftp://wat"
220 assert "ftp://wat" == subject.uri(1)
221 assert "https://example.org/serious" == subject.uri(0)
222 end
223
224 fun test_local_name_set is test do
225 var subject = sample
226
227 subject.local_name(0) = "trololol"
228 subject.local_name(1) = "ImYou42"
229 assert "trololol" == subject.local_name(0)
230 assert "ImYou42" == subject.local_name(1)
231 end
232
233 fun test_qname_set is test do
234 var subject = sample
235
236 subject.qname(0) = "go-to:bar"
237 subject.qname(1) = "yo:i-am_ME"
238 assert "go-to:bar" == subject.qname(0)
239 assert "yo:i-am_ME" == subject.qname(1)
240 end
241
242 fun test_type_of_set is test do
243 var subject = sample
244
245 subject.type_of(0) = "NMTOKENS"
246 subject.type_of(1) = "ENTITY"
247 assert "NMTOKENS" == subject.type_of(0)
248 assert "ENTITY" == subject.type_of(1)
249 end
250
251 fun test_value_of_set is test do
252 var subject = sample
253
254 subject.value_of(0) = "buz"
255 subject.value_of(1) = "bizzz"
256 assert "buz" == subject.value_of(0)
257 assert "bizzz" == subject.value_of(1)
258 end
259 end