/[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.16 - (hide annotations) (download) (as text)
Sat Jul 14 09:19:11 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.15: +10 -3 lines
File MIME type: application/x-troff
++ manakai/t/ChangeLog	14 Jul 2007 09:19:01 -0000
	* DOM-Node.t: Test data for new constants and attributes
	are added.

	* DOM-TypeInfo.t: Tests for constants are added.

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

++ manakai/lib/Message/DOM/ChangeLog	14 Jul 2007 09:17:51 -0000
	* AttributeDefinition.pm (node_value): Implemented.
	(create_attribute_definition): Implemented.

	* DOMConfiguration.pm (%{}, TIEHASH,
	get_parameter, set_parameter, can_set_parameter,
	EXISTS, DELETE, parameter_names, FETCH, STORE,
	FIRSTKEY, LASTKEY): Implemented.

	* DOMDocument.pm (____new): Set |error-handler| default.
	(get_elements_by_tag_name, get_elements_by_tag_name_ns): Implemented.

	* DOMElement.pm (get_elements_by_tag_name, get_elements_by_tag_name_ns):
	Implemented.

	* DOMException.pm: Error types for |DOMConfiguration|
	are added.

	* DOMStringList.pm (Message::DOM::DOMStringList::StaticList): New
	class.

	* DocumentType.pm (get_element_type_definition_node,
	get_general_entity_node, get_notation_node,
	set_element_type_definition_node, set_general_entity_node,
	set_notation_node, create_document_type_definition): Implemented.

	* ElementTypeDefinition.pm (get_attribute_definition_node,
	set_attribute_definition_node, create_element_type_definition):
	Implemented.

	* Entity.pm (create_general_entity): Implemented.

	* Node.pm: Constants in |OperationType| definition
	group are added.
	(manakai_language): Implemented.

	* NodeList.pm (Message::DOM::NodeList::GetElementsList): New
	class.

	* Notation.pm (create_notation): Implemented.

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

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24