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