Skip to content

Instantly share code, notes, and snippets.

@2shortplanks
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2shortplanks/1311a130cc4738550876 to your computer and use it in GitHub Desktop.
Save 2shortplanks/1311a130cc4738550876 to your computer and use it in GitHub Desktop.
CSS selector problem with Mojo::DOM and dd
#!/usr/bin/perl
use strict;
use warnings;
use Test::More tests => 2;
use Mojo::DOM;
# passes
{
my $dom = Mojo::DOM->new(<<'ENDOFHTML');
<p>
<b>bold</b>
<i>italic</i>
</div>
ENDOFHTML
is $dom->at("b + i")->text, "italic";
}
# passes
{
my $dom = Mojo::DOM->new(<<'ENDOFHTML');
<dl>
<dt>term</dt>
<dd>description</dd>
</dl>
ENDOFHTML
is $dom->at("dt + dd")->text, "description";
}
# fails
{
my $dom = Mojo::DOM->new(<<'ENDOFHTML');
<dl>
<dt>term</dt>
<dd>
<dl>
<dt>term 2</dt>
<dd>description</dd>
</dl>
</dd>
</dl>
ENDOFHTML
is $dom->at("dt + dd")->text, "description";
}
__END__
1..2
ok 1
ok 2
not ok 3
# Failed test at /tmp/barney.pl line 42.
# got: ''
# expected: 'description'
# Looks like you planned 2 tests but ran 3.
# Looks like you failed 1 test of 3 run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment