]> git.lizzy.rs Git - rust.git/blob - library/core/tests/asserting.rs
Auto merge of #105125 - matthiaskrgr:rollup-fr0snmj, r=matthiaskrgr
[rust.git] / library / core / tests / asserting.rs
1 use core::asserting::{Capture, TryCaptureGeneric, TryCapturePrintable, Wrapper};
2
3 macro_rules! test {
4     ($test_name:ident, $elem:expr, $captured_elem:expr, $output:literal) => {
5         #[test]
6         fn $test_name() {
7             let elem = $elem;
8             let mut capture = Capture::new();
9             assert!(capture.elem == None);
10             (&Wrapper(&elem)).try_capture(&mut capture);
11             assert!(capture.elem == $captured_elem);
12             assert_eq!(format!("{:?}", capture), $output);
13         }
14     };
15 }
16
17 #[derive(Debug, PartialEq)]
18 struct NoCopy;
19
20 #[derive(PartialEq)]
21 struct NoCopyNoDebug;
22
23 #[derive(Clone, Copy, PartialEq)]
24 struct NoDebug;
25
26 test!(
27     capture_with_non_copyable_and_non_debugabble_elem_has_correct_params,
28     NoCopyNoDebug,
29     None,
30     "N/A"
31 );
32
33 test!(capture_with_non_copyable_elem_has_correct_params, NoCopy, None, "N/A");
34
35 test!(capture_with_non_debugabble_elem_has_correct_params, NoDebug, None, "N/A");
36
37 test!(capture_with_copyable_and_debugabble_elem_has_correct_params, 1i32, Some(1i32), "1");