summaryrefslogtreecommitdiff
path: root/t/tag.t
blob: 5b0d9c824b6d9efc27faf2ebf0d559644a352ef5 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki;
  3. use warnings;
  4. use strict;
  5. use Test::More tests => 22;
  6. BEGIN { use_ok("IkiWiki"); }
  7. BEGIN { use_ok("IkiWiki::Render"); }
  8. BEGIN { use_ok("IkiWiki::Plugin::mdwn"); }
  9. BEGIN { use_ok("IkiWiki::Plugin::tag"); }
  10. ok(! system("rm -rf t/tmp; mkdir t/tmp"));
  11. $config{verbose} = 1;
  12. $config{srcdir} = 't/tmp';
  13. $config{underlaydir} = 't/tmp';
  14. $config{templatedir} = 'templates';
  15. $config{usedirs} = 1;
  16. $config{htmlext} = 'html';
  17. $config{wiki_file_chars} = "-[:alnum:]+/.:_";
  18. $config{userdir} = "users";
  19. $config{tagbase} = "tags";
  20. $config{tag_autocreate} = 1;
  21. $config{default_pageext} = "mdwn";
  22. $config{wiki_file_prune_regexps} = [qr/^\./];
  23. $config{underlaydirbase} = '.';
  24. is(checkconfig(), 1);
  25. %oldrenderedfiles=%pagectime=();
  26. %pagesources=%pagemtime=%oldlinks=%links=%depends=%typedlinks=%oldtypedlinks=
  27. %destsources=%renderedfiles=%pagecase=%pagestate=();
  28. foreach my $page (qw(tags/numbers tags/letters one two alpha beta)) {
  29. $pagesources{$page} = "$page.mdwn";
  30. $pagemtime{$page} = $pagectime{$page} = 1000000;
  31. writefile("$page.mdwn", "t/tmp", "your ad here");
  32. }
  33. $links{one}=[qw(tags/numbers alpha tags/letters)];
  34. $links{two}=[qw(tags/numbers)];
  35. $links{alpha}=[qw(tags/letters one)];
  36. $links{beta}=[qw(tags/letters)];
  37. $typedlinks{one}={tag => {"tags/numbers" => 1 }};
  38. $typedlinks{two}={tag => {"tags/numbers" => 1 }};
  39. $typedlinks{alpha}={tag => {"tags/letters" => 1 }};
  40. $typedlinks{beta}={tag => {"tags/letters" => 1 }};
  41. ok(pagespec_match("one", "tagged(numbers)"));
  42. ok(!pagespec_match("two", "tagged(alpha)"));
  43. ok(pagespec_match("one", "link(tags/numbers)"));
  44. ok(pagespec_match("one", "link(alpha)"));
  45. # emulate preprocessing [[!tag numbers primes lucky]] on page "seven", causing
  46. # the "numbers" and "primes" tag pages to be auto-created
  47. IkiWiki::Plugin::tag::preprocess_tag(page => "seven", numbers => undef, primes => undef, lucky => undef);
  48. is($autofiles{"tags/lucky.mdwn"}{plugin}, "tag");
  49. is($autofiles{"tags/numbers.mdwn"}{plugin}, "tag");
  50. is($autofiles{"tags/primes.mdwn"}{plugin}, "tag");
  51. ok(!-e "t/tmp/tags/lucky.mdwn");
  52. my (%pages, @del);
  53. IkiWiki::gen_autofile("tags/lucky.mdwn", \%pages, \@del);
  54. is_deeply(\%pages, {"t/tmp/tags/lucky" => 1});
  55. is_deeply(\@del, []);
  56. ok(-s "t/tmp/tags/lucky.mdwn");
  57. # generating an autofile that already exists does nothing
  58. %pages = @del = ();
  59. IkiWiki::gen_autofile("tags/numbers.mdwn", \%pages, \@del);
  60. is_deeply(\%pages, {});
  61. is_deeply(\@del, []);
  62. # generating an autofile that we just deleted does nothing
  63. %pages = ();
  64. @del = ('tags/primes.mdwn');
  65. IkiWiki::gen_autofile("tags/primes.mdwn", \%pages, \@del);
  66. is_deeply(\%pages, {});
  67. is_deeply(\@del, ['tags/primes.mdwn']);
  68. # cleanup
  69. ok(! system("rm -rf t/tmp"));
  70. 1;