1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
|
|
BEGIN { plan tests => 4 } |
5 |
|
|
|
6 |
|
|
require Message::DOM::DOMImplementation; |
7 |
wakaba |
1.3 |
use Message::Util::Error; |
8 |
wakaba |
1.1 |
|
9 |
|
|
my $dom = Message::DOM::DOMImplementation->____new; |
10 |
|
|
my $doc = $dom->create_document; |
11 |
|
|
|
12 |
|
|
## Constants |
13 |
|
|
my $constants = [ |
14 |
|
|
[ELEMENT_NODE => 1], |
15 |
|
|
[ATTRIBUTE_NODE => 2], |
16 |
|
|
[TEXT_NODE => 3], |
17 |
|
|
[CDATA_SECTION_NODE => 4], |
18 |
|
|
[ENTITY_REFERENCE_NODE => 5], |
19 |
|
|
[ENTITY_NODE => 6], |
20 |
|
|
[PROCESSING_INSTRUCTION_NODE => 7], |
21 |
|
|
[COMMENT_NODE => 8], |
22 |
|
|
[DOCUMENT_NODE => 9], |
23 |
|
|
[DOCUMENT_TYPE_NODE => 10], |
24 |
|
|
[DOCUMENT_FRAGMENT_NODE => 11], |
25 |
|
|
[NOTATION_NODE => 12], |
26 |
|
|
[ELEMENT_TYPE_DEFINITION_NODE => 81001], |
27 |
|
|
[ATTRIBUTE_DEFINITION_NODE => 81002], |
28 |
|
|
]; |
29 |
|
|
|
30 |
|
|
my $tests = { |
31 |
|
|
attr => { |
32 |
|
|
node => sub { |
33 |
|
|
my $attr = $doc->create_attribute ('a'); |
34 |
|
|
$attr->value ('b'); |
35 |
|
|
return $attr; |
36 |
|
|
}, |
37 |
|
|
attr_get => { |
38 |
wakaba |
1.2 |
first_child => undef, |
39 |
|
|
last_child => undef, |
40 |
|
|
local_name => 'a', |
41 |
|
|
manakai_local_name => 'a', |
42 |
|
|
namespace_uri => undef, |
43 |
|
|
next_sibling => undef, |
44 |
wakaba |
1.1 |
node_name => 'a', |
45 |
|
|
name => 'a', |
46 |
|
|
node_value => 'b', |
47 |
wakaba |
1.2 |
owner_document => $doc, |
48 |
|
|
parent_node => undef, |
49 |
|
|
prefix => undef, |
50 |
|
|
previous_sibling => undef, |
51 |
wakaba |
1.1 |
value => 'b', |
52 |
|
|
attributes => undef, |
53 |
|
|
}, |
54 |
|
|
}, |
55 |
|
|
attr_ns_default => { |
56 |
|
|
node => sub { |
57 |
|
|
my $attr = $doc->create_attribute_ns (undef, 'a'); |
58 |
|
|
$attr->value ('b'); |
59 |
|
|
return $attr; |
60 |
|
|
}, |
61 |
|
|
attr_get => { |
62 |
wakaba |
1.2 |
first_child => undef, |
63 |
|
|
last_child => undef, |
64 |
|
|
local_name => 'a', |
65 |
|
|
manakai_local_name => 'a', |
66 |
|
|
namespace_uri => undef, |
67 |
|
|
next_sibling => undef, |
68 |
wakaba |
1.1 |
node_name => 'a', |
69 |
|
|
name => 'a', |
70 |
|
|
node_value => 'b', |
71 |
wakaba |
1.2 |
owner_document => $doc, |
72 |
|
|
parent_node => undef, |
73 |
|
|
prefix => undef, |
74 |
wakaba |
1.1 |
value => 'b', |
75 |
|
|
attributes => undef, |
76 |
wakaba |
1.2 |
previous_sibling => undef, |
77 |
wakaba |
1.1 |
}, |
78 |
|
|
}, |
79 |
|
|
attr_ns_prefixed => { |
80 |
|
|
node => sub { |
81 |
|
|
my $attr = $doc->create_attribute_ns ('http://test/', 'a:b'); |
82 |
|
|
$attr->value ('c'); |
83 |
|
|
return $attr; |
84 |
|
|
}, |
85 |
|
|
attr_get => { |
86 |
wakaba |
1.2 |
first_child => undef, |
87 |
|
|
last_child => undef, |
88 |
|
|
local_name => 'b', |
89 |
|
|
manakai_local_name => 'b', |
90 |
|
|
namespace_uri => 'http://test/', |
91 |
|
|
next_sibling => undef, |
92 |
wakaba |
1.1 |
node_name => 'a:b', |
93 |
|
|
name => 'a:b', |
94 |
|
|
node_value => 'c', |
95 |
wakaba |
1.2 |
owner_document => $doc, |
96 |
|
|
parent_node => undef, |
97 |
|
|
prefix => 'a', |
98 |
wakaba |
1.1 |
value => 'c', |
99 |
|
|
attributes => undef, |
100 |
wakaba |
1.2 |
previous_sibling => undef, |
101 |
wakaba |
1.1 |
}, |
102 |
|
|
}, |
103 |
|
|
cdatasection => { |
104 |
|
|
node => sub { return $doc->create_cdata_section ('cdatadata') }, |
105 |
|
|
attr_get => { |
106 |
wakaba |
1.2 |
first_child => undef, |
107 |
|
|
last_child => undef, |
108 |
|
|
local_name => undef, |
109 |
|
|
manakai_local_name => undef, |
110 |
|
|
namespace_uri => undef, |
111 |
|
|
next_sibling => undef, |
112 |
wakaba |
1.1 |
node_name => '#cdata-section', |
113 |
|
|
node_value => 'cdatadata', |
114 |
wakaba |
1.2 |
owner_document => $doc, |
115 |
|
|
parent_node => undef, |
116 |
|
|
prefix => undef, |
117 |
wakaba |
1.1 |
data => 'cdatadata', |
118 |
|
|
attributes => undef, |
119 |
wakaba |
1.2 |
previous_sibling => undef, |
120 |
wakaba |
1.1 |
}, |
121 |
|
|
}, |
122 |
|
|
cdatasectionmde => { |
123 |
|
|
node => sub { return $doc->create_cdata_section ('cdata]]>data') }, |
124 |
|
|
attr_get => { |
125 |
wakaba |
1.2 |
first_child => undef, |
126 |
|
|
last_child => undef, |
127 |
|
|
local_name => undef, |
128 |
|
|
manakai_local_name => undef, |
129 |
|
|
namespace_uri => undef, |
130 |
|
|
next_sibling => undef, |
131 |
wakaba |
1.1 |
node_name => '#cdata-section', |
132 |
|
|
node_value => 'cdata]]>data', |
133 |
wakaba |
1.2 |
owner_document => $doc, |
134 |
|
|
parent_node => undef, |
135 |
|
|
prefix => undef, |
136 |
wakaba |
1.1 |
data => 'cdata]]>data', |
137 |
|
|
attributes => undef, |
138 |
wakaba |
1.2 |
previous_sibling => undef, |
139 |
wakaba |
1.1 |
}, |
140 |
|
|
}, |
141 |
|
|
comment => { |
142 |
|
|
node => sub { return $doc->create_comment ('commentdata') }, |
143 |
|
|
attr_get => { |
144 |
wakaba |
1.2 |
first_child => undef, |
145 |
|
|
last_child => undef, |
146 |
|
|
local_name => undef, |
147 |
|
|
manakai_local_name => undef, |
148 |
|
|
namespace_uri => undef, |
149 |
|
|
next_sibling => undef, |
150 |
wakaba |
1.1 |
node_name => '#comment', |
151 |
|
|
node_value => 'commentdata', |
152 |
wakaba |
1.2 |
owner_document => $doc, |
153 |
|
|
parent_node => undef, |
154 |
|
|
prefix => undef, |
155 |
wakaba |
1.1 |
data => 'commentdata', |
156 |
|
|
attributes => undef, |
157 |
wakaba |
1.2 |
previous_sibling => undef, |
158 |
wakaba |
1.1 |
}, |
159 |
|
|
}, |
160 |
|
|
commentcom1 => { |
161 |
|
|
node => sub { return $doc->create_comment ('comment--data') }, |
162 |
|
|
attr_get => { |
163 |
wakaba |
1.2 |
first_child => undef, |
164 |
|
|
last_child => undef, |
165 |
|
|
local_name => undef, |
166 |
|
|
manakai_local_name => undef, |
167 |
|
|
namespace_uri => undef, |
168 |
|
|
next_sibling => undef, |
169 |
wakaba |
1.1 |
node_name => '#comment', |
170 |
|
|
node_value => 'comment--data', |
171 |
wakaba |
1.2 |
owner_document => $doc, |
172 |
|
|
parent_node => undef, |
173 |
|
|
prefix => undef, |
174 |
wakaba |
1.1 |
data => 'comment--data', |
175 |
|
|
attributes => undef, |
176 |
wakaba |
1.2 |
previous_sibling => undef, |
177 |
wakaba |
1.1 |
}, |
178 |
|
|
}, |
179 |
|
|
commentcom2 => { |
180 |
|
|
node => sub { return $doc->create_comment ('commentdata-') }, |
181 |
|
|
attr_get => { |
182 |
wakaba |
1.2 |
first_child => undef, |
183 |
|
|
last_child => undef, |
184 |
|
|
local_name => undef, |
185 |
|
|
manakai_local_name => undef, |
186 |
|
|
namespace_uri => undef, |
187 |
|
|
next_sibling => undef, |
188 |
wakaba |
1.1 |
node_name => '#comment', |
189 |
|
|
node_value => 'commentdata-', |
190 |
wakaba |
1.2 |
owner_document => $doc, |
191 |
|
|
parent_node => undef, |
192 |
|
|
prefix => undef, |
193 |
wakaba |
1.1 |
data => 'commentdata-', |
194 |
|
|
attributes => undef, |
195 |
wakaba |
1.2 |
previous_sibling => undef, |
196 |
wakaba |
1.1 |
}, |
197 |
|
|
}, |
198 |
|
|
document => { |
199 |
|
|
node => sub { return $doc }, |
200 |
|
|
attr_get => { |
201 |
|
|
attributes => undef, |
202 |
wakaba |
1.2 |
first_child => undef, |
203 |
|
|
implementation => $dom, |
204 |
|
|
last_child => undef, |
205 |
wakaba |
1.1 |
local_name => undef, |
206 |
wakaba |
1.2 |
manakai_local_name => undef, |
207 |
wakaba |
1.1 |
namespace_uri => undef, |
208 |
wakaba |
1.2 |
next_sibling => undef, |
209 |
wakaba |
1.1 |
node_name => '#document', |
210 |
|
|
node_value => undef, |
211 |
wakaba |
1.2 |
owner_document => undef, |
212 |
wakaba |
1.1 |
parent_node => undef, |
213 |
|
|
prefix => undef, |
214 |
wakaba |
1.2 |
previous_sibling => undef, |
215 |
wakaba |
1.1 |
}, |
216 |
|
|
}, |
217 |
|
|
document_fragment => { |
218 |
|
|
node => sub { return $doc->create_document_fragment }, |
219 |
|
|
attr_get => { |
220 |
|
|
attributes => undef, |
221 |
wakaba |
1.2 |
first_child => undef, |
222 |
|
|
last_child => undef, |
223 |
|
|
local_name => undef, |
224 |
|
|
manakai_local_name => undef, |
225 |
|
|
namespace_uri => undef, |
226 |
|
|
next_sibling => undef, |
227 |
wakaba |
1.1 |
node_name => '#document-fragment', |
228 |
|
|
node_value => undef, |
229 |
wakaba |
1.2 |
owner_document => $doc, |
230 |
|
|
parent_node => undef, |
231 |
|
|
prefix => undef, |
232 |
|
|
previous_sibling => undef, |
233 |
wakaba |
1.1 |
}, |
234 |
|
|
}, |
235 |
|
|
document_type => { |
236 |
|
|
node => sub { return $doc->implementation->create_document_type ('n') }, |
237 |
|
|
attr_get => { |
238 |
|
|
attributes => undef, |
239 |
wakaba |
1.2 |
first_child => undef, |
240 |
|
|
implementation => $dom, |
241 |
|
|
last_child => undef, |
242 |
|
|
local_name => undef, |
243 |
|
|
manakai_local_name => undef, |
244 |
|
|
namespace_uri => undef, |
245 |
|
|
next_sibling => undef, |
246 |
wakaba |
1.1 |
node_name => 'n', |
247 |
|
|
node_value => undef, |
248 |
wakaba |
1.2 |
owner_document => undef, |
249 |
|
|
parent_node => undef, |
250 |
|
|
prefix => undef, |
251 |
|
|
previous_sibling => undef, |
252 |
wakaba |
1.1 |
}, |
253 |
|
|
}, |
254 |
|
|
document_type_definition => { |
255 |
|
|
node => sub { return $doc->create_document_type_definition ('n') }, |
256 |
|
|
attr_get => { |
257 |
|
|
attributes => undef, |
258 |
wakaba |
1.2 |
first_child => undef, |
259 |
|
|
implementation => $dom, |
260 |
|
|
last_child => undef, |
261 |
|
|
local_name => undef, |
262 |
|
|
manakai_local_name => undef, |
263 |
|
|
namespace_uri => undef, |
264 |
|
|
next_sibling => undef, |
265 |
wakaba |
1.1 |
node_name => 'n', |
266 |
|
|
node_value => undef, |
267 |
wakaba |
1.2 |
owner_document => $doc, |
268 |
|
|
parent_node => undef, |
269 |
|
|
prefix => undef, |
270 |
|
|
previous_sibling => undef, |
271 |
wakaba |
1.1 |
}, |
272 |
|
|
}, |
273 |
|
|
element => { |
274 |
|
|
node => sub { return $doc->create_element ('e') }, |
275 |
|
|
attr_get => { |
276 |
|
|
## TODO: attributes => |
277 |
wakaba |
1.2 |
first_child => undef, |
278 |
|
|
last_child => undef, |
279 |
|
|
local_name => 'e', |
280 |
|
|
manakai_local_name => 'e', |
281 |
|
|
namespace_uri => undef, |
282 |
|
|
next_sibling => undef, |
283 |
wakaba |
1.1 |
node_name => 'e', |
284 |
|
|
node_value => undef, |
285 |
wakaba |
1.2 |
owner_document => $doc, |
286 |
|
|
parent_node => undef, |
287 |
|
|
prefix => undef, |
288 |
|
|
previous_sibling => undef, |
289 |
wakaba |
1.1 |
}, |
290 |
|
|
}, |
291 |
|
|
element_ns_default => { |
292 |
|
|
node => sub { return $doc->create_element_ns ('http://test/', 'f') }, |
293 |
|
|
attr_get => { |
294 |
|
|
## TODO: attributes => |
295 |
wakaba |
1.2 |
first_child => undef, |
296 |
|
|
last_child => undef, |
297 |
|
|
local_name => 'f', |
298 |
|
|
manakai_local_name => 'f', |
299 |
|
|
namespace_uri => 'http://test/', |
300 |
|
|
next_sibling => undef, |
301 |
wakaba |
1.1 |
node_name => 'f', |
302 |
|
|
node_value => undef, |
303 |
wakaba |
1.2 |
owner_document => $doc, |
304 |
|
|
parent_node => undef, |
305 |
|
|
prefix => undef, |
306 |
|
|
previous_sibling => undef, |
307 |
wakaba |
1.1 |
}, |
308 |
|
|
}, |
309 |
|
|
element_ns_prefiexed => { |
310 |
|
|
node => sub { return $doc->create_element_ns ('http://test/', 'e:f') }, |
311 |
|
|
attr_get => { |
312 |
|
|
## TODO: attributes => |
313 |
wakaba |
1.2 |
first_child => undef, |
314 |
|
|
last_child => undef, |
315 |
|
|
local_name => 'f', |
316 |
|
|
manakai_local_name => 'f', |
317 |
|
|
namespace_uri => 'http://test/', |
318 |
|
|
next_sibling => undef, |
319 |
wakaba |
1.1 |
node_name => 'e:f', |
320 |
|
|
node_value => undef, |
321 |
wakaba |
1.2 |
owner_document => $doc, |
322 |
|
|
parent_node => undef, |
323 |
|
|
prefix => 'e', |
324 |
|
|
previous_sibling => undef, |
325 |
wakaba |
1.1 |
}, |
326 |
|
|
}, |
327 |
|
|
entity => { |
328 |
|
|
node => sub { return $doc->create_general_entity ('e') }, |
329 |
|
|
attr_get => { |
330 |
|
|
attributes => undef, |
331 |
wakaba |
1.2 |
first_child => undef, |
332 |
|
|
last_child => undef, |
333 |
|
|
next_sibling => undef, |
334 |
wakaba |
1.1 |
node_name => 'e', |
335 |
|
|
node_value => undef, |
336 |
wakaba |
1.2 |
owner_document => $doc, |
337 |
|
|
parent_node => undef, |
338 |
|
|
previous_sibling => undef, |
339 |
wakaba |
1.1 |
}, |
340 |
|
|
}, |
341 |
|
|
entity_reference => { |
342 |
|
|
node => sub { return $doc->create_entity_reference ('e') }, |
343 |
|
|
attr_get => { |
344 |
|
|
attributes => undef, |
345 |
wakaba |
1.2 |
first_child => undef, |
346 |
|
|
last_child => undef, |
347 |
|
|
local_name => undef, |
348 |
|
|
manakai_local_name => undef, |
349 |
|
|
namespace_uri => undef, |
350 |
|
|
next_sibling => undef, |
351 |
wakaba |
1.1 |
node_name => 'e', |
352 |
|
|
node_value => undef, |
353 |
wakaba |
1.2 |
owner_document => $doc, |
354 |
|
|
parent_node => undef, |
355 |
|
|
prefix => undef, |
356 |
|
|
previous_sibling => undef, |
357 |
wakaba |
1.1 |
}, |
358 |
|
|
}, |
359 |
|
|
notation => { |
360 |
|
|
node => sub { return $doc->create_notation ('e') }, |
361 |
|
|
attr_get => { |
362 |
|
|
attributes => undef, |
363 |
wakaba |
1.2 |
first_child => undef, |
364 |
|
|
last_child => undef, |
365 |
|
|
local_name => undef, |
366 |
|
|
manakai_local_name => undef, |
367 |
|
|
namespace_uri => undef, |
368 |
|
|
next_sibling => undef, |
369 |
wakaba |
1.1 |
node_name => 'e', |
370 |
|
|
node_value => undef, |
371 |
wakaba |
1.2 |
owner_document => $doc, |
372 |
|
|
parent_node => undef, |
373 |
|
|
prefix => undef, |
374 |
|
|
previous_sibling => undef, |
375 |
wakaba |
1.1 |
}, |
376 |
|
|
}, |
377 |
|
|
processing_instruction => { |
378 |
|
|
node => sub { return $doc->create_processing_instruction ('t', 'd') }, |
379 |
|
|
attr_get => { |
380 |
|
|
attributes => undef, |
381 |
wakaba |
1.2 |
first_child => undef, |
382 |
|
|
last_child => undef, |
383 |
|
|
local_name => undef, |
384 |
|
|
manakai_local_name => undef, |
385 |
|
|
namespace_uri => undef, |
386 |
|
|
next_sibling => undef, |
387 |
wakaba |
1.1 |
node_name => 't', |
388 |
|
|
node_value => 'd', |
389 |
wakaba |
1.2 |
owner_document => $doc, |
390 |
|
|
parent_node => undef, |
391 |
|
|
prefix => undef, |
392 |
|
|
previous_sibling => undef, |
393 |
wakaba |
1.1 |
}, |
394 |
|
|
}, |
395 |
|
|
text => { |
396 |
|
|
node => sub { return $doc->create_text_node ('textdata') }, |
397 |
|
|
attr_get => { |
398 |
|
|
attributes => undef, |
399 |
wakaba |
1.2 |
first_child => undef, |
400 |
|
|
last_child => undef, |
401 |
|
|
local_name => undef, |
402 |
|
|
manakai_local_name => undef, |
403 |
|
|
namespace_uri => undef, |
404 |
|
|
next_sibling => undef, |
405 |
wakaba |
1.1 |
node_name => '#text', |
406 |
|
|
node_value => 'textdata', |
407 |
wakaba |
1.2 |
owner_document => $doc, |
408 |
|
|
parent_node => undef, |
409 |
|
|
prefix => undef, |
410 |
|
|
previous_sibling => undef, |
411 |
wakaba |
1.1 |
}, |
412 |
|
|
}, |
413 |
|
|
element_type_definition => { |
414 |
|
|
node => sub { return $doc->create_element_type_definition ('e') }, |
415 |
|
|
attr_get => { |
416 |
|
|
attributes => undef, |
417 |
wakaba |
1.2 |
first_child => undef, |
418 |
|
|
last_child => undef, |
419 |
|
|
local_name => undef, |
420 |
|
|
manakai_local_name => undef, |
421 |
|
|
namespace_uri => undef, |
422 |
|
|
next_sibling => undef, |
423 |
wakaba |
1.1 |
node_name => 'e', |
424 |
|
|
node_value => undef, |
425 |
wakaba |
1.2 |
owner_document => $doc, |
426 |
|
|
parent_node => undef, |
427 |
|
|
prefix => undef, |
428 |
|
|
previous_sibling => undef, |
429 |
wakaba |
1.1 |
}, |
430 |
|
|
}, |
431 |
|
|
attribute_definition => { |
432 |
|
|
node => sub { return $doc->create_attribute_definition ('e') }, |
433 |
|
|
attr_get => { |
434 |
|
|
attributes => undef, |
435 |
wakaba |
1.2 |
first_child => undef, |
436 |
|
|
last_child => undef, |
437 |
|
|
local_name => undef, |
438 |
|
|
manakai_local_name => undef, |
439 |
|
|
namespace_uri => undef, |
440 |
|
|
next_sibling => undef, |
441 |
wakaba |
1.1 |
node_name => 'e', |
442 |
|
|
node_value => undef, |
443 |
wakaba |
1.2 |
owner_document => $doc, |
444 |
|
|
parent_node => undef, |
445 |
|
|
prefix => undef, |
446 |
|
|
previous_sibling => undef, |
447 |
wakaba |
1.1 |
}, |
448 |
|
|
}, |
449 |
|
|
}; |
450 |
|
|
|
451 |
|
|
for my $test_id (sort {$a cmp $b} keys %$tests) { |
452 |
|
|
my $test_def = $tests->{$test_id}; |
453 |
|
|
my $node = $test_def->{node}->(); |
454 |
|
|
|
455 |
|
|
for (@$constants) { |
456 |
|
|
my $const_name = $_->[0]; |
457 |
|
|
ok $node->can ($const_name) ? 1 : 0, 1, "$test_id->can ($const_name)"; |
458 |
|
|
ok $node->$const_name, $_->[1], "$test_id.$const_name"; |
459 |
|
|
} |
460 |
|
|
|
461 |
|
|
for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get}}) { |
462 |
|
|
my $expected = $test_def->{attr_get}->{$attr_name}; |
463 |
|
|
ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)"; |
464 |
|
|
my $actual = $node->$attr_name; |
465 |
|
|
ok $actual, $expected, "$test_id.$attr_name.get"; |
466 |
|
|
} |
467 |
|
|
} |
468 |
|
|
|
469 |
wakaba |
1.2 |
## Child node accessors' tests |
470 |
|
|
for my $parent (create_parent_nodes ()) { |
471 |
|
|
my $node1; |
472 |
|
|
my $node2; |
473 |
|
|
my $node3; |
474 |
|
|
if ($parent->node_type == $parent->DOCUMENT_TYPE_NODE) { |
475 |
|
|
$node1 = $doc->create_processing_instruction ('pi1', 'data1'); |
476 |
|
|
$node2 = $doc->create_processing_instruction ('pi2', 'data2'); |
477 |
|
|
$node3 = $doc->create_processing_instruction ('pi3', 'data3'); |
478 |
|
|
} elsif ($parent->node_type == $parent->DOCUMENT_NODE) { |
479 |
|
|
$node1 = $doc->create_comment ('comment1'); |
480 |
|
|
$node2 = $doc->create_comment ('comment2'); |
481 |
|
|
$node3 = $doc->create_comment ('comment3'); |
482 |
|
|
} else { |
483 |
|
|
$node1 = $doc->create_text_node ('text1'); |
484 |
|
|
$node2 = $doc->create_text_node ('text2'); |
485 |
|
|
$node3 = $doc->create_text_node ('text3'); |
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
$parent->append_child ($node1); |
489 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [1]"; |
490 |
|
|
ok $parent->last_child, $node1, $parent->node_name."->last_child [1]"; |
491 |
|
|
ok $node1->next_sibling, undef, $parent->node_name."->next_sibling [1]"; |
492 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."->previous_sibling [1]"; |
493 |
|
|
|
494 |
|
|
$parent->append_child ($node2); |
495 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [2]"; |
496 |
|
|
ok $parent->last_child, $node2, $parent->node_name."->last_child [2]"; |
497 |
|
|
ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [2]"; |
498 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [2]"; |
499 |
|
|
ok $node2->next_sibling, undef, $parent->node_name."2->next_sibling [2]"; |
500 |
|
|
ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [2]"; |
501 |
|
|
|
502 |
|
|
$parent->append_child ($node3); |
503 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [3]"; |
504 |
|
|
ok $parent->last_child, $node3, $parent->node_name."->last_child [3]"; |
505 |
|
|
ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [3]"; |
506 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [3]"; |
507 |
|
|
ok $node2->next_sibling, $node3, $parent->node_name."2->next_sibling [3]"; |
508 |
|
|
ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [3]"; |
509 |
|
|
ok $node3->next_sibling, undef, $parent->node_name."3->next_sibling [3]"; |
510 |
|
|
ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]"; |
511 |
|
|
} |
512 |
|
|
|
513 |
wakaba |
1.3 |
## |prefix| setter |
514 |
|
|
for my $node (create_nodes ()) { |
515 |
|
|
$node->manakai_set_read_only (0); |
516 |
|
|
|
517 |
|
|
$node->prefix ('non-null'); |
518 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
519 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
520 |
|
|
ok $node->prefix, 'non-null', $node->node_name . '->prefix (non-null)'; |
521 |
|
|
} else { |
522 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (non-null)'; |
523 |
|
|
} |
524 |
|
|
|
525 |
|
|
$node->prefix (undef); |
526 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
527 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
528 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
529 |
|
|
} else { |
530 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
531 |
|
|
} |
532 |
|
|
|
533 |
|
|
$node->manakai_set_read_only (1); |
534 |
|
|
my $err_type; |
535 |
|
|
try { |
536 |
|
|
$node->prefix ('non-null'); |
537 |
|
|
} catch Message::IF::DOMException with { |
538 |
|
|
my $err = shift; |
539 |
|
|
$err_type = $err->type; |
540 |
|
|
}; |
541 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
542 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
543 |
|
|
ok $err_type, 'NO_MODIFICATION_ALLOWED_ERR', |
544 |
|
|
$node->node_name . '->prefix exception (read-only)'; |
545 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
546 |
|
|
} else { |
547 |
|
|
ok $err_type, undef, $node->node_name . '->prefix exception (read-only)'; |
548 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
549 |
|
|
} |
550 |
|
|
} |
551 |
|
|
|
552 |
|
|
## |text_content| |
553 |
|
|
{ |
554 |
|
|
my $doc2 = $doc->implementation->create_document; |
555 |
|
|
$doc2->dom_config->set_parameter |
556 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1); |
557 |
|
|
for my $node ( |
558 |
|
|
$doc2, |
559 |
|
|
$doc->create_document_type_definition ('dt1'), |
560 |
|
|
$doc->implementation->create_document_type ('doctype1'), |
561 |
|
|
$doc->create_notation ('notation1'), |
562 |
|
|
$doc->create_element_type_definition ('et1'), |
563 |
|
|
) { |
564 |
|
|
ok $node->can ('text_content') ? 1 : 0, 1, |
565 |
|
|
$node->node_name . '->can text_content'; |
566 |
|
|
|
567 |
|
|
ok $node->text_content, undef, $node->node_name . '->text_content'; |
568 |
|
|
|
569 |
|
|
$node->manakai_set_read_only (0); |
570 |
|
|
$node->text_content ('new-text-content'); |
571 |
|
|
ok $node->text_content, undef, $node->node_name . '->text_content set'; |
572 |
|
|
|
573 |
|
|
$node->manakai_set_read_only (1); |
574 |
|
|
$node->text_content ('new-text-content'); |
575 |
|
|
ok $node->text_content, undef, |
576 |
|
|
$node->node_name . '->text_content set (read-only)'; |
577 |
|
|
} |
578 |
|
|
|
579 |
|
|
$doc2->dom_config->set_parameter |
580 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0); |
581 |
|
|
for my $node ( |
582 |
|
|
$doc2, |
583 |
|
|
$doc->create_attribute ('attr1'), |
584 |
|
|
$doc->create_attribute_definition ('at1'), |
585 |
|
|
$doc->create_element ('element1'), |
586 |
|
|
$doc->create_general_entity ('entity1'), |
587 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
588 |
|
|
$doc->create_document_fragment, |
589 |
|
|
) { |
590 |
|
|
ok $node->can ('text_content') ? 1 : 0, 1, |
591 |
|
|
$node->node_name . '->can text_content'; |
592 |
|
|
|
593 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content'; |
594 |
|
|
|
595 |
|
|
$node->manakai_set_read_only (0); |
596 |
|
|
$node->text_content ('text1'); |
597 |
|
|
ok $node->text_content, 'text1', $node->node_name . '->text_content set'; |
598 |
|
|
ok 0+@{$node->child_nodes}, 1, |
599 |
|
|
$node->node_name . '->text_content set child_nodes length'; |
600 |
|
|
|
601 |
|
|
$node->text_content (''); |
602 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
603 |
|
|
ok 0+@{$node->child_nodes}, 0, |
604 |
|
|
$node->node_name . '->text_content set empty child_nodes length'; |
605 |
|
|
|
606 |
|
|
$node->text_content ('text2'); |
607 |
|
|
$node->text_content (''); |
608 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
609 |
|
|
ok 0+@{$node->child_nodes}, 0, |
610 |
|
|
$node->node_name . '->text_content set empty child_nodes length'; |
611 |
|
|
|
612 |
|
|
$node->text_content ('text3'); |
613 |
|
|
$node->manakai_set_read_only (1); |
614 |
|
|
try { |
615 |
|
|
$node->text_content ('new-text-content'); |
616 |
|
|
ok undef, 'NO_MODIFICATION_ALLOWED_ERR', |
617 |
|
|
$node->node_name . '->text_content set (read-only)'; |
618 |
|
|
} catch Message::IF::DOMException with { |
619 |
|
|
my $err = shift; |
620 |
|
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
621 |
|
|
$node->node_name . '->text_content set (read-only)'; |
622 |
|
|
}; |
623 |
|
|
ok $node->text_content, 'text3', |
624 |
|
|
$node->node_name . '->text_content set (read-only) text_content'; |
625 |
|
|
} |
626 |
|
|
|
627 |
|
|
|
628 |
|
|
for (0..2) { |
629 |
|
|
my $el; |
630 |
|
|
my $ce; |
631 |
|
|
|
632 |
|
|
[ |
633 |
|
|
sub { |
634 |
|
|
$el = $doc->create_element ('nestingElement'); |
635 |
|
|
$ce = $doc->create_element ('el2'); |
636 |
|
|
}, |
637 |
|
|
sub { |
638 |
|
|
$el = $doc->create_element ('elementWithEntityReference'); |
639 |
|
|
$ce = $doc->create_entity_reference ('ent'); |
640 |
|
|
$ce->manakai_set_read_only (0, 1); |
641 |
|
|
}, |
642 |
|
|
sub { |
643 |
|
|
$el = $doc->create_general_entity ('generalEntityWithChild'); |
644 |
|
|
$ce = $doc->create_element ('el'); |
645 |
|
|
$el->manakai_set_read_only (0, 1); |
646 |
|
|
}, |
647 |
|
|
]->[$_]->(); |
648 |
|
|
$el->append_child ($ce); |
649 |
|
|
|
650 |
|
|
ok $el->text_content, '', $el->node_name . '->text_content [1]'; |
651 |
|
|
|
652 |
|
|
$ce->text_content ('gc'); |
653 |
|
|
ok $el->text_content, 'gc', $el->node_name . '->text_content [2]'; |
654 |
|
|
|
655 |
|
|
$el->manakai_append_text ('cc'); |
656 |
|
|
ok $el->text_content, 'gccc', $el->node_name . '->text_content [3]'; |
657 |
|
|
|
658 |
|
|
$el->text_content ('nc'); |
659 |
|
|
ok $el->text_content, 'nc', $el->node_name . '->text_content [4]'; |
660 |
|
|
ok 0+@{$el->child_nodes}, 1, |
661 |
|
|
$el->node_name . '->text_content child_nodes length [4]'; |
662 |
|
|
ok $ce->parent_node, undef, |
663 |
|
|
$el->node_name . '->text_content old_child parent_node [4]'; |
664 |
|
|
} |
665 |
|
|
} |
666 |
|
|
|
667 |
wakaba |
1.2 |
## TODO: parent_node tests, as with append_child tests |
668 |
|
|
|
669 |
wakaba |
1.3 |
## TODO: text_content tests for CharacterData and PI |
670 |
|
|
|
671 |
|
|
## TODO: manakai_read_only tests |
672 |
|
|
|
673 |
wakaba |
1.2 |
sub create_nodes () { |
674 |
|
|
( |
675 |
|
|
$doc->create_attribute ('attr1'), |
676 |
|
|
$doc->create_attribute_definition ('at1'), |
677 |
|
|
$doc->create_cdata_section ('cdata1'), |
678 |
|
|
$doc->create_comment ('comment1'), |
679 |
|
|
$doc->create_element ('element1'), |
680 |
|
|
$doc->create_element_type_definition ('et1'), |
681 |
|
|
$doc->create_general_entity ('entity1'), |
682 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
683 |
|
|
$doc->implementation->create_document, |
684 |
|
|
$doc->create_document_fragment, |
685 |
|
|
$doc->create_document_type_definition ('dt1'), |
686 |
|
|
$doc->create_notation ('notation1'), |
687 |
|
|
$doc->create_processing_instruction ('pi1', 'pi1data'), |
688 |
|
|
$doc->create_text_node ('text1'), |
689 |
|
|
); |
690 |
|
|
} # create_nodes |
691 |
|
|
|
692 |
|
|
sub create_parent_nodes () { |
693 |
|
|
( |
694 |
|
|
$doc->create_attribute ('attr1'), |
695 |
|
|
$doc->create_attribute_definition ('at1'), |
696 |
|
|
$doc->create_element ('element1'), |
697 |
|
|
$doc->create_general_entity ('entity1'), |
698 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
699 |
|
|
$doc->implementation->create_document, |
700 |
|
|
$doc->create_document_fragment, |
701 |
|
|
$doc->create_document_type_definition ('dt1'), |
702 |
|
|
); |
703 |
|
|
} # create_parent_nodes |
704 |
|
|
|
705 |
wakaba |
1.1 |
## License: Public Domain. |
706 |
wakaba |
1.3 |
## $Date: 2007/06/15 16:12:28 $ |