X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fselectors.t;h=5b6a60a4fcfc9296121e73bfc9c8274b724bc672;hb=bce61371d913754688d91e7a325f45b7bc7e6f1e;hp=9933e43b315df52e5428fc40cd1ca4d1a33cf329;hpb=eacf665fa4616e10efec9c80546bf71e05e4e96e;p=catagits%2FHTML-Zoom.git diff --git a/t/selectors.t b/t/selectors.t index 9933e43..5b6a60a 100644 --- a/t/selectors.t +++ b/t/selectors.t @@ -1,5 +1,4 @@ -use strict; -#use warnings FATAL => 'all'; +use strictures 1; use Test::More; use HTML::Zoom; @@ -32,6 +31,15 @@ is( HTML::Zoom->from_html('
'.$stub) '
grg
'.$stub, 'E.class works' ); + +# el.class\.1 +is( HTML::Zoom->from_html('
'.$stub) + ->select('div.yo\.yo') + ->replace_content('grg') + ->to_html, + '
grg
'.$stub, + 'E.class\.0 works' ); + # el[attr] is( HTML::Zoom->from_html('
'.$stub) ->select('div[frew]') @@ -40,6 +48,14 @@ is( HTML::Zoom->from_html('
'.$stub) '
grg
'.$stub, 'E[attr] works' ); +# *[attr] +is( HTML::Zoom->from_html('
'.$stub) + ->select('*[frew]') + ->replace_content('grg') + ->to_html, + '
grg
grg'.$stub, + '*[attr] works' ); + # el[attr="foo"] is( HTML::Zoom->from_html('
'.$stub) ->select('div[frew="yo"]') @@ -55,7 +71,22 @@ is( HTML::Zoom->from_html('
'.$stub) ->to_html, '
grg
'.$stub, 'E[attr=val] works' ); - + +# el[attr=foo\.bar] +is( HTML::Zoom->from_html('
'.$stub) + ->select('div[frew=yo\.yo]') + ->replace_content('grg') + ->to_html, + '
grg
'.$stub, + 'E[attr=foo\.bar] works' ); + +# el[attr!="foo"] +is( HTML::Zoom->from_html('
'.$stub) + ->select('div[class!="waargh"]') + ->replace_content('grg') + ->to_html, + '
grg
grg
'.$stub, + 'E[attr!="val"] works' ); # el[attr*="foo"] is( HTML::Zoom->from_html('
'.$stub) @@ -89,6 +120,24 @@ is( HTML::Zoom->from_html('
'.$stub) '
grg
'.$stub, 'E[attr*="val"] works' ); +# el[attr~="foo"] +is( HTML::Zoom->from_html('
'.$stub) + ->select('div[frew~="bar"]') + ->replace_content('grg') + ->to_html, + '
grg
'.$stub, + 'E[attr~="val"] works' ); + +# el[attr|="foo"] +is( HTML::Zoom->from_html('
'. + '
'.$stub) + ->select('div[lang|="en"]') + ->replace_content('grg') + ->to_html, + '
'. + '
grg
grg
'.$stub, + 'E[attr|="val"] works' ); + # [attr=bar] ok( check_select( '[prop=moo]'), '[attr=bar]' ); @@ -96,31 +145,43 @@ ok( check_select( '[prop=moo]'), '[attr=bar]' ); is( check_select('span[class=career],[prop=moo]'), 2, 'Multiple selectors: el[attr=bar],[attr=foo]'); -=pod +# selector parse error test: +eval{ + HTML::Zoom->from_html('') + ->select('[att=bar') + ->replace_content('cats') + ->to_html; +}; +like( $@, qr/Error parsing dispatch specification/, + 'Malformed attribute selector ([att=bar) results in a helpful error' ); + + +TODO: { +local $TODO = "descendant selectors doesn't work yet"; # sel1 sel2 -is( HTML::Zoom->from_html('
') +is( eval { HTML::Zoom->from_html('
') ->select('table tr') - ->replace_content(\'') - ->to_html, + ->replace_content('') + ->to_html }, '
', 'sel1 sel2 works' ); - +diag($@) if $@; # sel1 sel2 sel3 -is( HTML::Zoom->from_html('
') +is( eval { HTML::Zoom->from_html('
') ->select('table tr td') ->replace_content('frew') - ->to_html, + ->to_html }, '
frew
frew
', 'sel1 sel2 sel3 works' ); - -=cut +diag($@) if $@; +} done_testing; -sub check_select{ +sub check_select { # less crude?: my $output = HTML::Zoom ->from_html($tmpl)