1 |
wakaba |
1.1 |
#!/usr/bin/perl |
2 |
|
|
use strict; |
3 |
|
|
use Test; |
4 |
|
|
BEGIN { plan tests => 423 } |
5 |
|
|
|
6 |
|
|
require Message::DOM::DOMImplementation; |
7 |
|
|
use Message::Util::Error; |
8 |
|
|
|
9 |
|
|
my $dom = Message::DOM::DOMImplementation->new; |
10 |
|
|
my $doc = $dom->create_document; |
11 |
|
|
|
12 |
|
|
## |create_tree_walker| and attributes |
13 |
|
|
{ |
14 |
|
|
ok $doc->can ('create_tree_walker') ? 1 : 0, 1, 'Document->create_tw can'; |
15 |
|
|
|
16 |
|
|
my $el = $doc->create_element ('e'); |
17 |
|
|
my $tw = $doc->create_tree_walker ($el); |
18 |
|
|
|
19 |
|
|
ok $tw->isa ('Message::IF::TreeWalker') ? 1 : 0, 1, 'create_tw [1] if'; |
20 |
|
|
ok $tw->what_to_show, 0, 'create_tw [1] what_to_show'; |
21 |
|
|
ok $tw->filter, undef, 'create_tw [1] filter'; |
22 |
|
|
ok $tw->expand_entity_references ? 1 : 0, 0, 'create_tw [1] xent'; |
23 |
|
|
ok $tw->current_node, $el, 'create_tw [1] current_node'; |
24 |
|
|
ok $tw->root, $el, 'create_tw [1] root'; |
25 |
|
|
} |
26 |
|
|
{ |
27 |
|
|
my $el = $doc->create_element ('e'); |
28 |
|
|
my $filter = sub { }; |
29 |
|
|
my $tw = $doc->create_tree_walker ($el, 0xFFFFFFFF, $filter, 1); |
30 |
|
|
|
31 |
|
|
ok $tw->isa ('Message::IF::TreeWalker') ? 1 : 0, 1, 'create_tw [2] if'; |
32 |
|
|
ok $tw->what_to_show, 0xFFFFFFFF, 'create_tw [2] what_to_show'; |
33 |
|
|
ok $tw->filter, $filter, 'create_tw [2] filter'; |
34 |
|
|
ok $tw->expand_entity_references ? 1 : 0, 1, 'create_tw [2] xent'; |
35 |
|
|
ok $tw->current_node, $el, 'create_tw [2] current_node'; |
36 |
|
|
ok $tw->root, $el, 'create_tw [2] root'; |
37 |
|
|
} |
38 |
|
|
{ |
39 |
|
|
my $el = $doc->create_element ('e'); |
40 |
|
|
my $filter = sub { }; |
41 |
|
|
my $tw = $doc->create_tree_walker ($el, 0xFFFFFFFF, $filter, 0); |
42 |
|
|
|
43 |
|
|
ok $tw->isa ('Message::IF::TreeWalker') ? 1 : 0, 1, 'create_tw [3] if'; |
44 |
|
|
ok $tw->what_to_show, 0xFFFFFFFF, 'create_tw [3] what_to_show'; |
45 |
|
|
ok $tw->filter, $filter, 'create_tw [3] filter'; |
46 |
|
|
ok $tw->expand_entity_references ? 1 : 0, 0, 'create_tw [3] xent'; |
47 |
|
|
ok $tw->current_node, $el, 'create_tw [3] current_node'; |
48 |
|
|
ok $tw->root, $el, 'create_tw [3] root'; |
49 |
|
|
} |
50 |
|
|
try { |
51 |
|
|
$doc->create_tree_walker; |
52 |
|
|
ok 1, 0, 'create_tw [4]'; |
53 |
|
|
} catch Message::IF::DOMException with { |
54 |
|
|
ok $_[0]->type, 'NOT_SUPPORTED_ERR', 'create_tw [4]'; |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
my $tw = $doc->create_tree_walker ($doc); |
58 |
|
|
|
59 |
|
|
my %tree1; |
60 |
|
|
$tree1{el1} = $doc->create_element ('el1'); |
61 |
|
|
$tree1{el2} = $doc->create_element ('el2'); |
62 |
|
|
$tree1{el3} = $doc->create_element ('el3'); |
63 |
|
|
$tree1{el4} = $doc->create_element ('el4'); |
64 |
|
|
$tree1{el1}->append_child ($tree1{el2}); |
65 |
|
|
$tree1{el1}->append_child ($tree1{el3}); |
66 |
|
|
$tree1{el3}->append_child ($tree1{el4}); |
67 |
|
|
|
68 |
|
|
my %tree2; |
69 |
|
|
$tree2{el1} = $doc->create_element ('el1'); |
70 |
|
|
$tree2{el2} = $doc->create_element ('el2'); |
71 |
|
|
$tree2{el3} = $doc->create_element ('el3'); |
72 |
|
|
$tree2{el4} = $doc->create_element ('el4'); |
73 |
|
|
$tree2{el5} = $doc->create_element ('el5'); |
74 |
|
|
$tree2{el1}->append_child ($tree2{el2}); |
75 |
|
|
$tree2{el1}->append_child ($tree2{el3}); |
76 |
|
|
$tree2{el3}->append_child ($tree2{el4}); |
77 |
|
|
$tree2{el3}->append_child ($tree2{el5}); |
78 |
|
|
|
79 |
|
|
my %tree3; |
80 |
|
|
$tree3{el1} = $doc->create_element ('el1'); |
81 |
|
|
$tree3{el2} = $doc->create_element ('el2'); |
82 |
|
|
$tree3{el3} = $doc->create_element ('el3'); |
83 |
|
|
$tree3{el4} = $doc->create_element ('el4'); |
84 |
|
|
$tree3{el5} = $doc->create_element ('el5'); |
85 |
|
|
$tree3{el1}->append_child ($tree3{el2}); |
86 |
|
|
$tree3{el1}->append_child ($tree3{el3}); |
87 |
|
|
$tree3{el3}->append_child ($tree3{el4}); |
88 |
|
|
$tree3{el1}->append_child ($tree3{el5}); |
89 |
|
|
|
90 |
|
|
my %tree4; |
91 |
|
|
$tree4{el1} = $doc->create_element ('el1'); |
92 |
|
|
$tree4{er1} = $doc->create_entity_reference ('er1'); |
93 |
|
|
$tree4{er1}->manakai_set_read_only (0, 1); |
94 |
|
|
$tree4{el3} = $doc->create_element ('el3'); |
95 |
|
|
$tree4{el4} = $doc->create_element ('el4'); |
96 |
|
|
$tree4{el5} = $doc->create_element ('el5'); |
97 |
|
|
$tree4{el6} = $doc->create_element ('el6'); |
98 |
|
|
$tree4{el1}->append_child ($tree4{er1}); |
99 |
|
|
$tree4{er1}->append_child ($tree4{el3}); |
100 |
|
|
$tree4{el3}->append_child ($tree4{el4}); |
101 |
|
|
$tree4{er1}->append_child ($tree4{el5}); |
102 |
|
|
$tree4{el1}->append_child ($tree4{el6}); |
103 |
|
|
|
104 |
|
|
my %tree5; |
105 |
|
|
$tree5{el1} = $doc->create_element ('el1'); |
106 |
|
|
$tree5{el2} = $doc->create_element ('el2'); |
107 |
|
|
$tree5{er1} = $doc->create_entity_reference ('er1'); |
108 |
|
|
$tree5{er1}->manakai_set_read_only (0, 1); |
109 |
|
|
$tree5{el3} = $doc->create_element ('el3'); |
110 |
|
|
$tree5{el4} = $doc->create_element ('el4'); |
111 |
|
|
$tree5{el5} = $doc->create_element ('el5'); |
112 |
|
|
$tree5{el1}->append_child ($tree5{el2}); |
113 |
|
|
$tree5{el1}->append_child ($tree5{er1}); |
114 |
|
|
$tree5{er1}->append_child ($tree5{el3}); |
115 |
|
|
$tree5{er1}->append_child ($tree5{el5}); |
116 |
|
|
$tree5{el3}->append_child ($tree5{el4}); |
117 |
|
|
|
118 |
|
|
## |currentNode| |
119 |
|
|
{ |
120 |
|
|
my $el = $doc->create_element ('e'); |
121 |
|
|
$tw->current_node ($el); |
122 |
|
|
ok $tw->current_node, $el, 'current_node set [1]'; |
123 |
|
|
} |
124 |
|
|
try { |
125 |
|
|
$tw->current_node (undef); |
126 |
|
|
ok 1, 0, 'current_node set null'; |
127 |
|
|
} catch Message::IF::DOMException with { |
128 |
|
|
ok shift->type, 'NOT_SUPPORTED_ERR', 'current_node set null'; |
129 |
|
|
}; |
130 |
|
|
|
131 |
|
|
## |firstChild| |
132 |
|
|
{ |
133 |
|
|
my $tw = $doc->create_tree_walker ($tree2{el1}, 0xFFFFFFFF); |
134 |
|
|
ok $tw->can ('first_child') ? 1 : 0, 1, 'can first_child'; |
135 |
|
|
|
136 |
|
|
ok $tw->first_child, $tree2{el2}, 'fc fc [1]'; |
137 |
|
|
ok $tw->current_node, $tree2{el2}, 'fc cn [1]'; |
138 |
|
|
|
139 |
|
|
ok $tw->first_child, undef, 'fc fc [2]'; |
140 |
|
|
ok $tw->current_node, $tree2{el2}, 'fc cn [2]'; |
141 |
|
|
|
142 |
|
|
$tw->current_node ($tree2{el3}); |
143 |
|
|
ok $tw->first_child, $tree2{el4}, 'fc fc [3]'; |
144 |
|
|
ok $tw->current_node, $tree2{el4}, 'fc cn [3]'; |
145 |
|
|
|
146 |
|
|
ok $tw->first_child, undef, 'fc fc [4]'; |
147 |
|
|
ok $tw->current_node, $tree2{el4}, 'fc cn [4]'; |
148 |
|
|
} |
149 |
|
|
{ |
150 |
|
|
my $tw = $doc->create_tree_walker ($tree1{el1}, 0x00000002); # SHOW_ATTRIBUTE |
151 |
|
|
|
152 |
|
|
ok $tw->first_child, undef, 'fc fc [5]'; |
153 |
|
|
ok $tw->current_node, $tree1{el1}, 'fc cn [5]'; |
154 |
|
|
|
155 |
|
|
$tw->current_node ($tree1{el2}); |
156 |
|
|
ok $tw->first_child, undef, 'fc fc [6]'; |
157 |
|
|
ok $tw->current_node, $tree1{el2}, 'fc cn [6]'; |
158 |
|
|
|
159 |
|
|
$tw->current_node ($tree1{el3}); |
160 |
|
|
ok $tw->first_child, undef, 'fc fc [7]'; |
161 |
|
|
ok $tw->current_node, $tree1{el3}, 'fc cn [7]'; |
162 |
|
|
|
163 |
|
|
$tw->current_node ($tree1{el4}); |
164 |
|
|
ok $tw->first_child, undef, 'fc fc [8]'; |
165 |
|
|
ok $tw->current_node, $tree1{el4}, 'fc cn [8]'; |
166 |
|
|
} |
167 |
|
|
{ |
168 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, undef, 0); |
169 |
|
|
|
170 |
|
|
ok $tw->first_child, $tree4{er1}, 'fc fc [9]'; |
171 |
|
|
ok $tw->current_node, $tree4{er1}, 'fc cn [9]'; |
172 |
|
|
|
173 |
|
|
$tw->current_node ($tree4{er1}); |
174 |
|
|
ok $tw->first_child, undef, 'fc fc [10]'; |
175 |
|
|
ok $tw->current_node, $tree4{er1}, 'fc cn [10]'; |
176 |
|
|
|
177 |
|
|
$tw->current_node ($tree4{el3}); |
178 |
|
|
ok $tw->first_child, $tree4{el4}, 'fc fc [11]'; |
179 |
|
|
ok $tw->current_node, $tree4{el4}, 'fc cn [11]'; |
180 |
|
|
|
181 |
|
|
ok $tw->first_child, undef, 'fc fc [12]'; |
182 |
|
|
ok $tw->current_node, $tree4{el4}, 'fc cn [12]'; |
183 |
|
|
|
184 |
|
|
$tw->current_node ($tree4{el5}); |
185 |
|
|
ok $tw->first_child, undef, 'fc fc [13]'; |
186 |
|
|
ok $tw->current_node, $tree4{el5}, 'fc cn [13]'; |
187 |
|
|
|
188 |
|
|
$tw->current_node ($tree4{el6}); |
189 |
|
|
ok $tw->first_child, undef, 'fc fc [14]'; |
190 |
|
|
ok $tw->current_node, $tree4{el6}, 'fc cn [14]'; |
191 |
|
|
} |
192 |
|
|
{ |
193 |
|
|
## expandEntityReferences emulated by MANAKAI_FILTER_OPAQUE |
194 |
|
|
|
195 |
|
|
my $tw = $doc->create_tree_walker |
196 |
|
|
($tree4{el1}, 0xFFFFFFFF, sub { |
197 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE |
198 |
|
|
? 12101 : 1; |
199 |
|
|
}, 1); |
200 |
|
|
|
201 |
|
|
for ( |
202 |
|
|
['el1', undef, 'er1', 'er1'], |
203 |
|
|
['er1', 'er1', undef, 'er1'], |
204 |
|
|
['el3', 'el3', 'el4', 'el4'], |
205 |
|
|
['el4', undef, undef, 'el4'], |
206 |
|
|
['el5', 'el5', undef, 'el5'], |
207 |
|
|
['el6', 'el6', undef, 'el6'], |
208 |
|
|
) { |
209 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
210 |
|
|
ok $tw->first_child, $_->[2] ? $tree4{$_->[2]} : undef, |
211 |
|
|
'first_child [4] ' . $_->[0] . ' first_child'; |
212 |
|
|
ok $tw->current_node, $tree4{$_->[3]}, |
213 |
|
|
'first_child [4] ' . $_->[0] . ' current_node'; |
214 |
|
|
} |
215 |
|
|
} |
216 |
|
|
|
217 |
|
|
## |lastChild| |
218 |
|
|
{ |
219 |
|
|
my $tw = $doc->create_tree_walker ($tree2{el1}, 0xFFFFFFFF); |
220 |
|
|
ok $tw->can ('last_child') ? 1 : 0, 1, 'can last_child'; |
221 |
|
|
|
222 |
|
|
for ( |
223 |
|
|
['el1', undef, 'el3', 'el3'], |
224 |
|
|
['el3', undef, 'el5', 'el5'], |
225 |
|
|
['el5', undef, undef, 'el5'], |
226 |
|
|
['el2', 'el2', undef, 'el2'], |
227 |
|
|
['el4', 'el4', undef, 'el4'], |
228 |
|
|
) { |
229 |
|
|
$tw->current_node ($tree2{$_->[1]}) if $_->[1]; |
230 |
|
|
ok $tw->last_child, $_->[2] ? $tree2{$_->[2]} : undef, |
231 |
|
|
'last_child [1] ' . $_->[0] . ' last_child'; |
232 |
|
|
ok $tw->current_node, $tree2{$_->[3]}, |
233 |
|
|
'last_child [1] ' . $_->[0] . ' current_node'; |
234 |
|
|
} |
235 |
|
|
} |
236 |
|
|
{ |
237 |
|
|
my $tw = $doc->create_tree_walker ($tree1{el1}, 0x00000002); # SHOW_ATTRIBUTE |
238 |
|
|
|
239 |
|
|
for ( |
240 |
|
|
['el1', undef, undef], |
241 |
|
|
['el2', 'el2', undef], |
242 |
|
|
['el3', 'el3', undef], |
243 |
|
|
['el4', 'el4', undef], |
244 |
|
|
) { |
245 |
|
|
$tw->current_node ($tree1{$_->[1]}) if $_->[1]; |
246 |
|
|
ok $tw->last_child, $_->[2] ? $tree1{$_->[2]} : undef, |
247 |
|
|
'last_child [2] ' . $_->[0] . ' last_child'; |
248 |
|
|
ok $tw->current_node, $tree1{$_->[2] || $_->[1] || $_->[0]}, |
249 |
|
|
'last_child [2] ' . $_->[0] . ' current_node'; |
250 |
|
|
} |
251 |
|
|
} |
252 |
|
|
{ |
253 |
|
|
my $tw = $doc->create_tree_walker ($tree5{el1}, 0xFFFFFFFF, undef, 0); |
254 |
|
|
|
255 |
|
|
for ( |
256 |
|
|
['el1', undef, 'er1'], |
257 |
|
|
['er1', undef, undef], |
258 |
|
|
['el2', 'el2', undef], |
259 |
|
|
['el3', 'el3', 'el4'], |
260 |
|
|
['el4', undef, undef], |
261 |
|
|
['el5', 'el5', undef], |
262 |
|
|
) { |
263 |
|
|
$tw->current_node ($tree5{$_->[1]}) if $_->[1]; |
264 |
|
|
ok $tw->last_child, $_->[2] ? $tree5{$_->[2]} : undef, |
265 |
|
|
'last_child [3] ' . $_->[0] . ' last_child'; |
266 |
|
|
ok $tw->current_node, $tree5{$_->[2] || $_->[1] || $_->[0]}, |
267 |
|
|
'last_child [3] ' . $_->[0] . ' current_node'; |
268 |
|
|
} |
269 |
|
|
} |
270 |
|
|
{ |
271 |
|
|
my $tw = $doc->create_tree_walker ($tree5{el1}, 0xFFFFFFFF, sub { |
272 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE |
273 |
|
|
? 12101 : 1; |
274 |
|
|
}, 1); |
275 |
|
|
|
276 |
|
|
for ( |
277 |
|
|
['el1', undef, 'er1'], |
278 |
|
|
['er1', undef, undef], |
279 |
|
|
['el3', 'el3', 'el4'], |
280 |
|
|
['el4', undef, undef], |
281 |
|
|
['el5', 'el5', undef], |
282 |
|
|
['el2', 'el2', undef], |
283 |
|
|
) { |
284 |
|
|
$tw->current_node ($tree5{$_->[1]}) if $_->[1]; |
285 |
|
|
ok $tw->last_child, $_->[2] ? $tree5{$_->[2]} : undef, |
286 |
|
|
'last_child [4] ' . $_->[0] . ' last_child'; |
287 |
|
|
ok $tw->current_node, $tree5{$_->[2] || $_->[1] || $_->[0]}, |
288 |
|
|
'last_child [4] ' . $_->[0] . ' current_node'; |
289 |
|
|
} |
290 |
|
|
} |
291 |
|
|
|
292 |
|
|
## |parentNode| |
293 |
|
|
{ |
294 |
|
|
my $tw = $doc->create_tree_walker ($tree1{el1}, 0xFFFFFFFF); |
295 |
|
|
ok $tw->can ('parent_node') ? 1 : 0, 1, 'can parent_node'; |
296 |
|
|
|
297 |
|
|
for ( |
298 |
|
|
['el1', undef, undef], |
299 |
|
|
['el4', 'el4', 'el3'], |
300 |
|
|
['el3', undef, 'el1'], |
301 |
|
|
['el2', 'el2', 'el1'], |
302 |
|
|
) { |
303 |
|
|
$tw->current_node ($tree1{$_->[1]}) if $_->[1]; |
304 |
|
|
ok $tw->parent_node, $_->[2] ? $tree1{$_->[2]} : undef, |
305 |
|
|
'parent_node [1] ' . $_->[0] . ' parent_node'; |
306 |
|
|
ok $tw->current_node, $tree1{$_->[2] || $_->[1] || $_->[0]}, |
307 |
|
|
'parent_node [1] ' . $_->[0] . ' current_node'; |
308 |
|
|
} |
309 |
|
|
} |
310 |
|
|
{ |
311 |
|
|
my $tw = $doc->create_tree_walker ($tree1{el1}, 0xFFFFFFFF, sub { |
312 |
|
|
$_[0]->local_name eq 'el3' ? 1 : 2 # ACCEPT : REJECT |
313 |
|
|
}); |
314 |
|
|
|
315 |
|
|
for ( |
316 |
|
|
['el1', undef, undef], |
317 |
|
|
['el2', 'el2', undef], |
318 |
|
|
['el3', 'el3', undef], |
319 |
|
|
['el4', 'el4', 'el3'], |
320 |
|
|
) { |
321 |
|
|
$tw->current_node ($tree1{$_->[1]}) if $_->[1]; |
322 |
|
|
ok $tw->parent_node, $_->[2] ? $tree1{$_->[2]} : undef, |
323 |
|
|
'parent_node [2] ' . $_->[0] . ' parent_node'; |
324 |
|
|
ok $tw->current_node, $tree1{$_->[2] || $_->[1] || $_->[0]}, |
325 |
|
|
'parent_node [2] ' . $_->[0] . ' current_node'; |
326 |
|
|
} |
327 |
|
|
} |
328 |
|
|
{ |
329 |
|
|
my $tw = $doc->create_tree_walker ($tree1{el1}, 0xFFFFFFFF, sub { |
330 |
|
|
$_[0]->local_name eq 'el3' ? 3 : 1 # SKIP : ACCEPT |
331 |
|
|
}); |
332 |
|
|
|
333 |
|
|
for ( |
334 |
|
|
['el1', undef, undef], |
335 |
|
|
['el2', 'el2', 'el1'], |
336 |
|
|
['el3', 'el3', 'el1'], |
337 |
|
|
['el4', 'el4', 'el1'], |
338 |
|
|
) { |
339 |
|
|
$tw->current_node ($tree1{$_->[1]}) if $_->[1]; |
340 |
|
|
ok $tw->parent_node, $_->[2] ? $tree1{$_->[2]} : undef, |
341 |
|
|
'parent_node [3] ' . $_->[0] . ' parent_node'; |
342 |
|
|
ok $tw->current_node, $tree1{$_->[2] || $_->[1] || $_->[0]}, |
343 |
|
|
'parent_node [3] ' . $_->[0] . ' current_node'; |
344 |
|
|
} |
345 |
|
|
} |
346 |
|
|
{ |
347 |
|
|
## NOTE: FILTER_REJECT works as if FILTER_SKIP if the currentNode |
348 |
|
|
## is in the rejected subtree. |
349 |
|
|
|
350 |
|
|
my $tw = $doc->create_tree_walker ($tree1{el1}, 0xFFFFFFFF, sub { |
351 |
|
|
$_[0]->local_name eq 'el3' ? 2 : 1 # REJECT : ACCEPT |
352 |
|
|
}); |
353 |
|
|
|
354 |
|
|
for ( |
355 |
|
|
['el1', undef, undef], |
356 |
|
|
['el2', 'el2', 'el1'], |
357 |
|
|
['el3', 'el3', 'el1'], |
358 |
|
|
['el4', 'el4', 'el1'], |
359 |
|
|
) { |
360 |
|
|
$tw->current_node ($tree1{$_->[1]}) if $_->[1]; |
361 |
|
|
ok $tw->parent_node, $_->[2] ? $tree1{$_->[2]} : undef, |
362 |
|
|
'parent_node [4] ' . $_->[0] . ' parent_node'; |
363 |
|
|
ok $tw->current_node, $tree1{$_->[2] || $_->[1] || $_->[0]}, |
364 |
|
|
'parent_node [4] ' . $_->[0] . ' current_node'; |
365 |
|
|
} |
366 |
|
|
} |
367 |
|
|
{ |
368 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, undef, 0); |
369 |
|
|
|
370 |
|
|
for ( |
371 |
|
|
['el1', undef, undef], |
372 |
|
|
['er1', 'er1', 'el1'], |
373 |
|
|
['el3', 'el3', 'er1'], |
374 |
|
|
['el4', 'el4', 'er1'], |
375 |
|
|
['el5', 'el5', 'er1'], |
376 |
|
|
['el6', 'el6', 'el1'], |
377 |
|
|
) { |
378 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
379 |
|
|
ok $tw->parent_node, $_->[2] ? $tree4{$_->[2]} : undef, |
380 |
|
|
'parent_node [5] ' . $_->[0] . ' parent_node'; |
381 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
382 |
|
|
'parent_node [5] ' . $_->[0] . ' current_node'; |
383 |
|
|
} |
384 |
|
|
} |
385 |
|
|
{ |
386 |
|
|
my $tw = $doc->create_tree_walker |
387 |
|
|
($tree5{el1}, 0xFFFFFFFF, sub { |
388 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE |
389 |
|
|
? 12101 : 1; |
390 |
|
|
}, 1); |
391 |
|
|
|
392 |
|
|
for ( |
393 |
|
|
['el1', undef, undef], |
394 |
|
|
['er1', 'er1', 'el1'], |
395 |
|
|
['el3', 'el3', 'er1'], |
396 |
|
|
['el4', 'el4', 'el3'], |
397 |
|
|
['el5', 'el5', 'er1'], |
398 |
|
|
['el2', 'el2', 'el1'], |
399 |
|
|
) { |
400 |
|
|
$tw->current_node ($tree5{$_->[1]}) if $_->[1]; |
401 |
|
|
ok $tw->parent_node, $_->[2] ? $tree5{$_->[2]} : undef, |
402 |
|
|
'parent_node [6] ' . $_->[0] . ' parent_node'; |
403 |
|
|
ok $tw->current_node, $tree5{$_->[2] || $_->[1] || $_->[0]}, |
404 |
|
|
'parent_node [6] ' . $_->[0] . ' current_node'; |
405 |
|
|
} |
406 |
|
|
} |
407 |
|
|
|
408 |
|
|
## |nextNode| |
409 |
|
|
{ |
410 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF); |
411 |
|
|
ok $tw->can ('next_node') ? 1 : 0, 1, 'can next_node'; |
412 |
|
|
|
413 |
|
|
for ( |
414 |
|
|
['el1', undef, 'el2'], |
415 |
|
|
['el2', undef, 'el3'], |
416 |
|
|
['el3', undef, 'el4'], |
417 |
|
|
['el4', undef, 'el5'], |
418 |
|
|
['el5', undef, undef], |
419 |
|
|
) { |
420 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
421 |
|
|
ok $tw->next_node, $_->[2] ? $tree3{$_->[2]} : undef, |
422 |
|
|
'next_node [1] ' . $_->[0] . ' next_node'; |
423 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
424 |
|
|
'next_node [1] ' . $_->[0] . ' current_node'; |
425 |
|
|
} |
426 |
|
|
} |
427 |
|
|
{ |
428 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el3}, 0xFFFFFFFF); |
429 |
|
|
|
430 |
|
|
for ( |
431 |
|
|
['el1', 'el1', 'el2'], |
432 |
|
|
['el2', undef, 'el3'], |
433 |
|
|
['el3', undef, 'el4'], |
434 |
|
|
['el4', undef, undef], |
435 |
|
|
['el5', 'el5', undef], |
436 |
|
|
) { |
437 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
438 |
|
|
ok $tw->next_node, $_->[2] ? $tree3{$_->[2]} : undef, |
439 |
|
|
'next_node [2] ' . $_->[0] . ' next_node'; |
440 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
441 |
|
|
'next_node [2] ' . $_->[0] . ' current_node'; |
442 |
|
|
} |
443 |
|
|
} |
444 |
|
|
{ |
445 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
446 |
|
|
$_[0]->local_name eq 'el3' ? 3 : 1 # SKIP : ACCEPT |
447 |
|
|
}); |
448 |
|
|
|
449 |
|
|
for ( |
450 |
|
|
['el1', undef, 'el2'], |
451 |
|
|
['el2', undef, 'el4'], |
452 |
|
|
['el3', 'el3', 'el4'], |
453 |
|
|
['el4', undef, 'el5'], |
454 |
|
|
['el5', undef, undef], |
455 |
|
|
) { |
456 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
457 |
|
|
ok $tw->next_node, $_->[2] ? $tree3{$_->[2]} : undef, |
458 |
|
|
'next_node [3] ' . $_->[0] . ' next_node'; |
459 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
460 |
|
|
'next_node [3] ' . $_->[0] . ' current_node'; |
461 |
|
|
} |
462 |
|
|
} |
463 |
|
|
{ |
464 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
465 |
|
|
$_[0]->local_name eq 'el3' ? 2 : 1 # REJECT : ACCEPT |
466 |
|
|
}); |
467 |
|
|
|
468 |
|
|
for ( |
469 |
|
|
['el1', undef, 'el2'], |
470 |
|
|
['el2', undef, 'el5'], |
471 |
|
|
['el3', 'el3', 'el4'], |
472 |
|
|
['el4', undef, 'el5'], |
473 |
|
|
['el5', undef, undef], |
474 |
|
|
) { |
475 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
476 |
|
|
ok $tw->next_node, $_->[2] ? $tree3{$_->[2]} : undef, |
477 |
|
|
'next_node [4] ' . $_->[0] . ' next_node'; |
478 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
479 |
|
|
'next_node [4] ' . $_->[0] . ' current_node'; |
480 |
|
|
} |
481 |
|
|
} |
482 |
|
|
{ |
483 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF); |
484 |
|
|
|
485 |
|
|
for ( |
486 |
|
|
['el1', undef, 'er1'], |
487 |
|
|
['er1', undef, 'el6'], |
488 |
|
|
['el3', 'el3', 'el4'], |
489 |
|
|
['el4', undef, 'el6'], |
490 |
|
|
['el5', 'el5', 'el6'], |
491 |
|
|
['el6', undef, undef], |
492 |
|
|
) { |
493 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
494 |
|
|
ok $tw->next_node, $_->[2] ? $tree4{$_->[2]} : undef, |
495 |
|
|
'next_node [5] ' . $_->[0] . ' next_node'; |
496 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
497 |
|
|
'next_node [5] ' . $_->[0] . ' current_node'; |
498 |
|
|
} |
499 |
|
|
} |
500 |
|
|
{ |
501 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, sub { |
502 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE ? 12101 : 1; |
503 |
|
|
}, 1); |
504 |
|
|
|
505 |
|
|
for ( |
506 |
|
|
['el1', undef, 'er1'], |
507 |
|
|
['er1', undef, 'el6'], |
508 |
|
|
['el3', 'el3', 'el4'], |
509 |
|
|
['el4', undef, 'el5'], |
510 |
|
|
['el5', undef, 'el6'], |
511 |
|
|
['el6', undef, undef], |
512 |
|
|
) { |
513 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
514 |
|
|
ok $tw->next_node, $_->[2] ? $tree4{$_->[2]} : undef, |
515 |
|
|
'next_node [6] ' . $_->[0] . ' next_node'; |
516 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
517 |
|
|
'next_node [6] ' . $_->[0] . ' current_node'; |
518 |
|
|
} |
519 |
|
|
} |
520 |
|
|
|
521 |
|
|
## |nextSibling| |
522 |
|
|
{ |
523 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF); |
524 |
|
|
ok $tw->can ('next_sibling') ? 1 : 0, 1, 'can next_sibling'; |
525 |
|
|
|
526 |
|
|
for ( |
527 |
|
|
['el1', undef, undef], |
528 |
|
|
['el2', 'el2', 'el3'], |
529 |
|
|
['el3', undef, 'el5'], |
530 |
|
|
['el4', 'el4', undef], |
531 |
|
|
['el5', 'el5', undef], |
532 |
|
|
) { |
533 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
534 |
|
|
ok $tw->next_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
535 |
|
|
'next_sibling [1] ' . $_->[0] . ' next_sibling'; |
536 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
537 |
|
|
'next_sibling [1] ' . $_->[0] . ' current_node'; |
538 |
|
|
} |
539 |
|
|
} |
540 |
|
|
{ |
541 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el3}, 0xFFFFFFFF); |
542 |
|
|
|
543 |
|
|
for ( |
544 |
|
|
['el1', 'el1', undef], |
545 |
|
|
['el2', 'el2', 'el3'], |
546 |
|
|
['el3', 'el3', undef], |
547 |
|
|
['el4', 'el4', undef], |
548 |
|
|
['el5', 'el5', undef], |
549 |
|
|
) { |
550 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
551 |
|
|
ok $tw->next_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
552 |
|
|
'next_sibling [2] ' . $_->[0] . ' next_sibling'; |
553 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
554 |
|
|
'next_sibling [2] ' . $_->[0] . ' current_node'; |
555 |
|
|
} |
556 |
|
|
} |
557 |
|
|
{ |
558 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
559 |
|
|
$_[0]->local_name eq 'el3' ? 3 : 1 # SKIP : ACCEPT |
560 |
|
|
}); |
561 |
|
|
|
562 |
|
|
for ( |
563 |
|
|
['el1', undef, undef], |
564 |
|
|
['el2', 'el2', 'el4'], |
565 |
|
|
['el3', 'el3', 'el5'], |
566 |
|
|
['el4', 'el4', 'el5'], |
567 |
|
|
['el5', 'el5', undef], |
568 |
|
|
) { |
569 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
570 |
|
|
ok $tw->next_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
571 |
|
|
'next_sibling [3] ' . $_->[0] . ' next_sibling'; |
572 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
573 |
|
|
'next_sibling [3] ' . $_->[0] . ' current_node'; |
574 |
|
|
} |
575 |
|
|
} |
576 |
|
|
{ |
577 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
578 |
|
|
$_[0]->local_name eq 'el3' ? 2 : 1 # REJECT : ACCEPT |
579 |
|
|
}); |
580 |
|
|
|
581 |
|
|
for ( |
582 |
|
|
['el1', undef, undef], |
583 |
|
|
['el2', 'el2', 'el5'], |
584 |
|
|
['el3', 'el3', 'el5'], |
585 |
|
|
['el4', 'el4', undef], |
586 |
|
|
['el5', 'el5', undef], |
587 |
|
|
) { |
588 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
589 |
|
|
ok $tw->next_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
590 |
|
|
'next_sibling [4] ' . $_->[0] . ' next_sibling'; |
591 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
592 |
|
|
'next_sibling [4] ' . $_->[0] . ' current_node'; |
593 |
|
|
} |
594 |
|
|
} |
595 |
|
|
{ |
596 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, undef, 0); |
597 |
|
|
|
598 |
|
|
for ( |
599 |
|
|
['el1', undef, undef], |
600 |
|
|
['er1', 'er1', 'el6'], |
601 |
|
|
['el3', 'el3', undef], |
602 |
|
|
['el4', 'el4', undef], |
603 |
|
|
['el5', 'el5', undef], |
604 |
|
|
['el6', 'el6', undef], |
605 |
|
|
) { |
606 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
607 |
|
|
ok $tw->next_sibling, $_->[2] ? $tree4{$_->[2]} : undef, |
608 |
|
|
'next_sibling [5] ' . $_->[0] . ' next_sibling'; |
609 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
610 |
|
|
'next_sibling [5] ' . $_->[0] . ' current_node'; |
611 |
|
|
} |
612 |
|
|
} |
613 |
|
|
{ |
614 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, sub { |
615 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE ? 12101 : 1; |
616 |
|
|
}, 1); |
617 |
|
|
|
618 |
|
|
for ( |
619 |
|
|
['el1', undef, undef], |
620 |
|
|
['er1', 'er1', 'el6'], |
621 |
|
|
['el3', 'el3', 'el5'], |
622 |
|
|
['el4', 'el4', undef], |
623 |
|
|
['el5', 'el5', undef], |
624 |
|
|
['el6', 'el6', undef], |
625 |
|
|
) { |
626 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
627 |
|
|
ok $tw->next_sibling, $_->[2] ? $tree4{$_->[2]} : undef, |
628 |
|
|
'next_sibling [6] ' . $_->[0] . ' next_sibling'; |
629 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
630 |
|
|
'next_sibling [6] ' . $_->[0] . ' current_node'; |
631 |
|
|
} |
632 |
|
|
} |
633 |
|
|
|
634 |
|
|
## |previousNode| |
635 |
|
|
{ |
636 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF); |
637 |
|
|
ok $tw->can ('previous_node') ? 1 : 0, 1, 'can previous_node'; |
638 |
|
|
|
639 |
|
|
for ( |
640 |
|
|
['el1', undef, undef], |
641 |
|
|
['el2', 'el2', 'el1'], |
642 |
|
|
['el3', 'el3', 'el2'], |
643 |
|
|
['el4', 'el4', 'el3'], |
644 |
|
|
['el5', 'el5', 'el4'], |
645 |
|
|
) { |
646 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
647 |
|
|
ok $tw->previous_node, $_->[2] ? $tree3{$_->[2]} : undef, |
648 |
|
|
'previous_node [1] ' . $_->[0] . ' previous_node'; |
649 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
650 |
|
|
'previous_node [1] ' . $_->[0] . ' current_node'; |
651 |
|
|
} |
652 |
|
|
} |
653 |
|
|
{ |
654 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el3}, 0xFFFFFFFF); |
655 |
|
|
|
656 |
|
|
for ( |
657 |
|
|
['el1', 'el1', undef], |
658 |
|
|
['el2', 'el2', 'el1'], |
659 |
|
|
['el3', 'el3', undef], |
660 |
|
|
['el4', 'el4', 'el3'], |
661 |
|
|
['el5', 'el5', 'el4'], |
662 |
|
|
) { |
663 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
664 |
|
|
ok $tw->previous_node, $_->[2] ? $tree3{$_->[2]} : undef, |
665 |
|
|
'previous_node [2] ' . $_->[0] . ' next_node'; |
666 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
667 |
|
|
'previous_node [2] ' . $_->[0] . ' current_node'; |
668 |
|
|
} |
669 |
|
|
} |
670 |
|
|
{ |
671 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
672 |
|
|
$_[0]->local_name eq 'el3' ? 3 : 1 # SKIP : ACCEPT |
673 |
|
|
}); |
674 |
|
|
|
675 |
|
|
for ( |
676 |
|
|
['el1', undef, undef], |
677 |
|
|
['el2', 'el2', 'el1'], |
678 |
|
|
['el3', 'el3', 'el2'], |
679 |
|
|
['el4', 'el4', 'el2'], |
680 |
|
|
['el5', 'el5', 'el4'], |
681 |
|
|
) { |
682 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
683 |
|
|
ok $tw->previous_node, $_->[2] ? $tree3{$_->[2]} : undef, |
684 |
|
|
'previous_node [3] ' . $_->[0] . ' next_node'; |
685 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
686 |
|
|
'previous_node [3] ' . $_->[0] . ' current_node'; |
687 |
|
|
} |
688 |
|
|
} |
689 |
|
|
{ |
690 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
691 |
|
|
$_[0]->local_name eq 'el3' ? 2 : 1 # REJECT : ACCEPT |
692 |
|
|
}); |
693 |
|
|
|
694 |
|
|
for ( |
695 |
|
|
['el1', undef, undef], |
696 |
|
|
['el2', 'el2', 'el1'], |
697 |
|
|
['el3', 'el3', 'el2'], |
698 |
|
|
['el4', 'el4', 'el2'], |
699 |
|
|
['el5', 'el5', 'el2'], |
700 |
|
|
) { |
701 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
702 |
|
|
ok $tw->previous_node, $_->[2] ? $tree3{$_->[2]} : undef, |
703 |
|
|
'previous_node [4] ' . $_->[0] . ' next_node'; |
704 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
705 |
|
|
'previous_node [4] ' . $_->[0] . ' current_node'; |
706 |
|
|
} |
707 |
|
|
} |
708 |
|
|
{ |
709 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, undef, 0); |
710 |
|
|
|
711 |
|
|
for ( |
712 |
|
|
['el1', undef, undef], |
713 |
|
|
['er1', 'er1', 'el1'], |
714 |
|
|
['el3', 'el3', 'er1'], |
715 |
|
|
['el4', 'el4', 'er1'], |
716 |
|
|
['el5', 'el5', 'er1'], |
717 |
|
|
['el6', 'el6', 'er1'], |
718 |
|
|
) { |
719 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
720 |
|
|
ok $tw->previous_node, $_->[2] ? $tree4{$_->[2]} : undef, |
721 |
|
|
'previous_node [5] ' . $_->[0] . ' next_node'; |
722 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
723 |
|
|
'previous_node [5] ' . $_->[0] . ' current_node'; |
724 |
|
|
} |
725 |
|
|
} |
726 |
|
|
{ |
727 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, sub { |
728 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE ? 12101 : 1; |
729 |
|
|
}, 1); |
730 |
|
|
|
731 |
|
|
for ( |
732 |
|
|
['el1', undef, undef], |
733 |
|
|
['er1', 'er1', 'el1'], |
734 |
|
|
['el3', 'el3', 'er1'], |
735 |
|
|
['el4', 'el4', 'el3'], |
736 |
|
|
['el5', 'el5', 'el4'], |
737 |
|
|
['el6', 'el6', 'er1'], |
738 |
|
|
) { |
739 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
740 |
|
|
ok $tw->previous_node, $_->[2] ? $tree4{$_->[2]} : undef, |
741 |
|
|
'previous_node [6] ' . $_->[0] . ' previous_node'; |
742 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
743 |
|
|
'previous_node [6] ' . $_->[0] . ' current_node'; |
744 |
|
|
} |
745 |
|
|
} |
746 |
|
|
|
747 |
|
|
## |previousSibling| |
748 |
|
|
{ |
749 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF); |
750 |
|
|
ok $tw->can ('previous_sibling') ? 1 : 0, 1, 'can previous_sibling'; |
751 |
|
|
|
752 |
|
|
for ( |
753 |
|
|
['el1', undef, undef], |
754 |
|
|
['el2', 'el2', undef], |
755 |
|
|
['el3', 'el3', 'el2'], |
756 |
|
|
['el4', 'el4', undef], |
757 |
|
|
['el5', 'el5', 'el3'], |
758 |
|
|
) { |
759 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
760 |
|
|
ok $tw->previous_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
761 |
|
|
'previous_sibling [1] ' . $_->[0] . ' previous_sibling'; |
762 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
763 |
|
|
'previous_sibling [1] ' . $_->[0] . ' current_node'; |
764 |
|
|
} |
765 |
|
|
} |
766 |
|
|
{ |
767 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el3}, 0xFFFFFFFF); |
768 |
|
|
|
769 |
|
|
for ( |
770 |
|
|
['el1', 'el1', undef], |
771 |
|
|
['el2', 'el2', undef], |
772 |
|
|
['el3', 'el3', undef], |
773 |
|
|
['el4', 'el4', undef], |
774 |
|
|
['el5', 'el5', 'el3'], |
775 |
|
|
) { |
776 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
777 |
|
|
ok $tw->previous_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
778 |
|
|
'previous_sibling [2] ' . $_->[0] . ' previous_sibling'; |
779 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
780 |
|
|
'previous_sibling [2] ' . $_->[0] . ' current_node'; |
781 |
|
|
} |
782 |
|
|
} |
783 |
|
|
{ |
784 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
785 |
|
|
$_[0]->local_name eq 'el3' ? 3 : 1 # SKIP : ACCEPT |
786 |
|
|
}); |
787 |
|
|
|
788 |
|
|
for ( |
789 |
|
|
['el1', undef, undef], |
790 |
|
|
['el2', 'el2', undef], |
791 |
|
|
['el3', 'el3', 'el2'], |
792 |
|
|
['el4', 'el4', 'el2'], |
793 |
|
|
['el5', 'el5', 'el4'], |
794 |
|
|
) { |
795 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
796 |
|
|
ok $tw->previous_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
797 |
|
|
'previous_sibling [3] ' . $_->[0] . ' previous_sibling'; |
798 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
799 |
|
|
'previous_sibling [3] ' . $_->[0] . ' current_node'; |
800 |
|
|
} |
801 |
|
|
} |
802 |
|
|
{ |
803 |
|
|
my $tw = $doc->create_tree_walker ($tree3{el1}, 0xFFFFFFFF, sub { |
804 |
|
|
$_[0]->local_name eq 'el3' ? 2 : 1 # REJECT : ACCEPT |
805 |
|
|
}); |
806 |
|
|
|
807 |
|
|
for ( |
808 |
|
|
['el1', undef, undef], |
809 |
|
|
['el2', 'el2', undef], |
810 |
|
|
['el3', 'el3', 'el2'], |
811 |
|
|
['el4', 'el4', 'el2'], |
812 |
|
|
['el5', 'el5', 'el2'], |
813 |
|
|
) { |
814 |
|
|
$tw->current_node ($tree3{$_->[1]}) if $_->[1]; |
815 |
|
|
ok $tw->previous_sibling, $_->[2] ? $tree3{$_->[2]} : undef, |
816 |
|
|
'previous_sibling [4] ' . $_->[0] . ' previous_sibling'; |
817 |
|
|
ok $tw->current_node, $tree3{$_->[2] || $_->[1] || $_->[0]}, |
818 |
|
|
'previous_sibling [4] ' . $_->[0] . ' current_node'; |
819 |
|
|
} |
820 |
|
|
} |
821 |
|
|
{ |
822 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, undef, 0); |
823 |
|
|
|
824 |
|
|
for ( |
825 |
|
|
['el1', undef, undef], |
826 |
|
|
['er1', 'er1', undef], |
827 |
|
|
['el3', 'el3', undef], |
828 |
|
|
['el4', 'el4', undef], |
829 |
|
|
['el5', 'el5', undef], |
830 |
|
|
['el6', 'el6', 'er1'], |
831 |
|
|
) { |
832 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
833 |
|
|
ok $tw->previous_sibling, $_->[2] ? $tree4{$_->[2]} : undef, |
834 |
|
|
'previous_sibling [5] ' . $_->[0] . ' previous_sibling'; |
835 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
836 |
|
|
'previous_sibling [5] ' . $_->[0] . ' current_node'; |
837 |
|
|
} |
838 |
|
|
} |
839 |
|
|
{ |
840 |
|
|
my $tw = $doc->create_tree_walker ($tree4{el1}, 0xFFFFFFFF, sub { |
841 |
|
|
$_[0]->node_type == $_[0]->ENTITY_REFERENCE_NODE ? 12101 : 1; |
842 |
|
|
}, 1); |
843 |
|
|
|
844 |
|
|
for ( |
845 |
|
|
['el1', undef, undef], |
846 |
|
|
['er1', 'er1', undef], |
847 |
|
|
['el3', 'el3', undef], |
848 |
|
|
['el4', 'el4', undef], |
849 |
|
|
['el5', 'el5', 'el3'], |
850 |
|
|
['el6', 'el6', 'er1'], |
851 |
|
|
) { |
852 |
|
|
$tw->current_node ($tree4{$_->[1]}) if $_->[1]; |
853 |
|
|
ok $tw->previous_sibling, $_->[2] ? $tree4{$_->[2]} : undef, |
854 |
|
|
'previous_sibling [6] ' . $_->[0] . ' previous_sibling'; |
855 |
|
|
ok $tw->current_node, $tree4{$_->[2] || $_->[1] || $_->[0]}, |
856 |
|
|
'previous_sibling [6] ' . $_->[0] . ' current_node'; |
857 |
|
|
} |
858 |
|
|
} |
859 |
|
|
|
860 |
|
|
=head1 LICENSE |
861 |
|
|
|
862 |
|
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
863 |
|
|
|
864 |
|
|
This program is free software; you can redistribute it and/or |
865 |
|
|
modify it under the same terms as Perl itself. |
866 |
|
|
|
867 |
|
|
=cut |
868 |
|
|
|
869 |
|
|
## $Date: 2007/07/14 09:19:11 $ |