X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fselectors.t;h=e6be2c229704013e613a8d3cac6a110797d3d8e6;hb=24725e7b32b680b376c06b1f9d641ec11fc1d067;hp=33e050ba4fad75ee0f0f04a833cff4ac29e990b1;hpb=27ed88090f802326984a2d6c3c7c96ad74489eb3;p=catagits%2FHTML-Zoom.git diff --git a/t/selectors.t b/t/selectors.t index 33e050b..e6be2c2 100644 --- a/t/selectors.t +++ b/t/selectors.t @@ -55,7 +55,14 @@ is( HTML::Zoom->from_html('
'.$stub) ->to_html, '
grg
'.$stub, 'E[attr=val] 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 +96,14 @@ 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' ); + # [attr=bar] ok( check_select( '[prop=moo]'), '[attr=bar]' ); @@ -96,37 +111,49 @@ 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) ->select(shift)->replace("the monkey")->to_html; my $count = 0; - while ( $output =~ /\G?.*the monkey/gc ){ + while ( $output =~ /the monkey/g ){ $count++; } return $count;