Skip to content

Commit

Permalink
tests: update ChangeIdIndex test to include ancestors in set
Browse files Browse the repository at this point in the history
I plan to replace `Revset::change_id_index()` by
`Index::change_id_index(heads)`, but one of the tests currently uses a
set of commits that does not include ancestors. This patch updates it
to include ancestors (and changes the set of heads to keep the set
small enough for the test).
  • Loading branch information
martinvonz committed Jan 7, 2024
1 parent 5572102 commit 312d85b
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions lib/tests/test_revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2805,30 +2805,26 @@ fn test_change_id_index() {
.write()
.unwrap()
};
let commit_1 = commit_with_change_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
let commit_1 = commit_with_change_id("abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
let commit_2 = commit_with_change_id("aaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
let commit_3 = commit_with_change_id("abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
let commit_3 = commit_with_change_id("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
let commit_4 = commit_with_change_id("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
let commit_5 = commit_with_change_id("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");

let revset = revset_for_commits(
tx.repo(),
&[
&root_commit,
&commit_1,
&commit_2,
&commit_3,
&commit_4,
&commit_5,
],
);
let change_id_index = revset.change_id_index();
let index_for_heads = |commits: &[&Commit]| {
RevsetExpression::commits(commits.iter().map(|commit| commit.id().clone()).collect())
.ancestors()
.evaluate_programmatic(tx.repo())
.unwrap()
.change_id_index()
};
let change_id_index = index_for_heads(&[&commit_1, &commit_2, &commit_3, &commit_4, &commit_5]);
let prefix_len =
|commit: &Commit| change_id_index.shortest_unique_prefix_len(commit.change_id());
assert_eq!(prefix_len(&root_commit), 1);
assert_eq!(prefix_len(&commit_1), 6);
assert_eq!(prefix_len(&commit_1), 2);
assert_eq!(prefix_len(&commit_2), 6);
assert_eq!(prefix_len(&commit_3), 2);
assert_eq!(prefix_len(&commit_3), 6);
assert_eq!(prefix_len(&commit_4), 1);
assert_eq!(prefix_len(&commit_5), 1);
let resolve_prefix =
Expand All @@ -2843,15 +2839,15 @@ fn test_change_id_index() {
);
assert_eq!(
resolve_prefix("aaaaaa"),
PrefixResolution::SingleMatch(vec![commit_1.id().clone()])
PrefixResolution::SingleMatch(vec![commit_3.id().clone()])
);
assert_eq!(
resolve_prefix("aaaaab"),
PrefixResolution::SingleMatch(vec![commit_2.id().clone()])
);
assert_eq!(
resolve_prefix("ab"),
PrefixResolution::SingleMatch(vec![commit_3.id().clone()])
PrefixResolution::SingleMatch(vec![commit_1.id().clone()])
);
assert_eq!(
resolve_prefix("b"),
Expand All @@ -2860,32 +2856,35 @@ fn test_change_id_index() {
// Longer than necessary
assert_eq!(
resolve_prefix("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
PrefixResolution::SingleMatch(vec![commit_1.id().clone()])
PrefixResolution::SingleMatch(vec![commit_3.id().clone()])
);
// No match
assert_eq!(resolve_prefix("ba"), PrefixResolution::NoMatch);

// Test with a revset containing only some of the commits. We should get shorter
// prefixes and be able to resolve shorter prefixes.
let revset = revset_for_commits(tx.repo(), &[&commit_2, &commit_3]);
let change_id_index = revset.change_id_index();
let change_id_index = index_for_heads(&[&commit_1, &commit_2]);
let prefix_len =
|commit: &Commit| change_id_index.shortest_unique_prefix_len(commit.change_id());
assert_eq!(prefix_len(&commit_1), 6);
assert_eq!(prefix_len(&commit_1), 2);
assert_eq!(prefix_len(&commit_2), 2);
assert_eq!(prefix_len(&commit_3), 2);
assert_eq!(prefix_len(&commit_3), 6);
let resolve_prefix =
|prefix: &str| change_id_index.resolve_prefix(&HexPrefix::new(prefix).unwrap());
assert_eq!(resolve_prefix("0"), PrefixResolution::NoMatch);
assert_eq!(
resolve_prefix("0"),
PrefixResolution::SingleMatch(vec![root_commit.id().clone()])
);
assert_eq!(
resolve_prefix("aa"),
PrefixResolution::SingleMatch(vec![commit_2.id().clone()])
);
assert_eq!(
resolve_prefix("ab"),
PrefixResolution::SingleMatch(vec![commit_3.id().clone()])
PrefixResolution::SingleMatch(vec![commit_1.id().clone()])
);
assert_eq!(resolve_prefix("a"), PrefixResolution::AmbiguousMatch);
assert_eq!(resolve_prefix("b"), PrefixResolution::NoMatch);
}

#[test]
Expand Down

0 comments on commit 312d85b

Please sign in to comment.