From df1be14aa81672a8db83bae147a58c47228bbe94 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 15 Jan 2024 11:26:35 +0900 Subject: [PATCH] tests: split op id resolution tests, don't require merged op for prefix tests This makes it easy to set up crafted environment for prefix resolution tests. --- lib/tests/test_operations.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/tests/test_operations.rs b/lib/tests/test_operations.rs index 7fb282c7e..1d19e37b9 100644 --- a/lib/tests/test_operations.rs +++ b/lib/tests/test_operations.rs @@ -453,43 +453,50 @@ fn test_resolve_op_id() { ] "###); + let repo_loader = repo.loader(); + let resolve = |op_str: &str| op_walk::resolve_op_for_load(&repo_loader, op_str); + // Full id - assert_eq!( - op_walk::resolve_op_with_repo(&repo, &operations[0].id().hex()).unwrap(), - operations[0] - ); + assert_eq!(resolve(&operations[0].id().hex()).unwrap(), operations[0]); // Short id, odd length assert_eq!( - op_walk::resolve_op_with_repo(&repo, &operations[0].id().hex()[..3]).unwrap(), + resolve(&operations[0].id().hex()[..3]).unwrap(), operations[0] ); // Short id, even length assert_eq!( - op_walk::resolve_op_with_repo(&repo, &operations[1].id().hex()[..2]).unwrap(), + resolve(&operations[1].id().hex()[..2]).unwrap(), operations[1] ); // Ambiguous id assert_matches!( - op_walk::resolve_op_with_repo(&repo, "1"), + resolve("1"), Err(OpsetEvaluationError::OpsetResolution( OpsetResolutionError::AmbiguousIdPrefix(_) )) ); // Empty id assert_matches!( - op_walk::resolve_op_with_repo(&repo, ""), + resolve(""), Err(OpsetEvaluationError::OpsetResolution( OpsetResolutionError::InvalidIdPrefix(_) )) ); // Unknown id assert_matches!( - op_walk::resolve_op_with_repo(&repo, "deadbee"), + resolve("deadbee"), Err(OpsetEvaluationError::OpsetResolution( OpsetResolutionError::NoSuchOperation(_) )) ); - // Current op +} + +#[test] +fn test_resolve_current_op() { + let settings = stable_op_id_settings(); + let test_repo = TestRepo::init_with_settings(&settings); + let repo = test_repo.repo; + assert_eq!( op_walk::resolve_op_with_repo(&repo, "@").unwrap(), *repo.operation()