summaryrefslogtreecommitdiff
path: root/t/bestlink.t
blob: 0020a05e2ea9bc70a090fe069c1450899ca5caac (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 11;
  5. BEGIN { use_ok("IkiWiki"); }
  6. sub test ($$$) {
  7. my $page=shift;
  8. my $link=shift;
  9. my @existing_pages=@{shift()};
  10. %IkiWiki::pagecase=();
  11. %pagesources=();
  12. $IkiWiki::config{userdir}="foouserdir";
  13. foreach my $page (@existing_pages) {
  14. $IkiWiki::pagecase{lc $page}=$page;
  15. $pagesources{$page}="$page.mdwn";
  16. }
  17. return bestlink($page, $link);
  18. }
  19. is(test("bar", "foo", ["bar"]), "", "broken link");
  20. is(test("bar", "foo", ["bar", "foo"]), "foo", "simple link");
  21. is(test("bar", "FoO", ["bar", "foo"]), "foo", "simple link with different input case");
  22. is(test("bar", "foo", ["bar", "fOo"]), "fOo", "simple link with different page case");
  23. is(test("bar", "FoO", ["bar", "fOo"]), "fOo", "simple link with different page and input case");
  24. is(test("bar", "Foo", ["bar", "fOo", "foo", "fOO", "Foo", "fOo"]), "Foo", "in case of ambiguity, like case wins");
  25. is(test("bar", "foo", ["bar", "foo", "bar/foo"]), "bar/foo", "simple subpage link");
  26. is(test("bar", "foo/subpage", ["bar", "foo", "bar/subpage", "foo/subpage"]), "foo/subpage", "cross subpage link");
  27. is(test("bar", "bob", ["bar", "foo", "foouserdir/bob"]), "foouserdir/bob", "user link");
  28. is(test("bar", "bob", ["bar", "foo", "bob", "foouserdir/bob"]), "bob", "non-user link");