4 use Test::More tests => 16;
6 BEGIN { use_ok("IkiWiki"); }
13 my @existing_pages=@{shift()};
15 # This is what linkify and htmllink need set right now to work.
16 # This could change, if so, update it..
17 %IkiWiki::pagecase=();
19 foreach my $page (@existing_pages) {
20 $IkiWiki::pagecase{lc $page}=$page;
22 $renderedfiles{"$page.mdwn"}=[$page];
23 $destsources{$page}="$page.mdwn";
25 %config=IkiWiki::defaultconfig();
26 $config{cgiurl}="http://somehost/ikiwiki.cgi";
28 return IkiWiki::linkify($lpage, $page, $content);
35 if ($content =~ m!<a href="[^"]*\Q$link\E[^"]*">!) {
39 print STDERR "# expected link to $link in $content\n";
44 sub not_links_to ($$) {
48 if ($content !~ m!<a href="[^"]*\Q$link\E[^"]*">!) {
52 print STDERR "# expected no link to $link in $content\n";
61 if ($content =~ m!>\Q$text\E</a>!) {
65 print STDERR "# expected link text $text in $content\n";
71 ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "bar"])), "ok link");
72 ok(links_to("bar_baz", linkify("foo", "foo", "link to [[bar_baz]] ok", ["foo", "bar_baz"])), "ok link");
73 ok(not_links_to("bar", linkify("foo", "foo", "link to \\[[bar]] ok", ["foo", "bar"])), "escaped link");
74 ok(links_to("page=bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo"])), "broken link");
75 ok(links_to("bar", linkify("foo", "foo", "link to [[baz]] and [[bar]] ok", ["foo", "baz", "bar"])), "dual links");
76 ok(links_to("baz", linkify("foo", "foo", "link to [[baz]] and [[bar]] ok", ["foo", "baz", "bar"])), "dual links");
77 ok(links_to("bar", linkify("foo", "foo", "link to [[some_page|bar]] ok", ["foo", "bar"])), "named link");
78 ok(links_text("some page", linkify("foo", "foo", "link to [[some_page|bar]] ok", ["foo", "bar"])), "named link text");
79 ok(links_to("bar", linkify("foo", "foo", "link to [[some page|bar]] ok", ["foo", "bar"])), "named link, with whitespace");
80 ok(links_text("some page", linkify("foo", "foo", "link to [[some page|bar]] ok", ["foo", "bar"])), "named link text, with whitespace");
81 ok(links_text("0", linkify("foo", "foo", "link to [[0|bar]] ok", ["foo", "bar"])), "named link to 0");
82 ok(links_text("Some long, & complex page name.", linkify("foo", "foo", "link to [[Some long, & complex page name.|bar]] ok, and this is not a link]] here", ["foo", "bar"])), "complex named link text");
83 ok(links_to("foo/bar", linkify("foo/item", "foo", "link to [[bar]] ok", ["foo", "foo/item", "foo/bar"])), "inline page link");
84 ok(links_to("bar", linkify("foo", "foo", "link to [[bar]] ok", ["foo", "foo/item", "foo/bar"])), "same except not inline");
85 ok(links_to("bar#baz", linkify("foo", "foo", "link to [[bar#baz]] ok", ["foo", "bar"])), "anchor link");