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
42
43
44
45
46
47
48
49
50
51
52
53
use std::fmt;

use crate::core::Matcher;
use crate::matchers::default::BeDefaultMatcher;

use super::MismatchFormat;

/// Succeeds when the actual value equals the default value for the type.
///
/// # Examples
///
/// ```
/// use xpct::{expect, be_default};
///
/// expect!("").to(be_default());
/// ```
pub fn be_default<'a, Actual>() -> Matcher<'a, Actual, Actual>
where
    Actual: fmt::Debug + Default + PartialEq<Actual> + Eq + 'a,
{
    Matcher::new(
        BeDefaultMatcher::new(),
        MismatchFormat::new("to be the default value", "to not be the default value"),
    )
}

#[cfg(test)]
mod tests {
    use super::be_default;
    use crate::expect;

    #[test]
    fn succeeds_when_default_value() {
        expect!("").to(be_default());
    }

    #[test]
    fn succeeds_when_not_default_value() {
        expect!("not default").to_not(be_default());
    }

    #[test]
    #[should_panic]
    fn fails_when_default_value() {
        expect!("").to_not(be_default());
    }

    #[test]
    #[should_panic]
    fn fails_when_not_default_value() {
        expect!("not default").to(be_default());
    }
}