]> git.proxmox.com Git - rustc.git/blob - vendor/pretty_assertions/tests/assert_ne.rs
New upstream version 1.59.0+dfsg1
[rustc.git] / vendor / pretty_assertions / tests / assert_ne.rs
1 #[allow(unused_imports)]
2 use pretty_assertions::{assert_eq, assert_ne};
3 #[test]
4 #[should_panic(expected = r#"assertion failed: `(left != right)`
5
6 \e[1mBoth sides\e[0m:
7 Some(
8 Foo {
9 lorem: "Hello World!",
10 ipsum: 42,
11 dolor: Ok(
12 "hey"
13 )
14 }
15 )
16
17 "#)]
18 fn assert_ne() {
19 #[derive(Debug, PartialEq)]
20 struct Foo {
21 lorem: &'static str,
22 ipsum: u32,
23 dolor: Result<String, String>,
24 }
25
26 let x = Some(Foo {
27 lorem: "Hello World!",
28 ipsum: 42,
29 dolor: Ok("hey".to_string()),
30 });
31
32 assert_ne!(x, x);
33 }
34
35 #[test]
36 #[should_panic(
37 expected = r#"assertion failed: `(left != right)`: custom panic message
38
39 \e[1mBoth sides\e[0m:
40 Some(
41 Foo {
42 lorem: "Hello World!",
43 ipsum: 42,
44 dolor: Ok(
45 "hey"
46 )
47 }
48 )
49
50 "#
51 )]
52 fn assert_ne_custom() {
53 #[derive(Debug, PartialEq)]
54 struct Foo {
55 lorem: &'static str,
56 ipsum: u32,
57 dolor: Result<String, String>,
58 }
59
60 let x = Some(Foo {
61 lorem: "Hello World!",
62 ipsum: 42,
63 dolor: Ok("hey".to_string()),
64 });
65
66 assert_ne!(x, x, "custom panic message");
67 }
68
69 #[test]
70 #[should_panic]
71 fn assert_ne_non_empty_return() {
72 fn not_zero(x: u32) -> u32 {
73 assert_ne!(x, 0);
74 x
75 };
76 not_zero(0);
77 }
78
79 #[test]
80 #[should_panic(expected = r#"assertion failed: `(left != right)`
81
82 \e[1mDiff\e[0m \e[31m< left\e[0m / \e[32mright >\e[0m :
83 \e[31m<\e[0m\e[1;48;5;52;31m-\e[0m\e[31m0.0\e[0m
84 \e[32m>\e[0m\e[32m0.0\e[0m
85
86 \e[1;4mNote\e[0m: According to the `PartialEq` implementation, both of the values are partially equivalent, even if the `Debug` outputs differ.
87
88 "#)]
89 fn assert_ne_partial() {
90 // Workaround for https://github.com/rust-lang/rust/issues/47619
91 // can be removed, when we require rust 1.25 or higher
92 struct Foo(f32);
93
94 use ::std::fmt;
95 impl fmt::Debug for Foo {
96 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
97 write!(f, "{:.1?}", self.0)
98 }
99 }
100
101 impl PartialEq for Foo {
102 fn eq(&self, other: &Self) -> bool {
103 self.0 == other.0
104 }
105 }
106
107 assert_ne!(Foo(-0.0), Foo(0.0));
108 }
109
110 #[test]
111 #[should_panic(expected = r#"assertion failed: `(left != right)`
112
113 \e[1mBoth sides\e[0m:
114 Some(
115 Foo {
116 lorem: "Hello World!",
117 ipsum: 42,
118 dolor: Ok(
119 "hey"
120 )
121 }
122 )
123
124 "#)]
125 fn assert_ne_trailing_comma() {
126 #[derive(Debug, PartialEq)]
127 struct Foo {
128 lorem: &'static str,
129 ipsum: u32,
130 dolor: Result<String, String>,
131 }
132
133 let x = Some(Foo {
134 lorem: "Hello World!",
135 ipsum: 42,
136 dolor: Ok("hey".to_string()),
137 });
138
139 assert_ne!(x, x,);
140 }
141
142 #[test]
143 #[should_panic(
144 expected = r#"assertion failed: `(left != right)`: custom panic message
145
146 \e[1mBoth sides\e[0m:
147 Some(
148 Foo {
149 lorem: "Hello World!",
150 ipsum: 42,
151 dolor: Ok(
152 "hey"
153 )
154 }
155 )
156
157 "#
158 )]
159 fn assert_ne_custom_trailing_comma() {
160 #[derive(Debug, PartialEq)]
161 struct Foo {
162 lorem: &'static str,
163 ipsum: u32,
164 dolor: Result<String, String>,
165 }
166
167 let x = Some(Foo {
168 lorem: "Hello World!",
169 ipsum: 42,
170 dolor: Ok("hey".to_string()),
171 });
172
173 assert_ne!(x, x, "custom panic message",);
174 }