Skip to content

Commit 52b2070

Browse files
authored
Small wording/naming changes; some missing tests (#15)
* HashMapAssertions::is_non_empty() failure wording * test name * same for HashSet * same test rename for HashSet * missing parens * test name * closing bracket * test name * test name * same for vec * same for ref vec * separate tests for multiple should-panic's * tests for vec not empty
1 parent 52e7831 commit 52b2070

File tree

8 files changed

+56
-21
lines changed

8 files changed

+56
-21
lines changed

src/hashmap.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ where
9393

9494
if subject.is_empty() {
9595
AssertionFailure::from_spec(self)
96-
.with_expected("an non empty hashmap".to_string())
97-
.with_actual(format!("a hashmap with length <{:?}>", subject.len()))
96+
.with_expected("a non empty hashmap".to_string())
97+
.with_actual("an empty hashmap".to_string())
9898
.fail();
9999
}
100100
}
@@ -319,8 +319,8 @@ mod tests {
319319
}
320320

321321
#[test]
322-
#[should_panic(expected = "\n\texpected: an non empty hashmap\
323-
\n\t but was: a hashmap with length <0>")]
322+
#[should_panic(expected = "\n\texpected: a non empty hashmap\
323+
\n\t but was: an empty hashmap")]
324324
fn should_panic_if_hashmap_was_expected_to_not_be_empty_and_is() {
325325
let test_map: HashMap<u8, u8> = HashMap::new();
326326
assert_that(&test_map).is_not_empty();
@@ -348,7 +348,7 @@ mod tests {
348348
// Unfortunately the order of the keys can change. Doesn't seem to make sense to sort them
349349
// just for the sake of checking the panic message.
350350
#[should_panic]
351-
fn should_not_panic_if_hashmap_does_not_contain_key() {
351+
fn should_panic_if_hashmap_does_not_contain_key() {
352352
let mut test_map = HashMap::new();
353353
test_map.insert("hi", "hi");
354354
test_map.insert("hey", "hey");

src/hashset.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ where
7373

7474
if subject.is_empty() {
7575
AssertionFailure::from_spec(self)
76-
.with_expected("an non empty HashSet".to_string())
77-
.with_actual(format!("a HashSet with length <{:?}>", subject.len()))
76+
.with_expected("a non empty HashSet".to_string())
77+
.with_actual("an empty HashSet".to_string())
7878
.fail();
7979
}
8080
}
@@ -130,8 +130,8 @@ mod tests {
130130
}
131131

132132
#[test]
133-
#[should_panic(expected = "\n\texpected: an non empty HashSet\
134-
\n\t but was: a HashSet with length <0>")]
133+
#[should_panic(expected = "\n\texpected: a non empty HashSet\
134+
\n\t but was: an empty HashSet")]
135135
fn should_panic_if_hash_set_was_expected_to_be_empty_and_is_not() {
136136
let test_map: HashSet<u8> = HashSet::new();
137137
assert_that(&test_map).is_not_empty();
@@ -159,7 +159,7 @@ mod tests {
159159
// Unfortunately the order of the keys can change. Doesn't seem to make sense to sort them
160160
// just for the sake of checking the panic message.
161161
#[should_panic]
162-
fn should_not_panic_if_hash_set_does_not_contain() {
162+
fn should_panic_if_hash_set_does_not_contain() {
163163
let mut test_map = HashSet::new();
164164
test_map.insert("hi");
165165
test_map.insert("hey");

src/iter.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ where
364364
AssertionFailure::from_spec(spec)
365365
.with_expected(format!("Completed iterator (read <{:?}>)", read_expected))
366366
.with_actual(format!(
367-
"Iterator item of <{:?}> (read <{:?}>",
367+
"Iterator item of <{:?}> (read <{:?}>)",
368368
actual, read_subject
369369
))
370370
.fail();
@@ -374,10 +374,10 @@ where
374374
(None, Some(expected)) => {
375375
AssertionFailure::from_spec(spec)
376376
.with_expected(format!(
377-
"Iterator item of <{:?}> (read <{:?}>",
377+
"Iterator item of <{:?}> (read <{:?}>)",
378378
expected, read_expected
379379
))
380-
.with_actual(format!("Completed iterator (read <{:?}>", read_subject))
380+
.with_actual(format!("Completed iterator (read <{:?}>)", read_subject))
381381
.fail();
382382

383383
unreachable!();

src/numeric.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ mod tests {
176176
}
177177

178178
#[test]
179-
fn should_not_panic_if_value_is_less_than_or_equal_to_than_expected() {
179+
fn should_not_panic_if_value_is_less_than_or_equal_to_expected() {
180180
assert_that(&2).is_less_than_or_equal_to(&2);
181181
assert_that(&2).is_less_than_or_equal_to(&3);
182182
}

src/option.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ mod tests {
169169
}
170170

171171
#[test]
172-
#[should_panic(expected = "\n\texpected: option[none]\n\t but was: option<\"Hello\"")]
172+
#[should_panic(expected = "\n\texpected: option[none]\n\t but was: option<\"Hello\">")]
173173
fn should_panic_if_option_is_not_empty_but_was_expected_as_empty() {
174174
let option = Some("Hello");
175175
assert_that(&option).is_none();

src/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ mod tests {
219219
}
220220

221221
#[test]
222-
fn should_not_panic_if_result_is_ok_with_uncomparable_ok() {
222+
fn should_not_panic_if_result_is_ok_with_uncomparable_err() {
223223
#[derive(Debug)]
224224
struct Incomparable;
225225
let result: Result<&str, Incomparable> = Ok("Hello");

src/string.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ mod tests {
207207
}
208208

209209
#[test]
210-
fn should_not_panic_if_str_does_not_contains_value() {
210+
fn should_not_panic_if_str_does_not_contain_value() {
211211
let value = "Hello";
212212
assert_that(&value).does_not_contain("x");
213213
}

src/vec.rs

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl<T> VecAssertions for Spec<'_, Vec<T>> {
5757

5858
if subject.is_empty() {
5959
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())
6262
.fail();
6363
}
6464
}
@@ -113,8 +113,8 @@ impl<'s, T> VecAssertions for Spec<'s, &'s Vec<T>> {
113113

114114
if subject.is_empty() {
115115
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())
118118
.fail();
119119
}
120120
}
@@ -137,6 +137,12 @@ mod tests {
137137
fn should_panic_if_vec_length_does_not_match_expected() {
138138
let test_vec = vec![1, 2, 3];
139139
assert_that(&test_vec).has_length(1);
140+
}
141+
142+
#[test]
143+
#[should_panic(expected = "\n\texpected: 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];
140146
assert_that(&&test_vec).has_length(1);
141147
}
142148

@@ -152,6 +158,35 @@ mod tests {
152158
\n\t but was: a vec with length <1>")]
153159
fn should_panic_if_vec_was_expected_to_be_empty_and_is_not() {
154160
assert_that(&vec![1]).is_empty();
161+
}
162+
163+
#[test]
164+
#[should_panic(expected = "\n\texpected: 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() {
155167
assert_that(&&vec![1]).is_empty();
156168
}
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\texpected: 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\texpected: 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+
}
157192
}

0 commit comments

Comments
 (0)