aboutsummaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rwxr-xr-xt/404.t44
-rw-r--r--t/basewiki_brokenlinks/index.mdwn2
-rwxr-xr-xt/beautify_urlpath.t17
-rwxr-xr-xt/git.t19
-rwxr-xr-xt/htmlbalance.t23
-rwxr-xr-xt/openiduser.t37
-rwxr-xr-xt/pagename.t29
-rwxr-xr-xt/pagespec_match.t14
-rwxr-xr-xt/pagespec_merge.t12
-rwxr-xr-xt/pagetype.mdwn14
-rw-r--r--t/tinyblog/index.mdwn2
-rwxr-xr-xt/yesno.t21
12 files changed, 187 insertions, 47 deletions
diff --git a/t/404.t b/t/404.t
new file mode 100755
index 000000000..0bb3c6063
--- /dev/null
+++ b/t/404.t
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More tests => 17;
+
+BEGIN { use_ok("IkiWiki::Plugin::404"); }
+
+sub cgi_page_from_404 {
+ return IkiWiki::Plugin::404::cgi_page_from_404(shift, shift, shift);
+}
+
+$IkiWiki::config{htmlext} = 'html';
+
+is(cgi_page_from_404('/', 'http://example.com', 1), 'index');
+is(cgi_page_from_404('/index.html', 'http://example.com', 0), 'index');
+is(cgi_page_from_404('/', 'http://example.com/', 1), 'index');
+is(cgi_page_from_404('/index.html', 'http://example.com/', 0), 'index');
+
+is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user', 1),
+ 'foo/bar');
+is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user', 1),
+ 'foo/bar');
+is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user', 1),
+ 'foo/bar');
+is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user', 0),
+ 'foo/bar');
+
+is(cgi_page_from_404('/~user/foo/bar', 'http://example.com/~user/', 1),
+ 'foo/bar');
+is(cgi_page_from_404('/~user/foo/bar/index.html', 'http://example.com/~user/', 1),
+ 'foo/bar');
+is(cgi_page_from_404('/~user/foo/bar/', 'http://example.com/~user/', 1),
+ 'foo/bar');
+is(cgi_page_from_404('/~user/foo/bar.html', 'http://example.com/~user/', 0),
+ 'foo/bar');
+
+is(cgi_page_from_404('/~user/foo', 'https://example.com/~user', 1),
+ 'foo');
+is(cgi_page_from_404('/~user/foo/index.html', 'https://example.com/~user', 1),
+ 'foo');
+is(cgi_page_from_404('/~user/foo/', 'https://example.com/~user', 1),
+ 'foo');
+is(cgi_page_from_404('/~user/foo.html', 'https://example.com/~user', 0),
+ 'foo');
diff --git a/t/basewiki_brokenlinks/index.mdwn b/t/basewiki_brokenlinks/index.mdwn
index 0a6b2c39e..41768f782 100644
--- a/t/basewiki_brokenlinks/index.mdwn
+++ b/t/basewiki_brokenlinks/index.mdwn
@@ -1 +1 @@
-[[brokenlinks ]]
+[[!brokenlinks ]]
diff --git a/t/beautify_urlpath.t b/t/beautify_urlpath.t
new file mode 100755
index 000000000..94b923d3b
--- /dev/null
+++ b/t/beautify_urlpath.t
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More tests => 8;
+
+BEGIN { use_ok("IkiWiki"); }
+
+$IkiWiki::config{usedirs} = 1;
+$IkiWiki::config{htmlext} = "HTML";
+is(IkiWiki::beautify_urlpath("foo/bar"), "./foo/bar");
+is(IkiWiki::beautify_urlpath("../badger"), "../badger");
+is(IkiWiki::beautify_urlpath("./bleh"), "./bleh");
+is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/");
+is(IkiWiki::beautify_urlpath("index.HTML"), "./");
+is(IkiWiki::beautify_urlpath("../index.HTML"), "../");
+$IkiWiki::config{usedirs} = 0;
+is(IkiWiki::beautify_urlpath("foo/index.HTML"), "./foo/index.HTML");
diff --git a/t/git.t b/t/git.t
index b3aa6a80b..f1c24b359 100755
--- a/t/git.t
+++ b/t/git.t
@@ -3,19 +3,17 @@ use warnings;
use strict;
my $dir;
-my $gitrepo;
BEGIN {
$dir="/tmp/ikiwiki-test-git.$$";
- $gitrepo="$dir/repo";
my $git=`which git`;
chomp $git;
- if (! -x $git || ! mkdir($dir) || ! mkdir($gitrepo)) {
+ if (! -x $git || ! mkdir($dir)) {
eval q{
- use Test::More skip_all => "git not available or could not make test dirs"
+ use Test::More skip_all => "git not available or could not make test dir"
}
}
}
-use Test::More tests => 16;
+use Test::More tests => 18;
BEGIN { use_ok("IkiWiki"); }
@@ -25,17 +23,16 @@ $config{srcdir} = "$dir/src";
IkiWiki::loadplugins();
IkiWiki::checkconfig();
-system "cd $gitrepo && git init >/dev/null 2>&1";
-system "cd $gitrepo && echo dummy > dummy; git add . >/dev/null 2>&1";
-system "cd $gitrepo && git commit -m Initial >/dev/null 2>&1";
-system "git clone -l -s $gitrepo $config{srcdir} >/dev/null 2>&1";
+ok (mkdir($config{srcdir}));
+is (system("./ikiwiki-makerepo git $config{srcdir} $dir/repo"), 0);
my @changes;
@changes = IkiWiki::rcs_recentchanges(3);
is($#changes, 0); # counts for dummy commit during repo creation
-is($changes[0]{message}[0]{"line"}, "Initial");
-is($changes[0]{pages}[0]{"page"}, "dummy");
+# ikiwiki-makerepo's first commit is setting up the .gitignore
+is($changes[0]{message}[0]{"line"}, "initial commit");
+is($changes[0]{pages}[0]{"page"}, ".gitignore");
# Web commit
my $test1 = readfile("t/test1.mdwn");
diff --git a/t/htmlbalance.t b/t/htmlbalance.t
new file mode 100755
index 000000000..e5a5db0ee
--- /dev/null
+++ b/t/htmlbalance.t
@@ -0,0 +1,23 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+BEGIN {
+ eval q{
+ use HTML::TreeBuilder;
+ };
+ if ($@) {
+ eval q{use Test::More skip_all => "HTML::TreeBuilder not available"};
+ }
+ else {
+ eval q{use Test::More tests => 7};
+ }
+ use_ok("IkiWiki::Plugin::htmlbalance");
+}
+
+is(IkiWiki::Plugin::htmlbalance::sanitize(content => "<br></br>"), "<br />");
+is(IkiWiki::Plugin::htmlbalance::sanitize(content => "<div><p b=\"c\">hello world</div>"), "<div><p b=\"c\">hello world</p></div>");
+is(IkiWiki::Plugin::htmlbalance::sanitize(content => "<a></a></a>"), "<a></a>");
+is(IkiWiki::Plugin::htmlbalance::sanitize(content => "<b>foo <a</b>"), "<b>foo </b>");
+is(IkiWiki::Plugin::htmlbalance::sanitize(content => "<b> foo <a</a></b>"), "<b> foo </b>");
+is(IkiWiki::Plugin::htmlbalance::sanitize(content => "a>"), "a&gt;");
diff --git a/t/openiduser.t b/t/openiduser.t
new file mode 100755
index 000000000..52d879484
--- /dev/null
+++ b/t/openiduser.t
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+
+BEGIN {
+ eval q{
+ use Net::OpenID::VerifiedIdentity;
+ };
+ if ($@) {
+ eval q{use Test::More skip_all => "Net::OpenID::VerifiedIdentity not available"};
+ }
+ else {
+ eval q{use Test::More tests => 9};
+ }
+ use_ok("IkiWiki::Plugin::openid");
+}
+
+# Some typical examples:
+
+# This test, when run by Test::Harness using perl -w, exposes a warning in
+# Net::OpenID::VerifiedIdentity. Normally that warning is not displayed, as
+# that module does not use warnings. To avoid cluttering the test output,
+# disable the -w switch temporarily.
+$^W=0;
+is(IkiWiki::openiduser('http://josephturian.blogspot.com'), 'josephturian [blogspot.com]');
+$^W=1;
+
+is(IkiWiki::openiduser('http://yam655.livejournal.com/'), 'yam655 [livejournal.com]');
+is(IkiWiki::openiduser('http://id.mayfirst.org/jamie/'), 'jamie [id.mayfirst.org]');
+
+# and some less typical ones taken from the ikiwiki commit history
+
+is(IkiWiki::openiduser('http://thm.id.fedoraproject.org/'), 'thm [id.fedoraproject.org]');
+is(IkiWiki::openiduser('http://dtrt.org/'), 'dtrt.org');
+is(IkiWiki::openiduser('http://alcopop.org/me/openid/'), 'openid [alcopop.org/me]');
+is(IkiWiki::openiduser('http://id.launchpad.net/882/bielawski1'), 'bielawski1 [id.launchpad.net/882]');
+is(IkiWiki::openiduser('http://technorati.com/people/technorati/drajt'), 'drajt [technorati.com/people/technorati]');
diff --git a/t/pagename.t b/t/pagename.t
index c7f1ce180..540d10f4c 100755
--- a/t/pagename.t
+++ b/t/pagename.t
@@ -1,14 +1,35 @@
#!/usr/bin/perl
use warnings;
use strict;
-use Test::More tests => 5;
+use Test::More tests => 19;
BEGIN { use_ok("IkiWiki"); }
-# Used internally.
-$IkiWiki::hooks{htmlize}{mdwn}{call}=sub {};
-
+# define mdwn as an extension
+$IkiWiki::hooks{htmlize}{mdwn}={};
+is(pagetype("foo.mdwn"), "mdwn");
is(pagename("foo.mdwn"), "foo");
+is(pagetype("foo/bar.mdwn"), "mdwn");
is(pagename("foo/bar.mdwn"), "foo/bar");
+
+# bare files get the full filename as page name, undef type
+is(pagetype("foo.png"), undef);
is(pagename("foo.png"), "foo.png");
+is(pagetype("foo/bar.png"), undef);
+is(pagename("foo/bar.png"), "foo/bar.png");
+is(pagetype("foo"), undef);
is(pagename("foo"), "foo");
+
+# keepextension preserves the extension in the page name
+$IkiWiki::hooks{htmlize}{txt}={keepextension => 1};
+is(pagename("foo.txt"), "foo.txt");
+is(pagetype("foo.txt"), "txt");
+is(pagename("foo/bar.txt"), "foo/bar.txt");
+is(pagetype("foo/bar.txt"), "txt");
+
+# noextension makes extensionless files be treated as first-class pages
+$IkiWiki::hooks{htmlize}{Makefile}={noextension =>1};
+is(pagetype("Makefile"), "Makefile");
+is(pagename("Makefile"), "Makefile");
+is(pagetype("foo/Makefile"), "Makefile");
+is(pagename("foo/Makefile"), "foo/Makefile");
diff --git a/t/pagespec_match.t b/t/pagespec_match.t
index c61d16122..69cf361de 100755
--- a/t/pagespec_match.t
+++ b/t/pagespec_match.t
@@ -1,7 +1,7 @@
#!/usr/bin/perl
use warnings;
use strict;
-use Test::More tests => 56;
+use Test::More tests => 51;
BEGIN { use_ok("IkiWiki"); }
@@ -40,6 +40,7 @@ $links{"bugs/bar"}=[qw{done}];
$links{"done"}=[];
$links{"examples/softwaresite/bugs/fails_to_frobnicate"}=[qw{done}];
$links{"examples/softwaresite/bugs/done"}=[];
+$links{"ook"}=[qw{/blog/tags/foo}];
ok(pagespec_match("foo", "link(bar)"), "link");
ok(pagespec_match("foo", "link(ba?)"), "glob link");
@@ -55,6 +56,8 @@ ok(pagespec_match("bar", "backlink(foo)"), "backlink");
ok(! pagespec_match("quux", "backlink(foo)"), "failed backlink");
ok(! pagespec_match("bar", ""), "empty pagespec should match nothing");
ok(! pagespec_match("bar", " "), "blank pagespec should match nothing");
+ok(pagespec_match("ook", "link(blog/tags/foo)"), "link internal absolute success");
+ok(pagespec_match("ook", "link(/blog/tags/foo)"), "link explicit absolute success");
$IkiWiki::pagectime{foo}=1154532692; # Wed Aug 2 11:26 EDT 2006
$IkiWiki::pagectime{bar}=1154532695; # after
@@ -74,12 +77,3 @@ ok(! pagespec_match("foo", "no_such_function(foo)"), "foo");
my $ret=pagespec_match("foo", "(invalid");
ok(! $ret, "syntax error");
ok($ret =~ /syntax error/, "error message");
-
-# old style globlists
-ok(pagespec_match("foo", "foo bar"), "simple list");
-ok(pagespec_match("bar", "foo bar"), "simple list 2");
-ok(pagespec_match("foo", "f?? !foz"));
-ok(! pagespec_match("foo", "f?? !foo"));
-ok(! pagespec_match("foo", "* !foo"));
-ok(! pagespec_match("foo", "foo !foo"));
-ok(! pagespec_match("foo.png", "* !*.*"));
diff --git a/t/pagespec_merge.t b/t/pagespec_merge.t
index cbb06219c..9e38d5761 100755
--- a/t/pagespec_merge.t
+++ b/t/pagespec_merge.t
@@ -28,17 +28,17 @@ ok(same("!foo", "!bar", "foo"), "double inversion failed match");
ok(same("!foo", "!bar", "bar"), "double inversion failed match 2");
ok(same("*", "!bar", "foo"), "glob+inversion match");
ok(same("*", "!bar", "bar"), "matching glob and matching inversion");
-ok(same("* !foo", "!bar", "bar"), "matching glob and matching inversion");
-ok(same("* !foo", "!bar", "foo"), "matching glob with matching inversion and non-matching inversion");
-ok(same("* !foo", "!foo", "foo"), "matching glob with matching inversion and matching inversion");
+ok(same("* and !foo", "!bar", "bar"), "matching glob and matching inversion");
+ok(same("* and !foo", "!bar", "foo"), "matching glob with matching inversion and non-matching inversion");
+ok(same("* and !foo", "!foo", "foo"), "matching glob with matching inversion and matching inversion");
ok(same("b??", "!b??", "bar"), "matching glob and matching inverted glob");
ok(same("f?? !f??", "!bar", "bar"), "matching glob and matching inverted glob");
ok(same("b??", "!b?z", "bar"), "matching glob and non-matching inverted glob");
ok(same("f?? !f?z", "!bar", "bar"), "matching glob and non-matching inverted glob");
ok(same("!foo bar baz", "!bar", "bar"), "matching list and matching inversion");
ok(pagespec_match("foo/Discussion",
- IkiWiki::pagespec_merge("* !*/Discussion", "*/Discussion")), "should match");
-ok(same("* !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1");
-ok(same("*/Discussion", "* !*/Discussion", "foo/Discussion"), "Discussion merge 2");
+ IkiWiki::pagespec_merge("* and !*/Discussion", "*/Discussion")), "should match");
+ok(same("* and !*/Discussion", "*/Discussion", "foo/Discussion"), "Discussion merge 1");
+ok(same("*/Discussion", "* and !*/Discussion", "foo/Discussion"), "Discussion merge 2");
ok(same("*/Discussion !*/bar", "*/bar !*/Discussion", "foo/Discussion"), "bidirectional merge 1");
ok(same("*/Discussion !*/bar", "*/bar !*/Discussion", "foo/bar"), "bidirectional merge 2");
diff --git a/t/pagetype.mdwn b/t/pagetype.mdwn
deleted file mode 100755
index 76cacd8f7..000000000
--- a/t/pagetype.mdwn
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/usr/bin/perl
-use warnings;
-use strict;
-use Test::More tests => 5;
-
-BEGIN { use_ok("IkiWiki"); }
-
-# Used internally.
-$IkiWiki::hooks{htmlize}{mdwn}=1;
-
-is(pagetype("foo.mdwn"), "mdwn");
-is(pagetype("foo/bar.mdwn"), "mdwn");
-is(pagename("foo.png"), undef);
-is(pagename("foo"), undef);
diff --git a/t/tinyblog/index.mdwn b/t/tinyblog/index.mdwn
index 010c85de1..72ba7846a 100644
--- a/t/tinyblog/index.mdwn
+++ b/t/tinyblog/index.mdwn
@@ -1 +1 @@
-[[inline pages="post" rss=yes]]
+[[!inline pages="post" rss=yes]]
diff --git a/t/yesno.t b/t/yesno.t
new file mode 100755
index 000000000..60a8c071d
--- /dev/null
+++ b/t/yesno.t
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Test::More tests => 10;
+
+BEGIN { use_ok("IkiWiki"); }
+
+# note: yesno always accepts English even if localized.
+# So no need to bother setting locale to C.
+
+ok(IkiWiki::yesno("yes") == 1);
+ok(IkiWiki::yesno("Yes") == 1);
+ok(IkiWiki::yesno("YES") == 1);
+
+ok(IkiWiki::yesno("no") == 0);
+ok(IkiWiki::yesno("No") == 0);
+ok(IkiWiki::yesno("NO") == 0);
+
+ok(IkiWiki::yesno("1") == 1);
+ok(IkiWiki::yesno("0") == 0);
+ok(IkiWiki::yesno("mooooooooooo") == 0);