diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2023-08-27 10:16:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-27 11:16:09 +0200 |
commit | e1fe31508c471eeb7c30916abd780b3930f7e42b (patch) | |
tree | 63b34ea1ef4c5ceb75cbf80e64befe5883260e7a /cli/lsp/testing/definitions.rs | |
parent | 2080669943e79aba619bc80829172c696ec1f15c (diff) |
fix(lsp/testing): use full ancestry to compute static id of step (#20297)
Fixes https://github.com/denoland/vscode_deno/issues/656.
Test steps were ID'd by a checksum of `[origin, level, step_name]` which
is incorrect. Now it's `[origin, ...ancestor_names, step_name]`.
Diffstat (limited to 'cli/lsp/testing/definitions.rs')
-rw-r--r-- | cli/lsp/testing/definitions.rs | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/cli/lsp/testing/definitions.rs b/cli/lsp/testing/definitions.rs index 1022fc43a..6992c995d 100644 --- a/cli/lsp/testing/definitions.rs +++ b/cli/lsp/testing/definitions.rs @@ -15,7 +15,6 @@ use tower_lsp::lsp_types as lsp; #[derive(Debug, Clone, PartialEq)] pub struct TestDefinition { pub id: String, - pub level: usize, pub name: String, pub range: SourceRange, pub steps: Vec<TestDefinition>, @@ -26,33 +25,41 @@ impl TestDefinition { specifier: &ModuleSpecifier, name: String, range: SourceRange, - steps: Vec<TestDefinition>, + mut steps: Vec<TestDefinition>, ) -> Self { - let id = checksum::gen(&[specifier.as_str().as_bytes(), name.as_bytes()]); + let mut id_components = Vec::with_capacity(7); + id_components.push(specifier.as_str().as_bytes()); + id_components.push(name.as_bytes()); + let id = checksum::gen(&id_components); + Self::fix_ids(&mut steps, &mut id_components); Self { id, - level: 0, name, range, steps, } } + fn fix_ids<'a>( + steps: &'a mut Vec<TestDefinition>, + id_components: &mut Vec<&'a [u8]>, + ) { + for step in steps { + id_components.push(step.name.as_bytes()); + step.id = checksum::gen(id_components); + Self::fix_ids(&mut step.steps, id_components); + id_components.pop(); + } + } + pub fn new_step( name: String, range: SourceRange, - parent: String, - level: usize, steps: Vec<TestDefinition>, ) -> Self { - let id = checksum::gen(&[ - parent.as_bytes(), - &level.to_be_bytes(), - name.as_bytes(), - ]); Self { - id, - level, + // ID will be fixed later when the entire ancestry is available. + id: "".to_string(), name, range, steps, |