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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//! Assertion library for rust.
//!
//! In a function annotated wit assterer, you can use some macros.
//!
//! # `unwrap!(foo as Pat)`
//!
//! ```rust
//! use asserter::*;
//!
//! #[asserter]
//! fn main () {
//!     let foo = Some("example");
//!
//!     // If there's no issue with rustfmt, use `as` like the code below.
//!     unwrap!(foo as Some(s));
//!     assert_eq!(s, "example");
//! }
//! ```
//!
//! Sometimes, rustfmt does not work for the default syntax. There's an
//! alternative syntax to help rustfmt.
//!
//! ```rust
//! use asserter::*;
//! enum Complex {
//!     Struct { foo: usize, bar: usize },
//! }
//!
//! #[asserter]
//! fn main () {
//!     let foo = Complex::Struct { foo: 1, bar: 2 };
//!
//!     // This syntax allows formatting
//!     unwrap!(foo, Complex::Struct { foo, bar });
//! }
//! ```
//!
//! Note that you **can** use box_patterns inside `unwrap!()` (on stable).
//!
//! ```rust
//! use asserter::*;
//!
//! enum Complex {
//!     Normal(usize),
//!     Boxed(Box<Complex>),
//! }
//!
//! #[asserter]
//! fn main () {
//!     let foo = Complex::Boxed(Box::new(Complex::Normal(0)));
//!
//!     unwrap!(foo as Complex::Boxed(box Complex::Normal(v)));
//!     assert_eq!(v, 0);
//! }
//! ```
//!
//!
//! ## unbox!(Pat)
//!
//! If you want rustfmt to work correctly while unwrapping box, there's a helper
//! for it.
//! ```rust
//! use asserter::*;
//!
//! enum Complex {
//!     Normal(usize),
//!     Boxed(Box<Complex>),
//! }
//!
//! #[asserter]
//! fn main () {
//!     let foo = Complex::Boxed(Box::new(Complex::Normal(0)));
//!
//!     unwrap!(foo as Complex::Boxed(unbox!(Complex::Normal(v))));
//!     assert_eq!(v, 0);
//! }
//! ```
//!  

pub use asserter_macros::asserter;