added tests of SuccessReason/FailReason objects
[ikiwiki] / t / pagespec_match_result.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Test::More tests => 67;
5
6 BEGIN { use_ok("IkiWiki"); }
7
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") }
13
14 ok(S() eq "match");
15 ok(F() eq "no match");
16 ok(E() eq "error in matching");
17
18 ok(S());
19 ok(! F());
20 ok(! E());
21
22 ok(!(! S()));
23 ok(!(!(! F)));
24 ok(!(!(! E)));
25
26 ok(S() | F());
27 ok(F() | S());
28 ok(!(F() | E()));
29 ok(!(!S() | F() | E()));
30
31 ok(S() & S() & S());
32 ok(!(S() & E()));
33 ok(!(S() & F()));
34 ok(!(S() & F() & E()));
35 ok(S() & (F() | F() | S()));
36
37 # influences are always merged, no matter the operation performed,
38 # as long as the two items are always both present
39 foreach my $op ('$s | $f', '$s & $f', '$s & $f & E()', '$s | E() | $f',
40                 '! $s | ! $f', '!(!(!$s)) | $f') {
41         my $s=S();
42         $s->influences(foo => 1, bar => 1);
43         is($s->influences->{foo}, 1);
44         is($s->influences->{bar}, 1);
45         my $f=F();
46         $f->influences(bar => 2, baz => 1);
47         is($f->influences->{bar}, 2);
48         is($f->influences->{baz}, 1);
49         my $c = eval $op;
50         ok(ref $c);
51         is($c->influences->{foo}, 1, "foo ($op)");
52         is($c->influences->{bar}, (1 | 2), "bar ($op)");
53         is($c->influences->{baz}, 1, "baz ($op)");
54 }