/[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.7 - (hide annotations) (download) (as text)
Thu Jun 21 14:57:53 2007 UTC (17 years, 5 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +24 -1 lines
File MIME type: application/x-troff
++ manakai/t/ChangeLog	21 Jun 2007 14:57:40 -0000
2007-06-21  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Node.t: Tests for |node_type| are added.

++ manakai/lib/Message/DOM/ChangeLog	21 Jun 2007 14:57:15 -0000
	* Comment.pm (node_type): Node type was incorrect!

	* DOMConfiguration.pm (get_parameter): Alpha.

	* DOMImplementation.pm (create_mc_decode_handler,
	create_charset_name_from_uri, create_uri_from_charset_name):
	New autoload configuration.  Note that the Message::Charset::Encode
	module is subject to change.

	* XMLParserTemp.pm: Now it can be used with new version
	of DOM implementation.  Current plan is to replace it by
	an XML5 parser someday.

2007-06-21  Wakaba  <wakaba@suika.fam.cx>

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24