root/HTML-Selector-XPath/trunk/t/01_xpath.t

Revision 1991 (checked in by miyagawa, 14 years ago)

import HTML::Selector::XPath

Line 
1 use strict;
2 use Test::Base;
3 use HTML::Selector::XPath;
4
5 plan tests => 1 * blocks;
6 filters { selector => 'chomp', xpath => 'chomp' };
7
8 run {
9     my $block = shift;
10     my $selector = HTML::Selector::XPath->new($block->selector);
11     is $selector->to_xpath, $block->xpath, $block->selector;
12 }
13
14 __END__
15 ===
16 --- selector
17 *
18 --- xpath
19 //*
20
21 ===
22 --- selector
23 E
24 --- xpath
25 //E
26
27 ===
28 --- selector
29 E F
30 --- xpath
31 //E//F
32
33 ===
34 --- selector
35 E:first-child
36 --- xpath
37 //*[1]/self::E
38
39 ===
40 --- selector
41 F E:first-child
42 --- xpath
43 //F//*[1]/self::E
44
45 ===
46 --- selector
47 F > E:first-child
48 --- xpath
49 //F/*[1]/self::E
50
51 ===
52 --- selector
53 E:lang(c)
54 --- xpath
55 //E[@xml:lang='c' or starts-with(@xml:lang, 'c-')]
56
57 ===
58 --- selector
59 E + F
60 --- xpath
61 //E/following-sibling::*[1]/self::F
62
63 ===
64 --- selector
65 E + #bar
66 --- xpath
67 //E/following-sibling::*[1]/self::*[@id='bar']
68
69 ===
70 --- selector
71 E + .bar
72 --- xpath
73 //E/following-sibling::*[1]/self::*[contains(concat(' ', @class, ' '), ' bar ')]
74
75 ===
76 --- selector
77 E[foo]
78 --- xpath
79 //E[@foo]
80
81 ===
82 --- selector
83 E[foo="warning"]
84 --- xpath
85 //E[@foo='warning']
86
87 ===
88 --- selector
89 E[foo~="warning"]
90 --- xpath
91 //E[contains(concat(' ', @foo, ' '), ' warning ')]
92
93 ===
94 --- selector
95 E[lang|="en"]
96 --- xpath
97 //E[@lang='en' or starts-with(@lang, 'en-')]
98
99 ===
100 --- selector
101 DIV.warning
102 --- xpath
103 //DIV[contains(concat(' ', @class, ' '), ' warning ')]
104
105 ===
106 --- selector
107 E#myid
108 --- xpath
109 //E[@id='myid']
110
111 ===
112 --- selector
113 foo.bar, bar
114 --- xpath
115 //foo[contains(concat(' ', @class, ' '), ' bar ')] | //bar
Note: See TracBrowser for help on using the browser.