X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fselectors.t;h=13a8154d41f26cb3a6428f9bcfbbb135bdc71cb7;hb=5b63d2447b01acd333b2a0a9adb7aa793b72fcf6;hp=59d9c7c5d206edb2ae08f7d3b36fd5ceb97cd55b;hpb=682fa876be5265211f777cf85fac6528d4dd4d41;p=catagits%2FHTML-Zoom.git diff --git a/t/selectors.t b/t/selectors.t index 59d9c7c..13a8154 100644 --- a/t/selectors.t +++ b/t/selectors.t @@ -14,79 +14,89 @@ my $tmpl = < END +my $stub = '
'; + # el#id -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div#yo') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E#id works' ); # el.class1 -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div.yo') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E.class works' ); # el[attr] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[frew]') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E[attr] works' ); # el[attr="foo"] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[frew="yo"]') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E[attr="val"] works' ); # el[attr=foo] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[frew=yo]') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E[attr=val] works' ); # el[attr*="foo"] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[f*="oo"]') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E[attr*="val"] works' ); # el[attr^="foo"] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[f^="foo"]') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E[attr^="val"] works' ); # el[attr$="foo"] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[f$="bar"]') ->replace_content('grg') ->to_html, - '
grg
', + '
grg
'.$stub, 'E[attr$="val"] works' ); # el[attr*="foo"] -is( HTML::Zoom->from_html('
') +is( HTML::Zoom->from_html('
'.$stub) ->select('div[f*="bar"]') ->replace_content('grg') ->to_html, - '
grg
', + '
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' ); + # [attr=bar] ok( check_select( '[prop=moo]'), '[attr=bar]' ); @@ -95,6 +105,18 @@ is( check_select('span[class=career],[prop=moo]'), 2, 'Multiple selectors: el[attr=bar],[attr=foo]'); +# 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' ); + +=pod + # sel1 sel2 is( HTML::Zoom->from_html('
') ->select('table tr') @@ -112,6 +134,10 @@ is( HTML::Zoom->from_html('
') '
frew
frew
', 'sel1 sel2 sel3 works' ); + + +=cut + done_testing; @@ -121,7 +147,7 @@ sub check_select{ ->from_html($tmpl) ->select(shift)->replace("the monkey")->to_html; my $count = 0; - while ( $output =~ /\G?.*the monkey/gc ){ + while ( $output =~ /the monkey/g ){ $count++; } return $count;