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
54
55
56
57
58
59
60
61
62
63
64
use fmt;
use crateMatcher;
use crate;
use MismatchFormat;
/// Succeeds when the given pattern matches.
///
/// This matcher is used with the [`pattern!`] macro.
///
/// [`pattern!`]: crate::pattern
///
/// # Examples
///
/// Pattern matching lets you do things you can't do with other matchers, like test for a specific
/// enum variant when the enum doesn't implement `Eq`.
///
/// ```
/// use xpct::{expect, match_pattern, pattern};
///
/// #[derive(Debug)]
/// enum ConnectionError {
/// Disconnected,
/// Unavailable,
/// Unknown,
/// }
///
/// fn connect() -> Result<(), ConnectionError> {
/// Err(ConnectionError::Unavailable)
/// }
///
/// expect!(connect()).to(match_pattern(
/// pattern!(Err(ConnectionError::Unavailable))
/// ));
/// ```
///
/// You could also use it to test for an enum variant while ignoring its fields.
///
/// ```
/// use xpct::{expect, match_pattern, pattern};
///
/// #[derive(Debug)]
/// enum Command {
/// Create(String),
/// Update(String),
/// Delete,
/// }
///
/// let command = Command::Create("foo".into());
///
/// expect!(command).to(match_pattern(pattern!(
/// Command::Create(_) | Command::Delete
/// )));
/// ```