From f30857190e309f7fc6570fe985cd174686921b76 Mon Sep 17 00:00:00 2001 From: Evan Mesterhazy Date: Mon, 4 Mar 2024 22:47:46 -0500 Subject: [PATCH] Add more test cases for Index::common_ancestors --- lib/src/default_index/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/src/default_index/mod.rs b/lib/src/default_index/mod.rs index 6e52d99d1..a4af4cba7 100644 --- a/lib/src/default_index/mod.rs +++ b/lib/src/default_index/mod.rs @@ -1015,12 +1015,14 @@ mod tests { let id_3 = CommitId::from_hex("333333"); let id_4 = CommitId::from_hex("444444"); let id_5 = CommitId::from_hex("555555"); + let id_6 = CommitId::from_hex("666666"); index.add_commit_data(id_0.clone(), new_change_id(), &[]); index.add_commit_data(id_1.clone(), new_change_id(), &[id_0.clone()]); index.add_commit_data(id_2.clone(), new_change_id(), &[id_0.clone()]); index.add_commit_data(id_3.clone(), new_change_id(), &[id_0.clone()]); index.add_commit_data(id_4.clone(), new_change_id(), &[id_1.clone()]); index.add_commit_data(id_5.clone(), new_change_id(), &[id_4.clone(), id_2.clone()]); + index.add_commit_data(id_6.clone(), new_change_id(), &[id_4.clone()]); assert_eq!( index.common_ancestors(&[id_0.clone()], &[id_0.clone()]), @@ -1054,6 +1056,10 @@ mod tests { index.common_ancestors(&[id_5.clone()], &[id_3.clone()]), vec![id_0.clone()] ); + assert_eq!( + index.common_ancestors(&[id_2.clone()], &[id_6.clone()]), + vec![id_0.clone()] + ); // With multiple commits in an input set assert_eq!( @@ -1072,6 +1078,12 @@ mod tests { index.common_ancestors(&[id_1.clone(), id_2.clone()], &[id_4]), vec![id_1.clone()] ); + assert_eq!( + index.common_ancestors(&[id_5.clone(), id_6.clone()], &[id_2.clone()]), + &[id_2.clone()] + ); + // Both 1 and 2 are returned since (5) expands to (2, 4), which expands + // to (1,2) and matches the (1,2) of the first input set. assert_eq!( index.common_ancestors(&[id_1.clone(), id_2.clone()], &[id_5]), vec![id_1.clone(), id_2.clone()]