1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
wakaba |
1.4 |
BEGIN { plan tests => 1921 } |
5 |
wakaba |
1.1 |
|
6 |
|
|
require Message::DOM::DOMImplementation; |
7 |
wakaba |
1.3 |
use Message::Util::Error; |
8 |
wakaba |
1.1 |
|
9 |
|
|
my $dom = Message::DOM::DOMImplementation->____new; |
10 |
|
|
my $doc = $dom->create_document; |
11 |
|
|
|
12 |
wakaba |
1.4 |
|
13 |
|
|
sub create_nodes () { |
14 |
|
|
( |
15 |
|
|
$doc->create_attribute ('attr1'), |
16 |
|
|
$doc->create_attribute_definition ('at1'), |
17 |
|
|
$doc->create_cdata_section ('cdata1'), |
18 |
|
|
$doc->create_comment ('comment1'), |
19 |
|
|
$doc->create_element ('element1'), |
20 |
|
|
$doc->create_element_type_definition ('et1'), |
21 |
|
|
$doc->create_general_entity ('entity1'), |
22 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
23 |
|
|
$doc->implementation->create_document, |
24 |
|
|
$doc->create_document_fragment, |
25 |
|
|
$doc->create_document_type_definition ('dt1'), |
26 |
|
|
$doc->create_notation ('notation1'), |
27 |
|
|
$doc->create_processing_instruction ('pi1', 'pi1data'), |
28 |
|
|
$doc->create_text_node ('text1'), |
29 |
|
|
); |
30 |
|
|
} # create_nodes |
31 |
|
|
|
32 |
|
|
sub create_parent_nodes () { |
33 |
|
|
( |
34 |
|
|
$doc->create_attribute ('attr1'), |
35 |
|
|
$doc->create_attribute_definition ('at1'), |
36 |
|
|
$doc->create_element ('element1'), |
37 |
|
|
$doc->create_general_entity ('entity1'), |
38 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
39 |
|
|
$doc->implementation->create_document, |
40 |
|
|
$doc->create_document_fragment, |
41 |
|
|
$doc->create_document_type_definition ('dt1'), |
42 |
|
|
); |
43 |
|
|
} # create_parent_nodes |
44 |
|
|
|
45 |
wakaba |
1.1 |
## Constants |
46 |
|
|
my $constants = [ |
47 |
|
|
[ELEMENT_NODE => 1], |
48 |
|
|
[ATTRIBUTE_NODE => 2], |
49 |
|
|
[TEXT_NODE => 3], |
50 |
|
|
[CDATA_SECTION_NODE => 4], |
51 |
|
|
[ENTITY_REFERENCE_NODE => 5], |
52 |
|
|
[ENTITY_NODE => 6], |
53 |
|
|
[PROCESSING_INSTRUCTION_NODE => 7], |
54 |
|
|
[COMMENT_NODE => 8], |
55 |
|
|
[DOCUMENT_NODE => 9], |
56 |
|
|
[DOCUMENT_TYPE_NODE => 10], |
57 |
|
|
[DOCUMENT_FRAGMENT_NODE => 11], |
58 |
|
|
[NOTATION_NODE => 12], |
59 |
|
|
[ELEMENT_TYPE_DEFINITION_NODE => 81001], |
60 |
|
|
[ATTRIBUTE_DEFINITION_NODE => 81002], |
61 |
|
|
]; |
62 |
|
|
|
63 |
|
|
my $tests = { |
64 |
wakaba |
1.4 |
attr1 => { |
65 |
|
|
node => sub { return $doc->create_attribute ('a') }, |
66 |
|
|
attr_get => { |
67 |
|
|
manakai_attribute_type => 0, |
68 |
|
|
base_uri => undef, |
69 |
|
|
first_child => undef, |
70 |
|
|
last_child => undef, |
71 |
|
|
local_name => 'a', |
72 |
|
|
manakai_local_name => 'a', |
73 |
|
|
namespace_uri => undef, |
74 |
|
|
next_sibling => undef, |
75 |
|
|
node_name => 'a', |
76 |
|
|
name => 'a', |
77 |
|
|
node_value => '', |
78 |
|
|
owner_document => $doc, |
79 |
|
|
parent_node => undef, |
80 |
|
|
prefix => undef, |
81 |
|
|
previous_sibling => undef, |
82 |
|
|
value => '', |
83 |
|
|
attributes => undef, |
84 |
|
|
}, |
85 |
|
|
attr_get_bool => { |
86 |
|
|
specified => 1, |
87 |
|
|
}, |
88 |
|
|
}, |
89 |
|
|
attr2 => { |
90 |
wakaba |
1.1 |
node => sub { |
91 |
|
|
my $attr = $doc->create_attribute ('a'); |
92 |
|
|
$attr->value ('b'); |
93 |
|
|
return $attr; |
94 |
|
|
}, |
95 |
|
|
attr_get => { |
96 |
wakaba |
1.4 |
manakai_attribute_type => 0, |
97 |
|
|
base_uri => undef, |
98 |
wakaba |
1.2 |
local_name => 'a', |
99 |
|
|
manakai_local_name => 'a', |
100 |
|
|
namespace_uri => undef, |
101 |
|
|
next_sibling => undef, |
102 |
wakaba |
1.1 |
node_name => 'a', |
103 |
|
|
name => 'a', |
104 |
|
|
node_value => 'b', |
105 |
wakaba |
1.2 |
owner_document => $doc, |
106 |
|
|
parent_node => undef, |
107 |
|
|
prefix => undef, |
108 |
|
|
previous_sibling => undef, |
109 |
wakaba |
1.1 |
value => 'b', |
110 |
|
|
attributes => undef, |
111 |
|
|
}, |
112 |
wakaba |
1.4 |
attr_get_bool => { |
113 |
|
|
specified => 1, |
114 |
|
|
}, |
115 |
wakaba |
1.1 |
}, |
116 |
|
|
attr_ns_default => { |
117 |
wakaba |
1.4 |
node => sub { return $doc->create_attribute_ns (undef, 'a') }, |
118 |
wakaba |
1.1 |
attr_get => { |
119 |
wakaba |
1.4 |
base_uri => undef, |
120 |
wakaba |
1.2 |
local_name => 'a', |
121 |
|
|
manakai_local_name => 'a', |
122 |
|
|
namespace_uri => undef, |
123 |
|
|
next_sibling => undef, |
124 |
wakaba |
1.1 |
node_name => 'a', |
125 |
|
|
name => 'a', |
126 |
wakaba |
1.4 |
node_value => '', |
127 |
wakaba |
1.2 |
owner_document => $doc, |
128 |
|
|
parent_node => undef, |
129 |
|
|
prefix => undef, |
130 |
wakaba |
1.4 |
value => '', |
131 |
wakaba |
1.1 |
attributes => undef, |
132 |
wakaba |
1.2 |
previous_sibling => undef, |
133 |
wakaba |
1.1 |
}, |
134 |
|
|
}, |
135 |
|
|
attr_ns_prefixed => { |
136 |
wakaba |
1.4 |
node => sub { return $doc->create_attribute_ns ('http://test/', 'a:b') }, |
137 |
wakaba |
1.1 |
attr_get => { |
138 |
wakaba |
1.4 |
base_uri => undef, |
139 |
wakaba |
1.2 |
local_name => 'b', |
140 |
|
|
manakai_local_name => 'b', |
141 |
|
|
namespace_uri => 'http://test/', |
142 |
|
|
next_sibling => undef, |
143 |
wakaba |
1.1 |
node_name => 'a:b', |
144 |
|
|
name => 'a:b', |
145 |
wakaba |
1.4 |
node_value => '', |
146 |
wakaba |
1.2 |
owner_document => $doc, |
147 |
|
|
parent_node => undef, |
148 |
|
|
prefix => 'a', |
149 |
wakaba |
1.4 |
value => '', |
150 |
wakaba |
1.1 |
attributes => undef, |
151 |
wakaba |
1.2 |
previous_sibling => undef, |
152 |
wakaba |
1.1 |
}, |
153 |
|
|
}, |
154 |
|
|
cdatasection => { |
155 |
|
|
node => sub { return $doc->create_cdata_section ('cdatadata') }, |
156 |
|
|
attr_get => { |
157 |
wakaba |
1.4 |
base_uri => undef, |
158 |
wakaba |
1.2 |
first_child => undef, |
159 |
|
|
last_child => undef, |
160 |
|
|
local_name => undef, |
161 |
|
|
manakai_local_name => undef, |
162 |
|
|
namespace_uri => undef, |
163 |
|
|
next_sibling => undef, |
164 |
wakaba |
1.1 |
node_name => '#cdata-section', |
165 |
|
|
node_value => 'cdatadata', |
166 |
wakaba |
1.2 |
owner_document => $doc, |
167 |
|
|
parent_node => undef, |
168 |
|
|
prefix => undef, |
169 |
wakaba |
1.1 |
data => 'cdatadata', |
170 |
|
|
attributes => undef, |
171 |
wakaba |
1.2 |
previous_sibling => undef, |
172 |
wakaba |
1.1 |
}, |
173 |
|
|
}, |
174 |
|
|
cdatasectionmde => { |
175 |
|
|
node => sub { return $doc->create_cdata_section ('cdata]]>data') }, |
176 |
|
|
attr_get => { |
177 |
wakaba |
1.4 |
base_uri => undef, |
178 |
wakaba |
1.2 |
first_child => undef, |
179 |
|
|
last_child => undef, |
180 |
|
|
local_name => undef, |
181 |
|
|
manakai_local_name => undef, |
182 |
|
|
namespace_uri => undef, |
183 |
|
|
next_sibling => undef, |
184 |
wakaba |
1.1 |
node_name => '#cdata-section', |
185 |
|
|
node_value => 'cdata]]>data', |
186 |
wakaba |
1.2 |
owner_document => $doc, |
187 |
|
|
parent_node => undef, |
188 |
|
|
prefix => undef, |
189 |
wakaba |
1.1 |
data => 'cdata]]>data', |
190 |
|
|
attributes => undef, |
191 |
wakaba |
1.2 |
previous_sibling => undef, |
192 |
wakaba |
1.1 |
}, |
193 |
|
|
}, |
194 |
|
|
comment => { |
195 |
|
|
node => sub { return $doc->create_comment ('commentdata') }, |
196 |
|
|
attr_get => { |
197 |
wakaba |
1.4 |
base_uri => undef, |
198 |
wakaba |
1.2 |
first_child => undef, |
199 |
|
|
last_child => undef, |
200 |
|
|
local_name => undef, |
201 |
|
|
manakai_local_name => undef, |
202 |
|
|
namespace_uri => undef, |
203 |
|
|
next_sibling => undef, |
204 |
wakaba |
1.1 |
node_name => '#comment', |
205 |
|
|
node_value => 'commentdata', |
206 |
wakaba |
1.2 |
owner_document => $doc, |
207 |
|
|
parent_node => undef, |
208 |
|
|
prefix => undef, |
209 |
wakaba |
1.1 |
data => 'commentdata', |
210 |
|
|
attributes => undef, |
211 |
wakaba |
1.2 |
previous_sibling => undef, |
212 |
wakaba |
1.1 |
}, |
213 |
|
|
}, |
214 |
|
|
commentcom1 => { |
215 |
|
|
node => sub { return $doc->create_comment ('comment--data') }, |
216 |
|
|
attr_get => { |
217 |
wakaba |
1.4 |
base_uri => undef, |
218 |
wakaba |
1.2 |
first_child => undef, |
219 |
|
|
last_child => undef, |
220 |
|
|
local_name => undef, |
221 |
|
|
manakai_local_name => undef, |
222 |
|
|
namespace_uri => undef, |
223 |
|
|
next_sibling => undef, |
224 |
wakaba |
1.1 |
node_name => '#comment', |
225 |
|
|
node_value => 'comment--data', |
226 |
wakaba |
1.2 |
owner_document => $doc, |
227 |
|
|
parent_node => undef, |
228 |
|
|
prefix => undef, |
229 |
wakaba |
1.1 |
data => 'comment--data', |
230 |
|
|
attributes => undef, |
231 |
wakaba |
1.2 |
previous_sibling => undef, |
232 |
wakaba |
1.1 |
}, |
233 |
|
|
}, |
234 |
|
|
commentcom2 => { |
235 |
|
|
node => sub { return $doc->create_comment ('commentdata-') }, |
236 |
|
|
attr_get => { |
237 |
wakaba |
1.4 |
base_uri => undef, |
238 |
wakaba |
1.2 |
first_child => undef, |
239 |
|
|
last_child => undef, |
240 |
|
|
local_name => undef, |
241 |
|
|
manakai_local_name => undef, |
242 |
|
|
namespace_uri => undef, |
243 |
|
|
next_sibling => undef, |
244 |
wakaba |
1.1 |
node_name => '#comment', |
245 |
|
|
node_value => 'commentdata-', |
246 |
wakaba |
1.2 |
owner_document => $doc, |
247 |
|
|
parent_node => undef, |
248 |
|
|
prefix => undef, |
249 |
wakaba |
1.1 |
data => 'commentdata-', |
250 |
|
|
attributes => undef, |
251 |
wakaba |
1.2 |
previous_sibling => undef, |
252 |
wakaba |
1.1 |
}, |
253 |
|
|
}, |
254 |
|
|
document => { |
255 |
|
|
node => sub { return $doc }, |
256 |
|
|
attr_get => { |
257 |
|
|
attributes => undef, |
258 |
wakaba |
1.4 |
base_uri => undef, |
259 |
|
|
document_uri => undef, |
260 |
|
|
manakai_entity_base_uri => undef, |
261 |
wakaba |
1.2 |
first_child => undef, |
262 |
|
|
implementation => $dom, |
263 |
|
|
last_child => undef, |
264 |
wakaba |
1.1 |
local_name => undef, |
265 |
wakaba |
1.2 |
manakai_local_name => undef, |
266 |
wakaba |
1.1 |
namespace_uri => undef, |
267 |
wakaba |
1.2 |
next_sibling => undef, |
268 |
wakaba |
1.1 |
node_name => '#document', |
269 |
|
|
node_value => undef, |
270 |
wakaba |
1.2 |
owner_document => undef, |
271 |
wakaba |
1.1 |
parent_node => undef, |
272 |
|
|
prefix => undef, |
273 |
wakaba |
1.2 |
previous_sibling => undef, |
274 |
wakaba |
1.4 |
xml_encoding => undef, |
275 |
|
|
xml_version => '1.0', |
276 |
|
|
}, |
277 |
|
|
attr_get_bool => { |
278 |
|
|
all_declarations_processed => 0, |
279 |
|
|
manakai_is_html => 0, |
280 |
|
|
strict_error_checking => 1, |
281 |
|
|
xml_standalone => 0, |
282 |
wakaba |
1.1 |
}, |
283 |
|
|
}, |
284 |
|
|
document_fragment => { |
285 |
|
|
node => sub { return $doc->create_document_fragment }, |
286 |
|
|
attr_get => { |
287 |
|
|
attributes => undef, |
288 |
wakaba |
1.4 |
base_uri => undef, |
289 |
wakaba |
1.2 |
first_child => undef, |
290 |
|
|
last_child => undef, |
291 |
|
|
local_name => undef, |
292 |
|
|
manakai_local_name => undef, |
293 |
|
|
namespace_uri => undef, |
294 |
|
|
next_sibling => undef, |
295 |
wakaba |
1.1 |
node_name => '#document-fragment', |
296 |
|
|
node_value => undef, |
297 |
wakaba |
1.2 |
owner_document => $doc, |
298 |
|
|
parent_node => undef, |
299 |
|
|
prefix => undef, |
300 |
|
|
previous_sibling => undef, |
301 |
wakaba |
1.1 |
}, |
302 |
|
|
}, |
303 |
|
|
document_type => { |
304 |
|
|
node => sub { return $doc->implementation->create_document_type ('n') }, |
305 |
|
|
attr_get => { |
306 |
|
|
attributes => undef, |
307 |
wakaba |
1.4 |
base_uri => undef, |
308 |
|
|
declaration_base_uri => undef, |
309 |
|
|
manakai_declaration_base_uri => undef, |
310 |
wakaba |
1.2 |
first_child => undef, |
311 |
|
|
implementation => $dom, |
312 |
|
|
last_child => undef, |
313 |
|
|
local_name => undef, |
314 |
|
|
manakai_local_name => undef, |
315 |
|
|
namespace_uri => undef, |
316 |
|
|
next_sibling => undef, |
317 |
wakaba |
1.1 |
node_name => 'n', |
318 |
|
|
node_value => undef, |
319 |
wakaba |
1.2 |
owner_document => undef, |
320 |
|
|
parent_node => undef, |
321 |
|
|
prefix => undef, |
322 |
|
|
previous_sibling => undef, |
323 |
wakaba |
1.4 |
public_id => undef, |
324 |
|
|
system_id => undef, |
325 |
wakaba |
1.1 |
}, |
326 |
|
|
}, |
327 |
|
|
document_type_definition => { |
328 |
|
|
node => sub { return $doc->create_document_type_definition ('n') }, |
329 |
|
|
attr_get => { |
330 |
|
|
attributes => undef, |
331 |
wakaba |
1.4 |
base_uri => undef, |
332 |
|
|
declaration_base_uri => undef, |
333 |
|
|
manakai_declaration_base_uri => undef, |
334 |
wakaba |
1.2 |
first_child => undef, |
335 |
|
|
implementation => $dom, |
336 |
|
|
last_child => undef, |
337 |
|
|
local_name => undef, |
338 |
|
|
manakai_local_name => undef, |
339 |
|
|
namespace_uri => undef, |
340 |
|
|
next_sibling => undef, |
341 |
wakaba |
1.1 |
node_name => 'n', |
342 |
|
|
node_value => undef, |
343 |
wakaba |
1.2 |
owner_document => $doc, |
344 |
|
|
parent_node => undef, |
345 |
|
|
prefix => undef, |
346 |
|
|
previous_sibling => undef, |
347 |
wakaba |
1.4 |
public_id => undef, |
348 |
|
|
system_id => undef, |
349 |
wakaba |
1.1 |
}, |
350 |
|
|
}, |
351 |
|
|
element => { |
352 |
|
|
node => sub { return $doc->create_element ('e') }, |
353 |
|
|
attr_get => { |
354 |
|
|
## TODO: attributes => |
355 |
wakaba |
1.4 |
base_uri => undef, |
356 |
|
|
manakai_base_uri => undef, |
357 |
wakaba |
1.2 |
first_child => undef, |
358 |
|
|
last_child => undef, |
359 |
|
|
local_name => 'e', |
360 |
|
|
manakai_local_name => 'e', |
361 |
|
|
namespace_uri => undef, |
362 |
|
|
next_sibling => undef, |
363 |
wakaba |
1.1 |
node_name => 'e', |
364 |
|
|
node_value => undef, |
365 |
wakaba |
1.2 |
owner_document => $doc, |
366 |
|
|
parent_node => undef, |
367 |
|
|
prefix => undef, |
368 |
|
|
previous_sibling => undef, |
369 |
wakaba |
1.1 |
}, |
370 |
|
|
}, |
371 |
|
|
element_ns_default => { |
372 |
|
|
node => sub { return $doc->create_element_ns ('http://test/', 'f') }, |
373 |
|
|
attr_get => { |
374 |
|
|
## TODO: attributes => |
375 |
wakaba |
1.4 |
base_uri => undef, |
376 |
|
|
manakai_base_uri => undef, |
377 |
wakaba |
1.2 |
first_child => undef, |
378 |
|
|
last_child => undef, |
379 |
|
|
local_name => 'f', |
380 |
|
|
manakai_local_name => 'f', |
381 |
|
|
namespace_uri => 'http://test/', |
382 |
|
|
next_sibling => undef, |
383 |
wakaba |
1.1 |
node_name => 'f', |
384 |
|
|
node_value => undef, |
385 |
wakaba |
1.2 |
owner_document => $doc, |
386 |
|
|
parent_node => undef, |
387 |
|
|
prefix => undef, |
388 |
|
|
previous_sibling => undef, |
389 |
wakaba |
1.1 |
}, |
390 |
|
|
}, |
391 |
|
|
element_ns_prefiexed => { |
392 |
|
|
node => sub { return $doc->create_element_ns ('http://test/', 'e:f') }, |
393 |
|
|
attr_get => { |
394 |
|
|
## TODO: attributes => |
395 |
wakaba |
1.4 |
base_uri => undef, |
396 |
|
|
manakai_base_uri => undef, |
397 |
wakaba |
1.2 |
first_child => undef, |
398 |
|
|
last_child => undef, |
399 |
|
|
local_name => 'f', |
400 |
|
|
manakai_local_name => 'f', |
401 |
|
|
namespace_uri => 'http://test/', |
402 |
|
|
next_sibling => undef, |
403 |
wakaba |
1.1 |
node_name => 'e:f', |
404 |
|
|
node_value => undef, |
405 |
wakaba |
1.2 |
owner_document => $doc, |
406 |
|
|
parent_node => undef, |
407 |
|
|
prefix => 'e', |
408 |
|
|
previous_sibling => undef, |
409 |
wakaba |
1.1 |
}, |
410 |
|
|
}, |
411 |
|
|
entity => { |
412 |
|
|
node => sub { return $doc->create_general_entity ('e') }, |
413 |
|
|
attr_get => { |
414 |
|
|
attributes => undef, |
415 |
wakaba |
1.4 |
base_uri => undef, |
416 |
|
|
manakai_declaration_base_uri => undef, |
417 |
|
|
manakai_entity_base_uri => undef, |
418 |
|
|
manakai_entity_uri => undef, |
419 |
wakaba |
1.2 |
first_child => undef, |
420 |
|
|
last_child => undef, |
421 |
|
|
next_sibling => undef, |
422 |
wakaba |
1.1 |
node_name => 'e', |
423 |
|
|
node_value => undef, |
424 |
wakaba |
1.2 |
owner_document => $doc, |
425 |
|
|
parent_node => undef, |
426 |
|
|
previous_sibling => undef, |
427 |
wakaba |
1.4 |
public_id => undef, |
428 |
|
|
system_id => undef, |
429 |
wakaba |
1.1 |
}, |
430 |
|
|
}, |
431 |
|
|
entity_reference => { |
432 |
|
|
node => sub { return $doc->create_entity_reference ('e') }, |
433 |
|
|
attr_get => { |
434 |
|
|
attributes => undef, |
435 |
wakaba |
1.4 |
base_uri => undef, |
436 |
|
|
manakai_entity_base_uri => undef, |
437 |
wakaba |
1.2 |
first_child => undef, |
438 |
|
|
last_child => undef, |
439 |
|
|
local_name => undef, |
440 |
|
|
manakai_local_name => undef, |
441 |
|
|
namespace_uri => undef, |
442 |
|
|
next_sibling => undef, |
443 |
wakaba |
1.1 |
node_name => 'e', |
444 |
|
|
node_value => undef, |
445 |
wakaba |
1.2 |
owner_document => $doc, |
446 |
|
|
parent_node => undef, |
447 |
|
|
prefix => undef, |
448 |
|
|
previous_sibling => undef, |
449 |
wakaba |
1.1 |
}, |
450 |
wakaba |
1.4 |
attr_get_bool => { |
451 |
|
|
manakai_expanded => 0, |
452 |
|
|
manakai_external => 0, |
453 |
|
|
}, |
454 |
wakaba |
1.1 |
}, |
455 |
|
|
notation => { |
456 |
|
|
node => sub { return $doc->create_notation ('e') }, |
457 |
|
|
attr_get => { |
458 |
|
|
attributes => undef, |
459 |
wakaba |
1.4 |
base_uri => undef, |
460 |
|
|
manakai_declaration_base_uri => undef, |
461 |
wakaba |
1.2 |
first_child => undef, |
462 |
|
|
last_child => undef, |
463 |
|
|
local_name => undef, |
464 |
|
|
manakai_local_name => undef, |
465 |
|
|
namespace_uri => undef, |
466 |
|
|
next_sibling => undef, |
467 |
wakaba |
1.1 |
node_name => 'e', |
468 |
|
|
node_value => undef, |
469 |
wakaba |
1.2 |
owner_document => $doc, |
470 |
|
|
parent_node => undef, |
471 |
|
|
prefix => undef, |
472 |
|
|
previous_sibling => undef, |
473 |
wakaba |
1.4 |
public_id => undef, |
474 |
|
|
system_id => undef, |
475 |
wakaba |
1.1 |
}, |
476 |
|
|
}, |
477 |
|
|
processing_instruction => { |
478 |
|
|
node => sub { return $doc->create_processing_instruction ('t', 'd') }, |
479 |
|
|
attr_get => { |
480 |
|
|
attributes => undef, |
481 |
wakaba |
1.4 |
base_uri => undef, |
482 |
|
|
manakai_base_uri => undef, |
483 |
wakaba |
1.2 |
first_child => undef, |
484 |
|
|
last_child => undef, |
485 |
|
|
local_name => undef, |
486 |
|
|
manakai_local_name => undef, |
487 |
|
|
namespace_uri => undef, |
488 |
|
|
next_sibling => undef, |
489 |
wakaba |
1.1 |
node_name => 't', |
490 |
|
|
node_value => 'd', |
491 |
wakaba |
1.2 |
owner_document => $doc, |
492 |
|
|
parent_node => undef, |
493 |
|
|
prefix => undef, |
494 |
|
|
previous_sibling => undef, |
495 |
wakaba |
1.1 |
}, |
496 |
|
|
}, |
497 |
|
|
text => { |
498 |
|
|
node => sub { return $doc->create_text_node ('textdata') }, |
499 |
|
|
attr_get => { |
500 |
|
|
attributes => undef, |
501 |
wakaba |
1.4 |
base_uri => undef, |
502 |
wakaba |
1.2 |
first_child => undef, |
503 |
|
|
last_child => undef, |
504 |
|
|
local_name => undef, |
505 |
|
|
manakai_local_name => undef, |
506 |
|
|
namespace_uri => undef, |
507 |
|
|
next_sibling => undef, |
508 |
wakaba |
1.1 |
node_name => '#text', |
509 |
|
|
node_value => 'textdata', |
510 |
wakaba |
1.2 |
owner_document => $doc, |
511 |
|
|
parent_node => undef, |
512 |
|
|
prefix => undef, |
513 |
|
|
previous_sibling => undef, |
514 |
wakaba |
1.1 |
}, |
515 |
|
|
}, |
516 |
|
|
element_type_definition => { |
517 |
|
|
node => sub { return $doc->create_element_type_definition ('e') }, |
518 |
|
|
attr_get => { |
519 |
|
|
attributes => undef, |
520 |
wakaba |
1.4 |
base_uri => undef, |
521 |
wakaba |
1.2 |
first_child => undef, |
522 |
|
|
last_child => undef, |
523 |
|
|
local_name => undef, |
524 |
|
|
manakai_local_name => undef, |
525 |
|
|
namespace_uri => undef, |
526 |
|
|
next_sibling => undef, |
527 |
wakaba |
1.1 |
node_name => 'e', |
528 |
|
|
node_value => undef, |
529 |
wakaba |
1.2 |
owner_document => $doc, |
530 |
|
|
parent_node => undef, |
531 |
|
|
prefix => undef, |
532 |
|
|
previous_sibling => undef, |
533 |
wakaba |
1.1 |
}, |
534 |
|
|
}, |
535 |
|
|
attribute_definition => { |
536 |
|
|
node => sub { return $doc->create_attribute_definition ('e') }, |
537 |
|
|
attr_get => { |
538 |
|
|
attributes => undef, |
539 |
wakaba |
1.4 |
base_uri => undef, |
540 |
|
|
declared_type => 0, |
541 |
|
|
default_type => 0, |
542 |
wakaba |
1.2 |
first_child => undef, |
543 |
|
|
last_child => undef, |
544 |
|
|
local_name => undef, |
545 |
|
|
manakai_local_name => undef, |
546 |
|
|
namespace_uri => undef, |
547 |
|
|
next_sibling => undef, |
548 |
wakaba |
1.1 |
node_name => 'e', |
549 |
|
|
node_value => undef, |
550 |
wakaba |
1.2 |
owner_document => $doc, |
551 |
|
|
parent_node => undef, |
552 |
|
|
prefix => undef, |
553 |
|
|
previous_sibling => undef, |
554 |
wakaba |
1.1 |
}, |
555 |
|
|
}, |
556 |
|
|
}; |
557 |
|
|
|
558 |
|
|
for my $test_id (sort {$a cmp $b} keys %$tests) { |
559 |
|
|
my $test_def = $tests->{$test_id}; |
560 |
|
|
my $node = $test_def->{node}->(); |
561 |
|
|
|
562 |
|
|
for (@$constants) { |
563 |
|
|
my $const_name = $_->[0]; |
564 |
|
|
ok $node->can ($const_name) ? 1 : 0, 1, "$test_id->can ($const_name)"; |
565 |
|
|
ok $node->$const_name, $_->[1], "$test_id.$const_name"; |
566 |
|
|
} |
567 |
|
|
|
568 |
|
|
for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get}}) { |
569 |
|
|
my $expected = $test_def->{attr_get}->{$attr_name}; |
570 |
|
|
ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)"; |
571 |
|
|
my $actual = $node->$attr_name; |
572 |
|
|
ok $actual, $expected, "$test_id.$attr_name.get"; |
573 |
|
|
} |
574 |
wakaba |
1.4 |
|
575 |
|
|
for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get_bool} or {}}) { |
576 |
|
|
my $expected = $test_def->{attr_get_bool}->{$attr_name} ? 1 : 0; |
577 |
|
|
ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)"; |
578 |
|
|
my $actual = $node->$attr_name ? 1 : 0; |
579 |
|
|
ok $actual, $expected, "$test_id.$attr_name.get"; |
580 |
|
|
} |
581 |
wakaba |
1.1 |
} |
582 |
|
|
|
583 |
wakaba |
1.2 |
## Child node accessors' tests |
584 |
|
|
for my $parent (create_parent_nodes ()) { |
585 |
|
|
my $node1; |
586 |
|
|
my $node2; |
587 |
|
|
my $node3; |
588 |
|
|
if ($parent->node_type == $parent->DOCUMENT_TYPE_NODE) { |
589 |
|
|
$node1 = $doc->create_processing_instruction ('pi1', 'data1'); |
590 |
|
|
$node2 = $doc->create_processing_instruction ('pi2', 'data2'); |
591 |
|
|
$node3 = $doc->create_processing_instruction ('pi3', 'data3'); |
592 |
|
|
} elsif ($parent->node_type == $parent->DOCUMENT_NODE) { |
593 |
|
|
$node1 = $doc->create_comment ('comment1'); |
594 |
|
|
$node2 = $doc->create_comment ('comment2'); |
595 |
|
|
$node3 = $doc->create_comment ('comment3'); |
596 |
|
|
} else { |
597 |
|
|
$node1 = $doc->create_text_node ('text1'); |
598 |
|
|
$node2 = $doc->create_text_node ('text2'); |
599 |
|
|
$node3 = $doc->create_text_node ('text3'); |
600 |
|
|
} |
601 |
|
|
|
602 |
|
|
$parent->append_child ($node1); |
603 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [1]"; |
604 |
|
|
ok $parent->last_child, $node1, $parent->node_name."->last_child [1]"; |
605 |
|
|
ok $node1->next_sibling, undef, $parent->node_name."->next_sibling [1]"; |
606 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."->previous_sibling [1]"; |
607 |
|
|
|
608 |
|
|
$parent->append_child ($node2); |
609 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [2]"; |
610 |
|
|
ok $parent->last_child, $node2, $parent->node_name."->last_child [2]"; |
611 |
|
|
ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [2]"; |
612 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [2]"; |
613 |
|
|
ok $node2->next_sibling, undef, $parent->node_name."2->next_sibling [2]"; |
614 |
|
|
ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [2]"; |
615 |
|
|
|
616 |
|
|
$parent->append_child ($node3); |
617 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [3]"; |
618 |
|
|
ok $parent->last_child, $node3, $parent->node_name."->last_child [3]"; |
619 |
|
|
ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [3]"; |
620 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [3]"; |
621 |
|
|
ok $node2->next_sibling, $node3, $parent->node_name."2->next_sibling [3]"; |
622 |
|
|
ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [3]"; |
623 |
|
|
ok $node3->next_sibling, undef, $parent->node_name."3->next_sibling [3]"; |
624 |
|
|
ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]"; |
625 |
|
|
} |
626 |
|
|
|
627 |
wakaba |
1.3 |
## |prefix| setter |
628 |
|
|
for my $node (create_nodes ()) { |
629 |
|
|
$node->manakai_set_read_only (0); |
630 |
|
|
|
631 |
|
|
$node->prefix ('non-null'); |
632 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
633 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
634 |
|
|
ok $node->prefix, 'non-null', $node->node_name . '->prefix (non-null)'; |
635 |
|
|
} else { |
636 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (non-null)'; |
637 |
|
|
} |
638 |
|
|
|
639 |
|
|
$node->prefix (undef); |
640 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
641 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
642 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
643 |
|
|
} else { |
644 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
645 |
|
|
} |
646 |
|
|
|
647 |
|
|
$node->manakai_set_read_only (1); |
648 |
|
|
my $err_type; |
649 |
|
|
try { |
650 |
|
|
$node->prefix ('non-null'); |
651 |
|
|
} catch Message::IF::DOMException with { |
652 |
|
|
my $err = shift; |
653 |
|
|
$err_type = $err->type; |
654 |
|
|
}; |
655 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
656 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
657 |
|
|
ok $err_type, 'NO_MODIFICATION_ALLOWED_ERR', |
658 |
|
|
$node->node_name . '->prefix exception (read-only)'; |
659 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
660 |
|
|
} else { |
661 |
|
|
ok $err_type, undef, $node->node_name . '->prefix exception (read-only)'; |
662 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
663 |
|
|
} |
664 |
|
|
} |
665 |
|
|
|
666 |
|
|
## |text_content| |
667 |
|
|
{ |
668 |
|
|
my $doc2 = $doc->implementation->create_document; |
669 |
|
|
$doc2->dom_config->set_parameter |
670 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1); |
671 |
|
|
for my $node ( |
672 |
|
|
$doc2, |
673 |
|
|
$doc->create_document_type_definition ('dt1'), |
674 |
|
|
$doc->implementation->create_document_type ('doctype1'), |
675 |
|
|
$doc->create_notation ('notation1'), |
676 |
|
|
$doc->create_element_type_definition ('et1'), |
677 |
|
|
) { |
678 |
|
|
ok $node->can ('text_content') ? 1 : 0, 1, |
679 |
|
|
$node->node_name . '->can text_content'; |
680 |
|
|
|
681 |
|
|
ok $node->text_content, undef, $node->node_name . '->text_content'; |
682 |
|
|
|
683 |
|
|
$node->manakai_set_read_only (0); |
684 |
|
|
$node->text_content ('new-text-content'); |
685 |
|
|
ok $node->text_content, undef, $node->node_name . '->text_content set'; |
686 |
|
|
|
687 |
|
|
$node->manakai_set_read_only (1); |
688 |
|
|
$node->text_content ('new-text-content'); |
689 |
|
|
ok $node->text_content, undef, |
690 |
|
|
$node->node_name . '->text_content set (read-only)'; |
691 |
|
|
} |
692 |
|
|
|
693 |
|
|
$doc2->dom_config->set_parameter |
694 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0); |
695 |
|
|
for my $node ( |
696 |
|
|
$doc2, |
697 |
|
|
$doc->create_attribute ('attr1'), |
698 |
|
|
$doc->create_attribute_definition ('at1'), |
699 |
|
|
$doc->create_element ('element1'), |
700 |
|
|
$doc->create_general_entity ('entity1'), |
701 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
702 |
|
|
$doc->create_document_fragment, |
703 |
|
|
) { |
704 |
|
|
ok $node->can ('text_content') ? 1 : 0, 1, |
705 |
|
|
$node->node_name . '->can text_content'; |
706 |
|
|
|
707 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content'; |
708 |
|
|
|
709 |
|
|
$node->manakai_set_read_only (0); |
710 |
|
|
$node->text_content ('text1'); |
711 |
|
|
ok $node->text_content, 'text1', $node->node_name . '->text_content set'; |
712 |
|
|
ok 0+@{$node->child_nodes}, 1, |
713 |
|
|
$node->node_name . '->text_content set child_nodes length'; |
714 |
|
|
|
715 |
|
|
$node->text_content (''); |
716 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
717 |
|
|
ok 0+@{$node->child_nodes}, 0, |
718 |
|
|
$node->node_name . '->text_content set empty child_nodes length'; |
719 |
|
|
|
720 |
|
|
$node->text_content ('text2'); |
721 |
|
|
$node->text_content (''); |
722 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
723 |
|
|
ok 0+@{$node->child_nodes}, 0, |
724 |
|
|
$node->node_name . '->text_content set empty child_nodes length'; |
725 |
|
|
|
726 |
|
|
$node->text_content ('text3'); |
727 |
|
|
$node->manakai_set_read_only (1); |
728 |
|
|
try { |
729 |
|
|
$node->text_content ('new-text-content'); |
730 |
|
|
ok undef, 'NO_MODIFICATION_ALLOWED_ERR', |
731 |
|
|
$node->node_name . '->text_content set (read-only)'; |
732 |
|
|
} catch Message::IF::DOMException with { |
733 |
|
|
my $err = shift; |
734 |
|
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
735 |
|
|
$node->node_name . '->text_content set (read-only)'; |
736 |
|
|
}; |
737 |
|
|
ok $node->text_content, 'text3', |
738 |
|
|
$node->node_name . '->text_content set (read-only) text_content'; |
739 |
|
|
} |
740 |
|
|
|
741 |
|
|
|
742 |
|
|
for (0..2) { |
743 |
|
|
my $el; |
744 |
|
|
my $ce; |
745 |
|
|
|
746 |
|
|
[ |
747 |
|
|
sub { |
748 |
|
|
$el = $doc->create_element ('nestingElement'); |
749 |
|
|
$ce = $doc->create_element ('el2'); |
750 |
|
|
}, |
751 |
|
|
sub { |
752 |
|
|
$el = $doc->create_element ('elementWithEntityReference'); |
753 |
|
|
$ce = $doc->create_entity_reference ('ent'); |
754 |
|
|
$ce->manakai_set_read_only (0, 1); |
755 |
|
|
}, |
756 |
|
|
sub { |
757 |
|
|
$el = $doc->create_general_entity ('generalEntityWithChild'); |
758 |
|
|
$ce = $doc->create_element ('el'); |
759 |
|
|
$el->manakai_set_read_only (0, 1); |
760 |
|
|
}, |
761 |
|
|
]->[$_]->(); |
762 |
|
|
$el->append_child ($ce); |
763 |
|
|
|
764 |
|
|
ok $el->text_content, '', $el->node_name . '->text_content [1]'; |
765 |
|
|
|
766 |
|
|
$ce->text_content ('gc'); |
767 |
|
|
ok $el->text_content, 'gc', $el->node_name . '->text_content [2]'; |
768 |
|
|
|
769 |
|
|
$el->manakai_append_text ('cc'); |
770 |
|
|
ok $el->text_content, 'gccc', $el->node_name . '->text_content [3]'; |
771 |
|
|
|
772 |
|
|
$el->text_content ('nc'); |
773 |
|
|
ok $el->text_content, 'nc', $el->node_name . '->text_content [4]'; |
774 |
|
|
ok 0+@{$el->child_nodes}, 1, |
775 |
|
|
$el->node_name . '->text_content child_nodes length [4]'; |
776 |
|
|
ok $ce->parent_node, undef, |
777 |
|
|
$el->node_name . '->text_content old_child parent_node [4]'; |
778 |
|
|
} |
779 |
|
|
} |
780 |
|
|
|
781 |
wakaba |
1.4 |
## |manakaiReadOnly| and |manakaiSetReadOnly| |
782 |
|
|
{ |
783 |
|
|
for my $node (create_nodes ()) { |
784 |
|
|
$node->manakai_set_read_only (1, 0); |
785 |
|
|
ok $node->manakai_read_only ? 1 : 0, 1, |
786 |
|
|
$node->node_name . '->manakai_set_read_only (1, 0) [1]'; |
787 |
|
|
|
788 |
|
|
$node->manakai_set_read_only (0, 0); |
789 |
|
|
ok $node->manakai_read_only ? 1 : 0, 0, |
790 |
|
|
$node->node_name . '->manakai_set_read_only (0, 0)'; |
791 |
|
|
|
792 |
|
|
$node->manakai_set_read_only (1, 0); |
793 |
|
|
ok $node->manakai_read_only ? 1 : 0, 1, |
794 |
|
|
$node->node_name . '->manakai_set_read_only (1, 0) [2]'; |
795 |
|
|
} |
796 |
|
|
|
797 |
|
|
{ |
798 |
|
|
my $el = $doc->create_element ('readOnlyElement1'); |
799 |
|
|
my $c1 = $doc->create_element ('c1'); |
800 |
|
|
$el->append_child ($c1); |
801 |
|
|
my $c2 = $doc->create_text_node ('c2'); |
802 |
|
|
$el->append_child ($c2); |
803 |
|
|
my $c3 = $doc->create_element ('c3'); |
804 |
|
|
$el->append_child ($c3); |
805 |
|
|
my $c4 = $doc->create_attribute ('c4'); |
806 |
|
|
$el->set_attribute_node ($c4); |
807 |
|
|
my $c5 = $doc->create_entity_reference ('c5'); |
808 |
|
|
$el->append_child ($c5); |
809 |
|
|
|
810 |
|
|
$el->manakai_set_read_only (1, 1); |
811 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
812 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
813 |
|
|
$el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]'; |
814 |
|
|
} |
815 |
|
|
|
816 |
|
|
$el->manakai_set_read_only (0, 1); |
817 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
818 |
|
|
ok $_->manakai_read_only ? 1 : 0, 0, |
819 |
|
|
$el->node_name . '->read_only (1, 0) ' . $_->node_name; |
820 |
|
|
} |
821 |
|
|
|
822 |
|
|
$el->manakai_set_read_only (1, 1); |
823 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
824 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
825 |
|
|
$el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]'; |
826 |
|
|
} |
827 |
|
|
} |
828 |
|
|
|
829 |
|
|
{ |
830 |
|
|
my $dtd = $doc->create_document_type_definition ('readOnlyDTDef1'); |
831 |
|
|
my $c1 = $doc->create_processing_instruction ('c1', ''); |
832 |
|
|
$dtd->append_child ($c1); |
833 |
|
|
my $c2 = $doc->create_element_type_definition ('c2'); |
834 |
|
|
$dtd->set_element_type_definition_node ($c2); |
835 |
|
|
my $c3 = $doc->create_general_entity ('c3'); |
836 |
|
|
$dtd->set_general_entity_node ($c3); |
837 |
|
|
my $c4 = $doc->create_notation ('c4'); |
838 |
|
|
$dtd->set_notation_node ($c4); |
839 |
|
|
my $c5 = $doc->create_text_node ('c5'); |
840 |
|
|
$c3->append_child ($c5); |
841 |
|
|
|
842 |
|
|
$dtd->manakai_set_read_only (1, 1); |
843 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
844 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
845 |
|
|
$dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]'; |
846 |
|
|
} |
847 |
|
|
|
848 |
|
|
$dtd->manakai_set_read_only (0, 1); |
849 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
850 |
|
|
ok $_->manakai_read_only ? 1 : 0, 0, |
851 |
|
|
$dtd->node_name . '->read_only (1, 0) ' . $_->node_name; |
852 |
|
|
} |
853 |
|
|
|
854 |
|
|
$dtd->manakai_set_read_only (1, 1); |
855 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
856 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
857 |
|
|
$dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]'; |
858 |
|
|
} |
859 |
|
|
} |
860 |
|
|
|
861 |
|
|
{ |
862 |
|
|
my $et = $doc->create_element_type_definition ('readOnlyETDef1'); |
863 |
|
|
my $c1 = $doc->create_element ('c1'); |
864 |
|
|
$et->set_attribute_definition_node ($c1); |
865 |
|
|
my $c2 = $doc->create_text_node ('c2'); |
866 |
|
|
$c1->append_child ($c2); |
867 |
|
|
|
868 |
|
|
$et->manakai_set_read_only (1, 1); |
869 |
|
|
for ($c1, $c2) { |
870 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
871 |
|
|
$et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]'; |
872 |
|
|
} |
873 |
|
|
|
874 |
|
|
$et->manakai_set_read_only (0, 1); |
875 |
|
|
for ($c1, $c2) { |
876 |
|
|
ok $_->manakai_read_only ? 1 : 0, 0, |
877 |
|
|
$et->node_name . '->read_only (1, 0) ' . $_->node_name; |
878 |
|
|
} |
879 |
|
|
|
880 |
|
|
$et->manakai_set_read_only (1, 1); |
881 |
|
|
for ($c1, $c2) { |
882 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
883 |
|
|
$et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]'; |
884 |
|
|
} |
885 |
|
|
} |
886 |
|
|
} |
887 |
|
|
|
888 |
|
|
## |manakaiAppendText| |
889 |
|
|
{ |
890 |
|
|
my $doc2 = $doc->implementation->create_document; |
891 |
|
|
|
892 |
|
|
$doc2->dom_config->set_parameter |
893 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1); |
894 |
|
|
for my $node ( |
895 |
|
|
$doc2, |
896 |
|
|
$doc->create_notation ('Notation_manakaiAppendText'), |
897 |
|
|
$doc->create_document_type_definition ('DT_manakaiAppendText'), |
898 |
|
|
$doc->create_element_type_definition ('ET_manakaiAppendText'), |
899 |
|
|
) { |
900 |
|
|
ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can'; |
901 |
|
|
|
902 |
|
|
$node->manakai_append_text ('aaaa'); |
903 |
|
|
ok $node->text_content, undef, $node->node_name . ' [1]'; |
904 |
|
|
ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]'; |
905 |
|
|
} |
906 |
|
|
|
907 |
|
|
$doc2->dom_config->set_parameter |
908 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0); |
909 |
|
|
for my $node ( |
910 |
|
|
$doc->create_attribute ('Attr_manakaiAppendText'), |
911 |
|
|
$doc->create_element ('Element_manakaiAppendText'), |
912 |
|
|
$doc2, |
913 |
|
|
$doc->create_document_fragment, |
914 |
|
|
$doc->create_general_entity ('Entity_manakaiAppendText'), |
915 |
|
|
$doc->create_entity_reference ('ER_manakaiAppendText'), |
916 |
|
|
$doc->create_attribute_definition ('AT_manakaiAppendText'), |
917 |
|
|
) { |
918 |
|
|
$node->manakai_set_read_only (0, 1); |
919 |
|
|
ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can'; |
920 |
|
|
|
921 |
|
|
$node->manakai_append_text ('string'); |
922 |
|
|
ok $node->text_content, 'string', $node->node_name . ' [1]'; |
923 |
|
|
ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [1]'; |
924 |
|
|
|
925 |
|
|
$node->manakai_append_text ('STRING'); |
926 |
|
|
ok $node->text_content, 'stringSTRING', $node->node_name . ' [2]'; |
927 |
|
|
ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [2]'; |
928 |
|
|
|
929 |
|
|
my $er = $doc->create_entity_reference ('er'); |
930 |
|
|
$node->append_child ($er); |
931 |
|
|
|
932 |
|
|
$node->manakai_append_text ('text'); |
933 |
|
|
ok $node->text_content, 'stringSTRINGtext', $node->node_name . ' [3]'; |
934 |
|
|
ok 0+@{$node->child_nodes}, 3, $node->node_name . ' childNodes @{} 0+ [3]'; |
935 |
|
|
} |
936 |
|
|
|
937 |
|
|
for my $node ( |
938 |
|
|
$doc->create_text_node (''), |
939 |
|
|
$doc->create_cdata_section (''), |
940 |
|
|
$doc->create_comment (''), |
941 |
|
|
$doc->create_processing_instruction ('PI_manakaiAppendText'), |
942 |
|
|
) { |
943 |
|
|
ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can'; |
944 |
|
|
|
945 |
|
|
$node->manakai_append_text ('aaaa'); |
946 |
|
|
ok $node->text_content, 'aaaa', $node->node_name . ' [1]'; |
947 |
|
|
ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]'; |
948 |
|
|
|
949 |
|
|
$node->manakai_append_text ('bbbb'); |
950 |
|
|
ok $node->text_content, 'aaaabbbb', $node->node_name . ' [1]'; |
951 |
|
|
ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]'; |
952 |
|
|
} |
953 |
|
|
} |
954 |
|
|
|
955 |
|
|
## |baseURI| |
956 |
|
|
{ |
957 |
|
|
my $doc2 = $doc->implementation->create_document; |
958 |
|
|
|
959 |
|
|
$doc2->document_uri (q<ftp://suika.fam.cx/>); |
960 |
|
|
ok $doc2->base_uri, q<ftp://suika.fam.cx/>, 'Document->base_uri [1]'; |
961 |
|
|
|
962 |
|
|
$doc2->document_uri (undef); |
963 |
|
|
ok $doc2->base_uri, undef, 'Document->base_uri [2]'; |
964 |
|
|
ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [2]'; |
965 |
|
|
|
966 |
|
|
$doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>); |
967 |
|
|
ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [3]'; |
968 |
|
|
ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>, |
969 |
|
|
'Document->base_uri ebu [3]'; |
970 |
|
|
|
971 |
|
|
$doc2->manakai_entity_base_uri (undef); |
972 |
|
|
ok $doc2->base_uri, undef, 'Document->base_uri [4]'; |
973 |
|
|
ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [4]'; |
974 |
|
|
|
975 |
|
|
$doc2->document_uri (q<ftp://suika.fam.cx/>); |
976 |
|
|
$doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>); |
977 |
|
|
ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [5]'; |
978 |
|
|
ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>, |
979 |
|
|
'Document->base_uri ebu [5]'; |
980 |
|
|
} |
981 |
|
|
|
982 |
|
|
for my $method (qw/ |
983 |
|
|
create_document_fragment |
984 |
|
|
create_element_type_definition |
985 |
|
|
create_attribute_definition |
986 |
|
|
/) { |
987 |
|
|
my $doc2 = $doc->implementation->create_document; |
988 |
|
|
|
989 |
|
|
my $node = $doc2->$method ('a'); |
990 |
|
|
|
991 |
|
|
$doc2->document_uri (q<ftp://doc.test/>); |
992 |
|
|
ok $node->base_uri, q<ftp://doc.test/>, $node->node_name . '->base_uri [1]'; |
993 |
|
|
|
994 |
|
|
$doc2->manakai_entity_base_uri (q<ftp://suika.fam.cx/>); |
995 |
|
|
ok $node->base_uri, q<ftp://suika.fam.cx/>, |
996 |
|
|
$node->node_name . '->base_uri [2]'; |
997 |
|
|
} |
998 |
|
|
|
999 |
|
|
{ |
1000 |
|
|
my $doc2 = $doc->implementation->create_document; |
1001 |
|
|
|
1002 |
|
|
my $attr = $doc2->create_attribute_ns (undef, 'attr'); |
1003 |
|
|
|
1004 |
|
|
$doc2->document_uri (q<http://www.example.com/>); |
1005 |
|
|
ok $attr->base_uri, q<http://www.example.com/>, 'Attr->base_uri [1]'; |
1006 |
|
|
|
1007 |
|
|
my $el = $doc2->create_element_ns (undef, 'element'); |
1008 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', |
1009 |
|
|
'xml:base' => q<http://www.example.org/>); |
1010 |
|
|
$el->set_attribute_node_ns ($attr); |
1011 |
|
|
ok $attr->base_uri, q<http://www.example.org/>, 'Attr->base_uri [2]'; |
1012 |
|
|
} |
1013 |
|
|
|
1014 |
|
|
for my $i (0..1) { |
1015 |
|
|
my $xb = [ |
1016 |
|
|
['http://www.w3.org/XML/1998/namespace', 'xml:base'], |
1017 |
|
|
[undef, [undef, 'xml:base']], |
1018 |
|
|
]->[$i]; |
1019 |
|
|
|
1020 |
|
|
my $doc2 = $doc->implementation->create_document; |
1021 |
|
|
|
1022 |
|
|
my $attr = $doc2->create_attribute_ns (@$xb); |
1023 |
|
|
$attr->value (q<http://attr.test/>); |
1024 |
|
|
|
1025 |
|
|
ok $attr->base_uri, undef, 'xml:base->base_uri [0]' . $i; |
1026 |
|
|
|
1027 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1028 |
|
|
ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [1]' . $i; |
1029 |
|
|
|
1030 |
|
|
my $el = $doc2->create_element_ns (undef, 'e'); |
1031 |
|
|
$el->set_attribute_node_ns ($attr); |
1032 |
|
|
ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [2]' . $i; |
1033 |
|
|
|
1034 |
|
|
my $pel = $doc2->create_element_ns (undef, 'e'); |
1035 |
|
|
$pel->set_attribute_ns (@$xb, q<http://pel.test/>); |
1036 |
|
|
$pel->append_child ($el); |
1037 |
|
|
ok $attr->base_uri, q<http://pel.test/>, 'xml:base->base_uri [3]' . $i; |
1038 |
|
|
} |
1039 |
|
|
|
1040 |
|
|
for my $i (0..1) { |
1041 |
|
|
my $xb = [ |
1042 |
|
|
['http://www.w3.org/XML/1998/namespace', 'xml:base'], |
1043 |
|
|
[undef, [undef, 'xml:base']], |
1044 |
|
|
]->[$i]; |
1045 |
|
|
|
1046 |
|
|
my $doc2 = $doc->implementation->create_document; |
1047 |
|
|
|
1048 |
|
|
my $el = $doc2->create_element_ns (undef, 'el'); |
1049 |
|
|
|
1050 |
|
|
ok $el->base_uri, undef, "Element->base_uri [0]"; |
1051 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [0]"; |
1052 |
|
|
|
1053 |
|
|
$doc2->document_uri (q<http://foo.example/>); |
1054 |
|
|
ok $el->base_uri, q<http://foo.example/>, "Element->base_uri [1]"; |
1055 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [1]"; |
1056 |
|
|
|
1057 |
|
|
$el->set_attribute_ns (@$xb => q<http://www.example.com/>); |
1058 |
|
|
ok $el->base_uri, q<http://www.example.com/>, "Element->base_uri [2]"; |
1059 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [2]"; |
1060 |
|
|
|
1061 |
|
|
$el->set_attribute_ns (@$xb => q<bar>); |
1062 |
|
|
ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [3]"; |
1063 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [3]"; |
1064 |
|
|
|
1065 |
|
|
$el->manakai_base_uri (q<http://baz.example/>); |
1066 |
|
|
ok $el->base_uri, q<http://baz.example/>, "Element->base_uri [4]"; |
1067 |
|
|
ok $el->manakai_base_uri, q<http://baz.example/>, |
1068 |
|
|
"Element->manakai_base_uri [4]"; |
1069 |
|
|
|
1070 |
|
|
$el->manakai_base_uri (undef); |
1071 |
|
|
ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [5]"; |
1072 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [5]"; |
1073 |
|
|
} |
1074 |
|
|
|
1075 |
|
|
{ |
1076 |
|
|
my $doc2 = $doc->implementation->create_document; |
1077 |
|
|
|
1078 |
|
|
my $el = $doc2->create_element_ns (undef, 'el'); |
1079 |
|
|
|
1080 |
|
|
ok $el->base_uri, undef, "Element->base_uri [6]"; |
1081 |
|
|
|
1082 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1083 |
|
|
ok $el->base_uri, q<http://doc.test/>, "Element->base_uri [7]"; |
1084 |
|
|
|
1085 |
|
|
my $el0 = $doc2->create_element_ns (undef, 'e'); |
1086 |
|
|
$el0->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1087 |
|
|
q<http://el.test/>); |
1088 |
|
|
$el0->append_child ($el); |
1089 |
|
|
ok $el->base_uri, q<http://el.test/>, "Element->base_uri [8]"; |
1090 |
|
|
|
1091 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1092 |
|
|
$ent->manakai_set_read_only (0, 1); |
1093 |
|
|
$ent->manakai_external (1); |
1094 |
|
|
$ent->manakai_entity_base_uri (q<http://ent.test/>); |
1095 |
|
|
$el0->append_child ($ent); |
1096 |
|
|
$ent->append_child ($el); |
1097 |
|
|
ok $el->base_uri, q<http://ent.test/>, "Element->base_uri [9]"; |
1098 |
|
|
} |
1099 |
|
|
|
1100 |
|
|
for (qw/create_text_node create_cdata_section create_comment/) { |
1101 |
|
|
my $doc2 = $doc->implementation->create_document; |
1102 |
|
|
my $node = $doc2->$_ (''); |
1103 |
|
|
|
1104 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1105 |
|
|
ok $node->base_uri, q<http://doc.test/>, $node->node_name . "->base_uri [0]"; |
1106 |
|
|
|
1107 |
|
|
my $el = $doc2->create_element_ns (undef, 'e'); |
1108 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1109 |
|
|
q<http://el.test/>); |
1110 |
|
|
$el->append_child ($node); |
1111 |
|
|
ok $node->base_uri, q<http://el.test/>, $node->node_name . "->base_uri [1]"; |
1112 |
|
|
|
1113 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1114 |
|
|
$ent->manakai_set_read_only (0, 1); |
1115 |
|
|
$ent->manakai_external (1); |
1116 |
|
|
$ent->manakai_entity_base_uri (q<http://ent.test/>); |
1117 |
|
|
$el->append_child ($ent); |
1118 |
|
|
$ent->append_child ($node); |
1119 |
|
|
ok $node->base_uri, q<http://ent.test/>, $node->node_name . "->base_uri [2]"; |
1120 |
|
|
} |
1121 |
|
|
|
1122 |
|
|
{ |
1123 |
|
|
my $doc2 = $doc->implementation->create_document; |
1124 |
|
|
my $ent = $doc2->create_general_entity ('ent'); |
1125 |
|
|
|
1126 |
|
|
$doc2->document_uri (q<http://base.example/>); |
1127 |
|
|
ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [1]"; |
1128 |
|
|
|
1129 |
|
|
$ent->manakai_entity_base_uri (q<http://www.example.com/>); |
1130 |
|
|
ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [2]"; |
1131 |
|
|
|
1132 |
|
|
$ent->manakai_declaration_base_uri (q<http://www.example/>); |
1133 |
|
|
ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [3]"; |
1134 |
|
|
} |
1135 |
|
|
|
1136 |
|
|
{ |
1137 |
|
|
my $doc2 = $doc->implementation->create_document; |
1138 |
|
|
|
1139 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1140 |
|
|
$ent->manakai_set_read_only (0, 1); |
1141 |
|
|
|
1142 |
|
|
$doc2->document_uri (q<http://base.example/>); |
1143 |
|
|
ok $ent->base_uri, q<http://base.example/>, "ER->base_uri [1]"; |
1144 |
|
|
|
1145 |
|
|
$ent->manakai_entity_base_uri (q<http://www.example.com/>); |
1146 |
|
|
ok $ent->base_uri, q<http://base.example/>; |
1147 |
|
|
|
1148 |
|
|
my $el = $doc2->create_element_ns (undef, 'el'); |
1149 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1150 |
|
|
q<http://el.test/>); |
1151 |
|
|
$el->append_child ($ent); |
1152 |
|
|
ok $ent->base_uri, q<http://el.test/>, "ER->base_uri [2]"; |
1153 |
|
|
|
1154 |
|
|
my $xent = $doc2->create_entity_reference ('ext'); |
1155 |
|
|
$xent->manakai_set_read_only (0, 1); |
1156 |
|
|
$xent->manakai_entity_base_uri (q<http://ent.test/>); |
1157 |
|
|
$xent->manakai_external (1); |
1158 |
|
|
$el->append_child ($xent); |
1159 |
|
|
$xent->append_child ($ent); |
1160 |
|
|
ok $ent->base_uri, q<http://ent.test/>, "ER->base_uri [3]"; |
1161 |
|
|
} |
1162 |
|
|
|
1163 |
|
|
{ |
1164 |
|
|
my $doc2 = $doc->implementation->create_document; |
1165 |
|
|
|
1166 |
|
|
my $pi = $doc2->create_processing_instruction ('i'); |
1167 |
|
|
|
1168 |
|
|
ok $pi->base_uri, undef, "PI->base_uri [0]"; |
1169 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [0]"; |
1170 |
|
|
|
1171 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1172 |
|
|
ok $pi->base_uri, q<http://doc.test/>, "PI->base_uri [1]"; |
1173 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [1]"; |
1174 |
|
|
|
1175 |
|
|
my $el = $doc2->create_element_ns (undef, 'e'); |
1176 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1177 |
|
|
q<http://el.test/>); |
1178 |
|
|
$el->append_child ($pi); |
1179 |
|
|
ok $pi->base_uri, q<http://el.test/>, "PI->base_uri [2]"; |
1180 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [2]"; |
1181 |
|
|
|
1182 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1183 |
|
|
$ent->manakai_set_read_only (0, 1); |
1184 |
|
|
$ent->manakai_external (1); |
1185 |
|
|
$ent->manakai_entity_base_uri (q<http://ent.test/>); |
1186 |
|
|
$el->append_child ($ent); |
1187 |
|
|
$ent->append_child ($pi); |
1188 |
|
|
ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [3]"; |
1189 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [3]"; |
1190 |
|
|
|
1191 |
|
|
$pi->manakai_base_uri (q<http://pi.ent/>); |
1192 |
|
|
ok $pi->base_uri, q<http://pi.ent/>, "PI->base_uri [4]"; |
1193 |
|
|
ok $pi->manakai_base_uri, q<http://pi.ent/>, "PI->manakai_base_uri [4]"; |
1194 |
|
|
|
1195 |
|
|
$pi->manakai_base_uri (undef); |
1196 |
|
|
ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [5]"; |
1197 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [5]"; |
1198 |
|
|
} |
1199 |
|
|
|
1200 |
|
|
{ |
1201 |
|
|
my $doc2 = $doc->implementation->create_document; |
1202 |
|
|
|
1203 |
|
|
my $pi = $doc2->create_notation ('i'); |
1204 |
|
|
|
1205 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1206 |
|
|
ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [1]"; |
1207 |
|
|
|
1208 |
|
|
$pi->manakai_declaration_base_uri (q<http://www.example/>); |
1209 |
|
|
ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [2]"; |
1210 |
|
|
} |
1211 |
|
|
|
1212 |
|
|
{ |
1213 |
|
|
my $dt = $doc->implementation->create_document_type ('name'); |
1214 |
|
|
ok $dt->base_uri, undef, "DT->base_uri [0]"; |
1215 |
|
|
|
1216 |
|
|
my $doc2 = $doc->implementation->create_document; |
1217 |
|
|
$doc2->append_child ($dt); |
1218 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1219 |
|
|
ok $dt->owner_document, $doc2; |
1220 |
|
|
ok $dt->base_uri, q<http://doc.test/>, "DT->base_uri [1]"; |
1221 |
|
|
} |
1222 |
|
|
|
1223 |
|
|
|
1224 |
wakaba |
1.2 |
## TODO: parent_node tests, as with append_child tests |
1225 |
|
|
|
1226 |
wakaba |
1.3 |
## TODO: text_content tests for CharacterData and PI |
1227 |
|
|
|
1228 |
wakaba |
1.4 |
=head1 LICENSE |
1229 |
|
|
|
1230 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
1231 |
wakaba |
1.3 |
|
1232 |
wakaba |
1.4 |
This program is free software; you can redistribute it and/or |
1233 |
|
|
modify it under the same terms as Perl itself. |
1234 |
wakaba |
1.2 |
|
1235 |
wakaba |
1.4 |
=cut |
1236 |
wakaba |
1.2 |
|
1237 |
wakaba |
1.4 |
## $Date: 2007/06/16 08:49:00 $ |