diff options
author | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-06-02 05:05:22 +0000 |
---|---|---|
committer | joey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071> | 2007-06-02 05:05:22 +0000 |
commit | bf228acd0a17dc912e51fcaf84e2d6cfa1b465b3 (patch) | |
tree | 2f9b16c23d3b8a7955ce3784dd2a0edf75f23c47 | |
parent | 78323806ee775b8f0384255ba7cecf1e74e75e4f (diff) |
* Add test suite for preprocessor directive parsing.
-rw-r--r-- | debian/changelog | 3 | ||||
-rwxr-xr-x | t/preprocess.t | 54 |
2 files changed, 56 insertions, 1 deletions
diff --git a/debian/changelog b/debian/changelog index e0d5ee2bf..6b2794eaf 100644 --- a/debian/changelog +++ b/debian/changelog @@ -31,8 +31,9 @@ ikiwiki (2.2) UNRELEASED; urgency=low * Apply a patch from Carl Worth adding support for using globs in link() in a PageSpec. * Explode some of the more insane regexps. + * Add test suite for preprocessor directive parsing. - -- Joey Hess <joeyh@debian.org> Fri, 01 Jun 2007 19:39:38 -0400 + -- Joey Hess <joeyh@debian.org> Sat, 02 Jun 2007 01:03:37 -0400 ikiwiki (2.1) unstable; urgency=low diff --git a/t/preprocess.t b/t/preprocess.t new file mode 100755 index 000000000..e1afa4a26 --- /dev/null +++ b/t/preprocess.t @@ -0,0 +1,54 @@ +#!/usr/bin/perl +use warnings; +use strict; +use Test::More tests => 14; + +BEGIN { use_ok("IkiWiki"); } + +$IkiWiki::hooks{preprocess}{foo}{call}=sub { + my @bits; + while (@_) { + my $key=shift; + my $value=shift; + next if $key eq 'page' || $key eq 'destpage' || $key eq 'preview'; + if (length $value) { + push @bits, "$key => $value"; + } + else { + push @bits, $key; + } + } + return "foo(".join(", ", @bits).")"; +}; + +is(IkiWiki::preprocess("foo", "foo", "[[foo]]", 0, 0), "[[foo]]", "not wikilink"); +is(IkiWiki::preprocess("foo", "foo", "[[foo ]]", 0, 0), "foo()", "simple"); +is(IkiWiki::preprocess("foo", "foo", "[[foo a=1]]", 0, 0), "foo(a => 1)"); +is(IkiWiki::preprocess("foo", "foo", "[[foo ]] then [[foo a=2]]", 0, 0), + "foo() then foo(a => 2)"); +is(IkiWiki::preprocess("foo", "foo", "[[foo b c \"d\"]]", 0, 0), "foo(b, c, d)"); +is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 b c=1]]", 0, 0), + "foo(a => 1, b, c => 1)"); +is(IkiWiki::preprocess("foo", "foo", "[[foo a=1 a=2 a=3]]", 0, 0), + "foo(a => 1, a => 2, a => 3)", "dup item"); +is(IkiWiki::preprocess("foo", "foo", '[[foo a="[[bracketed]]" b=1]]', 0, 0), + "foo(a => [[bracketed]], b => 1)"); +my $multiline="here is my \"first\" +!! [[multiline ]] !! +string!"; +is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0), + "foo(a => $multiline)"); +is(IkiWiki::preprocess("foo", "foo", '[[foo """'.$multiline.'"""]]', 0, 0), + "foo($multiline)"); +is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'""" b="foo"]]', 0, 0), + "foo(a => $multiline, b => foo)"); +is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'."\n".$multiline."\n".'""" b="foo"]]', 0, 0), + "foo(a => $multiline, b => foo)", "leading/trailing newline stripped"); + +TODO: { + local $TODO = "nested strings not yet implemented"; + + $multiline='here is a string containing another [[foo val="""string""]]'; + is(IkiWiki::preprocess("foo", "foo", '[[foo a="""'.$multiline.'"""]]', 0, 0), + "foo(a=> $multiline)", "nested multiline strings"); +} |