/[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.14 - (hide annotations) (download) (as text)
Thu Jul 12 13:54:47 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.13: +14 -6 lines
File MIME type: application/x-troff
++ manakai/t/ChangeLog	12 Jul 2007 13:53:24 -0000
2007-07-12  Wakaba  <wakaba@suika.fam.cx>

	* DOM-Node.t: New attributes are added and
	some test results has been changed to sync with new implementation.

++ manakai/lib/Message/DOM/ChangeLog	12 Jul 2007 13:52:28 -0000
2007-07-12  Wakaba  <wakaba@suika.fam.cx>

	* AttributeDefinition.pm (owner_element_type_definition): Implemented.

	* DocumentType.pm (create_document_type_definition): Initialize
	|public_id|, |system_id|, and |internal_subset| attributes
	by empty strings for compatibility with Web browsers.
	(create_document_type): Initialize |internal_subset|
	attribute by an empty string for compatibility with
	Web browsers.

	* ElementTypeDefinition.pm, Entity.pm,
	Notation.pm (owner_document_type_definition): Implemented.

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24