summaryrefslogtreecommitdiff
path: root/t/pagespec_match_result.t
blob: 13fcdcad01facfa842931a49ca3fcc1dd377585c (plain)
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4. use Test::More tests => 138;
  5. BEGIN { use_ok("IkiWiki"); }
  6. # Note that new objects have to be constructed freshly for each test, since
  7. # object states are mutated as they are combined.
  8. sub S { IkiWiki::SuccessReason->new("match", @_) }
  9. sub F { IkiWiki::FailReason->new("no match", @_) }
  10. sub E { IkiWiki::ErrorReason->new("error in matching", @_) }
  11. ok(S() eq "match");
  12. ok(F() eq "no match");
  13. ok(E() eq "error in matching");
  14. ok(S());
  15. ok(! F());
  16. ok(! E());
  17. ok(!(! S()));
  18. ok(!(!(! F)));
  19. ok(!(!(! E)));
  20. ok(S() | F());
  21. ok(F() | S());
  22. ok(!(F() | E()));
  23. ok(!(!S() | F() | E()));
  24. ok(S() & S() & S());
  25. ok(!(S() & E()));
  26. ok(!(S() & F()));
  27. ok(!(S() & F() & E()));
  28. ok(S() & (F() | F() | S()));
  29. # influence merging tests
  30. foreach my $test (
  31. ['$s | $f' => 1], # OR merges
  32. ['! $s | ! $f' => 1], # OR merges with negated terms too
  33. ['!(!(!$s)) | $f' => 1],# OR merges with multiple negation too
  34. ['$s | $f | E()' => 1], # OR merges, even though E() has no influences
  35. ['$s | E() | $f' => 1], # ditto
  36. ['E() | $s | $f' => 1], # ditto
  37. ['!$s | !$f | E()' => 1],# negated terms also do not block merges
  38. ['!$s | E() | $f' => 1],# ditto
  39. ['E() | $s | !$f' => 1],# ditto
  40. ['$s & $f' => 1], # AND merges if both items have influences
  41. ['!$s & $f' => 1], # AND merges negated terms too
  42. ['$s & !$f' => 1], # AND merges negated terms too
  43. ['$s & $f & E()' => 0], # AND fails to merge since E() has no influences
  44. ['$s & E() & $f' => 0], # ditto
  45. ['E() & $s & $f' => 0], # ditto
  46. ) {
  47. my $op=$test->[0];
  48. my $influence=$test->[1];
  49. my $s=S(foo => 1, bar => 1);
  50. is($s->influences->{foo}, 1);
  51. is($s->influences->{bar}, 1);
  52. my $f=F(bar => 2, baz => 1);
  53. is($f->influences->{bar}, 2);
  54. is($f->influences->{baz}, 1);
  55. my $c = eval $op;
  56. ok(ref $c);
  57. if ($influence) {
  58. is($c->influences->{foo}, 1, "foo ($op)");
  59. is($c->influences->{bar}, (1 | 2), "bar ($op)");
  60. is($c->influences->{baz}, 1, "baz ($op)");
  61. }
  62. else {
  63. ok(! %{$c->influences}, "no influence for ($op)");
  64. }
  65. }
  66. my $s=S(foo => 0, bar => 1);
  67. $s->influences(baz => 1);
  68. ok(! $s->influences->{foo}, "removed 0 influence");
  69. ok(! $s->influences->{bar}, "removed 1 influence");
  70. ok($s->influences->{baz}, "set influence");
  71. ok($s->influences_static);
  72. $s=S(foo => 0, bar => 1);
  73. $s->influences(baz => 1, "" => 1);
  74. ok(! $s->influences_static);