extend test, some cases now fail
parent
54a48e15d8
commit
82537ecf19
91
t/map.t
91
t/map.t
|
@ -3,7 +3,7 @@ package IkiWiki;
|
||||||
|
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use HTML::TreeBuilder;
|
use XML::Twig;
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
|
||||||
BEGIN { use_ok("IkiWiki"); }
|
BEGIN { use_ok("IkiWiki"); }
|
||||||
|
@ -72,8 +72,8 @@ sub check_nodes {
|
||||||
|
|
||||||
# expected is a list of hashes
|
# expected is a list of hashes
|
||||||
# ul is a list of li
|
# ul is a list of li
|
||||||
foreach my $li ($ul->content_list) {
|
foreach my $li ($ul->children) {
|
||||||
my @kids = $li->content_list;
|
my @kids = $li->children;
|
||||||
|
|
||||||
is($li->tag, 'li');
|
is($li->tag, 'li');
|
||||||
|
|
||||||
|
@ -83,16 +83,15 @@ sub check_nodes {
|
||||||
my $a = $kids[0];
|
my $a = $kids[0];
|
||||||
|
|
||||||
if ($expectation->{parent}) {
|
if ($expectation->{parent}) {
|
||||||
is($a->attr('class'), 'mapparent');
|
is($a->att('class'), 'mapparent');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
is($a->attr('class'), 'mapitem');
|
is($a->att('class'), 'mapitem');
|
||||||
}
|
}
|
||||||
|
|
||||||
is_deeply([$a->content_list], [$expectation->{name}]);
|
is_deeply([$a->text], [$expectation->{name}]);
|
||||||
|
|
||||||
if (@{$expectation->{kids}}) {
|
if (@{$expectation->{kids}}) {
|
||||||
is($kids[1]->tag, 'ul');
|
|
||||||
is(scalar @kids, 2);
|
is(scalar @kids, 2);
|
||||||
|
|
||||||
check_nodes($kids[1], $expectation->{kids});
|
check_nodes($kids[1], $expectation->{kids});
|
||||||
|
@ -106,30 +105,37 @@ sub check_nodes {
|
||||||
sub check {
|
sub check {
|
||||||
my $pagespec = shift;
|
my $pagespec = shift;
|
||||||
my $expected = shift;
|
my $expected = shift;
|
||||||
|
print "*** $pagespec ***\n";
|
||||||
|
|
||||||
my $html = IkiWiki::Plugin::map::preprocess(pages => $pagespec,
|
my $html = IkiWiki::Plugin::map::preprocess(pages => $pagespec,
|
||||||
page => 'map',
|
page => 'map',
|
||||||
destpage => 'map');
|
destpage => 'map');
|
||||||
my $tree = HTML::TreeBuilder->new;
|
my $tree = XML::Twig->new(pretty_print => 'indented');
|
||||||
$tree->implicit_tags(0);
|
eval {
|
||||||
$tree->unbroken_text(1);
|
$tree->parse($html);
|
||||||
$tree->strict_end(1);
|
};
|
||||||
$tree->strict_names(1);
|
if ($@) {
|
||||||
$tree->strict_comment(1);
|
print "malformed XML: $@\n$html\n";
|
||||||
$tree->empty_element_tags(1);
|
ok(0);
|
||||||
$tree->parse_content($html);
|
}
|
||||||
my $fragment = $tree->disembowel;
|
my $fragment = $tree->root;
|
||||||
print $fragment->dump;
|
|
||||||
|
|
||||||
is($fragment->tag, 'div');
|
is($fragment->tag, 'div');
|
||||||
is($fragment->attr('class'), 'map');
|
is($fragment->att('class'), 'map');
|
||||||
|
|
||||||
check_nodes(($fragment->content_list)[0], $expected);
|
if (@$expected) {
|
||||||
|
check_nodes(($fragment->children)[0], $expected);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ok(! $fragment->children);
|
||||||
|
}
|
||||||
|
|
||||||
$fragment->delete;
|
$tree->dispose;
|
||||||
print "<!-- -->\n";
|
print "<!-- -->\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
check('doesnotexist', []);
|
||||||
|
|
||||||
check('alpha', [node('alpha', [])]);
|
check('alpha', [node('alpha', [])]);
|
||||||
|
|
||||||
check('alpha/*',
|
check('alpha/*',
|
||||||
|
@ -172,6 +178,51 @@ check('alpha or alpha/1 or beta',
|
||||||
node('beta', []),
|
node('beta', []),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
check('alpha/1 or beta',
|
||||||
|
[
|
||||||
|
node('alpha', [
|
||||||
|
node('1', []),
|
||||||
|
], parent => 1),
|
||||||
|
node('beta', []),
|
||||||
|
]);
|
||||||
|
|
||||||
|
check('alpha/1/i* or alpha/2/a or beta',
|
||||||
|
[
|
||||||
|
node('alpha', [
|
||||||
|
node('1', [
|
||||||
|
node('i', []),
|
||||||
|
node('ii', []),
|
||||||
|
node('iii', []),
|
||||||
|
node('iv', []),
|
||||||
|
], parent => 1),
|
||||||
|
node('2', [
|
||||||
|
node('a', []),
|
||||||
|
], parent => 1),
|
||||||
|
], parent => 1),
|
||||||
|
node('beta', []),
|
||||||
|
]);
|
||||||
|
|
||||||
|
check('alpha/1/i* or alpha/2/a',
|
||||||
|
[
|
||||||
|
node('1', [
|
||||||
|
node('i', []),
|
||||||
|
node('ii', []),
|
||||||
|
node('iii', []),
|
||||||
|
node('iv', []),
|
||||||
|
], parent => 1),
|
||||||
|
node('2', [
|
||||||
|
node('a', []),
|
||||||
|
], parent => 1),
|
||||||
|
]);
|
||||||
|
|
||||||
|
check('alpha/1/i*',
|
||||||
|
[
|
||||||
|
node('i', []),
|
||||||
|
node('ii', []),
|
||||||
|
node('iii', []),
|
||||||
|
node('iv', []),
|
||||||
|
]);
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in New Issue