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.5 |
notation_name => undef, |
425 |
wakaba |
1.2 |
owner_document => $doc, |
426 |
|
|
parent_node => undef, |
427 |
|
|
previous_sibling => undef, |
428 |
wakaba |
1.4 |
public_id => undef, |
429 |
|
|
system_id => undef, |
430 |
wakaba |
1.1 |
}, |
431 |
|
|
}, |
432 |
|
|
entity_reference => { |
433 |
|
|
node => sub { return $doc->create_entity_reference ('e') }, |
434 |
|
|
attr_get => { |
435 |
|
|
attributes => undef, |
436 |
wakaba |
1.4 |
base_uri => undef, |
437 |
|
|
manakai_entity_base_uri => undef, |
438 |
wakaba |
1.2 |
first_child => undef, |
439 |
|
|
last_child => undef, |
440 |
|
|
local_name => undef, |
441 |
|
|
manakai_local_name => undef, |
442 |
|
|
namespace_uri => undef, |
443 |
|
|
next_sibling => undef, |
444 |
wakaba |
1.1 |
node_name => 'e', |
445 |
|
|
node_value => undef, |
446 |
wakaba |
1.2 |
owner_document => $doc, |
447 |
|
|
parent_node => undef, |
448 |
|
|
prefix => undef, |
449 |
|
|
previous_sibling => undef, |
450 |
wakaba |
1.1 |
}, |
451 |
wakaba |
1.4 |
attr_get_bool => { |
452 |
|
|
manakai_expanded => 0, |
453 |
|
|
manakai_external => 0, |
454 |
|
|
}, |
455 |
wakaba |
1.1 |
}, |
456 |
|
|
notation => { |
457 |
|
|
node => sub { return $doc->create_notation ('e') }, |
458 |
|
|
attr_get => { |
459 |
|
|
attributes => undef, |
460 |
wakaba |
1.4 |
base_uri => undef, |
461 |
|
|
manakai_declaration_base_uri => undef, |
462 |
wakaba |
1.2 |
first_child => undef, |
463 |
|
|
last_child => undef, |
464 |
|
|
local_name => undef, |
465 |
|
|
manakai_local_name => undef, |
466 |
|
|
namespace_uri => undef, |
467 |
|
|
next_sibling => undef, |
468 |
wakaba |
1.1 |
node_name => 'e', |
469 |
|
|
node_value => undef, |
470 |
wakaba |
1.2 |
owner_document => $doc, |
471 |
|
|
parent_node => undef, |
472 |
|
|
prefix => undef, |
473 |
|
|
previous_sibling => undef, |
474 |
wakaba |
1.4 |
public_id => undef, |
475 |
|
|
system_id => undef, |
476 |
wakaba |
1.1 |
}, |
477 |
|
|
}, |
478 |
|
|
processing_instruction => { |
479 |
|
|
node => sub { return $doc->create_processing_instruction ('t', 'd') }, |
480 |
|
|
attr_get => { |
481 |
|
|
attributes => undef, |
482 |
wakaba |
1.4 |
base_uri => undef, |
483 |
|
|
manakai_base_uri => undef, |
484 |
wakaba |
1.2 |
first_child => undef, |
485 |
|
|
last_child => undef, |
486 |
|
|
local_name => undef, |
487 |
|
|
manakai_local_name => undef, |
488 |
|
|
namespace_uri => undef, |
489 |
|
|
next_sibling => undef, |
490 |
wakaba |
1.1 |
node_name => 't', |
491 |
|
|
node_value => 'd', |
492 |
wakaba |
1.2 |
owner_document => $doc, |
493 |
|
|
parent_node => undef, |
494 |
|
|
prefix => undef, |
495 |
|
|
previous_sibling => undef, |
496 |
wakaba |
1.1 |
}, |
497 |
|
|
}, |
498 |
|
|
text => { |
499 |
|
|
node => sub { return $doc->create_text_node ('textdata') }, |
500 |
|
|
attr_get => { |
501 |
|
|
attributes => undef, |
502 |
wakaba |
1.4 |
base_uri => undef, |
503 |
wakaba |
1.2 |
first_child => undef, |
504 |
|
|
last_child => undef, |
505 |
|
|
local_name => undef, |
506 |
|
|
manakai_local_name => undef, |
507 |
|
|
namespace_uri => undef, |
508 |
|
|
next_sibling => undef, |
509 |
wakaba |
1.1 |
node_name => '#text', |
510 |
|
|
node_value => 'textdata', |
511 |
wakaba |
1.2 |
owner_document => $doc, |
512 |
|
|
parent_node => undef, |
513 |
|
|
prefix => undef, |
514 |
|
|
previous_sibling => undef, |
515 |
wakaba |
1.1 |
}, |
516 |
|
|
}, |
517 |
|
|
element_type_definition => { |
518 |
|
|
node => sub { return $doc->create_element_type_definition ('e') }, |
519 |
|
|
attr_get => { |
520 |
|
|
attributes => undef, |
521 |
wakaba |
1.4 |
base_uri => undef, |
522 |
wakaba |
1.2 |
first_child => undef, |
523 |
|
|
last_child => undef, |
524 |
|
|
local_name => undef, |
525 |
|
|
manakai_local_name => undef, |
526 |
|
|
namespace_uri => undef, |
527 |
|
|
next_sibling => undef, |
528 |
wakaba |
1.1 |
node_name => 'e', |
529 |
|
|
node_value => undef, |
530 |
wakaba |
1.2 |
owner_document => $doc, |
531 |
|
|
parent_node => undef, |
532 |
|
|
prefix => undef, |
533 |
|
|
previous_sibling => undef, |
534 |
wakaba |
1.1 |
}, |
535 |
|
|
}, |
536 |
|
|
attribute_definition => { |
537 |
|
|
node => sub { return $doc->create_attribute_definition ('e') }, |
538 |
|
|
attr_get => { |
539 |
|
|
attributes => undef, |
540 |
wakaba |
1.4 |
base_uri => undef, |
541 |
|
|
declared_type => 0, |
542 |
|
|
default_type => 0, |
543 |
wakaba |
1.2 |
first_child => undef, |
544 |
|
|
last_child => undef, |
545 |
|
|
local_name => undef, |
546 |
|
|
manakai_local_name => undef, |
547 |
|
|
namespace_uri => undef, |
548 |
|
|
next_sibling => undef, |
549 |
wakaba |
1.1 |
node_name => 'e', |
550 |
|
|
node_value => undef, |
551 |
wakaba |
1.2 |
owner_document => $doc, |
552 |
|
|
parent_node => undef, |
553 |
|
|
prefix => undef, |
554 |
|
|
previous_sibling => undef, |
555 |
wakaba |
1.1 |
}, |
556 |
|
|
}, |
557 |
|
|
}; |
558 |
|
|
|
559 |
|
|
for my $test_id (sort {$a cmp $b} keys %$tests) { |
560 |
|
|
my $test_def = $tests->{$test_id}; |
561 |
|
|
my $node = $test_def->{node}->(); |
562 |
|
|
|
563 |
|
|
for (@$constants) { |
564 |
|
|
my $const_name = $_->[0]; |
565 |
|
|
ok $node->can ($const_name) ? 1 : 0, 1, "$test_id->can ($const_name)"; |
566 |
|
|
ok $node->$const_name, $_->[1], "$test_id.$const_name"; |
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get}}) { |
570 |
|
|
my $expected = $test_def->{attr_get}->{$attr_name}; |
571 |
|
|
ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)"; |
572 |
|
|
my $actual = $node->$attr_name; |
573 |
|
|
ok $actual, $expected, "$test_id.$attr_name.get"; |
574 |
|
|
} |
575 |
wakaba |
1.4 |
|
576 |
|
|
for my $attr_name (sort {$a cmp $b} keys %{$test_def->{attr_get_bool} or {}}) { |
577 |
|
|
my $expected = $test_def->{attr_get_bool}->{$attr_name} ? 1 : 0; |
578 |
|
|
ok $node->can ($attr_name) ? 1 : 0, 1, "$test_id->can ($attr_name)"; |
579 |
|
|
my $actual = $node->$attr_name ? 1 : 0; |
580 |
|
|
ok $actual, $expected, "$test_id.$attr_name.get"; |
581 |
|
|
} |
582 |
wakaba |
1.1 |
} |
583 |
|
|
|
584 |
wakaba |
1.2 |
## Child node accessors' tests |
585 |
|
|
for my $parent (create_parent_nodes ()) { |
586 |
|
|
my $node1; |
587 |
|
|
my $node2; |
588 |
|
|
my $node3; |
589 |
|
|
if ($parent->node_type == $parent->DOCUMENT_TYPE_NODE) { |
590 |
|
|
$node1 = $doc->create_processing_instruction ('pi1', 'data1'); |
591 |
|
|
$node2 = $doc->create_processing_instruction ('pi2', 'data2'); |
592 |
|
|
$node3 = $doc->create_processing_instruction ('pi3', 'data3'); |
593 |
|
|
} elsif ($parent->node_type == $parent->DOCUMENT_NODE) { |
594 |
|
|
$node1 = $doc->create_comment ('comment1'); |
595 |
|
|
$node2 = $doc->create_comment ('comment2'); |
596 |
|
|
$node3 = $doc->create_comment ('comment3'); |
597 |
|
|
} else { |
598 |
|
|
$node1 = $doc->create_text_node ('text1'); |
599 |
|
|
$node2 = $doc->create_text_node ('text2'); |
600 |
|
|
$node3 = $doc->create_text_node ('text3'); |
601 |
|
|
} |
602 |
|
|
|
603 |
|
|
$parent->append_child ($node1); |
604 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [1]"; |
605 |
|
|
ok $parent->last_child, $node1, $parent->node_name."->last_child [1]"; |
606 |
|
|
ok $node1->next_sibling, undef, $parent->node_name."->next_sibling [1]"; |
607 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."->previous_sibling [1]"; |
608 |
|
|
|
609 |
|
|
$parent->append_child ($node2); |
610 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [2]"; |
611 |
|
|
ok $parent->last_child, $node2, $parent->node_name."->last_child [2]"; |
612 |
|
|
ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [2]"; |
613 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [2]"; |
614 |
|
|
ok $node2->next_sibling, undef, $parent->node_name."2->next_sibling [2]"; |
615 |
|
|
ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [2]"; |
616 |
|
|
|
617 |
|
|
$parent->append_child ($node3); |
618 |
|
|
ok $parent->first_child, $node1, $parent->node_name."->first_child [3]"; |
619 |
|
|
ok $parent->last_child, $node3, $parent->node_name."->last_child [3]"; |
620 |
|
|
ok $node1->next_sibling, $node2, $parent->node_name."1->next_sibling [3]"; |
621 |
|
|
ok $node1->previous_sibling, undef, $parent->node_name."1->previous_sibling [3]"; |
622 |
|
|
ok $node2->next_sibling, $node3, $parent->node_name."2->next_sibling [3]"; |
623 |
|
|
ok $node2->previous_sibling, $node1, $parent->node_name."2->previous_sibling [3]"; |
624 |
|
|
ok $node3->next_sibling, undef, $parent->node_name."3->next_sibling [3]"; |
625 |
|
|
ok $node3->previous_sibling, $node2, $parent->node_name."3->previous_sibling [3]"; |
626 |
|
|
} |
627 |
|
|
|
628 |
wakaba |
1.3 |
## |prefix| setter |
629 |
|
|
for my $node (create_nodes ()) { |
630 |
|
|
$node->manakai_set_read_only (0); |
631 |
|
|
|
632 |
|
|
$node->prefix ('non-null'); |
633 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
634 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
635 |
|
|
ok $node->prefix, 'non-null', $node->node_name . '->prefix (non-null)'; |
636 |
|
|
} else { |
637 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (non-null)'; |
638 |
|
|
} |
639 |
|
|
|
640 |
|
|
$node->prefix (undef); |
641 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
642 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
643 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
644 |
|
|
} else { |
645 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (null)'; |
646 |
|
|
} |
647 |
|
|
|
648 |
|
|
$node->manakai_set_read_only (1); |
649 |
|
|
my $err_type; |
650 |
|
|
try { |
651 |
|
|
$node->prefix ('non-null'); |
652 |
|
|
} catch Message::IF::DOMException with { |
653 |
|
|
my $err = shift; |
654 |
|
|
$err_type = $err->type; |
655 |
|
|
}; |
656 |
|
|
if ($node->node_type == $node->ELEMENT_NODE or |
657 |
|
|
$node->node_type == $node->ATTRIBUTE_NODE) { |
658 |
|
|
ok $err_type, 'NO_MODIFICATION_ALLOWED_ERR', |
659 |
|
|
$node->node_name . '->prefix exception (read-only)'; |
660 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
661 |
|
|
} else { |
662 |
|
|
ok $err_type, undef, $node->node_name . '->prefix exception (read-only)'; |
663 |
|
|
ok $node->prefix, undef, $node->node_name . '->prefix (read-only)'; |
664 |
|
|
} |
665 |
|
|
} |
666 |
|
|
|
667 |
|
|
## |text_content| |
668 |
|
|
{ |
669 |
|
|
my $doc2 = $doc->implementation->create_document; |
670 |
|
|
$doc2->dom_config->set_parameter |
671 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1); |
672 |
|
|
for my $node ( |
673 |
|
|
$doc2, |
674 |
|
|
$doc->create_document_type_definition ('dt1'), |
675 |
|
|
$doc->implementation->create_document_type ('doctype1'), |
676 |
|
|
$doc->create_notation ('notation1'), |
677 |
|
|
$doc->create_element_type_definition ('et1'), |
678 |
|
|
) { |
679 |
|
|
ok $node->can ('text_content') ? 1 : 0, 1, |
680 |
|
|
$node->node_name . '->can text_content'; |
681 |
|
|
|
682 |
|
|
ok $node->text_content, undef, $node->node_name . '->text_content'; |
683 |
|
|
|
684 |
|
|
$node->manakai_set_read_only (0); |
685 |
|
|
$node->text_content ('new-text-content'); |
686 |
|
|
ok $node->text_content, undef, $node->node_name . '->text_content set'; |
687 |
|
|
|
688 |
|
|
$node->manakai_set_read_only (1); |
689 |
|
|
$node->text_content ('new-text-content'); |
690 |
|
|
ok $node->text_content, undef, |
691 |
|
|
$node->node_name . '->text_content set (read-only)'; |
692 |
|
|
} |
693 |
|
|
|
694 |
|
|
$doc2->dom_config->set_parameter |
695 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0); |
696 |
|
|
for my $node ( |
697 |
|
|
$doc2, |
698 |
|
|
$doc->create_attribute ('attr1'), |
699 |
|
|
$doc->create_attribute_definition ('at1'), |
700 |
|
|
$doc->create_element ('element1'), |
701 |
|
|
$doc->create_general_entity ('entity1'), |
702 |
|
|
$doc->create_entity_reference ('entity-reference1'), |
703 |
|
|
$doc->create_document_fragment, |
704 |
|
|
) { |
705 |
|
|
ok $node->can ('text_content') ? 1 : 0, 1, |
706 |
|
|
$node->node_name . '->can text_content'; |
707 |
|
|
|
708 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content'; |
709 |
|
|
|
710 |
|
|
$node->manakai_set_read_only (0); |
711 |
|
|
$node->text_content ('text1'); |
712 |
|
|
ok $node->text_content, 'text1', $node->node_name . '->text_content set'; |
713 |
|
|
ok 0+@{$node->child_nodes}, 1, |
714 |
|
|
$node->node_name . '->text_content set child_nodes length'; |
715 |
|
|
|
716 |
|
|
$node->text_content (''); |
717 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
718 |
|
|
ok 0+@{$node->child_nodes}, 0, |
719 |
|
|
$node->node_name . '->text_content set empty child_nodes length'; |
720 |
|
|
|
721 |
|
|
$node->text_content ('text2'); |
722 |
|
|
$node->text_content (''); |
723 |
|
|
ok $node->text_content, '', $node->node_name . '->text_content set empty'; |
724 |
|
|
ok 0+@{$node->child_nodes}, 0, |
725 |
|
|
$node->node_name . '->text_content set empty child_nodes length'; |
726 |
|
|
|
727 |
|
|
$node->text_content ('text3'); |
728 |
|
|
$node->manakai_set_read_only (1); |
729 |
|
|
try { |
730 |
|
|
$node->text_content ('new-text-content'); |
731 |
|
|
ok undef, 'NO_MODIFICATION_ALLOWED_ERR', |
732 |
|
|
$node->node_name . '->text_content set (read-only)'; |
733 |
|
|
} catch Message::IF::DOMException with { |
734 |
|
|
my $err = shift; |
735 |
|
|
ok $err->type, 'NO_MODIFICATION_ALLOWED_ERR', |
736 |
|
|
$node->node_name . '->text_content set (read-only)'; |
737 |
|
|
}; |
738 |
|
|
ok $node->text_content, 'text3', |
739 |
|
|
$node->node_name . '->text_content set (read-only) text_content'; |
740 |
|
|
} |
741 |
|
|
|
742 |
|
|
|
743 |
|
|
for (0..2) { |
744 |
|
|
my $el; |
745 |
|
|
my $ce; |
746 |
|
|
|
747 |
|
|
[ |
748 |
|
|
sub { |
749 |
|
|
$el = $doc->create_element ('nestingElement'); |
750 |
|
|
$ce = $doc->create_element ('el2'); |
751 |
|
|
}, |
752 |
|
|
sub { |
753 |
|
|
$el = $doc->create_element ('elementWithEntityReference'); |
754 |
|
|
$ce = $doc->create_entity_reference ('ent'); |
755 |
|
|
$ce->manakai_set_read_only (0, 1); |
756 |
|
|
}, |
757 |
|
|
sub { |
758 |
|
|
$el = $doc->create_general_entity ('generalEntityWithChild'); |
759 |
|
|
$ce = $doc->create_element ('el'); |
760 |
|
|
$el->manakai_set_read_only (0, 1); |
761 |
|
|
}, |
762 |
|
|
]->[$_]->(); |
763 |
|
|
$el->append_child ($ce); |
764 |
|
|
|
765 |
|
|
ok $el->text_content, '', $el->node_name . '->text_content [1]'; |
766 |
|
|
|
767 |
|
|
$ce->text_content ('gc'); |
768 |
|
|
ok $el->text_content, 'gc', $el->node_name . '->text_content [2]'; |
769 |
|
|
|
770 |
|
|
$el->manakai_append_text ('cc'); |
771 |
|
|
ok $el->text_content, 'gccc', $el->node_name . '->text_content [3]'; |
772 |
|
|
|
773 |
|
|
$el->text_content ('nc'); |
774 |
|
|
ok $el->text_content, 'nc', $el->node_name . '->text_content [4]'; |
775 |
|
|
ok 0+@{$el->child_nodes}, 1, |
776 |
|
|
$el->node_name . '->text_content child_nodes length [4]'; |
777 |
|
|
ok $ce->parent_node, undef, |
778 |
|
|
$el->node_name . '->text_content old_child parent_node [4]'; |
779 |
|
|
} |
780 |
|
|
} |
781 |
|
|
|
782 |
wakaba |
1.4 |
## |manakaiReadOnly| and |manakaiSetReadOnly| |
783 |
|
|
{ |
784 |
|
|
for my $node (create_nodes ()) { |
785 |
|
|
$node->manakai_set_read_only (1, 0); |
786 |
|
|
ok $node->manakai_read_only ? 1 : 0, 1, |
787 |
|
|
$node->node_name . '->manakai_set_read_only (1, 0) [1]'; |
788 |
|
|
|
789 |
|
|
$node->manakai_set_read_only (0, 0); |
790 |
|
|
ok $node->manakai_read_only ? 1 : 0, 0, |
791 |
|
|
$node->node_name . '->manakai_set_read_only (0, 0)'; |
792 |
|
|
|
793 |
|
|
$node->manakai_set_read_only (1, 0); |
794 |
|
|
ok $node->manakai_read_only ? 1 : 0, 1, |
795 |
|
|
$node->node_name . '->manakai_set_read_only (1, 0) [2]'; |
796 |
|
|
} |
797 |
|
|
|
798 |
|
|
{ |
799 |
|
|
my $el = $doc->create_element ('readOnlyElement1'); |
800 |
|
|
my $c1 = $doc->create_element ('c1'); |
801 |
|
|
$el->append_child ($c1); |
802 |
|
|
my $c2 = $doc->create_text_node ('c2'); |
803 |
|
|
$el->append_child ($c2); |
804 |
|
|
my $c3 = $doc->create_element ('c3'); |
805 |
|
|
$el->append_child ($c3); |
806 |
|
|
my $c4 = $doc->create_attribute ('c4'); |
807 |
|
|
$el->set_attribute_node ($c4); |
808 |
|
|
my $c5 = $doc->create_entity_reference ('c5'); |
809 |
|
|
$el->append_child ($c5); |
810 |
|
|
|
811 |
|
|
$el->manakai_set_read_only (1, 1); |
812 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
813 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
814 |
|
|
$el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]'; |
815 |
|
|
} |
816 |
|
|
|
817 |
|
|
$el->manakai_set_read_only (0, 1); |
818 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
819 |
|
|
ok $_->manakai_read_only ? 1 : 0, 0, |
820 |
|
|
$el->node_name . '->read_only (1, 0) ' . $_->node_name; |
821 |
|
|
} |
822 |
|
|
|
823 |
|
|
$el->manakai_set_read_only (1, 1); |
824 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
825 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
826 |
|
|
$el->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]'; |
827 |
|
|
} |
828 |
|
|
} |
829 |
|
|
|
830 |
|
|
{ |
831 |
|
|
my $dtd = $doc->create_document_type_definition ('readOnlyDTDef1'); |
832 |
|
|
my $c1 = $doc->create_processing_instruction ('c1', ''); |
833 |
|
|
$dtd->append_child ($c1); |
834 |
|
|
my $c2 = $doc->create_element_type_definition ('c2'); |
835 |
|
|
$dtd->set_element_type_definition_node ($c2); |
836 |
|
|
my $c3 = $doc->create_general_entity ('c3'); |
837 |
|
|
$dtd->set_general_entity_node ($c3); |
838 |
|
|
my $c4 = $doc->create_notation ('c4'); |
839 |
|
|
$dtd->set_notation_node ($c4); |
840 |
|
|
my $c5 = $doc->create_text_node ('c5'); |
841 |
|
|
$c3->append_child ($c5); |
842 |
|
|
|
843 |
|
|
$dtd->manakai_set_read_only (1, 1); |
844 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
845 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
846 |
|
|
$dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]'; |
847 |
|
|
} |
848 |
|
|
|
849 |
|
|
$dtd->manakai_set_read_only (0, 1); |
850 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
851 |
|
|
ok $_->manakai_read_only ? 1 : 0, 0, |
852 |
|
|
$dtd->node_name . '->read_only (1, 0) ' . $_->node_name; |
853 |
|
|
} |
854 |
|
|
|
855 |
|
|
$dtd->manakai_set_read_only (1, 1); |
856 |
|
|
for ($c1, $c2, $c3, $c4, $c5) { |
857 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
858 |
|
|
$dtd->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]'; |
859 |
|
|
} |
860 |
|
|
} |
861 |
|
|
|
862 |
|
|
{ |
863 |
|
|
my $et = $doc->create_element_type_definition ('readOnlyETDef1'); |
864 |
|
|
my $c1 = $doc->create_element ('c1'); |
865 |
|
|
$et->set_attribute_definition_node ($c1); |
866 |
|
|
my $c2 = $doc->create_text_node ('c2'); |
867 |
|
|
$c1->append_child ($c2); |
868 |
|
|
|
869 |
|
|
$et->manakai_set_read_only (1, 1); |
870 |
|
|
for ($c1, $c2) { |
871 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
872 |
|
|
$et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [1]'; |
873 |
|
|
} |
874 |
|
|
|
875 |
|
|
$et->manakai_set_read_only (0, 1); |
876 |
|
|
for ($c1, $c2) { |
877 |
|
|
ok $_->manakai_read_only ? 1 : 0, 0, |
878 |
|
|
$et->node_name . '->read_only (1, 0) ' . $_->node_name; |
879 |
|
|
} |
880 |
|
|
|
881 |
|
|
$et->manakai_set_read_only (1, 1); |
882 |
|
|
for ($c1, $c2) { |
883 |
|
|
ok $_->manakai_read_only ? 1 : 0, 1, |
884 |
|
|
$et->node_name . '->read_only (1, 1) ' . $_->node_name . ' [2]'; |
885 |
|
|
} |
886 |
|
|
} |
887 |
|
|
} |
888 |
|
|
|
889 |
|
|
## |manakaiAppendText| |
890 |
|
|
{ |
891 |
|
|
my $doc2 = $doc->implementation->create_document; |
892 |
|
|
|
893 |
|
|
$doc2->dom_config->set_parameter |
894 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 1); |
895 |
|
|
for my $node ( |
896 |
|
|
$doc2, |
897 |
|
|
$doc->create_notation ('Notation_manakaiAppendText'), |
898 |
|
|
$doc->create_document_type_definition ('DT_manakaiAppendText'), |
899 |
|
|
$doc->create_element_type_definition ('ET_manakaiAppendText'), |
900 |
|
|
) { |
901 |
|
|
ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can'; |
902 |
|
|
|
903 |
|
|
$node->manakai_append_text ('aaaa'); |
904 |
|
|
ok $node->text_content, undef, $node->node_name . ' [1]'; |
905 |
|
|
ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]'; |
906 |
|
|
} |
907 |
|
|
|
908 |
|
|
$doc2->dom_config->set_parameter |
909 |
|
|
('http://suika.fam.cx/www/2006/dom-config/strict-document-children' => 0); |
910 |
|
|
for my $node ( |
911 |
|
|
$doc->create_attribute ('Attr_manakaiAppendText'), |
912 |
|
|
$doc->create_element ('Element_manakaiAppendText'), |
913 |
|
|
$doc2, |
914 |
|
|
$doc->create_document_fragment, |
915 |
|
|
$doc->create_general_entity ('Entity_manakaiAppendText'), |
916 |
|
|
$doc->create_entity_reference ('ER_manakaiAppendText'), |
917 |
|
|
$doc->create_attribute_definition ('AT_manakaiAppendText'), |
918 |
|
|
) { |
919 |
|
|
$node->manakai_set_read_only (0, 1); |
920 |
|
|
ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can'; |
921 |
|
|
|
922 |
|
|
$node->manakai_append_text ('string'); |
923 |
|
|
ok $node->text_content, 'string', $node->node_name . ' [1]'; |
924 |
|
|
ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [1]'; |
925 |
|
|
|
926 |
|
|
$node->manakai_append_text ('STRING'); |
927 |
|
|
ok $node->text_content, 'stringSTRING', $node->node_name . ' [2]'; |
928 |
|
|
ok 0+@{$node->child_nodes}, 1, $node->node_name . ' childNodes @{} 0+ [2]'; |
929 |
|
|
|
930 |
|
|
my $er = $doc->create_entity_reference ('er'); |
931 |
|
|
$node->append_child ($er); |
932 |
|
|
|
933 |
|
|
$node->manakai_append_text ('text'); |
934 |
|
|
ok $node->text_content, 'stringSTRINGtext', $node->node_name . ' [3]'; |
935 |
|
|
ok 0+@{$node->child_nodes}, 3, $node->node_name . ' childNodes @{} 0+ [3]'; |
936 |
|
|
} |
937 |
|
|
|
938 |
|
|
for my $node ( |
939 |
|
|
$doc->create_text_node (''), |
940 |
|
|
$doc->create_cdata_section (''), |
941 |
|
|
$doc->create_comment (''), |
942 |
|
|
$doc->create_processing_instruction ('PI_manakaiAppendText'), |
943 |
|
|
) { |
944 |
|
|
ok $node->can ('manakai_append_text') ? 1 : 0, 1, $node->node_name . 'can'; |
945 |
|
|
|
946 |
|
|
$node->manakai_append_text ('aaaa'); |
947 |
|
|
ok $node->text_content, 'aaaa', $node->node_name . ' [1]'; |
948 |
|
|
ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]'; |
949 |
|
|
|
950 |
|
|
$node->manakai_append_text ('bbbb'); |
951 |
|
|
ok $node->text_content, 'aaaabbbb', $node->node_name . ' [1]'; |
952 |
|
|
ok 0+@{$node->child_nodes}, 0, $node->node_name . ' childNodes @{} 0+ [1]'; |
953 |
|
|
} |
954 |
|
|
} |
955 |
|
|
|
956 |
|
|
## |baseURI| |
957 |
|
|
{ |
958 |
|
|
my $doc2 = $doc->implementation->create_document; |
959 |
|
|
|
960 |
|
|
$doc2->document_uri (q<ftp://suika.fam.cx/>); |
961 |
|
|
ok $doc2->base_uri, q<ftp://suika.fam.cx/>, 'Document->base_uri [1]'; |
962 |
|
|
|
963 |
|
|
$doc2->document_uri (undef); |
964 |
|
|
ok $doc2->base_uri, undef, 'Document->base_uri [2]'; |
965 |
|
|
ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [2]'; |
966 |
|
|
|
967 |
|
|
$doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>); |
968 |
|
|
ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [3]'; |
969 |
|
|
ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>, |
970 |
|
|
'Document->base_uri ebu [3]'; |
971 |
|
|
|
972 |
|
|
$doc2->manakai_entity_base_uri (undef); |
973 |
|
|
ok $doc2->base_uri, undef, 'Document->base_uri [4]'; |
974 |
|
|
ok $doc2->manakai_entity_base_uri, undef, 'Document->base_uri ebu [4]'; |
975 |
|
|
|
976 |
|
|
$doc2->document_uri (q<ftp://suika.fam.cx/>); |
977 |
|
|
$doc2->manakai_entity_base_uri (q<https://suika.fam.cx/>); |
978 |
|
|
ok $doc2->base_uri, q<https://suika.fam.cx/>, 'Document->base_uri [5]'; |
979 |
|
|
ok $doc2->manakai_entity_base_uri, q<https://suika.fam.cx/>, |
980 |
|
|
'Document->base_uri ebu [5]'; |
981 |
|
|
} |
982 |
|
|
|
983 |
|
|
for my $method (qw/ |
984 |
|
|
create_document_fragment |
985 |
|
|
create_element_type_definition |
986 |
|
|
create_attribute_definition |
987 |
|
|
/) { |
988 |
|
|
my $doc2 = $doc->implementation->create_document; |
989 |
|
|
|
990 |
|
|
my $node = $doc2->$method ('a'); |
991 |
|
|
|
992 |
|
|
$doc2->document_uri (q<ftp://doc.test/>); |
993 |
|
|
ok $node->base_uri, q<ftp://doc.test/>, $node->node_name . '->base_uri [1]'; |
994 |
|
|
|
995 |
|
|
$doc2->manakai_entity_base_uri (q<ftp://suika.fam.cx/>); |
996 |
|
|
ok $node->base_uri, q<ftp://suika.fam.cx/>, |
997 |
|
|
$node->node_name . '->base_uri [2]'; |
998 |
|
|
} |
999 |
|
|
|
1000 |
|
|
{ |
1001 |
|
|
my $doc2 = $doc->implementation->create_document; |
1002 |
|
|
|
1003 |
|
|
my $attr = $doc2->create_attribute_ns (undef, 'attr'); |
1004 |
|
|
|
1005 |
|
|
$doc2->document_uri (q<http://www.example.com/>); |
1006 |
|
|
ok $attr->base_uri, q<http://www.example.com/>, 'Attr->base_uri [1]'; |
1007 |
|
|
|
1008 |
|
|
my $el = $doc2->create_element_ns (undef, 'element'); |
1009 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', |
1010 |
|
|
'xml:base' => q<http://www.example.org/>); |
1011 |
|
|
$el->set_attribute_node_ns ($attr); |
1012 |
|
|
ok $attr->base_uri, q<http://www.example.org/>, 'Attr->base_uri [2]'; |
1013 |
|
|
} |
1014 |
|
|
|
1015 |
|
|
for my $i (0..1) { |
1016 |
|
|
my $xb = [ |
1017 |
|
|
['http://www.w3.org/XML/1998/namespace', 'xml:base'], |
1018 |
|
|
[undef, [undef, 'xml:base']], |
1019 |
|
|
]->[$i]; |
1020 |
|
|
|
1021 |
|
|
my $doc2 = $doc->implementation->create_document; |
1022 |
|
|
|
1023 |
|
|
my $attr = $doc2->create_attribute_ns (@$xb); |
1024 |
|
|
$attr->value (q<http://attr.test/>); |
1025 |
|
|
|
1026 |
|
|
ok $attr->base_uri, undef, 'xml:base->base_uri [0]' . $i; |
1027 |
|
|
|
1028 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1029 |
|
|
ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [1]' . $i; |
1030 |
|
|
|
1031 |
|
|
my $el = $doc2->create_element_ns (undef, 'e'); |
1032 |
|
|
$el->set_attribute_node_ns ($attr); |
1033 |
|
|
ok $attr->base_uri, q<http://doc.test/>, 'xml:base->base_uri [2]' . $i; |
1034 |
|
|
|
1035 |
|
|
my $pel = $doc2->create_element_ns (undef, 'e'); |
1036 |
|
|
$pel->set_attribute_ns (@$xb, q<http://pel.test/>); |
1037 |
|
|
$pel->append_child ($el); |
1038 |
|
|
ok $attr->base_uri, q<http://pel.test/>, 'xml:base->base_uri [3]' . $i; |
1039 |
|
|
} |
1040 |
|
|
|
1041 |
|
|
for my $i (0..1) { |
1042 |
|
|
my $xb = [ |
1043 |
|
|
['http://www.w3.org/XML/1998/namespace', 'xml:base'], |
1044 |
|
|
[undef, [undef, 'xml:base']], |
1045 |
|
|
]->[$i]; |
1046 |
|
|
|
1047 |
|
|
my $doc2 = $doc->implementation->create_document; |
1048 |
|
|
|
1049 |
|
|
my $el = $doc2->create_element_ns (undef, 'el'); |
1050 |
|
|
|
1051 |
|
|
ok $el->base_uri, undef, "Element->base_uri [0]"; |
1052 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [0]"; |
1053 |
|
|
|
1054 |
|
|
$doc2->document_uri (q<http://foo.example/>); |
1055 |
|
|
ok $el->base_uri, q<http://foo.example/>, "Element->base_uri [1]"; |
1056 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [1]"; |
1057 |
|
|
|
1058 |
|
|
$el->set_attribute_ns (@$xb => q<http://www.example.com/>); |
1059 |
|
|
ok $el->base_uri, q<http://www.example.com/>, "Element->base_uri [2]"; |
1060 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [2]"; |
1061 |
|
|
|
1062 |
|
|
$el->set_attribute_ns (@$xb => q<bar>); |
1063 |
|
|
ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [3]"; |
1064 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [3]"; |
1065 |
|
|
|
1066 |
|
|
$el->manakai_base_uri (q<http://baz.example/>); |
1067 |
|
|
ok $el->base_uri, q<http://baz.example/>, "Element->base_uri [4]"; |
1068 |
|
|
ok $el->manakai_base_uri, q<http://baz.example/>, |
1069 |
|
|
"Element->manakai_base_uri [4]"; |
1070 |
|
|
|
1071 |
|
|
$el->manakai_base_uri (undef); |
1072 |
|
|
ok $el->base_uri, q<http://foo.example/bar>, "Element->base_uri [5]"; |
1073 |
|
|
ok $el->manakai_base_uri, undef, "Element->manakai_base_uri [5]"; |
1074 |
|
|
} |
1075 |
|
|
|
1076 |
|
|
{ |
1077 |
|
|
my $doc2 = $doc->implementation->create_document; |
1078 |
|
|
|
1079 |
|
|
my $el = $doc2->create_element_ns (undef, 'el'); |
1080 |
|
|
|
1081 |
|
|
ok $el->base_uri, undef, "Element->base_uri [6]"; |
1082 |
|
|
|
1083 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1084 |
|
|
ok $el->base_uri, q<http://doc.test/>, "Element->base_uri [7]"; |
1085 |
|
|
|
1086 |
|
|
my $el0 = $doc2->create_element_ns (undef, 'e'); |
1087 |
|
|
$el0->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1088 |
|
|
q<http://el.test/>); |
1089 |
|
|
$el0->append_child ($el); |
1090 |
|
|
ok $el->base_uri, q<http://el.test/>, "Element->base_uri [8]"; |
1091 |
|
|
|
1092 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1093 |
|
|
$ent->manakai_set_read_only (0, 1); |
1094 |
|
|
$ent->manakai_external (1); |
1095 |
|
|
$ent->manakai_entity_base_uri (q<http://ent.test/>); |
1096 |
|
|
$el0->append_child ($ent); |
1097 |
|
|
$ent->append_child ($el); |
1098 |
|
|
ok $el->base_uri, q<http://ent.test/>, "Element->base_uri [9]"; |
1099 |
|
|
} |
1100 |
|
|
|
1101 |
|
|
for (qw/create_text_node create_cdata_section create_comment/) { |
1102 |
|
|
my $doc2 = $doc->implementation->create_document; |
1103 |
|
|
my $node = $doc2->$_ (''); |
1104 |
|
|
|
1105 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1106 |
|
|
ok $node->base_uri, q<http://doc.test/>, $node->node_name . "->base_uri [0]"; |
1107 |
|
|
|
1108 |
|
|
my $el = $doc2->create_element_ns (undef, 'e'); |
1109 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1110 |
|
|
q<http://el.test/>); |
1111 |
|
|
$el->append_child ($node); |
1112 |
|
|
ok $node->base_uri, q<http://el.test/>, $node->node_name . "->base_uri [1]"; |
1113 |
|
|
|
1114 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1115 |
|
|
$ent->manakai_set_read_only (0, 1); |
1116 |
|
|
$ent->manakai_external (1); |
1117 |
|
|
$ent->manakai_entity_base_uri (q<http://ent.test/>); |
1118 |
|
|
$el->append_child ($ent); |
1119 |
|
|
$ent->append_child ($node); |
1120 |
|
|
ok $node->base_uri, q<http://ent.test/>, $node->node_name . "->base_uri [2]"; |
1121 |
|
|
} |
1122 |
|
|
|
1123 |
|
|
{ |
1124 |
|
|
my $doc2 = $doc->implementation->create_document; |
1125 |
|
|
my $ent = $doc2->create_general_entity ('ent'); |
1126 |
|
|
|
1127 |
|
|
$doc2->document_uri (q<http://base.example/>); |
1128 |
|
|
ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [1]"; |
1129 |
|
|
|
1130 |
|
|
$ent->manakai_entity_base_uri (q<http://www.example.com/>); |
1131 |
|
|
ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [2]"; |
1132 |
|
|
|
1133 |
|
|
$ent->manakai_declaration_base_uri (q<http://www.example/>); |
1134 |
|
|
ok $ent->base_uri, q<http://base.example/>, "Entity->base_uri [3]"; |
1135 |
|
|
} |
1136 |
|
|
|
1137 |
|
|
{ |
1138 |
|
|
my $doc2 = $doc->implementation->create_document; |
1139 |
|
|
|
1140 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1141 |
|
|
$ent->manakai_set_read_only (0, 1); |
1142 |
|
|
|
1143 |
|
|
$doc2->document_uri (q<http://base.example/>); |
1144 |
|
|
ok $ent->base_uri, q<http://base.example/>, "ER->base_uri [1]"; |
1145 |
|
|
|
1146 |
|
|
$ent->manakai_entity_base_uri (q<http://www.example.com/>); |
1147 |
|
|
ok $ent->base_uri, q<http://base.example/>; |
1148 |
|
|
|
1149 |
|
|
my $el = $doc2->create_element_ns (undef, 'el'); |
1150 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1151 |
|
|
q<http://el.test/>); |
1152 |
|
|
$el->append_child ($ent); |
1153 |
|
|
ok $ent->base_uri, q<http://el.test/>, "ER->base_uri [2]"; |
1154 |
|
|
|
1155 |
|
|
my $xent = $doc2->create_entity_reference ('ext'); |
1156 |
|
|
$xent->manakai_set_read_only (0, 1); |
1157 |
|
|
$xent->manakai_entity_base_uri (q<http://ent.test/>); |
1158 |
|
|
$xent->manakai_external (1); |
1159 |
|
|
$el->append_child ($xent); |
1160 |
|
|
$xent->append_child ($ent); |
1161 |
|
|
ok $ent->base_uri, q<http://ent.test/>, "ER->base_uri [3]"; |
1162 |
|
|
} |
1163 |
|
|
|
1164 |
|
|
{ |
1165 |
|
|
my $doc2 = $doc->implementation->create_document; |
1166 |
|
|
|
1167 |
|
|
my $pi = $doc2->create_processing_instruction ('i'); |
1168 |
|
|
|
1169 |
|
|
ok $pi->base_uri, undef, "PI->base_uri [0]"; |
1170 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [0]"; |
1171 |
|
|
|
1172 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1173 |
|
|
ok $pi->base_uri, q<http://doc.test/>, "PI->base_uri [1]"; |
1174 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [1]"; |
1175 |
|
|
|
1176 |
|
|
my $el = $doc2->create_element_ns (undef, 'e'); |
1177 |
|
|
$el->set_attribute_ns ('http://www.w3.org/XML/1998/namespace', 'xml:base', |
1178 |
|
|
q<http://el.test/>); |
1179 |
|
|
$el->append_child ($pi); |
1180 |
|
|
ok $pi->base_uri, q<http://el.test/>, "PI->base_uri [2]"; |
1181 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [2]"; |
1182 |
|
|
|
1183 |
|
|
my $ent = $doc2->create_entity_reference ('ent'); |
1184 |
|
|
$ent->manakai_set_read_only (0, 1); |
1185 |
|
|
$ent->manakai_external (1); |
1186 |
|
|
$ent->manakai_entity_base_uri (q<http://ent.test/>); |
1187 |
|
|
$el->append_child ($ent); |
1188 |
|
|
$ent->append_child ($pi); |
1189 |
|
|
ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [3]"; |
1190 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [3]"; |
1191 |
|
|
|
1192 |
|
|
$pi->manakai_base_uri (q<http://pi.ent/>); |
1193 |
|
|
ok $pi->base_uri, q<http://pi.ent/>, "PI->base_uri [4]"; |
1194 |
|
|
ok $pi->manakai_base_uri, q<http://pi.ent/>, "PI->manakai_base_uri [4]"; |
1195 |
|
|
|
1196 |
|
|
$pi->manakai_base_uri (undef); |
1197 |
|
|
ok $pi->base_uri, q<http://ent.test/>, "PI->base_uri [5]"; |
1198 |
|
|
ok $pi->manakai_base_uri, undef, "PI->manakai_base_uri [5]"; |
1199 |
|
|
} |
1200 |
|
|
|
1201 |
|
|
{ |
1202 |
|
|
my $doc2 = $doc->implementation->create_document; |
1203 |
|
|
|
1204 |
|
|
my $pi = $doc2->create_notation ('i'); |
1205 |
|
|
|
1206 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1207 |
|
|
ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [1]"; |
1208 |
|
|
|
1209 |
|
|
$pi->manakai_declaration_base_uri (q<http://www.example/>); |
1210 |
|
|
ok $pi->base_uri, q<http://doc.test/>, "Notation->base_uri [2]"; |
1211 |
|
|
} |
1212 |
|
|
|
1213 |
|
|
{ |
1214 |
|
|
my $dt = $doc->implementation->create_document_type ('name'); |
1215 |
|
|
ok $dt->base_uri, undef, "DT->base_uri [0]"; |
1216 |
|
|
|
1217 |
|
|
my $doc2 = $doc->implementation->create_document; |
1218 |
|
|
$doc2->append_child ($dt); |
1219 |
|
|
$doc2->document_uri (q<http://doc.test/>); |
1220 |
|
|
ok $dt->owner_document, $doc2; |
1221 |
|
|
ok $dt->base_uri, q<http://doc.test/>, "DT->base_uri [1]"; |
1222 |
|
|
} |
1223 |
|
|
|
1224 |
|
|
|
1225 |
wakaba |
1.2 |
## TODO: parent_node tests, as with append_child tests |
1226 |
|
|
|
1227 |
wakaba |
1.3 |
## TODO: text_content tests for CharacterData and PI |
1228 |
|
|
|
1229 |
wakaba |
1.4 |
=head1 LICENSE |
1230 |
|
|
|
1231 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
1232 |
wakaba |
1.3 |
|
1233 |
wakaba |
1.4 |
This program is free software; you can redistribute it and/or |
1234 |
|
|
modify it under the same terms as Perl itself. |
1235 |
wakaba |
1.2 |
|
1236 |
wakaba |
1.4 |
=cut |
1237 |
wakaba |
1.2 |
|
1238 |
wakaba |
1.5 |
## $Date: 2007/06/17 13:37:42 $ |