root/lang/perl/HTML-Selector-XPath/trunk/t/02_html.t @ 1139

Revision 1139, 1.6 kB (checked in by miyagawa, 7 years ago)

r5477@rock (orig r1993): miyagawa | 2006-10-02 09:33:02 -0700
fixed SYNOPSIS. Added functional interface. Added test using H::TB::XPath

Line 
1use strict;
2use Test::Base;
3use HTML::Selector::XPath;
4
5eval { require HTML::TreeBuilder::XPath };
6plan skip_all => "HTML::TreeBuilder::XPath is not installed." if $@;
7
8filters { selector => 'chomp', expected => 'lines' };
9plan tests => 1 * blocks;
10
11run {
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
30div.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
41ul 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
53ul 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
65li.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
75div#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
85div#bar, div.baz
86--- expected
87<div id="bar">baz</div>
88<div class="baz">baz</div>
89
90
91
Note: See TracBrowser for help on using the browser.