Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sajjon committed Dec 9, 2023
1 parent 0dcad07 commit 5d9328c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/identified_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,37 @@ mod tests {
assert_eq!(identified_vec.update_at(2, 1), 2)
}

#[test]
#[should_panic(expected = "Expected element at index {index}")]
fn update_at_expect_panic_unknown_index() {
let mut identified_vec = SUT::from_iter([1, 2, 3]);
identified_vec.update_at(0, 999);
}

#[test]
#[should_panic(expected = "The replacement item must match the identity of the original")]
fn update_at_expect_panic_other_id() {
struct User {
id: &'static str,
name: &'static str,
}
impl Identifiable for User {
type ID = &'static str;
fn id(&self) -> Self::ID {
self.id
}
}
impl User {
fn new(id: &'static str, name: &'static str) -> Self {
Self { id, name }
}
}
let mut identified_vec = IdentifiedVecOf::<User>::new();
identified_vec.append(User::new("u_42", "Zelda"));
assert_eq!(identified_vec.get_at_index(0).unwrap().name, "Zelda");
identified_vec.update_at(User::new("u_999999", "Zelda"), 0);
}

#[test]
fn update_or_append() {
let mut identified_vec = SUT::from_iter([1, 2, 3]);
Expand Down Expand Up @@ -1253,6 +1284,13 @@ mod tests {
assert_eq!(identified_vec.elements(), [&2])
}

#[test]
#[should_panic(expected = "Precondition failure, index out of bounds")]
fn remove_at_out_of_bounds() {
let mut identified_vec = SUT::from_iter([1, 2, 3]);
identified_vec.remove_at(999);
}

#[test]
fn serde() {
let identified_vec = SUT::from_iter([1, 2, 3]);
Expand Down

0 comments on commit 5d9328c

Please sign in to comment.