X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fselectors.t;h=59d9c7c5d206edb2ae08f7d3b36fd5ceb97cd55b;hb=682fa876be5265211f777cf85fac6528d4dd4d41;hp=01e11cffaa335e46e512502c8cb0a8c1fe6e5e36;hpb=de4457aae9433f7f960ac2205f4805fef3474c91;p=catagits%2FHTML-Zoom.git diff --git a/t/selectors.t b/t/selectors.t index 01e11cf..59d9c7c 100644 --- a/t/selectors.t +++ b/t/selectors.t @@ -4,6 +4,16 @@ use Test::More; use HTML::Zoom; +my $tmpl = < +
+ Bob + Builder +
+
+ +END + # el#id is( HTML::Zoom->from_html('
') ->select('div#yo') @@ -36,6 +46,15 @@ is( HTML::Zoom->from_html('
') '
grg
', 'E[attr="val"] works' ); +# el[attr=foo] +is( HTML::Zoom->from_html('
') + ->select('div[frew=yo]') + ->replace_content('grg') + ->to_html, + '
grg
', + 'E[attr=val] works' ); + + # el[attr*="foo"] is( HTML::Zoom->from_html('
') ->select('div[f*="oo"]') @@ -68,6 +87,14 @@ is( HTML::Zoom->from_html('
') '
grg
', 'E[attr*="val"] works' ); +# [attr=bar] +ok( check_select( '[prop=moo]'), '[attr=bar]' ); + +# el[attr=bar],[prop=foo] +is( check_select('span[class=career],[prop=moo]'), 2, + 'Multiple selectors: el[attr=bar],[attr=foo]'); + + # sel1 sel2 is( HTML::Zoom->from_html('
') ->select('table tr') @@ -86,3 +113,16 @@ is( HTML::Zoom->from_html('
') 'sel1 sel2 sel3 works' ); done_testing; + + +sub check_select{ + # less crude?: + my $output = HTML::Zoom + ->from_html($tmpl) + ->select(shift)->replace("the monkey")->to_html; + my $count = 0; + while ( $output =~ /\G?.*the monkey/gc ){ + $count++; + } + return $count; +}