Commit tests
[catagits/HTML-Zoom.git] / t / selectors.t
1 use strict;
2 #use warnings FATAL => 'all';
3 use Test::More;
4
5 use HTML::Zoom;
6
7 # el#id
8 is( HTML::Zoom->from_html('<div id="yo"></div>')
9    ->select('div#yo')
10       ->replace_content('grg')
11    ->to_html,
12    '<div id="yo">grg</div>',
13    'E#id works' );
14
15 # el.class1
16 is( HTML::Zoom->from_html('<div class="yo"></div>')
17    ->select('div.yo')
18       ->replace_content('grg')
19    ->to_html,
20    '<div class="yo">grg</div>',
21    'E.class works' );
22
23 # el[attr]
24 is( HTML::Zoom->from_html('<div frew="yo"></div>')
25    ->select('div[frew]')
26       ->replace_content('grg')
27    ->to_html,
28    '<div frew="yo">grg</div>',
29    'E[attr] works' );
30
31 # el[attr="foo"]
32 is( HTML::Zoom->from_html('<div frew="yo"></div>')
33    ->select('div[frew="yo"]')
34       ->replace_content('grg')
35    ->to_html,
36    '<div frew="yo">grg</div>',
37    'E[attr="val"] works' );
38
39 # el[attr*="foo"]
40 is( HTML::Zoom->from_html('<div f="frew goog"></div>')
41    ->select('div[f*="oo"]')
42       ->replace_content('grg')
43    ->to_html,
44    '<div f="frew goog">grg</div>',
45    'E[attr*="val"] works' );
46
47 # el[attr^="foo"]
48 is( HTML::Zoom->from_html('<div f="foobar"></div>')
49    ->select('div[f^="foo"]')
50       ->replace_content('grg')
51    ->to_html,
52    '<div f="foobar">grg</div>',
53    'E[attr^="val"] works' );
54
55 # el[attr$="foo"]
56 is( HTML::Zoom->from_html('<div f="foobar"></div>')
57    ->select('div[f$="bar"]')
58       ->replace_content('grg')
59    ->to_html,
60    '<div f="foobar">grg</div>',
61    'E[attr$="val"] works' );
62
63 # el[attr*="foo"]
64 is( HTML::Zoom->from_html('<div f="foo bar"></div>')
65    ->select('div[f*="bar"]')
66       ->replace_content('grg')
67    ->to_html,
68    '<div f="foo bar">grg</div>',
69    'E[attr*="val"] works' );
70
71 # sel1 sel2
72 is( HTML::Zoom->from_html('<table><tr></tr><tr></tr></table>')
73    ->select('table tr')
74       ->replace_content(\'<td></td>')
75    ->to_html,
76    '<table><tr><td></td></tr><tr><td></td></tr></table>',
77    'sel1 sel2 works' );
78
79
80 # sel1 sel2 sel3
81 is( HTML::Zoom->from_html('<table><tr><td></td></tr><tr><td></td></tr></table>')
82    ->select('table tr td')
83       ->replace_content('frew')
84    ->to_html,
85    '<table><tr><td>frew</td></tr><tr><td>frew</td></tr></table>',
86    'sel1 sel2 sel3 works' );
87
88 done_testing;