Test-XPath-0.19/ 0000755 0001750 0001750 00000000000 13303120314 012726 5 ustar manwar manwar Test-XPath-0.19/t/ 0000755 0001750 0001750 00000000000 13303120314 013171 5 ustar manwar manwar Test-XPath-0.19/t/xmlns.t 0000644 0001750 0001750 00000001572 13302416000 014523 0 ustar manwar manwar #!/usr/bin/perl -w
use strict;
use Test::More tests => 4;
BEGIN { use_ok 'Test::XPath' or die; }
# Borrowed from http://www.w3schools.com/XML/xml_namespaces.asp
my $xml = <<'XML';
Apples
Bananas
first
post
'; ok my $xp = Test::XPath->new( xml => $html, is_html => 1, ), 'Should be able to parse HTML'; # Try a recursive call. $xp->ok( '/html/body/p', 'Find paragraphs' ) { shift->ok('./em', 'Find em under para') { shift->ok('./b', 'Find b under em'); }; }; # Now without descriptions. $xp->ok( '/html/body/p' ) { shift->ok('./em') { shift->ok('./b'); }; }; Test-XPath-0.19/t/simple.t 0000644 0001750 0001750 00000006573 13302416000 014661 0 ustar manwar manwar #!/usr/bin/perl -w use strict; use Test::Builder::Tester tests => 23; use Test::More; use File::Spec; BEGIN { use_ok 'Test::XPath' or die; } my $html = 'first
post
'; ok my $xp = Test::XPath->new( xml => $html, is_html => 1, ), 'Create Test::XPath object'; # Try successful ok. test_out( 'ok 1 - whatever'); $xp->ok('/html/head/title', 'whatever'); test_test('ok works'); # Try failed ok. my $file = File::Spec->catfile(split m{/} => __FILE__); test_out('not ok 1 - whatever'); test_err(qq{# Failed test 'whatever'\n# at $file line 26.}); $xp->ok('/html/head/foo', 'whatever'); test_test('ok fail works'); # Try a recursive call. test_out( 'ok 1 - p'); test_out( 'ok 2 - em'); test_out( 'ok 3 - b'); test_out( 'ok 4 - em'); test_out( 'ok 5 - b'); $xp->ok( '/html/body/p', sub { shift->ok('./em', sub { $_->ok('./b', 'b'); }, 'em'); }, 'p'); test_test('recursive ok should work'); # Try is, like, and cmp_ok. $xp->is( '/html/head/title', 'Hello', 'is should work'); $xp->isnt( '/html/head/title', 'Bye', 'isnt should work'); $xp->like( '/html/head/title', qr{^Hel{2}o$}, 'like should work'); $xp->unlike( '/html/head/title', qr{^Bye$}, 'unlike should work'); $xp->cmp_ok('/html/head/title', 'eq', 'Hello', 'cmp_ok should work'); # Make them fail. test_out('not ok 1 - is should work'); test_out('not ok 2 - isnt should work'); test_out('not ok 3 - like should work'); test_out('not ok 4 - unlike should work'); test_out('not ok 5 - cmp_ok should work'); $xp->is( '/html/head/title', 'Bye', 'is should work'); $xp->isnt( '/html/head/title', 'Hello', 'isnt should work'); $xp->like( '/html/head/title', qr{^Bye$}, 'like should work'); $xp->unlike( '/html/head/title', qr{^Hel{2}o$}, 'unlike should work'); $xp->cmp_ok('/html/head/title', 'ne', 'Hello', 'cmp_ok should work'); test_test( skip_err => 1, title => 'Failures in the simple methods should work', ); # Try multiples. $xp->is('/html/body/p', 'firstpost', 'Should work for multiples'); # Try an attribute. $xp->is('/html/body/p/@class', 'foo', 'Should get attribute value'); $xp->ok('/html/body/p[@class="foo"]', 'Should find by attribute value'); # Try a function. $xp->is('count(/html/body/p)', 2, 'Should work for functions'); # Try boolean function. $xp->ok('boolean(1)', 'boolean(1) should be true'); $xp->ok('true()', 'true() should be true'); # Try a false boolean. test_out('not ok 1 - false boolean'); $xp->ok('false()', 'false boolean'); test_test( skip_err => 1, title => 'Boolean true returned by XPath should be true in ok()', ); # Try a comparison function. $xp->ok('contains(//title, "Hell")', 'Title should contain "hell"'); # Try a false comparison. test_out('not ok 1 - heck'); $xp->ok('contains(//title, "Heck")', 'heck'); test_test( skip_err => 1, title => 'Boolean false returned by XPath should be false in ok()', ); # Try a non-existent node. test_out('not ok 1'); $xp->ok('/foo/baz'); test_test( skip_err => 1, title => 'Nonexistent node should be false in ok()', ); # Try successful ok. test_out( 'ok 1 - whatever'); $xp->not_ok('/html/head/foo', 'whatever'); test_test('not_ok works'); # Try failed ok. test_out('not ok 1 - whatever'); test_err(qq{# Failed test 'whatever'\n# at $file line 114.}); $xp->not_ok('/html/head/title', 'whatever'); test_test('not_ok fail works'); Test-XPath-0.19/t/xpath.t 0000644 0001750 0001750 00000005631 13302416000 014506 0 ustar manwar manwar #!/usr/bin/perl -w use strict; use Test::More tests => 57; #use Test::More 'no_plan'; use File::Spec::Functions 'catfile'; use utf8; BEGIN { use_ok 'Test::XPath' or die; } # Try failure. eval { Test::XPath->new }; like $@, qr{Test::XPath->new requires the "xml", "file", or "doc" parameter}, 'Should get an exception for invalid params'; my $xml = 'first
post
'; ok my $xp = Test::XPath->new( xml => $xml, ), 'Should be able to create an object'; isa_ok $xp, 'Test::XPath'; isa_ok $xp->{xpc}, 'XML::LibXML::XPathContext'; ok +Test::XPath->new( xml => $xml, options => { no_network => 1, keep_blanks => 1, suppress_errors => 1 }, ), 'Should be able to configure the parser'; ok $xp = Test::XPath->new( xml => $html, is_html => 1, ), 'Should be able to parse HTML'; isa_ok $xp, 'Test::XPath'; isa_ok $xp->{xpc}, 'XML::LibXML::XPathContext'; # Do some tests with it. $xp->ok('/html/head/title', 'Should find the title'); # Try a recursive call. $xp->ok( '/html/body/p', sub { shift->ok('./em', sub { $_->ok('./b', 'Find b under em'); }, 'Find em under para'); }, 'Find paragraphs'); # Make sure that find_value() works. is $xp->find_value('/html/head/title'), 'Hello', 'find_value should work'; # Try is, like, and cmp_ok. $xp->is( '/html/head/title', 'Hello', 'is should work'); $xp->isnt( '/html/head/title', 'Bye', 'isnt should work'); $xp->like( '/html/head/title', qr{^Hel{2}o$}, 'like should work'); $xp->unlike( '/html/head/title', qr{^Bye$}, 'unlike should work'); $xp->cmp_ok('/html/head/title', 'eq', 'Hello', 'cmp_ok should work'); # Try multiples. $xp->is('/html/body/p', 'firstpost', 'Two values should concatenate'); # Try loading a file. my $file = catfile qw(t menu.xml); ok $xp = Test::XPath->new( file => $file ), 'Should create with file'; # Do some tests on the XML. $xp->is('/menu/restaurant', 'Trébol', 'Should find Unicode value in file'); # Use recursive ok() to ensure all items have the appropriate parts. my $i = 0; $xp->ok('/menu/item', sub { ++$i; $_->ok('./name', "Item $i should have a name"); $_->ok('./price', "Item $i should have a price"); $_->ok('./description', "Item $i should have a description"); }, 'Should have items' ); # Hey, so no try using the doc param. ok $xp = Test::XPath->new( doc => XML::LibXML->new->parse_file($file), ), 'Should create with doc'; $xp->is('/menu/restaurant', 'Trébol', 'Should find Unicode value in doc'); # Use a namespace. ok $xp = Test::XPath->new( xml => $xml, xmlns => { 'ex' => 'http://w3.org/ex' }, ), 'Should create with real namespace'; $xp->ok('/ex:foo/ex:bar', 'We should find an ex:bar'); $xp->is('/ex:foo/ex:bar[1]', 'first', 'Should be able to check the first ex:bar value'); Test-XPath-0.19/t/menu.xml 0000644 0001750 0001750 00000004263 13302416000 014663 0 ustar manwar manwar Test-XPath-0.19/t/ex.t 0000644 0001750 0001750 00000005343 13302416000 013776 0 ustar manwar manwar #!/usr/bin/perl -w use strict; use File::Spec::Functions 'catfile'; # Synopsis. # use Test::More tests => 28; # Use when PerlX::MethodCallWithBlock tests uncommented. use Test::More tests => 22; use Test::XPath; my $xml = <<'XML';first
post
'; ok my $xp = Test::XPath->new( xml => $html, is_html => 1, filter => 'css_selector', ), 'Create Test::XPath object with CSS selector support'; # Try successful ok. test_out( 'ok 1 - whatever'); $xp->ok('> html > head > title', 'whatever'); test_test('ok works'); # Try failed ok. my $file = File::Spec->catfile(split m{/} => __FILE__); test_out('not ok 1 - whatever'); test_err(qq{# Failed test 'whatever'\n# at $file line 34.}); $xp->ok('> html > head > foo', 'whatever'); test_test('ok fail works'); # Try a recursive call. test_out( 'ok 1 - p'); test_out( 'ok 2 - em'); test_out( 'ok 3 - b'); test_out( 'ok 4 - em'); test_out( 'ok 5 - b'); $xp->ok( '> html > body > p', sub { shift->ok('> em', sub { $_->ok('> b', 'b'); }, 'em'); }, 'p'); test_test('recursive ok should work'); # Try is, like, and cmp_ok. $xp->is( ' > html > head > title', 'Hello', 'is should work'); $xp->isnt( ' > html > head > title', 'Bye', 'isnt should work'); $xp->like( ' > html > head > title', qr{^Hel{2}o$}, 'like should work'); $xp->unlike( ' > html > head > title', qr{^Bye$}, 'unlike should work'); $xp->cmp_ok(' > html > head > title', 'eq', 'Hello', 'cmp_ok should work'); # Make them fail. test_out('not ok 1 - is should work'); test_out('not ok 2 - isnt should work'); test_out('not ok 3 - like should work'); test_out('not ok 4 - unlike should work'); test_out('not ok 5 - cmp_ok should work'); $xp->is( ' > html > head > title', 'Bye', 'is should work'); $xp->isnt( ' > html > head > title', 'Hello', 'isnt should work'); $xp->like( ' > html > head > title', qr{^Bye$}, 'like should work'); $xp->unlike( ' > html > head > title', qr{^Hel{2}o$}, 'unlike should work'); $xp->cmp_ok(' > html > head > title', 'ne', 'Hello', 'cmp_ok should work'); test_test( skip_err => 1, title => 'Failures in the simple methods should work', ); # Try multiples. $xp->is(' > html > body > p', 'firstpost', 'Should work for multiples'); # Try an attribute. $xp->ok(' > html > body > p[class="foo"]', 'Should find by attribute value'); # Try a non-existent node. test_out('not ok 1'); $xp->ok(' > foo > baz'); test_test( skip_err => 1, title => 'Nonexistent node should be false in ok()', ); # Try successful ok. test_out( 'ok 1 - whatever'); $xp->not_ok(' > html > head > foo', 'whatever'); test_test('not_ok works'); # Try failed ok. test_out('not ok 1 - whatever'); test_err(qq{# Failed test 'whatever'\n# at $file line 97.}); $xp->not_ok(' > html > head > title', 'whatever'); test_test('not_ok fail works'); Test-XPath-0.19/t/atom.xml 0000644 0001750 0001750 00000004562 13302416000 014661 0 ustar manwar manwar[Update: The Atom draft is finished.]
[Update: The Atom draft is finished.]
Select all "p" nodes that have any attribute.
=item C