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