Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 19 additions & 119 deletions test/src/findReferences.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
suite('FindReferencesProvider', () => {
const mainDocUri = getTestDocUri('src/Main.flix')
const dividableDocUri = getTestDocUri('src/Dividable.flix')
const areaDocUri = getTestDocUri('src/Area.flix')
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.Location[]>('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(mainDocUri, 's1')
const locations = await testFindReferences(mainDocUri, 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)),
])
const position = await findMarkerPosition(mainDocUri, 's2')
const locations = await testFindReferences(mainDocUri, position)
assert.strictEqual(locations.length, 2)
})

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)),
])
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', 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)),
])
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)
})

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)),
])
})
async function testFindReferences(uri: vscode.Uri, position: vscode.Position): Promise<vscode.Location[]> {
return vscode.commands.executeCommand<vscode.Location[]>('vscode.executeReferenceProvider', uri, position)
}
})
13 changes: 0 additions & 13 deletions test/testWorkspaces/findReferences/src/Area.flix

This file was deleted.

3 changes: 0 additions & 3 deletions test/testWorkspaces/findReferences/src/Assert.flix

This file was deleted.

38 changes: 0 additions & 38 deletions test/testWorkspaces/findReferences/src/Date.flix

This file was deleted.

9 changes: 0 additions & 9 deletions test/testWorkspaces/findReferences/src/Dividable.flix

This file was deleted.

45 changes: 0 additions & 45 deletions test/testWorkspaces/findReferences/src/Equatable.flix

This file was deleted.

9 changes: 8 additions & 1 deletion test/testWorkspaces/findReferences/src/Main.flix
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// Blank line
/// An algebraic data type for shapes.
enum Shape {
case Circle(Int32), // circle radius
case Square(Int32), // side length
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)))