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
65
use crate::prelude::*;
use bevy::prelude::*;
use std::fmt::Debug;
#[extend::ext(name=MatcherResult)]
pub impl<T: Debug, E: Debug> Result<T, E> {
/// Performs an assertion ensuring this value is an `Ok(_)`.
///
/// ## Example
///
/// ```
/// # use beet_core::prelude::*;
/// Ok::<(), ()>(()).xpect_ok();
/// ```
///
/// ## Panics
///
/// Panics if the value is not `Ok(_)`.
#[track_caller]
fn xpect_ok(&self) -> &Self {
match self {
Ok(_) => self,
Err(_) => {
panic_ext::panic_expected_received_display_debug("Ok", self);
}
}
}
/// Performs an assertion ensuring this value is an `Err(_)`.
///
/// ## Example
///
/// ```
/// # use beet_core::prelude::*;
/// Err::<(), ()>(()).xpect_err();
/// ```
///
/// ## Panics
///
/// Panics if the value is not `Err(_)`.
#[track_caller]
fn xpect_err(&self) -> &Self {
match self {
Err(_) => self,
Ok(_) => {
panic_ext::panic_expected_received_display_debug("Err", self);
}
}
}
}
#[cfg(test)]
mod test {
use crate::prelude::*;
use bevy::prelude::*;
#[test]
fn result() {
let ok = || -> Result { Ok(()) };
ok().xpect_ok();
let err = || -> Result { Err("foo".into()) };
err().xpect_err();
}
}