Skip to content

Commit

Permalink
test: fix hover test case for new parser (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
sockmaster27 authored May 20, 2024
1 parent f636acc commit 2b4db8d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 34 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
14 changes: 6 additions & 8 deletions test/src/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)')
Expand Down
10 changes: 4 additions & 6 deletions test/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
7 changes: 0 additions & 7 deletions test/testWorkspaces/hover/latent/Broken.flix

This file was deleted.

13 changes: 0 additions & 13 deletions test/testWorkspaces/hover/src/Area.flix

This file was deleted.

10 changes: 10 additions & 0 deletions test/testWorkspaces/hover/src/Main.flix
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit 2b4db8d

Please sign in to comment.