/[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.9 - (hide annotations) (download) (as text)
Sat Jul 7 11:11:34 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.8: +4 -1 lines
File MIME type: application/x-troff
++ manakai/t/ChangeLog	7 Jul 2007 11:11:27 -0000
	* DOM-Element.t: New tests for |create_element|
	and |create_element_ns| are added.

	* DOM-EntityReference.t: New tests for |create_entity_reference|
	are added.

	* DOM-Node.t: Test data for |is_element_content_whitespace|
	are added.

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

++ manakai/lib/Message/DOM/ChangeLog	7 Jul 2007 11:10:33 -0000
	* CDATASection.pm (is_element_content_whitespace): New.

	* DOMElement.pm (has_attribute): Alpha version.
	(create_element, create_element_ns): Implemented.

	* DocumentType.pm (get_general_entity_node): Alpha version.

	* EntityReference.pm (create_entity_reference): Implemented.

	* ProcessingInstruction.pm (create_processing_instruction): Implemented.

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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24