X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fselectors.t;h=8a800b1c6ecc0497d179ad0c3658b973c7fadfb1;hb=6d80bb9ab1285f5a97311117d29e5a5e1431988a;hp=46e8439dfc1caf24aaa4e0c3e85b169c85d11b3a;hpb=c9448e2171d246c09274ccb5585cf62573d57089;p=catagits%2FHTML-Zoom.git diff --git a/t/selectors.t b/t/selectors.t index 46e8439..8a800b1 100644 --- a/t/selectors.t +++ b/t/selectors.t @@ -40,6 +40,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 +63,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 +104,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,46 +129,43 @@ ok( check_select( '[prop=moo]'), '[attr=bar]' ); is( check_select('span[class=career],[prop=moo]'), 2, 'Multiple selectors: el[attr=bar],[attr=foo]'); -TODO:{ - local $TODO = 'Fix selector error messages'; - # selector parse error test: - eval{ - HTML::Zoom->from_html('') - ->select('[att=bar') - ->replace_content('cats') + +# 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 results in a helpful error' ); }; +like( $@, qr/Error parsing dispatch specification/, + 'Malformed attribute selector ([att=bar) results in a helpful error' ); -=pod +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)