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", @_) }
15 ok
(F
() eq "no match");
16 ok
(E
() eq "error in matching");
29 ok
(!(!S
() | F
() | E
()));
34 ok
(!(S
() & F
() & E
()));
35 ok
(S
() & (F
() | F
() | S
()));
37 # influence merging tests
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
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);
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)");
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);