From 572d16551114d8e83379530417ddda21625c6c6c Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sun, 8 Feb 2026 00:26:46 +0100 Subject: [PATCH 1/2] Assert that the domain contains the content range --- .../src/suite/scopes.vscode.test.ts | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts b/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts index 6467409598..270fc9fcc4 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts @@ -2,6 +2,8 @@ import type { ScopeSupportFacet, ScopeType, PlaintextScopeSupportFacet, + ScopeRangeConfig, + Range, } from "@cursorless/common"; import { asyncSafety, @@ -132,9 +134,10 @@ async function runTest(file: string, languageId: string, facetId: string) { await openNewEditor(code, { languageId }); const editor = ide.activeTextEditor!; + const updateFixture = shouldUpdateFixtures(); const [outputFixture, numScopes] = ((): [string, number] => { - const config = { + const config: ScopeRangeConfig = { visibleOnly: false, scopeType, }; @@ -147,6 +150,16 @@ async function runTest(file: string, languageId: string, facetId: string) { includeNestedTargets: false, }, ); + + if (!updateFixture) { + assert.isFalse( + iterationScopes.some((s) => + s.ranges.some((r) => isContained(s.domain, r.range)), + ), + "Iteration range should not contain the domain", + ); + } + return [ serializeIterationScopeFixture(code, iterationScopes), iterationScopes.length, @@ -155,10 +168,25 @@ async function runTest(file: string, languageId: string, facetId: string) { const scopes = scopeProvider.provideScopeRanges(editor, config); + if (!updateFixture) { + assert.isFalse( + scopes.some((s) => + s.targets.some((t) => isContained(s.domain, t.contentRange)), + ), + "Content range should not contain the domain", + ); + assert.isFalse( + scopes.some((s) => + s.targets.some((t) => isContained(t.removalRange, t.contentRange)), + ), + "Content range should not contain the removal range", + ); + } + return [serializeScopeFixture(facetId, code, scopes), scopes.length]; })(); - if (shouldUpdateFixtures()) { + if (updateFixture) { await fsp.writeFile(file, outputFixture); } else { assert.isAbove(numScopes, 0, "No scopes found"); @@ -191,3 +219,7 @@ function getFacetInfo( isIteration: isIteration ?? false, }; } + +function isContained(domain: Range, range: Range): boolean { + return range.contains(domain) && !range.isRangeEqual(domain); +} From 9344b56f09682855cee4e1458b4fcf1097585748 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Sun, 8 Feb 2026 00:38:03 +0100 Subject: [PATCH 2/2] Cleanup --- .../src/suite/scopes.vscode.test.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts b/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts index 270fc9fcc4..053b0c2c0a 100644 --- a/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts +++ b/packages/cursorless-vscode-e2e/src/suite/scopes.vscode.test.ts @@ -3,7 +3,6 @@ import type { ScopeType, PlaintextScopeSupportFacet, ScopeRangeConfig, - Range, } from "@cursorless/common"; import { asyncSafety, @@ -154,7 +153,7 @@ async function runTest(file: string, languageId: string, facetId: string) { if (!updateFixture) { assert.isFalse( iterationScopes.some((s) => - s.ranges.some((r) => isContained(s.domain, r.range)), + s.ranges.some((r) => !s.domain.contains(r.range)), ), "Iteration range should not contain the domain", ); @@ -171,13 +170,13 @@ async function runTest(file: string, languageId: string, facetId: string) { if (!updateFixture) { assert.isFalse( scopes.some((s) => - s.targets.some((t) => isContained(s.domain, t.contentRange)), + s.targets.some((t) => !s.domain.contains(t.contentRange)), ), "Content range should not contain the domain", ); assert.isFalse( scopes.some((s) => - s.targets.some((t) => isContained(t.removalRange, t.contentRange)), + s.targets.some((t) => !s.domain.contains(t.contentRange)), ), "Content range should not contain the removal range", ); @@ -219,7 +218,3 @@ function getFacetInfo( isIteration: isIteration ?? false, }; } - -function isContained(domain: Range, range: Range): boolean { - return range.contains(domain) && !range.isRangeEqual(domain); -}