/[suikacvs]/messaging/manakai/t/DOM-Node.t
Suika

Contents of /messaging/manakai/t/DOM-Node.t

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (hide annotations) (download) (as text)
Sun Jul 8 13:04:39 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.12: +7 -2 lines
File MIME type: application/x-troff
++ manakai/t/ChangeLog	8 Jul 2007 13:03:58 -0000
	* DOM-Element.t: Tests for |attributes| are added.

	* DOM-Entity.t: Tests for |is_externally_declared|
	and |input_encoding| are added.

	* DOM-Node.t: Test data for |tag_name| and
	|get_feature| are added.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	8 Jul 2007 13:02:01 -0000
	* Attr.pm (value, node_value): Now it is defined
	as |text_content| itself.

	* AttributeDefinition.pm, ElementTypeDefinition.pm,
	Node.pm (AUTOLOAD): Unused block is removed.

	* CDATASection.pm, DocumentFragment.pm (AUTOLOAD): Removed.  Unused.

	* DocumentType.pm (internal_subset): Implemented.

	* Entity.pm (is_externally_declared, input_encoding,
	xml_version): Implemented.

	* ProcessingInstruction.pm (target, data): Implemented.

2007-07-08  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3     use Test;
4 wakaba 1.13 BEGIN { plan tests => 4429 }
5 wakaba 1.1
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 wakaba 1.4
13     sub create_nodes () {
14     (
15     $doc->create_attribute ('attr1'),
16     $doc->create_attribute_definition ('at1'),
17     $doc->create_cdata_section ('cdata1'),
18     $doc->create_comment ('comment1'),
19     $doc->create_element ('element1'),
20     $doc->create_element_type_definition ('et1'),
21     $doc->create_general_entity ('entity1'),
22     $doc->create_entity_reference ('entity-reference1'),
23     $doc->implementation->create_document,
24     $doc->create_document_fragment,
25     $doc->create_document_type_definition ('dt1'),
26     $doc->create_notation ('notation1'),
27     $doc->create_processing_instruction ('pi1', 'pi1data'),
28     $doc->create_text_node ('text1'),
29     );
30     } # create_nodes
31    
32     sub create_parent_nodes () {
33     (
34     $doc->create_attribute ('attr1'),
35     $doc->create_attribute_definition ('at1'),
36     $doc->create_element ('element1'),
37     $doc->create_general_entity ('entity1'),
38     $doc->create_entity_reference ('entity-reference1'),
39     $doc->implementation->create_document,
40     $doc->create_document_fragment,
41     $doc->create_document_type_definition ('dt1'),
42     );
43     } # create_parent_nodes
44    
45 wakaba 1.1 ## Constants
46     my $constants = [
47     [ELEMENT_NODE => 1],
48     [ATTRIBUTE_NODE => 2],
49     [TEXT_NODE => 3],
50     [CDATA_SECTION_NODE => 4],
51     [ENTITY_REFERENCE_NODE => 5],
52     [ENTITY_NODE => 6],
53     [PROCESSING_INSTRUCTION_NODE => 7],
54     [COMMENT_NODE => 8],
55     [DOCUMENT_NODE => 9],
56     [DOCUMENT_TYPE_NODE => 10],
57     [DOCUMENT_FRAGMENT_NODE => 11],
58     [NOTATION_NODE => 12],
59     [ELEMENT_TYPE_DEFINITION_NODE => 81001],
60     [ATTRIBUTE_DEFINITION_NODE => 81002],
61 wakaba 1.6
62     [DOCUMENT_POSITION_DISCONNECTED => 0x01],
63     [DOCUMENT_POSITION_PRECEDING => 0x02],
64     [DOCUMENT_POSITION_FOLLOWING => 0x04],
65     [DOCUMENT_POSITION_CONTAINS => 0x08],
66     [DOCUMENT_POSITION_CONTAINED_BY => 0x10],
67     [DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC => 0x20],
68 wakaba 1.1 ];
69    
70     my $tests = {
71 wakaba 1.4 attr1 => {
72     node => sub { return $doc->create_attribute ('a') },
73     attr_get => {
74     manakai_attribute_type => 0,
75     base_uri => undef,
76 wakaba 1.6 manakai_expanded_uri => 'a',
77 wakaba 1.4 first_child => undef,
78     last_child => undef,
79     local_name => 'a',
80     manakai_local_name => 'a',
81     namespace_uri => undef,
82     next_sibling => undef,
83     node_name => 'a',
84 wakaba 1.7 node_type => 2,
85 wakaba 1.4 name => 'a',
86     node_value => '',
87     owner_document => $doc,
88     parent_node => undef,
89     prefix => undef,
90     previous_sibling => undef,
91     value => '',
92     attributes => undef,
93     },
94     attr_get_bool => {
95 wakaba 1.6 has_attributes => 0,
96     has_child_nodes => 0,
97 wakaba 1.10 manakai_read_only => 0,
98 wakaba 1.4 specified => 1,
99     },
100     },
101     attr2 => {
102 wakaba 1.1 node => sub {
103     my $attr = $doc->create_attribute ('a');
104     $attr->value ('b');
105     return $attr;
106     },
107     attr_get => {
108 wakaba 1.4 manakai_attribute_type => 0,
109     base_uri => undef,
110 wakaba 1.6 manakai_expanded_uri => 'a',
111 wakaba 1.2 local_name => 'a',
112     manakai_local_name => 'a',
113     namespace_uri => undef,
114     next_sibling => undef,
115 wakaba 1.1 node_name => 'a',
116 wakaba 1.7 node_type => 2,
117 wakaba 1.1 name => 'a',
118     node_value => 'b',
119 wakaba 1.2 owner_document => $doc,
120     parent_node => undef,
121     prefix => undef,
122     previous_sibling => undef,
123 wakaba 1.1 value => 'b',
124     attributes => undef,
125     },
126 wakaba 1.4 attr_get_bool => {
127 wakaba 1.6 has_attributes => 0,
128     has_child_nodes => 1,
129 wakaba 1.10 manakai_read_only => 0,
130 wakaba 1.4 specified => 1,
131     },
132 wakaba 1.1 },
133     attr_ns_default => {
134 wakaba 1.4 node => sub { return $doc->create_attribute_ns (undef, 'a') },
135 wakaba 1.1 attr_get => {
136 wakaba 1.4 base_uri => undef,
137 wakaba 1.6 manakai_expanded_uri => 'a',
138 wakaba 1.2 local_name => 'a',
139     manakai_local_name => 'a',
140     namespace_uri => undef,
141     next_sibling => undef,
142 wakaba 1.1 node_name => 'a',
143 wakaba 1.7 node_type => 2,
144 wakaba 1.1 name => 'a',
145 wakaba 1.4 node_value => '',
146 wakaba 1.2 owner_document => $doc,
147     parent_node => undef,
148     prefix => undef,
149 wakaba 1.4 value => '',
150 wakaba 1.1 attributes => undef,
151 wakaba 1.2 previous_sibling => undef,
152 wakaba 1.1 },
153 wakaba 1.6 attr_get_bool => {
154     has_attributes => 0,
155     has_child_nodes => 0,
156 wakaba 1.10 manakai_read_only => 0,
157 wakaba 1.6 specified => 1,
158     },
159 wakaba 1.1 },
160     attr_ns_prefixed => {
161 wakaba 1.4 node => sub { return $doc->create_attribute_ns ('http://test/', 'a:b') },
162 wakaba 1.1 attr_get => {
163 wakaba 1.4 base_uri => undef,
164 wakaba 1.6 manakai_expanded_uri => 'http://test/b',
165 wakaba 1.2 local_name => 'b',
166     manakai_local_name => 'b',
167     namespace_uri => 'http://test/',
168     next_sibling => undef,
169 wakaba 1.1 node_name => 'a:b',
170 wakaba 1.7 node_type => 2,
171 wakaba 1.1 name => 'a:b',
172 wakaba 1.4 node_value => '',
173 wakaba 1.2 owner_document => $doc,
174     parent_node => undef,
175     prefix => 'a',
176 wakaba 1.4 value => '',
177 wakaba 1.1 attributes => undef,
178 wakaba 1.2 previous_sibling => undef,
179 wakaba 1.1 },
180 wakaba 1.6 attr_get_bool => {
181     has_attributes => 0,
182     has_child_nodes => 0,
183 wakaba 1.10 manakai_read_only => 0,
184 wakaba 1.6 specified => 1,
185     },
186 wakaba 1.1 },
187 wakaba 1.8 attr_ns_prefixed_array => {
188     node => sub { $doc->create_attribute_ns ('http://test/', ['a', 'b']) },
189     attr_get => {
190     base_uri => undef,
191     manakai_expanded_uri => 'http://test/b',
192     local_name => 'b',
193     manakai_local_name => 'b',
194     namespace_uri => 'http://test/',
195     next_sibling => undef,
196     node_name => 'a:b',
197     node_type => 2,
198     name => 'a:b',
199     node_value => '',
200     owner_document => $doc,
201     parent_node => undef,
202     prefix => 'a',
203     value => '',
204     attributes => undef,
205     previous_sibling => undef,
206     },
207     attr_get_bool => {
208     has_attributes => 0,
209     has_child_nodes => 0,
210 wakaba 1.10 manakai_read_only => 0,
211 wakaba 1.8 specified => 1,
212     },
213     },
214 wakaba 1.1 cdatasection => {
215     node => sub { return $doc->create_cdata_section ('cdatadata') },
216     attr_get => {
217 wakaba 1.4 base_uri => undef,
218 wakaba 1.6 manakai_expanded_uri => undef,
219 wakaba 1.2 first_child => undef,
220     last_child => undef,
221     local_name => undef,
222     manakai_local_name => undef,
223     namespace_uri => undef,
224     next_sibling => undef,
225 wakaba 1.1 node_name => '#cdata-section',
226 wakaba 1.7 node_type => 4,
227 wakaba 1.1 node_value => 'cdatadata',
228 wakaba 1.2 owner_document => $doc,
229     parent_node => undef,
230     prefix => undef,
231 wakaba 1.1 data => 'cdatadata',
232     attributes => undef,
233 wakaba 1.2 previous_sibling => undef,
234 wakaba 1.1 },
235 wakaba 1.6 attr_get_bool => {
236     has_attributes => 0,
237     has_child_nodes => 0,
238 wakaba 1.9 is_element_content_whitespace => 0,
239 wakaba 1.10 manakai_read_only => 0,
240 wakaba 1.6 },
241 wakaba 1.1 },
242     cdatasectionmde => {
243     node => sub { return $doc->create_cdata_section ('cdata]]>data') },
244     attr_get => {
245 wakaba 1.4 base_uri => undef,
246 wakaba 1.6 manakai_expanded_uri => undef,
247 wakaba 1.2 first_child => undef,
248     last_child => undef,
249     local_name => undef,
250     manakai_local_name => undef,
251     namespace_uri => undef,
252     next_sibling => undef,
253 wakaba 1.1 node_name => '#cdata-section',
254 wakaba 1.7 node_type => 4,
255 wakaba 1.1 node_value => 'cdata]]>data',
256 wakaba 1.2 owner_document => $doc,
257     parent_node => undef,
258     prefix => undef,
259 wakaba 1.1 data => 'cdata]]>data',
260     attributes => undef,
261 wakaba 1.2 previous_sibling => undef,
262 wakaba 1.1 },
263 wakaba 1.6 attr_get_bool => {
264     has_attributes => 0,
265     has_child_nodes => 0,
266 wakaba 1.9 is_element_content_whitespace => 0,
267 wakaba 1.10 manakai_read_only => 0,
268 wakaba 1.6 },
269 wakaba 1.1 },
270     comment => {
271     node => sub { return $doc->create_comment ('commentdata') },
272     attr_get => {
273 wakaba 1.4 base_uri => undef,
274 wakaba 1.6 manakai_expanded_uri => undef,
275 wakaba 1.2 first_child => undef,
276     last_child => undef,
277     local_name => undef,
278     manakai_local_name => undef,
279     namespace_uri => undef,
280     next_sibling => undef,
281 wakaba 1.1 node_name => '#comment',
282 wakaba 1.7 node_type => 8,
283 wakaba 1.1 node_value => 'commentdata',
284 wakaba 1.2 owner_document => $doc,
285     parent_node => undef,
286     prefix => undef,
287 wakaba 1.1 data => 'commentdata',
288     attributes => undef,
289 wakaba 1.2 previous_sibling => undef,
290 wakaba 1.6 },
291     attr_get_bool => {
292     has_attributes => 0,
293     has_child_nodes => 0,
294 wakaba 1.10 manakai_read_only => 0,
295 wakaba 1.1 },
296     },
297     commentcom1 => {
298     node => sub { return $doc->create_comment ('comment--data') },
299     attr_get => {
300 wakaba 1.4 base_uri => undef,
301 wakaba 1.6 manakai_expanded_uri => undef,
302 wakaba 1.2 first_child => undef,
303     last_child => undef,
304     local_name => undef,
305     manakai_local_name => undef,
306     namespace_uri => undef,
307     next_sibling => undef,
308 wakaba 1.1 node_name => '#comment',
309 wakaba 1.7 node_type => 8,
310 wakaba 1.1 node_value => 'comment--data',
311 wakaba 1.2 owner_document => $doc,
312     parent_node => undef,
313     prefix => undef,
314 wakaba 1.1 data => 'comment--data',
315     attributes => undef,
316 wakaba 1.2 previous_sibling => undef,
317 wakaba 1.1 },
318 wakaba 1.6 attr_get_bool => {
319     has_attributes => 0,
320     has_child_nodes => 0,
321 wakaba 1.10 manakai_read_only => 0,
322 wakaba 1.6 },
323 wakaba 1.1 },
324     commentcom2 => {
325     node => sub { return $doc->create_comment ('commentdata-') },
326     attr_get => {
327 wakaba 1.4 base_uri => undef,
328 wakaba 1.6 manakai_expanded_uri => undef,
329 wakaba 1.2 first_child => undef,
330     last_child => undef,
331     local_name => undef,
332     manakai_local_name => undef,
333     namespace_uri => undef,
334     next_sibling => undef,
335 wakaba 1.1 node_name => '#comment',
336 wakaba 1.7 node_type => 8,
337 wakaba 1.1 node_value => 'commentdata-',
338 wakaba 1.2 owner_document => $doc,
339     parent_node => undef,
340     prefix => undef,
341 wakaba 1.1 data => 'commentdata-',
342     attributes => undef,
343 wakaba 1.2 previous_sibling => undef,
344 wakaba 1.1 },
345 wakaba 1.6 attr_get_bool => {
346     has_attributes => 0,
347     has_child_nodes => 0,
348 wakaba 1.10 manakai_read_only => 0,
349 wakaba 1.6 },
350 wakaba 1.1 },
351     document => {
352     node => sub { return $doc },
353     attr_get => {
354     attributes => undef,
355 wakaba 1.4 base_uri => undef,
356     document_uri => undef,
357     manakai_entity_base_uri => undef,
358 wakaba 1.6 manakai_expanded_uri => undef,
359 wakaba 1.2 first_child => undef,
360     implementation => $dom,
361     last_child => undef,
362 wakaba 1.1 local_name => undef,
363 wakaba 1.2 manakai_local_name => undef,
364 wakaba 1.1 namespace_uri => undef,
365 wakaba 1.2 next_sibling => undef,
366 wakaba 1.1 node_name => '#document',
367 wakaba 1.7 node_type => 9,
368 wakaba 1.1 node_value => undef,
369 wakaba 1.2 owner_document => undef,
370 wakaba 1.1 parent_node => undef,
371     prefix => undef,
372 wakaba 1.2 previous_sibling => undef,
373 wakaba 1.4 xml_encoding => undef,
374     xml_version => '1.0',
375     },
376     attr_get_bool => {
377     all_declarations_processed => 0,
378 wakaba 1.6 has_attributes => 0,
379     has_child_nodes => 0,
380 wakaba 1.4 manakai_is_html => 0,
381 wakaba 1.10 manakai_read_only => 0,
382 wakaba 1.4 strict_error_checking => 1,
383     xml_standalone => 0,
384 wakaba 1.1 },
385     },
386     document_fragment => {
387     node => sub { return $doc->create_document_fragment },
388     attr_get => {
389     attributes => undef,
390 wakaba 1.4 base_uri => undef,
391 wakaba 1.6 manakai_expanded_uri => undef,
392 wakaba 1.2 first_child => undef,
393     last_child => undef,
394     local_name => undef,
395     manakai_local_name => undef,
396     namespace_uri => undef,
397     next_sibling => undef,
398 wakaba 1.1 node_name => '#document-fragment',
399 wakaba 1.7 node_type => 11,
400 wakaba 1.1 node_value => undef,
401 wakaba 1.2 owner_document => $doc,
402     parent_node => undef,
403     prefix => undef,
404     previous_sibling => undef,
405 wakaba 1.1 },
406 wakaba 1.6 attr_get_bool => {
407     has_attributes => 0,
408     has_child_nodes => 0,
409 wakaba 1.10 manakai_read_only => 0,
410 wakaba 1.6 },
411 wakaba 1.1 },
412     document_type => {
413     node => sub { return $doc->implementation->create_document_type ('n') },
414     attr_get => {
415     attributes => undef,
416 wakaba 1.4 base_uri => undef,
417     declaration_base_uri => undef,
418     manakai_declaration_base_uri => undef,
419 wakaba 1.6 manakai_expanded_uri => undef,
420 wakaba 1.2 first_child => undef,
421     implementation => $dom,
422     last_child => undef,
423     local_name => undef,
424     manakai_local_name => undef,
425     namespace_uri => undef,
426     next_sibling => undef,
427 wakaba 1.1 node_name => 'n',
428 wakaba 1.7 node_type => 10,
429 wakaba 1.1 node_value => undef,
430 wakaba 1.2 owner_document => undef,
431     parent_node => undef,
432     prefix => undef,
433     previous_sibling => undef,
434 wakaba 1.4 public_id => undef,
435     system_id => undef,
436 wakaba 1.1 },
437 wakaba 1.6 attr_get_bool => {
438     has_attributes => 0,
439     has_child_nodes => 0,
440 wakaba 1.10 manakai_read_only => 1,
441 wakaba 1.6 },
442 wakaba 1.1 },
443     document_type_definition => {
444     node => sub { return $doc->create_document_type_definition ('n') },
445     attr_get => {
446     attributes => undef,
447 wakaba 1.4 base_uri => undef,
448     declaration_base_uri => undef,
449     manakai_declaration_base_uri => undef,
450 wakaba 1.6 manakai_expanded_uri => undef,
451 wakaba 1.2 first_child => undef,
452     implementation => $dom,
453     last_child => undef,
454     local_name => undef,
455     manakai_local_name => undef,
456     namespace_uri => undef,
457     next_sibling => undef,
458 wakaba 1.1 node_name => 'n',
459 wakaba 1.7 node_type => 10,
460 wakaba 1.1 node_value => undef,
461 wakaba 1.2 owner_document => $doc,
462     parent_node => undef,
463     prefix => undef,
464     previous_sibling => undef,
465 wakaba 1.4 public_id => undef,
466     system_id => undef,
467 wakaba 1.1 },
468 wakaba 1.6 attr_get_bool => {
469     has_attributes => 0,
470     has_child_nodes => 0,
471 wakaba 1.10 manakai_read_only => 0,
472 wakaba 1.6 },
473 wakaba 1.1 },
474     element => {
475     node => sub { return $doc->create_element ('e') },
476     attr_get => {
477     ## TODO: attributes =>
478 wakaba 1.4 base_uri => undef,
479     manakai_base_uri => undef,
480 wakaba 1.6 manakai_expanded_uri => 'e',
481 wakaba 1.2 first_child => undef,
482     last_child => undef,
483     local_name => 'e',
484     manakai_local_name => 'e',
485     namespace_uri => undef,
486     next_sibling => undef,
487 wakaba 1.1 node_name => 'e',
488 wakaba 1.7 node_type => 1,
489 wakaba 1.1 node_value => undef,
490 wakaba 1.2 owner_document => $doc,
491     parent_node => undef,
492     prefix => undef,
493     previous_sibling => undef,
494 wakaba 1.13 tag_name => 'e',
495 wakaba 1.1 },
496 wakaba 1.6 attr_get_bool => {
497     has_attributes => 0,
498     has_child_nodes => 0,
499 wakaba 1.10 manakai_read_only => 0,
500 wakaba 1.6 },
501 wakaba 1.1 },
502     element_ns_default => {
503     node => sub { return $doc->create_element_ns ('http://test/', 'f') },
504     attr_get => {
505     ## TODO: attributes =>
506 wakaba 1.4 base_uri => undef,
507     manakai_base_uri => undef,
508 wakaba 1.6 manakai_expanded_uri => 'http://test/f',
509 wakaba 1.2 first_child => undef,
510     last_child => undef,
511     local_name => 'f',
512     manakai_local_name => 'f',
513     namespace_uri => 'http://test/',
514     next_sibling => undef,
515 wakaba 1.1 node_name => 'f',
516 wakaba 1.7 node_type => 1,
517 wakaba 1.1 node_value => undef,
518 wakaba 1.2 owner_document => $doc,
519     parent_node => undef,
520     prefix => undef,
521     previous_sibling => undef,
522 wakaba 1.13 tag_name => 'f',
523 wakaba 1.1 },
524 wakaba 1.6 attr_get_bool => {
525     has_attributes => 0,
526     has_child_nodes => 0,
527 wakaba 1.10 manakai_read_only => 0,
528 wakaba 1.6 },
529 wakaba 1.1 },
530     element_ns_prefiexed => {
531     node => sub { return $doc->create_element_ns ('http://test/', 'e:f') },
532     attr_get => {
533     ## TODO: attributes =>
534 wakaba 1.4 base_uri => undef,
535     manakai_base_uri => undef,
536 wakaba 1.6 manakai_expanded_uri => 'http://test/f',
537 wakaba 1.2 first_child => undef,
538     last_child => undef,
539     local_name => 'f',
540     manakai_local_name => 'f',
541     namespace_uri => 'http://test/',
542     next_sibling => undef,
543 wakaba 1.1 node_name => 'e:f',
544 wakaba 1.7 node_type => 1,
545 wakaba 1.1 node_value => undef,
546 wakaba 1.2 owner_document => $doc,
547     parent_node => undef,
548     prefix => 'e',
549     previous_sibling => undef,
550 wakaba 1.13 tag_name => 'e:f',
551 wakaba 1.1 },
552 wakaba 1.6 attr_get_bool => {
553     has_attributes => 0,
554     has_child_nodes => 0,
555 wakaba 1.10 manakai_read_only => 0,
556 wakaba 1.6 },
557 wakaba 1.1 },
558     entity => {
559     node => sub { return $doc->create_general_entity ('e') },
560     attr_get => {
561     attributes => undef,
562 wakaba 1.4 base_uri => undef,
563     manakai_declaration_base_uri => undef,
564     manakai_entity_base_uri => undef,
565     manakai_entity_uri => undef,
566 wakaba 1.6 manakai_expanded_uri => undef,
567 wakaba 1.2 first_child => undef,
568     last_child => undef,
569     next_sibling => undef,
570 wakaba 1.1 node_name => 'e',
571 wakaba 1.7 node_type => 6,
572 wakaba 1.1 node_value => undef,
573 wakaba 1.5 notation_name => undef,
574 wakaba 1.2 owner_document => $doc,
575     parent_node => undef,
576     previous_sibling => undef,
577 wakaba 1.4 public_id => undef,
578     system_id => undef,
579 wakaba 1.1 },
580 wakaba 1.6 attr_get_bool => {
581     has_attributes => 0,
582     has_child_nodes => 0,
583 wakaba 1.10 manakai_read_only => 0,
584 wakaba 1.6 },
585 wakaba 1.1 },
586     entity_reference => {
587     node => sub { return $doc->create_entity_reference ('e') },
588     attr_get => {
589     attributes => undef,
590 wakaba 1.4 base_uri => undef,
591     manakai_entity_base_uri => undef,
592 wakaba 1.6 manakai_expanded_uri => undef,
593 wakaba 1.2 first_child => undef,
594     last_child => undef,
595     local_name => undef,
596     manakai_local_name => undef,
597     namespace_uri => undef,
598     next_sibling => undef,
599 wakaba 1.1 node_name => 'e',
600 wakaba 1.7 node_type => 5,
601 wakaba 1.1 node_value => undef,
602 wakaba 1.2 owner_document => $doc,
603     parent_node => undef,
604     prefix => undef,
605     previous_sibling => undef,
606 wakaba 1.1 },
607 wakaba 1.4 attr_get_bool => {
608     manakai_expanded => 0,
609     manakai_external => 0,
610 wakaba 1.6 has_attributes => 0,
611     has_child_nodes => 0,
612 wakaba 1.10 manakai_read_only => 1,
613 wakaba 1.4 },
614 wakaba 1.1 },
615     notation => {
616     node => sub { return $doc->create_notation ('e') },
617     attr_get => {
618     attributes => undef,
619 wakaba 1.4 base_uri => undef,
620     manakai_declaration_base_uri => undef,
621 wakaba 1.6 manakai_expanded_uri => undef,
622 wakaba 1.2 first_child => undef,
623     last_child => undef,
624     local_name => undef,
625     manakai_local_name => undef,
626     namespace_uri => undef,
627     next_sibling => undef,
628 wakaba 1.1 node_name => 'e',
629 wakaba 1.7 node_type => 12,
630 wakaba 1.1 node_value => undef,
631 wakaba 1.2 owner_document => $doc,
632     parent_node => undef,
633     prefix => undef,
634     previous_sibling => undef,
635 wakaba 1.4 public_id => undef,
636     system_id => undef,
637 wakaba 1.1 },
638 wakaba 1.6 attr_get_bool => {
639     has_attributes => 0,
640     has_child_nodes => 0,
641 wakaba 1.10 manakai_read_only => 0,
642 wakaba 1.6 },
643 wakaba 1.1 },
644     processing_instruction => {
645     node => sub { return $doc->create_processing_instruction ('t', 'd') },
646     attr_get => {
647     attributes => undef,
648 wakaba 1.4 base_uri => undef,
649     manakai_base_uri => undef,
650 wakaba 1.6 manakai_expanded_uri => undef,
651 wakaba 1.2 first_child => undef,
652     last_child => undef,
653     local_name => undef,
654     manakai_local_name => undef,
655     namespace_uri => undef,
656     next_sibling => undef,
657 wakaba 1.1 node_name => 't',
658 wakaba 1.7 node_type => 7,
659 wakaba 1.1 node_value => 'd',
660 wakaba 1.2 owner_document => $doc,
661     parent_node => undef,
662     prefix => undef,
663     previous_sibling => undef,
664 wakaba 1.1 },
665 wakaba 1.6 attr_get_bool => {
666     has_attributes => 0,
667     has_child_nodes => 0,
668 wakaba 1.10 manakai_read_only => 0,
669 wakaba 1.6 },
670 wakaba 1.1 },
671     text => {
672     node => sub { return $doc->create_text_node ('textdata') },
673     attr_get => {
674     attributes => undef,
675 wakaba 1.4 base_uri => undef,
676 wakaba 1.6 manakai_expanded_uri => undef,
677 wakaba 1.2 first_child => undef,
678     last_child => undef,
679     local_name => undef,
680     manakai_local_name => undef,
681     namespace_uri => undef,
682     next_sibling => undef,
683 wakaba 1.1 node_name => '#text',
684 wakaba 1.7 node_type => 3,
685 wakaba 1.1 node_value => 'textdata',
686 wakaba 1.2 owner_document => $doc,
687     parent_node => undef,
688     prefix => undef,
689     previous_sibling => undef,
690 wakaba 1.1 },
691 wakaba 1.6 attr_get_bool => {
692     has_attributes => 0,
693     has_child_nodes => 0,
694 wakaba 1.9 is_element_content_whitespace => 0,
695 wakaba 1.10 manakai_read_only => 0,
696 wakaba 1.6 },
697 wakaba 1.1 },
698     element_type_definition => {
699     node => sub { return $doc->create_element_type_definition ('e') },
700     attr_get => {
701     attributes => undef,
702 wakaba 1.4 base_uri => undef,
703 wakaba 1.6 manakai_expanded_uri => undef,
704 wakaba 1.2 first_child => undef,
705     last_child => undef,
706     local_name => undef,
707     manakai_local_name => undef,
708     namespace_uri => undef,
709     next_sibling => undef,
710 wakaba 1.1 node_name => 'e',
711 wakaba 1.7 node_type => 81001,
712 wakaba 1.1 node_value => undef,
713 wakaba 1.2 owner_document => $doc,
714     parent_node => undef,
715     prefix => undef,
716     previous_sibling => undef,
717 wakaba 1.1 },
718 wakaba 1.6 attr_get_bool => {
719     has_attributes => 0,
720     has_child_nodes => 0,
721 wakaba 1.10 manakai_read_only => 0,
722 wakaba 1.6 },
723 wakaba 1.1 },
724     attribute_definition => {
725     node => sub { return $doc->create_attribute_definition ('e') },
726     attr_get => {
727     attributes => undef,
728 wakaba 1.4 base_uri => undef,
729     declared_type => 0,
730     default_type => 0,
731 wakaba 1.6 manakai_expanded_uri => undef,
732 wakaba 1.2 first_child => undef,
733     last_child => undef,
734     local_name => undef,
735     manakai_local_name => undef,
736     namespace_uri => undef,
737     next_sibling => undef,
738 wakaba 1.1 node_name => 'e',
739 wakaba 1.7 node_type => 81002,
740 wakaba 1.1 node_value => undef,
741 wakaba 1.2 owner_document => $doc,
742     parent_node => undef,
743     prefix => undef,
744     previous_sibling => undef,
745 wakaba 1.1 },
746 wakaba 1.6 attr_get_bool => {
747     has_attributes => 0,
748     has_child_nodes => 0,
749 wakaba 1.10 manakai_read_only => 0,
750 wakaba 1.6 },
751 wakaba 1.1 },
752     };
753    
754     for my $test_id (sort {$a cmp $b} keys %$tests) {
755     my $test_def = $tests->{$test_id};
756     my $node = $test_def->{node}->();
757    
758     for (@$constants) {
759     my $const_name = $_->[0];
760     ok $node->can ($const_name) ? 1 : 0, 1, "$test_id->can ($const_name)";
761     ok $node->$const_name, $_->[1], "$test_id.$const_name";
762     }
763    
764     for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get}}) {
765     my $expected = $test_def->{attr_get}->{$attr_name};
766     ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)";
767     my $actual = $node->$attr_name;
768     ok $actual, $expected, "$test_id.$attr_name.get";
769     }
770 wakaba 1.4
771     for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get_bool} or {}}) {
772     my $expected = $test_def->{attr_get_bool}->{$attr_name} ? 1 : 0;
773     ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)";
774     my $actual = $node->$attr_name ? 1 : 0;
775     ok $actual, $expected, "$test_id.$attr_name.get";
776     }
777 wakaba 1.1 }
778    
779 wakaba 1.2 ## Child node accessors' tests
780     for my $parent (create_parent_nodes ()) {
781 wakaba 1.12 my $doc = $parent->owner_document || $parent;
782 wakaba 1.2 my $node1;
783     my $node2;
784     my $node3;
785     if ($parent->node_type == $parent->DOCUMENT_TYPE_NODE) {
786     $node1 = $doc->create_processing_instruction ('pi1', 'data1');
787     $node2 = $doc->create_processing_instruction ('pi2', 'data2');
788     $node3 = $doc->create_processing_instruction ('pi3', 'data3');
789     } elsif ($parent->node_type == $parent->DOCUMENT_NODE) {
790     $node1 = $doc->create_comment ('comment1');
791     $node2 = $doc->create_comment ('comment2');
792     $node3 = $doc->create_comment ('comment3');
793     } else {
794     $node1 = $doc->create_text_node ('text1');
795     $node2 = $doc->create_text_node ('text2');
796     $node3 = $doc->create_text_node ('text3');
797     }
798    
799 wakaba 1.12 $parent->manakai_set_read_only (0, 1);
800 wakaba 1.2 $parent->append_child ($node1);
801     ok $parent->first_child, $node1, $parent->node_name."->first_child [1]";
802     ok $parent->last_child, $node1, $parent->node_name."->last_child [1]";
803     ok $node1->next_sibling, undef, $parent->node_name."->next_sibling [1]";
804     ok $node1->previous_sibling, undef, $parent->node_name."->previous_sibling [1]";
805    
806     $parent->append_child ($node2);
807     ok $parent->first_child, $node1, $parent->node_name."->first_child [2]";
808     ok $parent->last_child, $node2, $parent->node_name."->last_child [2]";
809     ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [2]";
810     ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [2]";
811     ok $node2->next_sibling, undef, $parent->node_name."2->next_sibling [2]";
812     ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [2]";
813    
814     $parent->append_child ($node3);
815     ok $parent->first_child, $node1, $parent->node_name."->first_child [3]";
816     ok $parent->last_child, $node3, $parent->node_name."->last_child [3]";
817     ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [3]";
818     ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [3]";
819     ok $node2->next_sibling, $node3, $parent->node_name."2->next_sibling [3]";
820     ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [3]";
821     ok $node3->next_sibling, undef, $parent->node_name."3->next_sibling [3]";
822     ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]";
823     }
824    
825 wakaba 1.3 ## |prefix| setter
826     for my $node (create_nodes ()) {
827     $node->manakai_set_read_only (0);
828    
829     $node->prefix ('non-null');
830     if ($node->node_type == $node->ELEMENT_NODE or
831     $node->node_type == $node->ATTRIBUTE_NODE) {
832     ok $node->prefix, 'non-null', $node->node_name . '->prefix (non-null)';
833     } else {
834     ok $node->prefix, undef, $node->node_name . '->prefix (non-null)';
835     }
836    
837     $node->prefix (undef);
838     if ($node->node_type == $node->ELEMENT_NODE or
839     $node->node_type == $node->ATTRIBUTE_NODE) {
840     ok $node->prefix, undef, $node->node_name . '->prefix (null)';
841     } else {
842     ok $node->prefix, undef, $node->node_name . '->prefix (null)';
843     }
844    
845     $node->manakai_set_read_only (1);
846     my $err_type;
847     try {
848     $node->prefix ('non-null');
849     } catch Message::IF::DOMException with {
850     my $err = shift;
851     $err_type = $err->type;
852     };
853     if ($node->node_type == $node->ELEMENT_NODE or
854     $node->node_type == $node->ATTRIBUTE_NODE) {
855     ok $err_type, 'NO_MODIFICATION_ALLOWED_ERR',
856     $node->node_name . '->prefix exception (read-only)';
857     ok $node->prefix, undef, $node->node_name . '->prefix (read-only)';
858     } else {
859     ok $err_type, undef, $node->node_name . '->prefix exception (read-only)';
860     ok $node->prefix, undef, $node->node_name . '->prefix (read-only)';
861     }
862     }
863    
864     ## |text_content|
865     {
866     my $doc2 = $doc->implementation->create_document;
867     $doc2->dom_config->set_parameter
868     ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1);
869     for my $node (
870     $doc2,
871     $doc->create_document_type_definition ('dt1'),
872     $doc->implementation->create_document_type ('doctype1'),
873     $doc->create_notation ('notation1'),
874     $doc->create_element_type_definition ('et1'),
875     ) {
876     ok $node->can ('text_content') ? 1 : 0, 1,
877     $node->node_name . '->can text_content';
878    
879     ok $node->text_content, undef, $node->node_name . '->text_content';
880    
881     $node->manakai_set_read_only (0);
882     $node->text_content ('new-text-content');
883     ok $node->text_content, undef, $node->node_name . '->text_content set';
884    
885     $node->manakai_set_read_only (1);
886     $node->text_content ('new-text-content');
887     ok $node->text_content, undef,
888     $node->node_name . '->text_content set (read-only)';
889     }
890    
891     $doc2->dom_config->set_parameter
892     ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0);
893     for my $node (
894     $doc2,
895     $doc->create_attribute ('attr1'),
896     $doc->create_attribute_definition ('at1'),
897     $doc->create_element ('element1'),
898     $doc->create_general_entity ('entity1'),
899     $doc->create_entity_reference ('entity-reference1'),
900     $doc->create_document_fragment,
901     ) {
902     ok $node->can ('text_content') ? 1 : 0, 1,
903     $node->node_name . '->can text_content';
904    
905     ok $node->text_content, '', $node->node_name . '->text_content';
906    
907     $node->manakai_set_read_only (0);
908     $node->text_content ('text1');
909     ok $node->text_content, 'text1', $node->node_name . '->text_content set';
910     ok 0+@{$node->child_nodes}, 1,
911     $node->node_name . '->text_content set child_nodes length';
912    
913     $node->text_content ('');
914     ok $node->text_content, '', $node->node_name . '->text_content set empty';
915     ok 0+@{$node->child_nodes}, 0,
916     $node->node_name . '->text_content set empty child_nodes length';
917    
918     $node->text_content ('text2');
919     $node->text_content ('');
920     ok $node->text_content, '', $node->node_name . '->text_content set empty';
921     ok 0+@{$node->child_nodes}, 0,
922     $node->node_name . '->text_content set empty child_nodes length';
923    
924     $node->text_content ('text3');
925     $node->manakai_set_read_only (1);
926     try {
927     $node->text_content ('new-text-content');
928     ok undef, 'NO_MODIFICATION_ALLOWED_ERR',
929     $node->node_name . '->text_content set (read-only)';
930     } catch Message::IF::DOMException with {
931     my $err = shift;
932     ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR',
933     $node->node_name . '->text_content set (read-only)';
934     };
935     ok $node->text_content, 'text3',
936     $node->node_name . '->text_content set (read-only) text_content';
937     }
938    
939    
940     for (0..2) {
941     my $el;
942     my $ce;
943    
944     [
945     sub {
946     $el = $doc->create_element ('nestingElement');
947     $ce = $doc->create_element ('el2');
948     },
949     sub {
950     $el = $doc->create_element ('elementWithEntityReference');
951     $ce = $doc->create_entity_reference ('ent');
952     $ce->manakai_set_read_only (0, 1);
953     },
954     sub {
955     $el = $doc->create_general_entity ('generalEntityWithChild');
956     $ce = $doc->create_element ('el');
957     $el->manakai_set_read_only (0, 1);
958     },
959     ]->[$_]->();
960     $el->append_child ($ce);
961    
962     ok $el->text_content, '', $el->node_name . '->text_content [1]';
963    
964     $ce->text_content ('gc');
965     ok $el->text_content, 'gc', $el->node_name . '->text_content [2]';
966    
967     $el->manakai_append_text ('cc');
968     ok $el->text_content, 'gccc', $el->node_name . '->text_content [3]';
969    
970     $el->text_content ('nc');
971     ok $el->text_content, 'nc', $el->node_name . '->text_content [4]';
972     ok 0+@{$el->child_nodes}, 1,
973     $el->node_name . '->text_content child_nodes length [4]';
974     ok $ce->parent_node, undef,
975     $el->node_name . '->text_content old_child parent_node [4]';
976     }
977     }
978    
979 wakaba 1.4 ## |manakaiReadOnly| and |manakaiSetReadOnly|
980     {
981     for my $node (create_nodes ()) {
982     $node->manakai_set_read_only (1, 0);
983     ok $node->manakai_read_only ? 1 : 0, 1,
984     $node->node_name . '->manakai_set_read_only (1, 0) [1]';
985    
986     $node->manakai_set_read_only (0, 0);
987     ok $node->manakai_read_only ? 1 : 0, 0,
988     $node->node_name . '->manakai_set_read_only (0, 0)';
989    
990     $node->manakai_set_read_only (1, 0);
991     ok $node->manakai_read_only ? 1 : 0, 1,
992     $node->node_name . '->manakai_set_read_only (1, 0) [2]';
993     }
994    
995     {
996     my $el = $doc->create_element ('readOnlyElement1');
997     my $c1 = $doc->create_element ('c1');
998     $el->append_child ($c1);
999     my $c2 = $doc->create_text_node ('c2');
1000     $el->append_child ($c2);
1001     my $c3 = $doc->create_element ('c3');
1002     $el->append_child ($c3);
1003     my $c4 = $doc->create_attribute ('c4');
1004     $el->set_attribute_node ($c4);
1005     my $c5 = $doc->create_entity_reference ('c5');
1006     $el->append_child ($c5);
1007    
1008     $el->manakai_set_read_only (1, 1);
1009     for ($c1, $c2, $c3, $c4, $c5) {
1010     ok $_->manakai_read_only ? 1 : 0, 1,
1011     $el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]';
1012     }
1013    
1014     $el->manakai_set_read_only (0, 1);
1015     for ($c1, $c2, $c3, $c4, $c5) {
1016     ok $_->manakai_read_only ? 1 : 0, 0,
1017     $el->node_name . '->read_only (1, 0) ' . $_->node_name;
1018     }
1019    
1020     $el->manakai_set_read_only (1, 1);
1021     for ($c1, $c2, $c3, $c4, $c5) {
1022     ok $_->manakai_read_only ? 1 : 0, 1,
1023     $el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]';
1024     }
1025     }
1026    
1027     {
1028     my $dtd = $doc->create_document_type_definition ('readOnlyDTDef1');
1029     my $c1 = $doc->create_processing_instruction ('c1', '');
1030     $dtd->append_child ($c1);
1031     my $c2 = $doc->create_element_type_definition ('c2');
1032     $dtd->set_element_type_definition_node ($c2);
1033     my $c3 = $doc->create_general_entity ('c3');
1034     $dtd->set_general_entity_node ($c3);
1035     my $c4 = $doc->create_notation ('c4');
1036     $dtd->set_notation_node ($c4);
1037     my $c5 = $doc->create_text_node ('c5');
1038     $c3->append_child ($c5);
1039    
1040     $dtd->manakai_set_read_only (1, 1);
1041     for ($c1, $c2, $c3, $c4, $c5) {
1042     ok $_->manakai_read_only ? 1 : 0, 1,
1043     $dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]';
1044     }
1045    
1046     $dtd->manakai_set_read_only (0, 1);
1047     for ($c1, $c2, $c3, $c4, $c5) {
1048     ok $_->manakai_read_only ? 1 : 0, 0,
1049     $dtd->node_name . '->read_only (1, 0) ' . $_->node_name;
1050     }
1051    
1052     $dtd->manakai_set_read_only (1, 1);
1053     for ($c1, $c2, $c3, $c4, $c5) {
1054     ok $_->manakai_read_only ? 1 : 0, 1,
1055     $dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]';
1056     }
1057     }
1058    
1059     {
1060     my $et = $doc->create_element_type_definition ('readOnlyETDef1');
1061     my $c1 = $doc->create_element ('c1');
1062     $et->set_attribute_definition_node ($c1);
1063     my $c2 = $doc->create_text_node ('c2');
1064     $c1->append_child ($c2);
1065    
1066     $et->manakai_set_read_only (1, 1);
1067     for ($c1, $c2) {
1068     ok $_->manakai_read_only ? 1 : 0, 1,
1069     $et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]';
1070     }
1071    
1072     $et->manakai_set_read_only (0, 1);
1073     for ($c1, $c2) {
1074     ok $_->manakai_read_only ? 1 : 0, 0,
1075     $et->node_name . '->read_only (1, 0) ' . $_->node_name;
1076     }
1077    
1078     $et->manakai_set_read_only (1, 1);
1079     for ($c1, $c2) {
1080     ok $_->manakai_read_only ? 1 : 0, 1,
1081     $et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]';
1082     }
1083     }
1084     }
1085    
1086     ## |manakaiAppendText|
1087     {
1088     my $doc2 = $doc->implementation->create_document;
1089    
1090     $doc2->dom_config->set_parameter
1091     ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1);
1092     for my $node (
1093     $doc2,
1094     $doc->create_notation ('Notation_manakaiAppendText'),
1095     $doc->create_document_type_definition ('DT_manakaiAppendText'),
1096     $doc->create_element_type_definition ('ET_manakaiAppendText'),
1097     ) {
1098     ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can';
1099    
1100     $node->manakai_append_text ('aaaa');
1101     ok $node->text_content, undef, $node->node_name . ' [1]';
1102     ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]';
1103     }
1104    
1105     $doc2->dom_config->set_parameter
1106     ('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0);
1107     for my $node (
1108     $doc->create_attribute ('Attr_manakaiAppendText'),
1109     $doc->create_element ('Element_manakaiAppendText'),
1110     $doc2,
1111     $doc->create_document_fragment,
1112     $doc->create_general_entity ('Entity_manakaiAppendText'),
1113     $doc->create_entity_reference ('ER_manakaiAppendText'),
1114     $doc->create_attribute_definition ('AT_manakaiAppendText'),
1115     ) {
1116     $node->manakai_set_read_only (0, 1);
1117     ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can';
1118    
1119     $node->manakai_append_text ('string');
1120     ok $node->text_content, 'string', $node->node_name . ' [1]';
1121     ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [1]';
1122    
1123     $node->manakai_append_text ('STRING');
1124     ok $node->text_content, 'stringSTRING', $node->node_name . ' [2]';
1125     ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [2]';
1126    
1127 wakaba 1.12 my $er = ($node->owner_document || $node)->create_entity_reference ('er');
1128 wakaba 1.4 $node->append_child ($er);
1129    
1130     $node->manakai_append_text ('text');
1131     ok $node->text_content, 'stringSTRINGtext', $node->node_name . ' [3]';
1132     ok 0+@{$node->child_nodes}, 3, $node->node_name . ' childNodes @{} 0+ [3]';
1133     }
1134    
1135     for my $node (
1136     $doc->create_text_node (''),
1137     $doc->create_cdata_section (''),
1138     $doc->create_comment (''),
1139     $doc->create_processing_instruction ('PI_manakaiAppendText'),
1140     ) {
1141     ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can';
1142    
1143     $node->manakai_append_text ('aaaa');
1144     ok $node->text_content, 'aaaa', $node->node_name . ' [1]';
1145     ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]';
1146    
1147     $node->manakai_append_text ('bbbb');
1148     ok $node->text_content, 'aaaabbbb', $node->node_name . ' [1]';
1149     ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]';
1150     }
1151     }
1152    
1153     ## |baseURI|
1154     {
1155     my $doc2 = $doc->implementation->create_document;
1156    
1157     $doc2->document_uri (q<ftp://suika.fam.cx/>);
1158     ok $doc2->base_uri, q<ftp://suika.fam.cx/>, 'Document->base_uri [1]';
1159    
1160     $doc2->document_uri (undef);
1161     ok $doc2->base_uri, undef, 'Document->base_uri [2]';
1162     ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [2]';
1163    
1164     $doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>);
1165     ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [3]';
1166     ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>,
1167     'Document->base_uri ebu [3]';
1168    
1169     $doc2->manakai_entity_base_uri (undef);
1170     ok $doc2->base_uri, undef, 'Document->base_uri [4]';
1171     ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [4]';
1172    
1173     $doc2->document_uri (q<ftp://suika.fam.cx/>);
1174     $doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>);
1175     ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [5]';
1176     ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>,
1177     'Document->base_uri ebu [5]';
1178     }
1179    
1180     for my $method (qw/
1181     create_document_fragment
1182     create_element_type_definition
1183     create_attribute_definition
1184     /) {
1185     my $doc2 = $doc->implementation->create_document;
1186    
1187     my $node = $doc2->$method ('a');
1188    
1189     $doc2->document_uri (q<ftp://doc.test/>);
1190     ok $node->base_uri, q<ftp://doc.test/>, $node->node_name . '->base_uri [1]';
1191    
1192     $doc2->manakai_entity_base_uri (q<ftp://suika.fam.cx/>);
1193     ok $node->base_uri, q<ftp://suika.fam.cx/>,
1194     $node->node_name . '->base_uri [2]';
1195     }
1196    
1197     {
1198     my $doc2 = $doc->implementation->create_document;
1199    
1200     my $attr = $doc2->create_attribute_ns (undef, 'attr');
1201    
1202     $doc2->document_uri (q<http://www.example.com/>);
1203     ok $attr->base_uri, q<http://www.example.com/>, 'Attr->base_uri [1]';
1204    
1205     my $el = $doc2->create_element_ns (undef, 'element');
1206     $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace',
1207     'xml:base' => q<http://www.example.org/>);
1208     $el->set_attribute_node_ns ($attr);
1209     ok $attr->base_uri, q<http://www.example.org/>, 'Attr->base_uri [2]';
1210     }
1211    
1212     for my $i (0..1) {
1213     my $xb = [
1214     ['http://www.w3.org/XML/1998/namespace', 'xml:base'],
1215     [undef, [undef, 'xml:base']],
1216     ]->[$i];
1217    
1218     my $doc2 = $doc->implementation->create_document;
1219 wakaba 1.8 $doc2->strict_error_checking (0);
1220 wakaba 1.4
1221     my $attr = $doc2->create_attribute_ns (@$xb);
1222     $attr->value (q<http://attr.test/>);
1223    
1224     ok $attr->base_uri, undef, 'xml:base->base_uri [0]' . $i;
1225    
1226     $doc2->document_uri (q<http://doc.test/>);
1227     ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [1]' . $i;
1228    
1229     my $el = $doc2->create_element_ns (undef, 'e');
1230     $el->set_attribute_node_ns ($attr);
1231     ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [2]' . $i;
1232    
1233     my $pel = $doc2->create_element_ns (undef, 'e');
1234     $pel->set_attribute_ns (@$xb, q<http://pel.test/>);
1235     $pel->append_child ($el);
1236     ok $attr->base_uri, q<http://pel.test/>, 'xml:base->base_uri [3]' . $i;
1237     }
1238    
1239     for my $i (0..1) {
1240     my $xb = [
1241     ['http://www.w3.org/XML/1998/namespace', 'xml:base'],
1242     [undef, [undef, 'xml:base']],
1243     ]->[$i];
1244    
1245     my $doc2 = $doc->implementation->create_document;
1246    
1247     my $el = $doc2->create_element_ns (undef, 'el');
1248    
1249     ok $el->base_uri, undef, "Element->base_uri [0]";
1250     ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [0]";
1251    
1252     $doc2->document_uri (q<http://foo.example/>);
1253     ok $el->base_uri, q<http://foo.example/>, "Element->base_uri [1]";
1254     ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [1]";
1255    
1256     $el->set_attribute_ns (@$xb => q<http://www.example.com/>);
1257     ok $el->base_uri, q<http://www.example.com/>, "Element->base_uri [2]";
1258     ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [2]";
1259    
1260     $el->set_attribute_ns (@$xb => q<bar>);
1261     ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [3]";
1262     ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [3]";
1263    
1264     $el->manakai_base_uri (q<http://baz.example/>);
1265     ok $el->base_uri, q<http://baz.example/>, "Element->base_uri [4]";
1266     ok $el->manakai_base_uri, q<http://baz.example/>,
1267     "Element->manakai_base_uri [4]";
1268    
1269     $el->manakai_base_uri (undef);
1270     ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [5]";
1271     ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [5]";
1272     }
1273    
1274     {
1275     my $doc2 = $doc->implementation->create_document;
1276    
1277     my $el = $doc2->create_element_ns (undef, 'el');
1278    
1279     ok $el->base_uri, undef, "Element->base_uri [6]";
1280    
1281     $doc2->document_uri (q<http://doc.test/>);
1282     ok $el->base_uri, q<http://doc.test/>, "Element->base_uri [7]";
1283    
1284     my $el0 = $doc2->create_element_ns (undef, 'e');
1285     $el0->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1286     q<http://el.test/>);
1287     $el0->append_child ($el);
1288     ok $el->base_uri, q<http://el.test/>, "Element->base_uri [8]";
1289    
1290     my $ent = $doc2->create_entity_reference ('ent');
1291     $ent->manakai_set_read_only (0, 1);
1292     $ent->manakai_external (1);
1293     $ent->manakai_entity_base_uri (q<http://ent.test/>);
1294     $el0->append_child ($ent);
1295     $ent->append_child ($el);
1296     ok $el->base_uri, q<http://ent.test/>, "Element->base_uri [9]";
1297     }
1298    
1299     for (qw/create_text_node create_cdata_section create_comment/) {
1300     my $doc2 = $doc->implementation->create_document;
1301     my $node = $doc2->$_ ('');
1302    
1303     $doc2->document_uri (q<http://doc.test/>);
1304     ok $node->base_uri, q<http://doc.test/>, $node->node_name . "->base_uri [0]";
1305    
1306     my $el = $doc2->create_element_ns (undef, 'e');
1307     $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1308     q<http://el.test/>);
1309     $el->append_child ($node);
1310     ok $node->base_uri, q<http://el.test/>, $node->node_name . "->base_uri [1]";
1311    
1312     my $ent = $doc2->create_entity_reference ('ent');
1313     $ent->manakai_set_read_only (0, 1);
1314     $ent->manakai_external (1);
1315     $ent->manakai_entity_base_uri (q<http://ent.test/>);
1316     $el->append_child ($ent);
1317     $ent->append_child ($node);
1318     ok $node->base_uri, q<http://ent.test/>, $node->node_name . "->base_uri [2]";
1319     }
1320    
1321     {
1322     my $doc2 = $doc->implementation->create_document;
1323     my $ent = $doc2->create_general_entity ('ent');
1324    
1325     $doc2->document_uri (q<http://base.example/>);
1326     ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [1]";
1327    
1328     $ent->manakai_entity_base_uri (q<http://www.example.com/>);
1329     ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [2]";
1330    
1331     $ent->manakai_declaration_base_uri (q<http://www.example/>);
1332     ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [3]";
1333     }
1334    
1335     {
1336     my $doc2 = $doc->implementation->create_document;
1337    
1338     my $ent = $doc2->create_entity_reference ('ent');
1339     $ent->manakai_set_read_only (0, 1);
1340    
1341     $doc2->document_uri (q<http://base.example/>);
1342     ok $ent->base_uri, q<http://base.example/>, "ER->base_uri [1]";
1343    
1344     $ent->manakai_entity_base_uri (q<http://www.example.com/>);
1345     ok $ent->base_uri, q<http://base.example/>;
1346    
1347     my $el = $doc2->create_element_ns (undef, 'el');
1348     $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1349     q<http://el.test/>);
1350     $el->append_child ($ent);
1351     ok $ent->base_uri, q<http://el.test/>, "ER->base_uri [2]";
1352    
1353     my $xent = $doc2->create_entity_reference ('ext');
1354     $xent->manakai_set_read_only (0, 1);
1355     $xent->manakai_entity_base_uri (q<http://ent.test/>);
1356     $xent->manakai_external (1);
1357     $el->append_child ($xent);
1358     $xent->append_child ($ent);
1359     ok $ent->base_uri, q<http://ent.test/>, "ER->base_uri [3]";
1360     }
1361    
1362     {
1363     my $doc2 = $doc->implementation->create_document;
1364    
1365     my $pi = $doc2->create_processing_instruction ('i');
1366    
1367     ok $pi->base_uri, undef, "PI->base_uri [0]";
1368     ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [0]";
1369    
1370     $doc2->document_uri (q<http://doc.test/>);
1371     ok $pi->base_uri, q<http://doc.test/>, "PI->base_uri [1]";
1372     ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [1]";
1373    
1374     my $el = $doc2->create_element_ns (undef, 'e');
1375     $el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base',
1376     q<http://el.test/>);
1377     $el->append_child ($pi);
1378     ok $pi->base_uri, q<http://el.test/>, "PI->base_uri [2]";
1379     ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [2]";
1380    
1381     my $ent = $doc2->create_entity_reference ('ent');
1382     $ent->manakai_set_read_only (0, 1);
1383     $ent->manakai_external (1);
1384     $ent->manakai_entity_base_uri (q<http://ent.test/>);
1385     $el->append_child ($ent);
1386     $ent->append_child ($pi);
1387     ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [3]";
1388     ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [3]";
1389    
1390     $pi->manakai_base_uri (q<http://pi.ent/>);
1391     ok $pi->base_uri, q<http://pi.ent/>, "PI->base_uri [4]";
1392     ok $pi->manakai_base_uri, q<http://pi.ent/>, "PI->manakai_base_uri [4]";
1393    
1394     $pi->manakai_base_uri (undef);
1395     ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [5]";
1396     ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [5]";
1397     }
1398    
1399     {
1400     my $doc2 = $doc->implementation->create_document;
1401    
1402     my $pi = $doc2->create_notation ('i');
1403    
1404     $doc2->document_uri (q<http://doc.test/>);
1405     ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [1]";
1406    
1407     $pi->manakai_declaration_base_uri (q<http://www.example/>);
1408     ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [2]";
1409     }
1410    
1411     {
1412     my $dt = $doc->implementation->create_document_type ('name');
1413     ok $dt->base_uri, undef, "DT->base_uri [0]";
1414    
1415     my $doc2 = $doc->implementation->create_document;
1416     $doc2->append_child ($dt);
1417     $doc2->document_uri (q<http://doc.test/>);
1418     ok $dt->owner_document, $doc2;
1419     ok $dt->base_uri, q<http://doc.test/>, "DT->base_uri [1]";
1420     }
1421    
1422 wakaba 1.6 ## |hasAttribute|
1423     {
1424     my $el = $doc->create_element ('e');
1425     ok $el->has_attributes ? 1 : 0, 0, "Element->has_attributes [0]";
1426    
1427     $el->set_attribute (a => 'b');
1428     ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [1]";
1429    
1430     $el->set_attribute (c => 'd');
1431     ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [2]";
1432    
1433     $el->remove_attribute ('c');
1434     ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [3]";
1435    
1436     $el->get_attribute_node ('a')->specified (0);
1437     ok $el->has_attributes ? 1 : 0, 1, "Element->has_attributes [4]";
1438    
1439     $el->remove_attribute ('a');
1440     ok $el->has_attributes ? 1 : 0, 0, "Element->has_attributes [5]";
1441     }
1442    
1443     ## |hasChildNodes|
1444     {
1445     my $doc2 = $doc->implementation->create_document;
1446    
1447     ok $doc2->has_child_nodes ? 1 : 0, 0, "Document->has_child_nodes [0]";
1448    
1449     $doc2->append_child ($doc2->create_comment (''));
1450     ok $doc2->has_child_nodes ? 1 : 0, 1, "Document->has_child_nodes [1]";
1451    
1452     $doc2->append_child ($doc2->create_comment (''));
1453     ok $doc2->has_child_nodes ? 1 : 0, 1, "Document->has_child_nodes [2]";
1454    
1455     $doc2->remove_child ($doc2->first_child);
1456     ok $doc2->has_child_nodes ? 1 : 0, 1, "Document->has_child_nodes [3]";
1457    
1458     $doc2->remove_child ($doc2->first_child);
1459     ok $doc2->has_child_nodes ? 1 : 0, 0, "Document->has_child_nodes [4]";
1460     }
1461    
1462     ## |compareDocumentPosition|
1463     {
1464     my $e1 = $doc->create_element ('e1');
1465     my $e2 = $doc->create_element ('e2');
1466    
1467     my $dp2 = $e1->compare_document_position ($e2);
1468    
1469     ok $dp2 & $e1->DOCUMENT_POSITION_DISCONNECTED ? 1 : 0, 1, "cdp [1]";
1470     ok $dp2 & $e1->DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC ? 1 : 0, 1, "edp [2]";
1471     ok (($dp2 & $e1->DOCUMENT_POSITION_PRECEDING ||
1472     $dp2 & $e1->DOCUMENT_POSITION_FOLLOWING) ? 1 : 0, 1, "cdp [3]");
1473    
1474     my $dp1 = $e2->compare_document_position ($e1);
1475    
1476     ok $dp1 & $e1->DOCUMENT_POSITION_DISCONNECTED ? 1 : 0, 1, "cdp [4]";
1477     ok $dp1 & $e1->DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC ? 1 : 0, 1, "cdp [5]";
1478     ok (($dp1 & $e1->DOCUMENT_POSITION_PRECEDING ||
1479     $dp1 & $e1->DOCUMENT_POSITION_FOLLOWING) ? 1 : 0, 1, "cdp [6]");
1480     }
1481    
1482     {
1483     my $e1 = $doc->create_element ('e1');
1484     my $e2 = $doc->create_element ('e2');
1485    
1486     my $pe = $doc->create_element ('pe');
1487     $pe->append_child ($e1);
1488     $pe->append_child ($e2);
1489    
1490     my $dp2 = $e1->compare_document_position ($e2);
1491    
1492     ok $dp2 & $e1->DOCUMENT_POSITION_FOLLOWING ? 1 : 0, 1, "cde [7]";
1493    
1494     my $dp1 = $e2->compare_document_position ($e1);
1495    
1496     ok $dp1 & $e1->DOCUMENT_POSITION_PRECEDING ? 1 : 0, 1, "cde [8]";
1497     }
1498     ## TODO: Apparently compare_document_position requires more tests.
1499    
1500     ## |lookupNamespaceURI|
1501     {
1502     for my $node (create_nodes ()) {
1503     ok $node->lookup_namespace_uri ('ns1'), undef, $node->node_name . " lnu [0]";
1504     ok $node->lookup_namespace_uri ('xml'), undef, $node->node_name . " lnu [1]";
1505     ok $node->lookup_namespace_uri ('xmlns'), undef, $node->node_name . " lnu [2]";
1506     ok $node->lookup_namespace_uri (''), undef, $node->node_name . " lnu [3]";
1507     ok $node->lookup_namespace_uri (undef), undef, $node->node_name . " lnu [4]";
1508     }
1509    
1510     my $el = $doc->create_element_ns ('about:', 'el');
1511     ok $el->lookup_namespace_uri ('ns1'), undef, 'Element->lnu [0]';
1512    
1513     $el->prefix ('ns1');
1514     ok $el->lookup_namespace_uri ('ns1'), 'about:', 'Element->lnu [1]';
1515    
1516     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns:ns1', 'DAV:');
1517     ok $el->lookup_namespace_uri ('ns1'), 'about:', 'Element->lnu [2]';
1518    
1519     $el->prefix (undef);
1520     ok $el->lookup_namespace_uri ('ns1'), 'DAV:', 'Element->lnu [3]';
1521     }
1522    
1523     ## |lookupPrefix|
1524     {
1525     for my $node (create_nodes ()) {
1526     ok $node->lookup_prefix ('http://test/'), undef, $node->node_name . "lp [0]";
1527     ok $node->lookup_prefix ('http://www.w3.org/XML/1998/namespace'), undef, $node->node_name . "lp [1]";
1528     ok $node->lookup_prefix ('http://www.w3.org/2000/xmlns/'), undef, $node->node_name . "lp [2]";
1529     ok $node->lookup_prefix ('http://www.w3.org/1999/xhtml'), undef, $node->node_name . "lp [3]";
1530     ok $node->lookup_prefix (''), undef, $node->node_name . "lp [4]";
1531     ok $node->lookup_prefix (undef), undef, $node->node_name . "lp [5]";
1532     }
1533    
1534     my $el = $doc->create_element_ns ('http://test/', 'e');
1535     ok $el->lookup_prefix ('ns'), undef, "Element->lp [0]";;
1536    
1537     my $el2 = $doc->create_element_ns ('http://test/', 'f');
1538     $el2->append_child ($el);
1539     $el2->prefix ('ns');
1540     ok $el->lookup_prefix ('http://test/'), 'ns', "Element->lp [1]";
1541    
1542     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns:a',
1543     'http://test/');
1544     ok $el->lookup_prefix ('http://test/'), 'a', "Element->lp [2]";
1545    
1546     $el->prefix ('b');
1547     ok $el->lookup_prefix ('http://test/'), 'b', "Element->lp [3]";
1548     }
1549    
1550     ## |isDefaultNamespace|
1551     {
1552     for my $node (create_nodes ()) {
1553     next if $node->node_type == 1;
1554     ok $node->is_default_namespace ('about:') ? 1 : 0, 0, $node->node_name."idn[0]";
1555     ok $node->is_default_namespace ('http://www.w3.org/XML/1998/namespace') ? 1 : 0, 0, $node->node_name."idn[2]";
1556     ok $node->is_default_namespace ('http://www.w3.org/2000/xmlns/') ? 1 : 0, 0, $node->node_name."idn[3]";
1557     ok $node->is_default_namespace ('') ? 1 : 0, 0, $node->node_name."idn[4]";
1558     ok $node->is_default_namespace (undef) ? 1 : 0, 0, $node->node_name."idn[5]";
1559     }
1560    
1561     my $el = $doc->create_element_ns ('about:', 'el');
1562     ok $el->is_default_namespace ('about:') ? 1 : 0, 1, "Element->idn [0]";
1563    
1564     $el->prefix ('ns1');
1565     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [1]";
1566    
1567     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'DAV:');
1568     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [2]";
1569    
1570     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'about:');
1571     ok $el->is_default_namespace ('about:') ? 1 : 0, 1, "Element->idn [3]";
1572    
1573     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', '');
1574     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [4]";
1575     }
1576    
1577     {
1578     my $el = $doc->create_element_ns ('about:', 'p:el');
1579     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [5]";
1580    
1581     $el->prefix ('ns1');
1582     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [6]";
1583    
1584     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'DAV:');
1585     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [7]";
1586    
1587     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'about:');
1588     ok $el->is_default_namespace ('about:') ? 1 : 0, 1, "Element->idn [8]";
1589    
1590     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', '');
1591     ok $el->is_default_namespace ('about:') ? 1 : 0, 0, "Element->idn [9]";
1592     }
1593    
1594     {
1595     my $el = $doc->create_element ('e');
1596    
1597     ## NOTE: This might look like strange, but it is how it is defined!
1598     ok $el->is_default_namespace (undef) ? 1 : 0, 0, "Element->idn [10]";
1599     ok $el->is_default_namespace ('') ? 1 : 0, 0, "Element->idn [11]";
1600    
1601     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', 'DAV:');
1602     ok $el->is_default_namespace (undef) ? 1 : 0, 0, "Element->idn [12]";
1603     ok $el->is_default_namespace ('') ? 1 : 0, 0, "Element->idn [13]";
1604    
1605     $el->set_attribute_ns ('http://www.w3.org/2000/xmlns/', 'xmlns', '');
1606     ok $el->is_default_namespace (undef) ? 1 : 0, 0, "Element->idn [14]";
1607     ok $el->is_default_namespace ('') ? 1 : 0, 0, "Element->idn [15]";
1608     }
1609    
1610     ## |manakaiParentElement|
1611     {
1612     my $el = $doc->create_element ('el');
1613     ok $el->manakai_parent_element, undef, "mpe [0]";
1614    
1615     my $el2 = $doc->create_element ('el2');
1616     $el->append_child ($el2);
1617     ok $el2->manakai_parent_element, $el, "mpe [1]";
1618    
1619     my $er1 = $doc->create_entity_reference ('er1');
1620     $er1->manakai_set_read_only (0, 1);
1621     $el->append_child ($er1);
1622     $er1->append_child ($el2);
1623     ok $el2->manakai_parent_element, $el, "mpe [1]";
1624     }
1625    
1626     {
1627     my $el = $doc->create_element ('el');
1628     my $t1 = $doc->create_text_node ('t1');
1629     my $t2 = $doc->create_text_node ('t2');
1630     $el->append_child ($t1);
1631     $el->append_child ($t2);
1632     $el->normalize;
1633    
1634     ok $el->text_content, 't1t2', 'normalize [0]';
1635     ok 0+@{$el->child_nodes}, 1, 'normalize [1]';
1636     }
1637    
1638     {
1639     my $el = $doc->create_element ('el');
1640     my $t1 = $doc->create_text_node ('t1');
1641     my $t2 = $doc->create_text_node ('t2');
1642     my $t3 = $doc->create_text_node ('t3');
1643     my $t4 = $doc->create_text_node ('t4');
1644     $el->append_child ($t1);
1645     $el->append_child ($t2);
1646     $el->append_child ($t3);
1647     $el->append_child ($t4);
1648     $el->normalize;
1649    
1650     ok $el->text_content, 't1t2t3t4', 'normalize [2]';
1651     ok 0+@{$el->child_nodes}, 1, 'normalize [3]';
1652     }
1653    
1654     {
1655     my $el = $doc->create_element ('el');
1656     my $t1 = $doc->create_text_node ('t1');
1657     my $t2 = $doc->create_text_node ('t2');
1658     my $c1 = $doc->create_cdata_section ('c1');
1659     my $t3 = $doc->create_text_node ('t3');
1660     my $t4 = $doc->create_text_node ('t4');
1661     $el->append_child ($t1);
1662     $el->append_child ($t2);
1663     $el->append_child ($c1);
1664     $el->append_child ($t3);
1665     $el->append_child ($t4);
1666     $el->normalize;
1667    
1668     ok $el->text_content, 't1t2c1t3t4', 'normalize [4]';
1669     ok 0+@{$el->child_nodes}, 3, 'normalize [5]';
1670     ok $el->first_child->text_content, 't1t2', 'normalize [6]';
1671     ok $el->last_child->text_content, 't3t4', 'normalize [7]';
1672     }
1673    
1674     {
1675     my $el = $doc->create_element ('el');
1676     my $t1 = $doc->create_text_node ('t1');
1677     my $t2 = $doc->create_text_node ('');
1678     $el->append_child ($t1);
1679     $el->append_child ($t2);
1680     $el->normalize;
1681    
1682     ok $el->text_content, 't1', 'normalize [8]';
1683     ok 0+@{$el->child_nodes}, 1, 'normalize [9]';
1684     }
1685    
1686     {
1687     my $el = $doc->create_element ('el');
1688     my $t1 = $doc->create_text_node ('');
1689     my $t2 = $doc->create_text_node ('t2');
1690     $el->append_child ($t1);
1691     $el->append_child ($t2);
1692     $el->normalize;
1693    
1694     ok $el->text_content, 't2', 'normalize [10]';
1695     ok 0+@{$el->child_nodes}, 1, 'normalize [11]';
1696     }
1697    
1698     {
1699     my $el = $doc->create_element ('el');
1700     my $t1 = $doc->create_text_node ('');
1701     $el->append_child ($t1);
1702     $el->normalize;
1703    
1704     ok $el->text_content, '', 'normalize [12]';
1705     ok 0+@{$el->child_nodes}, 0, 'normalize [13]';
1706     }
1707    
1708     {
1709     my $pe = $doc->create_element ('pe');
1710     my $el = $doc->create_element ('el');
1711     my $t1 = $doc->create_text_node ('t1');
1712     my $t2 = $doc->create_text_node ('t2');
1713     $el->append_child ($t1);
1714     $el->append_child ($t2);
1715     $pe->append_child ($el);
1716     $pe->normalize;
1717    
1718     ok $el->text_content, 't1t2', 'normalize [14]';
1719     ok 0+@{$el->child_nodes}, 1, 'normalize [15]';
1720     }
1721    
1722     {
1723     my $pe = $doc->create_element ('pe');
1724     my $el = $doc->create_attribute ('a');
1725     my $t1 = $doc->create_text_node ('t1');
1726     my $t2 = $doc->create_text_node ('t2');
1727     $el->append_child ($t1);
1728     $el->append_child ($t2);
1729     $pe->set_attribute_node ($el);
1730     $pe->normalize;
1731    
1732     ok $el->text_content, 't1t2', 'normalize [16]';
1733     ok 0+@{$el->child_nodes}, 1, 'normalize [17]';
1734     }
1735    
1736     {
1737     my $pe = $doc->create_element_type_definition ('pe');
1738     my $el = $doc->create_attribute_definition ('a');
1739     my $t1 = $doc->create_text_node ('t1');
1740     my $t2 = $doc->create_text_node ('t2');
1741     $el->append_child ($t1);
1742     $el->append_child ($t2);
1743     $pe->set_attribute_definition_node ($el);
1744     $pe->normalize;
1745    
1746     ok $el->text_content, 't1t2', 'normalize [16]';
1747     ok 0+@{$el->child_nodes}, 1, 'normalize [17]';
1748     }
1749    
1750     {
1751     my $dt = $doc->create_document_type_definition ('dt');
1752     my $pe = $doc->create_element_type_definition ('pe');
1753     my $el = $doc->create_attribute_definition ('a');
1754     my $t1 = $doc->create_text_node ('t1');
1755     my $t2 = $doc->create_text_node ('t2');
1756     $el->append_child ($t1);
1757     $el->append_child ($t2);
1758     $pe->set_attribute_definition_node ($el);
1759     $dt->set_element_type_definition_node ($pe);
1760     $dt->normalize;
1761    
1762     ok $el->text_content, 't1t2', 'normalize [18]';
1763     ok 0+@{$el->child_nodes}, 1, 'normalize [19]';
1764     }
1765    
1766     {
1767     my $pe = $doc->create_document_type_definition ('pe');
1768     my $el = $doc->create_general_entity ('a');
1769     my $t1 = $doc->create_text_node ('t1');
1770     my $t2 = $doc->create_text_node ('t2');
1771     $el->append_child ($t1);
1772     $el->append_child ($t2);
1773     $pe->set_general_entity_node ($el);
1774     $pe->normalize;
1775    
1776     ok $el->text_content, 't1t2', 'normalize [20]';
1777     ok 0+@{$el->child_nodes}, 1, 'normalize [21]';
1778     }
1779 wakaba 1.4
1780 wakaba 1.11 ## |getFeature| and |isSupported|
1781     for my $node (create_nodes ()) {
1782     for (
1783     [Core => '1.0', 1],
1784     [Core => '2.0', 1],
1785     [Core => '3.0', 1],
1786     ['+Core' => '3.0', 1],
1787     ['++Core' => '3.0', 0],
1788     [Core => '', 1],
1789     [Core => undef, 1],
1790     [Core => 3, 0],
1791     [XML => '1.0', 1],
1792     [XML => '2.0', 1],
1793     [XML => '3.0', 1],
1794     [XML => '', 1],
1795     [XML => undef, 1],
1796     ['+XML' => undef, 1],
1797     [XMLVersion => '1.0', 1],
1798     [XMLVersion => '1.1', 1],
1799     [XMLVersion => '', 1],
1800     [XMLVersion => undef, 1],
1801     ['+XMLVersion' => undef, 1],
1802     [unknown => 3, 0],
1803     [unknown => '', 0],
1804     [unknown => undef, 0],
1805     ['+unknown' => undef, 0],
1806 wakaba 1.13 [q<http://suika.fam.cx/www/2006/feature/xdoctype> => '', 1],
1807     [q<http://suika.fam.cx/www/2006/feature/xdoctype> => '3.0', 1],
1808 wakaba 1.11 ) {
1809     my $label = $node->node_name . ' ' . $_->[0] . ', ' .
1810     (defined $_->[1] ? $_->[1] : 'undef');
1811     ok $node->can ('get_feature') ? 1 : 0, 1, 'can get_feature ' . $label;
1812     ok $node->get_feature ($_->[0], $_->[1]), $_->[2] ? $node : undef,
1813     'get_feature ' . $label;
1814     ok $node->can ('is_supported') ? 1 : 0, 1, 'can is_supported ' . $label;
1815     ok $node->is_supported ($_->[0], $_->[1]) ? 1 : 0, $_->[2],
1816     'is_supported ' . $label;
1817     }
1818     }
1819    
1820     ## |isEqualNode|
1821     for my $node (create_nodes ()) {
1822     ok $node->can ('is_equal_node') ? 1 : 0, 1, $node->node_name . '->is_eq_n can';
1823    
1824     ok $node->is_equal_node ($node) ? 1 : 0, 1, $node->node_name . '->iseq self';
1825     ok $node == $node ? 1 : 0, 1, $node->node_name . ' == self';
1826     ok $node != $node ? 1 : 0, 0, $node->node_name . ' != self';
1827     ok $node == 'node' ? 1 : 0, 0, $node->node_name . ' == string';
1828     ok $node != 'node' ? 1 : 0, 1, $node->node_name . ' != string';
1829     ok $node == 0 ? 1 : 0, 0, $node->node_name . ' == num';
1830     ok $node != 0 ? 1 : 0, 1, $node->node_name . ' != num';
1831     ok $node == '' ? 1 : 0, 0, $node->node_name . ' == empty';
1832     ok $node != '' ? 1 : 0, 1, $node->node_name . ' != empty';
1833     ok $node == undef () ? 1 : 0, 0, $node->node_name . ' == undef';
1834     ok $node != undef () ? 1 : 0, 1, $node->node_name . ' != undef';
1835     }
1836    
1837     {
1838     my $el1 = $doc->create_element_ns (undef, 'type');
1839     my $el2 = $doc->create_element_ns (undef, 'type');
1840     my $el3 = $doc->create_element_ns (undef, 'TYPE');
1841    
1842     ok $el1 == $el2 ? 1 : 0, 1, 'Element == [1]';
1843     ok $el1 != $el2 ? 1 : 0, 0, 'Element != [1]';
1844     ok $el1 == $el3 ? 1 : 0, 0, 'Element == [2]';
1845     ok $el1 != $el3 ? 1 : 0, 1, 'Element != [2]';
1846    
1847     my $el4 = $doc->create_element_ns ('about:', 'type');
1848     my $el5 = $doc->create_element_ns ('about:', 'type');
1849     my $el6 = $doc->create_element_ns ('about:', 'TYPE');
1850     my $el7 = $doc->create_element_ns ('DAV:', 'type');
1851    
1852     ok $el1 == $el4 ? 1 : 0, 0, 'Element == [3]';
1853     ok $el1 != $el4 ? 1 : 0, 1, 'Element != [3]';
1854     ok $el4 == $el5 ? 1 : 0, 1, 'Element == [4]';
1855     ok $el4 != $el5 ? 1 : 0, 0, 'Element != [4]';
1856     ok $el4 == $el6 ? 1 : 0, 0, 'Element == [5]';
1857     ok $el4 != $el6 ? 1 : 0, 1, 'Element != [5]';
1858     ok $el4 == $el7 ? 1 : 0, 0, 'Element == [6]';
1859     ok $el4 != $el7 ? 1 : 0, 1, 'Element != [6]';
1860    
1861     $el5->prefix ('prefix');
1862     ok $el4 == $el5 ? 1 : 0, 0, 'Element == [7]';
1863     ok $el4 != $el5 ? 1 : 0, 1, 'Element != [7]';
1864     }
1865    
1866     ## |getUserData|, |setUserData|
1867     {
1868     my $node = $dom->create_document;
1869    
1870     my $data = ['2'];
1871     my $handler = sub { 1 };
1872    
1873     ok $node->set_user_data ('key1', $data, $handler), undef,
1874     'set_user_data [1]';
1875    
1876     my $key1_data = $node->get_user_data ('key1');
1877     ok $key1_data, $data, 'set_user_data [2]';
1878     ok $key1_data->[0], $data->[0], 'set_user_data [3]';
1879    
1880     my $data2 = ['4'];
1881     ok $node->set_user_data ('key1', $data2, undef), $data, 'set_user_data [4]';
1882     ok $node->get_user_data ('key1'), $data2, 'set_user_data [5]';
1883    
1884     $node->set_user_data (key1 => undef, $handler);
1885     ok $node->get_user_data ('key1'), undef, 'set_user_data [6]';
1886    
1887     $node->set_user_data (key1 => undef, undef);
1888     ok $node->get_user_data ('key1'), undef, 'set_user_data [7]';
1889     }
1890    
1891 wakaba 1.12 ## |removeChild|
1892     {
1893     my $el = $doc->create_element ('p');
1894     my $c1 = $doc->create_element ('e');
1895     $el->append_child ($c1);
1896     my $c2 = $doc->create_element ('f');
1897     $el->append_child ($c2);
1898     my $c3 = $doc->create_element ('g');
1899     $el->append_child ($c3);
1900     ok $el->can ('remove_child') ? 1 : 0, 1, 'Node->remove_child can [0]';
1901    
1902     my $return = $el->remove_child ($c1);
1903     ok $return, $c1, 'Node->remove_child return [1]';
1904     ok $c1->parent_node, undef, 'Node->remove_child parent_node [1]';
1905     ok $el->first_child, $c2, 'Node->remove_child first_child [1]';
1906     ok $el->last_child, $c3, 'Node->remove_child last_child [1]';
1907     ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [1]';
1908     }
1909     {
1910     my $el = $doc->create_element ('p');
1911     my $c1 = $doc->create_element ('e');
1912     $el->append_child ($c1);
1913     my $c2 = $doc->create_element ('f');
1914     $el->append_child ($c2);
1915     my $c3 = $doc->create_element ('g');
1916     $el->append_child ($c3);
1917    
1918     my $return = $el->remove_child ($c2);
1919     ok $return, $c2, 'Node->remove_child return [2]';
1920     ok $c2->parent_node, undef, 'Node->remove_child parent_node [2]';
1921     ok $el->first_child, $c1, 'Node->remove_child first_child [2]';
1922     ok $el->last_child, $c3, 'Node->remove_child last_child [2]';
1923     ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [2]';
1924     }
1925     {
1926     my $el = $doc->create_element ('p');
1927     my $c1 = $doc->create_element ('e');
1928     $el->append_child ($c1);
1929     my $c2 = $doc->create_element ('f');
1930     $el->append_child ($c2);
1931     my $c3 = $doc->create_element ('g');
1932     $el->append_child ($c3);
1933    
1934     my $return = $el->remove_child ($c3);
1935     ok $return, $c3, 'Node->remove_child return [3]';
1936     ok $c3->parent_node, undef, 'Node->remove_child parent_node [3]';
1937     ok $el->first_child, $c1, 'Node->remove_child first_child [3]';
1938     ok $el->last_child, $c2, 'Node->remove_child last_child [3]';
1939     ok 0+@{$el->child_nodes}, 2, 'Node->remove_child child_nodes [3]';
1940     }
1941     {
1942     my $el = $doc->create_element ('p');
1943     my $c1 = $doc->create_element ('e');
1944     $el->append_child ($c1);
1945    
1946     my $return = $el->remove_child ($c1);
1947     ok $return, $c1, 'Node->remove_child return [4]';
1948     ok $c1->parent_node, undef, 'Node->remove_child parent_node [4]';
1949     ok $el->first_child, undef, 'Node->remove_child first_child [4]';
1950     ok $el->last_child, undef, 'Node->remove_child last_child [4]';
1951     ok 0+@{$el->child_nodes}, 0, 'Node->remove_child child_nodes [4]';
1952     }
1953    
1954 wakaba 1.2 ## TODO: parent_node tests, as with append_child tests
1955    
1956 wakaba 1.3 ## TODO: text_content tests for CharacterData and PI
1957    
1958 wakaba 1.11 ## |UserDataHandler|, |setData|, and |NODE_DELETED|
1959     ## NOTE: This should be the last test, since it does define
1960     ## Node.DESTORY.
1961     {
1962     my $doc = $dom->create_document ('http://test/', 'ex');
1963     my $node = $doc->document_element;
1964    
1965     $node->set_user_data (key => {}, sub {
1966     my ($op, $key, $data, $src, $dest) = @_;
1967    
1968     ok $op, 3, 'set_user_data operation [8]'; # NODE_DELETED
1969     ok $key, 'key', 'set_user_data key [8]';
1970     ok ref $data, 'HASH', 'set_user_data data [8]';
1971     ok $src, undef, 'set_user_data src [8]';
1972     ok $dest, undef, 'set_user_data dest [8]';
1973     });
1974    
1975     undef $node;
1976     undef $doc;
1977    
1978     ## NOTE: We cannot control exactly when it is called.
1979     }
1980    
1981 wakaba 1.4 =head1 LICENSE
1982    
1983     Copyright 2007 Wakaba <w@suika.fam.cx>
1984 wakaba 1.3
1985 wakaba 1.4 This program is free software; you can redistribute it and/or
1986     modify it under the same terms as Perl itself.
1987 wakaba 1.2
1988 wakaba 1.4 =cut
1989 wakaba 1.2
1990 wakaba 1.13 ## $Date: 2007/07/08 05:42:37 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24