-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy path21_all_nodes.t
65 lines (54 loc) · 1.51 KB
/
21_all_nodes.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use v6.c;
use Test;
use XML::XPath;
plan 15;
my $x = XML::XPath.new(xml => q:to/ENDXML/);
<AAA>
<BBB>
<CCC/>
<ZZZ/>
</BBB>
<XXX>
<DDD>
<EEE/>
<FFF>
<HHH/>
<GGG> <!-- Watch this node -->
<JJJ>
<QQQ/>
</JJJ>
<JJJ/>
</GGG>
<VVV/>
</FFF>
</DDD>
</XXX>
<CCC>
<DDD/>
</CCC>
</AAA>
ENDXML
my $set;
$set = $x.find('//GGG/ancestor::*');
is $set.elems, 4, '4 ancestors';
$set = $x.find('//GGG/descendant::*');
is $set.elems, 3, '3 descendants';
$set = $x.find('//GGG/following::*');
is $set.elems, 3, '3 following';
is $set[0].name, 'VVV', '1st following is VVV';
is $set[1].name, 'CCC', '2nd following is CCC';
is $set[2].name, 'DDD', '3rd following is DDD';
$set = $x.find('//GGG/preceding::*');
is $set.elems, 5, '5 preceding';
# document order: BBB not HHH
is $set[0].name, 'BBB', 'first following is BBB';
is $set[1].name, 'CCC', 'first following is CCC';
is $set[2].name, 'ZZZ', 'first following is ZZZ';
is $set[3].name, 'EEE', 'first following is EEE';
is $set[4].name, 'HHH', 'first following is HHH';
$set = $x.find('//GGG/self::*');
does-ok $set , XML::Node, '1 self';
is $set.name, 'GGG', 'first following is GGG';
$set = $x.find('//GGG/ancestor::* | //GGG/descendant::* | //GGG/following::* | //GGG/preceding::* | //GGG/self::*');
is $set.elems, 16, '16 nodes summary';
done-testing;