]> sipb.mit.edu Git - ikiwiki.git/commitdiff
extend test, some cases now fail
authorSimon McVittie <smcv@debian.org>
Fri, 29 Jul 2011 19:46:07 +0000 (20:46 +0100)
committerSimon McVittie <smcv@debian.org>
Sun, 24 Feb 2013 13:10:24 +0000 (13:10 +0000)
t/map.t

diff --git a/t/map.t b/t/map.t
index a21ae91bff95e2d206079df98312554d7ecf37f7..4c8e5ede655aa69756c1873219d1d6fe34484069 100755 (executable)
--- a/t/map.t
+++ b/t/map.t
@@ -3,7 +3,7 @@ package IkiWiki;
 
 use warnings;
 use strict;
-use HTML::TreeBuilder;
+use XML::Twig;
 use Test::More;
 
 BEGIN { use_ok("IkiWiki"); }
@@ -72,8 +72,8 @@ sub check_nodes {
 
        # expected is a list of hashes
        # ul is a list of li
-       foreach my $li ($ul->content_list) {
-               my @kids = $li->content_list;
+       foreach my $li ($ul->children) {
+               my @kids = $li->children;
 
                is($li->tag, 'li');
 
@@ -83,16 +83,15 @@ sub check_nodes {
                my $a = $kids[0];
 
                if ($expectation->{parent}) {
-                       is($a->attr('class'), 'mapparent');
+                       is($a->att('class'), 'mapparent');
                }
                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}}) {
-                       is($kids[1]->tag, 'ul');
                        is(scalar @kids, 2);
 
                        check_nodes($kids[1], $expectation->{kids});
@@ -106,30 +105,37 @@ sub check_nodes {
 sub check {
        my $pagespec = shift;
        my $expected = shift;
+       print "*** $pagespec ***\n";
 
        my $html = IkiWiki::Plugin::map::preprocess(pages => $pagespec,
                page => 'map',
                destpage => 'map');
-       my $tree = HTML::TreeBuilder->new;
-       $tree->implicit_tags(0);
-       $tree->unbroken_text(1);
-       $tree->strict_end(1);
-       $tree->strict_names(1);
-       $tree->strict_comment(1);
-       $tree->empty_element_tags(1);
-       $tree->parse_content($html);
-       my $fragment = $tree->disembowel;
-       print $fragment->dump;
+       my $tree = XML::Twig->new(pretty_print => 'indented');
+       eval { 
+               $tree->parse($html);
+       };
+       if ($@) {
+               print "malformed XML: $@\n$html\n";
+               ok(0);
+       }
+       my $fragment = $tree->root;
 
        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";
 }
 
+check('doesnotexist', []);
+
 check('alpha', [node('alpha', [])]);
 
 check('alpha/*',
@@ -172,6 +178,51 @@ check('alpha or alpha/1 or 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;
 
 1;