Got PassFail matcher tested
[kakapo:kakapo.git] / src / Matchers / PassFail.nqp
1 # Copyright (C) 2010, Austin Hastings. See accompanying LICENSE file, or 
2 # http://www.opensource.org/licenses/artistic-license-2.0.php for license.
3
4 # Evaluates match in boolean context
5 module Matcher::PassFail;
6
7 has $!returning;
8
9 INIT {
10         Kakapo::depends_on(|<
11                 Matcher 
12                 Matcher::Factory
13         >);
14 }
15
16 sub _initload() {
17         extends(        'Matcher' );
18         has(            <$!returning> );
19         auto_accessors( :private );
20         
21         Matcher::Factory::export_sub(Matcher::PassFail::factory_fail, :as('fail'));
22         Matcher::Factory::export_sub(Matcher::PassFail::factory_pass, :as('pass'));
23 }
24
25 method describe_self($previous? = '') {
26         $previous ~ ($!returning
27                 ?? 'a "pass," always'
28                 !! 'a "fail," always');
29 }
30
31 sub factory_fail()              { Matcher::PassFail.new(:fail); }
32 sub factory_pass()              { Matcher::PassFail.new(:pass); }
33 method matches($item)   { $!returning; }
34
35 method pass($ignore)    { $!returning := 1; }
36 method fail($ignore)            { $!returning := 0; }