From 9c050eb6586b3afd4e717b6e7d1fd704e517b5a0 Mon Sep 17 00:00:00 2001 From: Magnus Madsen Date: Thu, 8 Jan 2026 16:45:05 +0100 Subject: [PATCH 1/2] refactor: simplify find references tests --- test/src/findReferences.test.ts | 136 +++--------------- .../findReferences/src/Equatable.flix | 8 +- 2 files changed, 22 insertions(+), 122 deletions(-) diff --git a/test/src/findReferences.test.ts b/test/src/findReferences.test.ts index 86fadc95..55ef2e6d 100644 --- a/test/src/findReferences.test.ts +++ b/test/src/findReferences.test.ts @@ -17,140 +17,40 @@ import * as assert from 'assert' import * as vscode from 'vscode' -import { getTestDocUri, init, normalizeLocation } from './util' +import { findMarkerPosition, getTestDocUri, init } from './util' -suite('Find references', () => { - const mainDocUri = getTestDocUri('src/Main.flix') - const dividableDocUri = getTestDocUri('src/Dividable.flix') - const areaDocUri = getTestDocUri('src/Area.flix') +suite('FindReferencesProvider', () => { const equatableDocUri = getTestDocUri('src/Equatable.flix') - const dateDocUri = getTestDocUri('src/Date.flix') suiteSetup(async () => { await init('findReferences') }) - async function testFindReferences(uri: vscode.Uri, position: vscode.Position, expectedLocations: vscode.Location[]) { - const r = await vscode.commands.executeCommand('vscode.executeReferenceProvider', uri, position) - const actualLocations = r.map(normalizeLocation) - - assert.deepStrictEqual(new Set(actualLocations), new Set(expectedLocations)) - } - - test('Should find references to Shape.Circle enum case', async () => { - await testFindReferences(mainDocUri, new vscode.Position(3, 9), [ - new vscode.Location(mainDocUri, new vscode.Range(3, 9, 3, 15)), - new vscode.Location(areaDocUri, new vscode.Range(5, 13, 5, 25)), - ]) - }) - - test('Should find references to Shape.Circle enum case-use', async () => { - await testFindReferences(areaDocUri, new vscode.Position(5, 13), [ - new vscode.Location(mainDocUri, new vscode.Range(3, 9, 3, 15)), - new vscode.Location(areaDocUri, new vscode.Range(5, 13, 5, 25)), - ]) - }) - - test('Should find references to Dividable trait', async () => { - await testFindReferences(dividableDocUri, new vscode.Position(1, 6), [ - new vscode.Location(dividableDocUri, new vscode.Range(1, 6, 1, 15)), - new vscode.Location(dividableDocUri, new vscode.Range(5, 9, 5, 18)), - ]) - }) - - test('Should find references to area def', async () => { - await testFindReferences(areaDocUri, new vscode.Position(3, 4), [ - new vscode.Location(areaDocUri, new vscode.Range(3, 4, 3, 8)), - new vscode.Location(areaDocUri, new vscode.Range(12, 39, 12, 43)), - new vscode.Location(mainDocUri, new vscode.Range(10, 12, 10, 16)), - ]) - }) - - test('Should find references to area def-use', async () => { - await testFindReferences(areaDocUri, new vscode.Position(12, 39), [ - new vscode.Location(areaDocUri, new vscode.Range(3, 4, 3, 8)), - new vscode.Location(areaDocUri, new vscode.Range(12, 39, 12, 43)), - new vscode.Location(mainDocUri, new vscode.Range(10, 12, 10, 16)), - ]) - }) - - test('Should find references to Equatable.equals signature', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(2, 12), [ - new vscode.Location(equatableDocUri, new vscode.Range(2, 12, 2, 18)), - new vscode.Location(equatableDocUri, new vscode.Range(9, 41, 9, 57)), - new vscode.Location(equatableDocUri, new vscode.Range(6, 12, 6, 18)), - new vscode.Location(equatableDocUri, new vscode.Range(15, 12, 15, 18)), - new vscode.Location(equatableDocUri, new vscode.Range(22, 4, 22, 20)), - new vscode.Location(equatableDocUri, new vscode.Range(29, 4, 29, 20)), - new vscode.Location(equatableDocUri, new vscode.Range(36, 8, 36, 24)), - new vscode.Location(equatableDocUri, new vscode.Range(43, 8, 43, 24)), - ]) - }) - - test('Should find references to Equatable.equals signature-use', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(29, 14), [ - new vscode.Location(equatableDocUri, new vscode.Range(2, 12, 2, 18)), - new vscode.Location(equatableDocUri, new vscode.Range(9, 41, 9, 57)), - new vscode.Location(equatableDocUri, new vscode.Range(22, 4, 22, 20)), - new vscode.Location(equatableDocUri, new vscode.Range(29, 4, 29, 20)), - new vscode.Location(equatableDocUri, new vscode.Range(36, 8, 36, 24)), - new vscode.Location(equatableDocUri, new vscode.Range(43, 8, 43, 24)), - ]) - }) - - test('Should find references to Shape enum', async () => { - await testFindReferences(mainDocUri, new vscode.Position(2, 5), [ - new vscode.Location(mainDocUri, new vscode.Range(2, 5, 2, 10)), - new vscode.Location(areaDocUri, new vscode.Range(3, 12, 3, 17)), - ]) - }) - - test('Should find references to Year type alias', async () => { - await testFindReferences(dateDocUri, new vscode.Position(17, 11), [ - new vscode.Location(dateDocUri, new vscode.Range(17, 11, 17, 15)), - new vscode.Location(dateDocUri, new vscode.Range(21, 10, 21, 14)), - ]) - }) - test('Should find references to function parameter', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(6, 19), [ - new vscode.Location(equatableDocUri, new vscode.Range(6, 19, 6, 20)), - new vscode.Location(equatableDocUri, new vscode.Range(7, 15, 7, 16)), - ]) + const position = await findMarkerPosition(equatableDocUri, 'x1') + const locations = await testFindReferences(equatableDocUri, position) + assert.strictEqual(locations.length, 2) }) test('Should find references to function parameter-use', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(7, 15), [ - new vscode.Location(equatableDocUri, new vscode.Range(6, 19, 6, 20)), - new vscode.Location(equatableDocUri, new vscode.Range(7, 15, 7, 16)), - ]) - }) - - test('Should find references to match-extracted variable', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(9, 23), [ - new vscode.Location(equatableDocUri, new vscode.Range(9, 23, 9, 25)), - new vscode.Location(equatableDocUri, new vscode.Range(9, 58, 9, 60)), - ]) - }) - - test('Should find references to match-extracted variable-use', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(9, 58), [ - new vscode.Location(equatableDocUri, new vscode.Range(9, 23, 9, 25)), - new vscode.Location(equatableDocUri, new vscode.Range(9, 58, 9, 60)), - ]) + const position = await findMarkerPosition(equatableDocUri, 'x2') + const locations = await testFindReferences(equatableDocUri, position) + assert.strictEqual(locations.length, 2) }) test('Should find references to let-bound variable', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(20, 8), [ - new vscode.Location(equatableDocUri, new vscode.Range(20, 8, 20, 13)), - new vscode.Location(equatableDocUri, new vscode.Range(22, 21, 22, 26)), - ]) + const position = await findMarkerPosition(equatableDocUri, 'first1') + const locations = await testFindReferences(equatableDocUri, position) + assert.strictEqual(locations.length, 2) }) test('Should find references to let-bound variable-use', async () => { - await testFindReferences(equatableDocUri, new vscode.Position(22, 21), [ - new vscode.Location(equatableDocUri, new vscode.Range(20, 8, 20, 13)), - new vscode.Location(equatableDocUri, new vscode.Range(22, 21, 22, 26)), - ]) + const position = await findMarkerPosition(equatableDocUri, 'first2') + const locations = await testFindReferences(equatableDocUri, position) + assert.strictEqual(locations.length, 2) }) + + async function testFindReferences(uri: vscode.Uri, position: vscode.Position): Promise { + return vscode.commands.executeCommand('vscode.executeReferenceProvider', uri, position) + } }) diff --git a/test/testWorkspaces/findReferences/src/Equatable.flix b/test/testWorkspaces/findReferences/src/Equatable.flix index e6b69602..25427e29 100644 --- a/test/testWorkspaces/findReferences/src/Equatable.flix +++ b/test/testWorkspaces/findReferences/src/Equatable.flix @@ -4,8 +4,8 @@ trait Equatable[t] { } instance Equatable[Option[t]] with Equatable[t] { - pub def equals(x: Option[t], y: Option[t]): Bool = - match (x, y) { + pub def equals(x /*!x1*/: Option[t], y: Option[t]): Bool = + match (x /*!x2*/, y) { case (None, None) => true case (Some(v1), Some(v2)) => Equatable.equals(v1, v2) case _ => false @@ -18,9 +18,9 @@ instance Equatable[Int32] { def testOptionEquatable01(): Bool = { - let first = Some(1); + let first /*!first1*/ = Some(1); let second = Some(1); - Equatable.equals(first, second) + Equatable.equals(first /*!first2*/, second) } From 5d248c6194bc660f64c21ba9b4f6adfd162c3610 Mon Sep 17 00:00:00 2001 From: Magnus Madsen Date: Thu, 8 Jan 2026 16:51:54 +0100 Subject: [PATCH 2/2] . --- test/src/findReferences.test.ts | 26 +++++------ .../findReferences/src/Area.flix | 13 ------ .../findReferences/src/Assert.flix | 3 -- .../findReferences/src/Date.flix | 38 ---------------- .../findReferences/src/Dividable.flix | 9 ---- .../findReferences/src/Equatable.flix | 45 ------------------- .../findReferences/src/Main.flix | 9 +++- 7 files changed, 21 insertions(+), 122 deletions(-) delete mode 100644 test/testWorkspaces/findReferences/src/Area.flix delete mode 100644 test/testWorkspaces/findReferences/src/Assert.flix delete mode 100644 test/testWorkspaces/findReferences/src/Date.flix delete mode 100644 test/testWorkspaces/findReferences/src/Dividable.flix delete mode 100644 test/testWorkspaces/findReferences/src/Equatable.flix diff --git a/test/src/findReferences.test.ts b/test/src/findReferences.test.ts index 55ef2e6d..ddef12c0 100644 --- a/test/src/findReferences.test.ts +++ b/test/src/findReferences.test.ts @@ -20,34 +20,34 @@ import * as vscode from 'vscode' import { findMarkerPosition, getTestDocUri, init } from './util' suite('FindReferencesProvider', () => { - const equatableDocUri = getTestDocUri('src/Equatable.flix') + const mainDocUri = getTestDocUri('src/Main.flix') suiteSetup(async () => { await init('findReferences') }) test('Should find references to function parameter', async () => { - const position = await findMarkerPosition(equatableDocUri, 'x1') - const locations = await testFindReferences(equatableDocUri, position) + const position = await findMarkerPosition(mainDocUri, 's1') + const locations = await testFindReferences(mainDocUri, position) assert.strictEqual(locations.length, 2) }) test('Should find references to function parameter-use', async () => { - const position = await findMarkerPosition(equatableDocUri, 'x2') - const locations = await testFindReferences(equatableDocUri, position) + const position = await findMarkerPosition(mainDocUri, 's2') + const locations = await testFindReferences(mainDocUri, position) assert.strictEqual(locations.length, 2) }) - test('Should find references to let-bound variable', async () => { - const position = await findMarkerPosition(equatableDocUri, 'first1') - const locations = await testFindReferences(equatableDocUri, position) - assert.strictEqual(locations.length, 2) + test('Should find references to pattern variable', async () => { + const position = await findMarkerPosition(mainDocUri, 'r1') + const locations = await testFindReferences(mainDocUri, position) + assert.strictEqual(locations.length, 3) }) - test('Should find references to let-bound variable-use', async () => { - const position = await findMarkerPosition(equatableDocUri, 'first2') - const locations = await testFindReferences(equatableDocUri, position) - assert.strictEqual(locations.length, 2) + test('Should find references to pattern variable-use', async () => { + const position = await findMarkerPosition(mainDocUri, 'r2') + const locations = await testFindReferences(mainDocUri, position) + assert.strictEqual(locations.length, 3) }) async function testFindReferences(uri: vscode.Uri, position: vscode.Position): Promise { diff --git a/test/testWorkspaces/findReferences/src/Area.flix b/test/testWorkspaces/findReferences/src/Area.flix deleted file mode 100644 index ce98a6ec..00000000 --- a/test/testWorkspaces/findReferences/src/Area.flix +++ /dev/null @@ -1,13 +0,0 @@ -// Blank line -/// Computes the area of the given shape using -/// pattern matching and basic arithmetic. -def area(s: Shape): Int32 = { - match s { - case Shape.Circle(r) => circleArea(r) - case Shape.Square(w) => w * w - case Shape.Rectangle(h, w) => h * w - } -} - - -def testSquareArea(): Bool = Assert.eq(area(Shape.Square(5)), 25) diff --git a/test/testWorkspaces/findReferences/src/Assert.flix b/test/testWorkspaces/findReferences/src/Assert.flix deleted file mode 100644 index 1962b5d9..00000000 --- a/test/testWorkspaces/findReferences/src/Assert.flix +++ /dev/null @@ -1,3 +0,0 @@ -mod Assert { - pub def eq(_: t, _: t): Bool = true -} diff --git a/test/testWorkspaces/findReferences/src/Date.flix b/test/testWorkspaces/findReferences/src/Date.flix deleted file mode 100644 index d8ac2bba..00000000 --- a/test/testWorkspaces/findReferences/src/Date.flix +++ /dev/null @@ -1,38 +0,0 @@ -// Blank line -/// We derive the traits Eq, Order, and ToString for the enum Month -enum Month with Eq, Order, ToString { - case January - case February - case March - case April - case May - case June - case July - case August - case September - case October - case November - case December -} - -type alias Year = Int32 -type alias Day = Int32 - -/// The Date type derives the traits Eq and Order -enum Date(Year, Month, Day) with Eq, Order - -/// We implement our own instance of ToString for Date -/// since we don't want the default "Date(1948, December, 10)" -instance ToString[Date] { - pub def toString(x: Date): String = - let Date.Date(y, m, d) = x; - "${d} ${m}, ${y}" -} - -/// Thanks to the Eq and Order traits, we can easily compare dates. -def earlierDate(d1: Date, d2: Date): Date = Order.min(d1, d2) - -/// Thanks to the ToString trait, we can easily convert dates to strings. -def printDate(d: Date): Unit \ IO = - let message = "The date is ${d}!"; - println(message) diff --git a/test/testWorkspaces/findReferences/src/Dividable.flix b/test/testWorkspaces/findReferences/src/Dividable.flix deleted file mode 100644 index 5c880a9a..00000000 --- a/test/testWorkspaces/findReferences/src/Dividable.flix +++ /dev/null @@ -1,9 +0,0 @@ -// Blank line -trait Dividable[t] { - pub def div(x: t, y: t): t -} - -instance Dividable[Int32] { - pub def div(x: Int32, y: Int32): Int32 = - x / y -} diff --git a/test/testWorkspaces/findReferences/src/Equatable.flix b/test/testWorkspaces/findReferences/src/Equatable.flix deleted file mode 100644 index 25427e29..00000000 --- a/test/testWorkspaces/findReferences/src/Equatable.flix +++ /dev/null @@ -1,45 +0,0 @@ -// Blank line -trait Equatable[t] { - pub def equals(x: t, y: t): Bool -} - -instance Equatable[Option[t]] with Equatable[t] { - pub def equals(x /*!x1*/: Option[t], y: Option[t]): Bool = - match (x /*!x2*/, y) { - case (None, None) => true - case (Some(v1), Some(v2)) => Equatable.equals(v1, v2) - case _ => false - } -} - -instance Equatable[Int32] { - pub def equals(x: Int32, y: Int32): Bool = x == y -} - - -def testOptionEquatable01(): Bool = { - let first /*!first1*/ = Some(1); - let second = Some(1); - Equatable.equals(first /*!first2*/, second) -} - - -def testOptionEquatable02(): Bool = { - let first: Option[Int32] = None; - let second: Option[Int32] = None; - Equatable.equals(first, second) -} - - -def testOptionEquatable03(): Bool = { - let first = Some(1); - let second: Option[Int32] = None; - not Equatable.equals(first, second) -} - - -def testOptionEquatable04(): Bool = { - let first = Some(1); - let second = Some(2); - not Equatable.equals(first, second) -} diff --git a/test/testWorkspaces/findReferences/src/Main.flix b/test/testWorkspaces/findReferences/src/Main.flix index 9d926bf3..9897a97c 100644 --- a/test/testWorkspaces/findReferences/src/Main.flix +++ b/test/testWorkspaces/findReferences/src/Main.flix @@ -1,4 +1,3 @@ -// Blank line /// An algebraic data type for shapes. enum Shape { case Circle(Int32), // circle radius @@ -6,6 +5,14 @@ enum Shape { case Rectangle(Int32, Int32) // height and width } +/// Computes the area of the given shape using +/// pattern matching and basic arithmetic. +def area(s /*!s1*/: Shape): Int32 = match s /*!s2*/ { + case Shape.Circle(r /*!r1*/) => 3 * (r /*!r2*/ * r) + case Shape.Square(w) => w * w + case Shape.Rectangle(h, w) => h * w +} + // Computes the area of a 2 by 4. def main(): Unit \ IO = println(area(Shape.Rectangle(2, 4)))