1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#![macro_use] use matchers::matcher::Matcher;

pub struct Expect<T> {
    value: T,
    negated: bool
}

impl<T: Clone> Expect<T> {
    pub fn to(&self, other: Box<Matcher<T>>) {
        let mut cond = !other.assert_check(self.value.clone());

        if self.negated {
            cond = !cond;
        }

        if cond {
            self.fail(other)
        }
    }

    pub fn not_to(&mut self, other: Box<Matcher<T>>) {
        self.negated = true;
        self.to(other);
    }

    fn fail(&self, other: Box<Matcher<T>>) {
        let mut msg;

        if self.negated {
            msg = other.negated_msg(self.value.clone());
        } else {
            msg = other.msg(self.value.clone());
        }

        ::std::rt::begin_unwind(msg, &other.get_file_line());
    }
}

pub fn expect<T: Clone>(value: &T) -> Expect<T> {
    Expect { value: value.clone(), negated: false }
}