@@ -57,8 +57,8 @@ impl<T> VecAssertions for Spec<'_, Vec<T>> {
57
57
58
58
if subject. is_empty ( ) {
59
59
AssertionFailure :: from_spec ( self )
60
- . with_expected ( "an non empty vec" . to_string ( ) )
61
- . with_actual ( format ! ( "a vec with length {}" , subject . len ( ) ) )
60
+ . with_expected ( "a non empty vec" . to_string ( ) )
61
+ . with_actual ( "an empty vec" . to_string ( ) )
62
62
. fail ( ) ;
63
63
}
64
64
}
@@ -113,8 +113,8 @@ impl<'s, T> VecAssertions for Spec<'s, &'s Vec<T>> {
113
113
114
114
if subject. is_empty ( ) {
115
115
AssertionFailure :: from_spec ( self )
116
- . with_expected ( "an non empty vec" . to_string ( ) )
117
- . with_actual ( format ! ( "a vec with length {}" , subject . len ( ) ) )
116
+ . with_expected ( "a non empty vec" . to_string ( ) )
117
+ . with_actual ( "an empty vec" . to_string ( ) )
118
118
. fail ( ) ;
119
119
}
120
120
}
@@ -137,6 +137,12 @@ mod tests {
137
137
fn should_panic_if_vec_length_does_not_match_expected ( ) {
138
138
let test_vec = vec ! [ 1 , 2 , 3 ] ;
139
139
assert_that ( & test_vec) . has_length ( 1 ) ;
140
+ }
141
+
142
+ #[ test]
143
+ #[ should_panic( expected = "\n \t expected: vec to have length <1>\n \t but was: <3>" ) ]
144
+ fn should_panic_if_ref_vec_length_does_not_match_expected ( ) {
145
+ let test_vec = vec ! [ 1 , 2 , 3 ] ;
140
146
assert_that ( & & test_vec) . has_length ( 1 ) ;
141
147
}
142
148
@@ -152,6 +158,35 @@ mod tests {
152
158
\n \t but was: a vec with length <1>") ]
153
159
fn should_panic_if_vec_was_expected_to_be_empty_and_is_not ( ) {
154
160
assert_that ( & vec ! [ 1 ] ) . is_empty ( ) ;
161
+ }
162
+
163
+ #[ test]
164
+ #[ should_panic( expected = "\n \t expected: an empty vec\
165
+ \n \t but was: a vec with length <1>") ]
166
+ fn should_panic_if_ref_vec_was_expected_to_be_empty_and_is_not ( ) {
155
167
assert_that ( & & vec ! [ 1 ] ) . is_empty ( ) ;
156
168
}
169
+
170
+ #[ test]
171
+ fn should_not_panic_if_vec_was_expected_to_be_not_empty_and_is ( ) {
172
+ let test_vec: Vec < u8 > = vec ! [ 1 ] ;
173
+ assert_that ( & test_vec) . is_not_empty ( ) ;
174
+ assert_that ( & & test_vec) . is_not_empty ( ) ;
175
+ }
176
+
177
+ #[ test]
178
+ #[ should_panic( expected = "\n \t expected: a non empty vec\
179
+ \n \t but was: an empty vec") ]
180
+ fn should_panic_if_vec_was_expected_to_be_not_empty_and_is_not ( ) {
181
+ let test_vec: Vec < u8 > = vec ! [ ] ;
182
+ assert_that ( & test_vec) . is_not_empty ( ) ;
183
+ }
184
+
185
+ #[ test]
186
+ #[ should_panic( expected = "\n \t expected: a non empty vec\
187
+ \n \t but was: an empty vec") ]
188
+ fn should_panic_if_ref_vec_was_expected_to_be_not_empty_and_is_not ( ) {
189
+ let test_vec: Vec < u8 > = vec ! [ ] ;
190
+ assert_that ( & & test_vec) . is_not_empty ( ) ;
191
+ }
157
192
}
0 commit comments