root/HTML-Selector-XPath/trunk/t/02_html.t

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

fixed handling of :not pseudo-class to work on XPath 1.0 implementation. This be 0.02

Line 
1 use strict;
2 use Test::Base;
3 use HTML::Selector::XPath;
4
5 eval { require HTML::TreeBuilder::XPath };
6 plan skip_all => "HTML::TreeBuilder::XPath is not installed." if $@;
7
8 filters { selector => 'chomp', expected => [ 'lines', 'array' ] };
9 plan tests => 1 * blocks;
10
11 run {
12     my $block = shift;
13     my $tree = HTML::TreeBuilder::XPath->new;
14     $tree->parse($block->input);
15     $tree->eof;
16
17     my @nodes = $tree->findnodes( HTML::Selector::XPath->new($block->selector)->to_xpath );
18     is_deeply [ map $_->as_XML, @nodes ], $block->expected;
19 }
20
21 __END__
22
23 ===
24 --- input
25 <body>
26 <div class="foo">foo</div>
27 <div class="bar">foo</div>
28 </body>
29 --- selector
30 div.foo
31 --- expected
32 <div class="foo">foo</div>
33
34 ===
35 --- input
36 <ul>
37 <li><a href="foo.html">bar</a></li>
38 <li><a href="foo.html">baz</a></li>
39 </ul>
40 --- selector
41 ul li
42 --- expected
43 <li><a href="foo.html">bar</a></li>
44 <li><a href="foo.html">baz</a></li>
45
46 ===
47 --- input
48 <ul>
49 <li><a href="foo.html">bar</a></li>
50 <li><a href="foo.html">baz</a></li>
51 </ul>
52 --- selector
53 ul li:first-child
54 --- expected
55 <li><a href="foo.html">bar</a></li>
56
57 ===
58 --- input
59 <ul>
60 <li><a href="foo.html">bar</a></li>
61 <li class="bar baz"><a href="foo.html">baz</a></li>
62 <li class="bar"><a href="foo.html">baz</a></li>
63 </ul>
64 --- selector
65 li.bar
66 --- expected
67 <li class="bar baz"><a href="foo.html">baz</a></li>
68 <li class="bar"><a href="foo.html">baz</a></li>
69
70 ===
71 --- input
72 <div>foo</div>
73 <div id="bar">baz</div>
74 --- selector
75 div#bar
76 --- expected
77 <div id="bar">baz</div>
78
79 ===
80 --- input
81 <div>foo</div>
82 <div id="bar">baz</div>
83 <div class="baz">baz</div>
84 --- selector
85 div#bar, div.baz
86 --- expected
87 <div id="bar">baz</div>
88 <div class="baz">baz</div>
89
90 ===
91 --- input
92 <div>foo</div>
93 <div lang="en">baz</div>
94 <div lang="en-us">baz</div>
95 --- selector
96 div:not([lang|="en"])
97 --- expected
98 <div>foo</div>
99
100 ===
101 --- input
102 <div>foo</div>
103 <div class="foo">baz</div>
104 <div class="foob">baz</div>
105 --- selector
106 div:not([class~="foo"])
107 --- expected
108 <div>foo</div>
109 <div class="foob">baz</div>
110
111 ===
112 --- input
113 <div>foo</div>
114 <div class="foo">baz</div>
115 <div class="foob">baz</div>
116 --- selector
117 div:not([class])
118 --- expected
119 <div>foo</div>
120
Note: See TracBrowser for help on using the browser.