Skip to content

Commit 0dbfb69

Browse files
authored
Merge pull request #4 from Sajjon/code_cov_increase
more tests
2 parents 0dcad07 + 5d9328c commit 0dbfb69

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/identified_vec.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,37 @@ mod tests {
12251225
assert_eq!(identified_vec.update_at(2, 1), 2)
12261226
}
12271227

1228+
#[test]
1229+
#[should_panic(expected = "Expected element at index {index}")]
1230+
fn update_at_expect_panic_unknown_index() {
1231+
let mut identified_vec = SUT::from_iter([1, 2, 3]);
1232+
identified_vec.update_at(0, 999);
1233+
}
1234+
1235+
#[test]
1236+
#[should_panic(expected = "The replacement item must match the identity of the original")]
1237+
fn update_at_expect_panic_other_id() {
1238+
struct User {
1239+
id: &'static str,
1240+
name: &'static str,
1241+
}
1242+
impl Identifiable for User {
1243+
type ID = &'static str;
1244+
fn id(&self) -> Self::ID {
1245+
self.id
1246+
}
1247+
}
1248+
impl User {
1249+
fn new(id: &'static str, name: &'static str) -> Self {
1250+
Self { id, name }
1251+
}
1252+
}
1253+
let mut identified_vec = IdentifiedVecOf::<User>::new();
1254+
identified_vec.append(User::new("u_42", "Zelda"));
1255+
assert_eq!(identified_vec.get_at_index(0).unwrap().name, "Zelda");
1256+
identified_vec.update_at(User::new("u_999999", "Zelda"), 0);
1257+
}
1258+
12281259
#[test]
12291260
fn update_or_append() {
12301261
let mut identified_vec = SUT::from_iter([1, 2, 3]);
@@ -1253,6 +1284,13 @@ mod tests {
12531284
assert_eq!(identified_vec.elements(), [&2])
12541285
}
12551286

1287+
#[test]
1288+
#[should_panic(expected = "Precondition failure, index out of bounds")]
1289+
fn remove_at_out_of_bounds() {
1290+
let mut identified_vec = SUT::from_iter([1, 2, 3]);
1291+
identified_vec.remove_at(999);
1292+
}
1293+
12561294
#[test]
12571295
fn serde() {
12581296
let identified_vec = SUT::from_iter([1, 2, 3]);

0 commit comments

Comments
 (0)