From fe1fb422cf625710f2dd50a76402c63ba7a82b6b Mon Sep 17 00:00:00 2001 From: sockmaster27 <61235930+sockmaster27@users.noreply.github.com> Date: Sun, 28 Apr 2024 16:13:39 +0200 Subject: [PATCH] test: add tests for finding references --- test/src/findReferences.test.ts | 71 +++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 test/src/findReferences.test.ts diff --git a/test/src/findReferences.test.ts b/test/src/findReferences.test.ts new file mode 100644 index 00000000..cf2905ca --- /dev/null +++ b/test/src/findReferences.test.ts @@ -0,0 +1,71 @@ +/* + * Copyright 2024 Holger Dal Mogensen + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as assert from 'assert' +import * as vscode from 'vscode' +import { getTestDocUri, activate } from './util' + +suite('Code actions', () => { + const mainDocUri = getTestDocUri('src/Main.flix') + const areaDocUri = getTestDocUri('src/Area.flix') + + suiteSetup(async () => { + await activate() + }) + + test('Should find references to enum case', async () => { + const position = new vscode.Position(3, 9) + const r = (await vscode.commands.executeCommand( + 'vscode.executeReferenceProvider', + mainDocUri, + position, + )) as vscode.Location[] + + assert.strictEqual(r.length, 2) + + const mainReference = r.find(l => l.uri.path.endsWith(mainDocUri.path)) + const areaReference = r.find(l => l.uri.path.endsWith(areaDocUri.path)) + + assert.notStrictEqual(mainReference, undefined) + assert.notStrictEqual(areaReference, undefined) + + assert.deepStrictEqual(mainReference?.range, new vscode.Range(3, 9, 3, 22)) + assert.deepStrictEqual(areaReference?.range, new vscode.Range(6, 13, 6, 25)) + }) + + test('Should find references to def', async () => { + const position = new vscode.Position(3, 4) + const r = (await vscode.commands.executeCommand( + 'vscode.executeReferenceProvider', + areaDocUri, + position, + )) as vscode.Location[] + + assert.strictEqual(r.length, 3) + + const defReference = r.find(l => l.uri.path.endsWith(areaDocUri.path) && l.range.start.line === 3) + const testReference = r.find(l => l.uri.path.endsWith(areaDocUri.path) && l.range.start.line === 13) + const mainReference = r.find(l => l.uri.path.endsWith(mainDocUri.path)) + + assert.notStrictEqual(defReference, undefined) + assert.notStrictEqual(testReference, undefined) + assert.notStrictEqual(mainReference, undefined) + + assert.deepStrictEqual(defReference?.range, new vscode.Range(3, 4, 3, 8)) + assert.deepStrictEqual(testReference?.range, new vscode.Range(13, 39, 13, 43)) + assert.deepStrictEqual(mainReference?.range, new vscode.Range(10, 12, 10, 16)) + }) +})