/[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.15 - (show annotations) (download) (as text)
Sat Jul 14 06:12:56 2007 UTC (17 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.14: +8 -2 lines
File MIME type: application/x-troff
++ manakai/t/ChangeLog	14 Jul 2007 06:12:48 -0000
2007-07-14  Wakaba  <wakaba@suika.fam.cx>

	* DOM-TypeInfo.t: New test script.

	* DOM-Node.t: Test data for new attributes are added.

++ manakai/lib/Message/DOM/ChangeLog	14 Jul 2007 06:11:45 -0000
2007-07-14  Wakaba  <wakaba@suika.fam.cx>

	* TypeInfo.pm: New Perl module.

	* Attr.pm: Use |manakai_local_name| rather than |local_name|
	to avoid HTML5 case normalization.
	(is_id): Implemented.
	(manakai_name): New attribute.
	(schema_type_info): Implemented.
	(create_attribute_ns): Empty string as namespace URI
	was not supported.

	* DOMElement.pm (clone_node): Removed since now it is
	defined in |Node.pm|.
	(schema_type_info): Implemented.
	(manakai_tag_name): New attribute.
	(get_attribute, get_attribute_node, get_attribute_ns,
	get_attribute_node_ns, has_attribute, has_attribute_ns,
	remove_attribute, remove_attribute_ns,
	remove_attribute_node, set_attribute, set_attribute_ns,
	set_id_attribute, set_id_attribute_node,
	set_id_attribute_ns): Implemented.
	(create_element_ns): Empty string as namespace URI
	was not supported.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24