Subject: | Doesn't handle doctypes, doesn't handle XML declarations, doesn't handle selectors |
Attached is a fairly simple test case of parsing a file and then looking
for a CSS stylesheet. Result:
1..7
not ok 1 - Saw some HTML with DOCTYPE and XML signature...
# Failed test 'Saw some HTML with DOCTYPE and XML signature...'
# in testcase.pl at line 7.
# undef
# doesn't match '(?-xism:<)'
# Failed test '...without dying'
# in testcase.pl at line 8.
# '
# expected: ''
not ok 2 - ...without dying
# Failed test 'Saw some HTML just with a DOCTYPE...'
# in testcase.pl at line 13.
# undef
# doesn't match '(?-xism:<)'
# Failed test '...without dying'
# in testcase.pl at line 14.
# got: 'Can't call method "innerHTML" without a package or
object reference at /Library/Perl/5.8.8/pQuery.pm line 260, <DATA> line 1.
# '
# expected: ''
not ok 3 - Saw some HTML just with a DOCTYPE...
not ok 4 - ...without dying
ok 5 - Saw some HTML...
ok 6 - ...without dying
Can't locate object method "_props" via package "pQuery" at
/Library/Perl/5.8.8/pQuery.pm line 618, <DATA> line 1.
# Looks like you planned 7 tests but only ran 6.
# Looks like you failed 4 tests of 6 run.
# Looks like your test died just after 6.
Subject: | testcase.pl |
use pQuery;
use Test::More tests => 7;
my $foo = do { local $/; <DATA> };
my $html = eval { pQuery($foo)->html };
like($html, qr/</, "Saw some HTML with DOCTYPE and XML signature...");
is($@, "", "...without dying");
$foo =~s/<\?xml.*\n//;
my $html = eval { pQuery($foo)->html };
like($html, qr/</, "Saw some HTML just with a DOCTYPE...");
is($@, "", "...without dying");
$foo =~s/<!DOCTYPE.*\n//;
my $html = eval { pQuery($foo)->html };
like($html, qr/</, "Saw some HTML...");
is($@, "", "...without dying");
my $p = pQuery($foo);
$p->find("link[rel=stylesheet]")->each(sub {
ok(1, "Got a stylesheet");
});
__DATA__
<?xml version="1.0"?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<html>
<head>
<link rel="stylesheet" href="test.css" type="text/css"/>
</head>
<body> <p> Hello World </p> </body>
</html>