Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki.git] / t / bestlink.t
blob0020a05e2ea9bc70a090fe069c1450899ca5caac
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 11;
6 BEGIN { use_ok("IkiWiki"); }
8 sub test ($$$) {
9 my $page=shift;
10 my $link=shift;
11 my @existing_pages=@{shift()};
13 %IkiWiki::pagecase=();
14 %pagesources=();
15 $IkiWiki::config{userdir}="foouserdir";
16 foreach my $page (@existing_pages) {
17 $IkiWiki::pagecase{lc $page}=$page;
18 $pagesources{$page}="$page.mdwn";
21 return bestlink($page, $link);
24 is(test("bar", "foo", ["bar"]), "", "broken link");
25 is(test("bar", "foo", ["bar", "foo"]), "foo", "simple link");
26 is(test("bar", "FoO", ["bar", "foo"]), "foo", "simple link with different input case");
27 is(test("bar", "foo", ["bar", "fOo"]), "fOo", "simple link with different page case");
28 is(test("bar", "FoO", ["bar", "fOo"]), "fOo", "simple link with different page and input case");
29 is(test("bar", "Foo", ["bar", "fOo", "foo", "fOO", "Foo", "fOo"]), "Foo", "in case of ambiguity, like case wins");
30 is(test("bar", "foo", ["bar", "foo", "bar/foo"]), "bar/foo", "simple subpage link");
31 is(test("bar", "foo/subpage", ["bar", "foo", "bar/subpage", "foo/subpage"]), "foo/subpage", "cross subpage link");
32 is(test("bar", "bob", ["bar", "foo", "foouserdir/bob"]), "foouserdir/bob", "user link");
33 is(test("bar", "bob", ["bar", "foo", "bob", "foouserdir/bob"]), "bob", "non-user link");