From 2b4db8d2e9ecffd57acc9564ca5fff5f56c7ad8f Mon Sep 17 00:00:00 2001 From: Holger Dal Mogensen <61235930+sockmaster27@users.noreply.github.com> Date: Mon, 20 May 2024 09:53:23 +0200 Subject: [PATCH] test: fix hover test case for new parser (#407) --- package.json | 5 +++++ test/src/hover.test.ts | 14 ++++++-------- test/src/util.ts | 10 ++++------ test/testWorkspaces/hover/latent/Broken.flix | 7 ------- test/testWorkspaces/hover/src/Area.flix | 13 ------------- test/testWorkspaces/hover/src/Main.flix | 10 ++++++++++ 6 files changed, 25 insertions(+), 34 deletions(-) delete mode 100644 test/testWorkspaces/hover/latent/Broken.flix delete mode 100644 test/testWorkspaces/hover/src/Area.flix diff --git a/package.json b/package.json index 9fd236d6..69b2f6e5 100644 --- a/package.json +++ b/package.json @@ -78,6 +78,11 @@ { "command": "flix.startRepl", "title": "Flix: Start REPL" + }, + { + "command": "flix.allJobsFinished", + "title": "Flix (debugging): Wait for the compiler to finish processing", + "enablement": "false" } ], "languages": [ diff --git a/test/src/hover.test.ts b/test/src/hover.test.ts index 46c952af..49764e01 100644 --- a/test/src/hover.test.ts +++ b/test/src/hover.test.ts @@ -16,21 +16,15 @@ import * as assert from 'assert' import * as vscode from 'vscode' -import { getTestDocUri, activate, open, copyFile, tryDeleteFile } from './util' +import { getTestDocUri, activate, open, typeText } from './util' suite('Hover info', () => { const docUri = getTestDocUri('src/Main.flix') - const brokenDocUriLatent = getTestDocUri('latent/Broken.flix') - const brokenDocUri = getTestDocUri('src/Broken.flix') - suiteSetup(async () => { await activate('hover') await open(docUri) }) - teardown(async () => { - await tryDeleteFile(brokenDocUri) - }) test('Hovering on an empty line should not show anything', async () => { const position = new vscode.Position(0, 0) @@ -87,7 +81,11 @@ suite('Hover info', () => { }) test('Hovering on area()-call in broken project should still show def', async () => { - await copyFile(brokenDocUriLatent, brokenDocUri) + // Create a syntax error + // `def area(s: Shape): Int32` -> `def area(s: Shape)asdf: Int32` + const editor = vscode.window.activeTextEditor + editor.selection = new vscode.Selection(new vscode.Position(14, 18), new vscode.Position(14, 18)) + await typeText('asdf') const position = new vscode.Position(10, 12) await testHoverAtPosition(position, '(Information may not be current)') diff --git a/test/src/util.ts b/test/src/util.ts index 1889aaeb..46b7c0d6 100644 --- a/test/src/util.ts +++ b/test/src/util.ts @@ -89,6 +89,8 @@ export async function open(docUri: vscode.Uri) { */ export async function typeText(text: string) { await vscode.commands.executeCommand('type', { text }) + await vscode.window.activeTextEditor.document.save() + await processFileChange() } function getTestDocPath(p: string) { @@ -112,12 +114,8 @@ async function processFileChange() { // Wait for the file system watcher to pick up the change await sleep(1000) - try { - // Wait for the compiler to process the change - await vscode.commands.executeCommand('flix.allJobsFinished') - } catch { - // Compiler is not running - } + // Wait for the compiler to process the change + await vscode.commands.executeCommand('flix.allJobsFinished') // Wait for the diagnostics to be updated await sleep(1000) diff --git a/test/testWorkspaces/hover/latent/Broken.flix b/test/testWorkspaces/hover/latent/Broken.flix deleted file mode 100644 index 5e7230cd..00000000 --- a/test/testWorkspaces/hover/latent/Broken.flix +++ /dev/null @@ -1,7 +0,0 @@ -// This file is intentionally broken for use in the error tests. - -/// We can easily construct and append lists: -def l(): List[Int32] = - let l1 = 1 :: 2 :: 3 :: Nil; - let l2 = 4 :: 5 :: 6 :: Nil // <- Missing semi-colon - l1 ::: l2 diff --git a/test/testWorkspaces/hover/src/Area.flix b/test/testWorkspaces/hover/src/Area.flix deleted file mode 100644 index d033174d..00000000 --- a/test/testWorkspaces/hover/src/Area.flix +++ /dev/null @@ -1,13 +0,0 @@ - -/// Computes the area of the given shape using -/// pattern matching and basic arithmetic. -def area(s: Shape): Int32 = { - match s { - case Shape.Circle(r) => 3 * r * r - case Shape.Square(w) => w * w - case Shape.Rectangle(h, w) => h * w - } -} - -@Test -def testSquareArea(): Bool = Assert.eq(area(Shape.Square(5)), 25) diff --git a/test/testWorkspaces/hover/src/Main.flix b/test/testWorkspaces/hover/src/Main.flix index 9e6a1e13..9bc67b83 100644 --- a/test/testWorkspaces/hover/src/Main.flix +++ b/test/testWorkspaces/hover/src/Main.flix @@ -9,3 +9,13 @@ enum Shape { // Computes the area of a 2 by 4. def main(): Unit \ IO = println(area(Shape.Rectangle(2, 4))) + +/// Computes the area of the given shape using +/// pattern matching and basic arithmetic. +def area(s: Shape): Int32 = { + match s { + case Shape.Circle(r) => 3 * r * r + case Shape.Square(w) => w * w + case Shape.Rectangle(h, w) => h * w + } +}