From 54a48e15d8804a7e61d01b70a5c5f2bbbfa6bf71 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Wed, 20 Jul 2011 22:44:08 +0100 Subject: Add a test for the map directive --- t/map.t | 177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) create mode 100755 t/map.t (limited to 't') diff --git a/t/map.t b/t/map.t new file mode 100755 index 000000000..a21ae91bf --- /dev/null +++ b/t/map.t @@ -0,0 +1,177 @@ +#!/usr/bin/perl +package IkiWiki; + +use warnings; +use strict; +use HTML::TreeBuilder; +use Test::More; + +BEGIN { use_ok("IkiWiki"); } +BEGIN { use_ok("IkiWiki::Render"); } +BEGIN { use_ok("IkiWiki::Plugin::map"); } +BEGIN { use_ok("IkiWiki::Plugin::mdwn"); } + +ok(! system("rm -rf t/tmp; mkdir t/tmp")); + +$config{verbose} = 1; +$config{srcdir} = 't/tmp'; +$config{underlaydir} = 't/tmp'; +$config{underlaydirbase} = '.'; +$config{templatedir} = 'templates'; +$config{usedirs} = 1; +$config{htmlext} = 'html'; +$config{wiki_file_chars} = "-[:alnum:]+/.:_"; +$config{userdir} = "users"; +$config{tagbase} = "tags"; +$config{default_pageext} = "mdwn"; +$config{wiki_file_prune_regexps} = [qr/^\./]; +$config{autoindex_commit} = 0; + +is(checkconfig(), 1); + +%oldrenderedfiles=%pagectime=(); +%pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks= +%destsources=%renderedfiles=%pagecase=%pagestate=(); + +my @pages = qw( +alpha +alpha/1 +alpha/1/i +alpha/1/ii +alpha/1/iii +alpha/1/iv +alpha/2 +alpha/2/a +alpha/2/b +alpha/3 +beta +); + +foreach my $page (@pages) { + # we use a non-default extension for these, so they're distinguishable + # from programmatically-created pages + $pagesources{$page} = "$page.mdwn"; + $destsources{$page} = "$page.mdwn"; + $pagemtime{$page} = $pagectime{$page} = 1000000; + writefile("$page.mdwn", "t/tmp", "your ad here"); +} + +sub node { + my $name = shift; + my $kids = shift; + my %stuff = @_; + + return { %stuff, name => $name, kids => $kids }; +} + +sub check_nodes { + my $ul = shift; + my $expected = shift; + + is($ul->tag, 'ul'); + + # expected is a list of hashes + # ul is a list of li + foreach my $li ($ul->content_list) { + my @kids = $li->content_list; + + is($li->tag, 'li'); + + my $expectation = shift @$expected; + + is($kids[0]->tag, 'a'); + my $a = $kids[0]; + + if ($expectation->{parent}) { + is($a->attr('class'), 'mapparent'); + } + else { + is($a->attr('class'), 'mapitem'); + } + + is_deeply([$a->content_list], [$expectation->{name}]); + + if (@{$expectation->{kids}}) { + is($kids[1]->tag, 'ul'); + is(scalar @kids, 2); + + check_nodes($kids[1], $expectation->{kids}); + } + else { + is_deeply([@kids], [$a]); + } + } +} + +sub check { + my $pagespec = shift; + my $expected = shift; + + 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; + + is($fragment->tag, 'div'); + is($fragment->attr('class'), 'map'); + + check_nodes(($fragment->content_list)[0], $expected); + + $fragment->delete; + print "\n"; +} + +check('alpha', [node('alpha', [])]); + +check('alpha/*', + [ + node('1', [ + node('i', []), + node('ii', []), + node('iii', []), + node('iv', []), + ]), + node('2', [ + node('a', []), + node('b', []), + ]), + node('3', []), + ]); + +check('alpha or alpha/*', + [ + node('alpha', [ + node('1', [ + node('i', []), + node('ii', []), + node('iii', []), + node('iv', []), + ]), + node('2', [ + node('a', []), + node('b', []), + ]), + node('3', []), + ]), + ]); + +check('alpha or alpha/1 or beta', + [ + node('alpha', [ + node('1', []), + ]), + node('beta', []), + ]); + +done_testing; + +1; -- cgit v1.2.3 From 82537ecf19e57d2a4b096bcc51180df0a0cf6ad7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 29 Jul 2011 20:46:07 +0100 Subject: extend test, some cases now fail --- t/map.t | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 71 insertions(+), 20 deletions(-) (limited to 't') diff --git a/t/map.t b/t/map.t index a21ae91bf..4c8e5ede6 100755 --- 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; -- cgit v1.2.3 From 12ca01fd5c67c158e916c9068453271235a2a0e7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 3 Aug 2012 12:49:20 +0100 Subject: map test: print maps' source as comments --- t/map.t | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 't') diff --git a/t/map.t b/t/map.t index 4c8e5ede6..e764457d1 100755 --- a/t/map.t +++ b/t/map.t @@ -56,6 +56,12 @@ foreach my $page (@pages) { writefile("$page.mdwn", "t/tmp", "your ad here"); } +sub comment { + my $str = shift; + $str =~ s/^/# /gm; + print $str; +} + sub node { my $name = shift; my $kids = shift; @@ -105,13 +111,14 @@ sub check_nodes { sub check { my $pagespec = shift; my $expected = shift; - print "*** $pagespec ***\n"; + comment("*** $pagespec ***\n"); my $html = IkiWiki::Plugin::map::preprocess(pages => $pagespec, page => 'map', destpage => 'map'); + comment($html); my $tree = XML::Twig->new(pretty_print => 'indented'); - eval { + eval { $tree->parse($html); }; if ($@) { @@ -131,7 +138,6 @@ sub check { } $tree->dispose; - print "\n"; } check('doesnotexist', []); -- cgit v1.2.3 From 2bdb0c59021d7d1ae906f82b606638e560726469 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 24 Feb 2013 13:16:13 +0000 Subject: map test: clean up after ourselves --- t/map.t | 1 + 1 file changed, 1 insertion(+) (limited to 't') diff --git a/t/map.t b/t/map.t index e764457d1..7f3df61f7 100755 --- a/t/map.t +++ b/t/map.t @@ -229,6 +229,7 @@ check('alpha/1/i*', node('iv', []), ]); +ok(! system("rm -rf t/tmp")); done_testing; 1; -- cgit v1.2.3 From 766a2c7ab1c48e1fe3acabaaf7b40bcd60e15688 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Sun, 24 Feb 2013 13:18:34 +0000 Subject: permalink test: start by deleting t/tmp Otherwise, tests that don't end by deleting t/tmp (which is a useful change when debugging a failing test) would cause this one to fail. --- t/permalink.t | 1 + 1 file changed, 1 insertion(+) (limited to 't') diff --git a/t/permalink.t b/t/permalink.t index 81d4d1820..36be984c5 100755 --- a/t/permalink.t +++ b/t/permalink.t @@ -3,6 +3,7 @@ use warnings; use strict; use Test::More 'no_plan'; +ok(! system("rm -rf t/tmp")); ok(! system("mkdir t/tmp")); ok(! system("make -s ikiwiki.out")); ok(! system("perl -I. ./ikiwiki.out -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tinyblog t/tmp/out")); -- cgit v1.2.3