-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
test: Add tests for signatureHelp #253
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
18b7454
test: Add tests for signatureHelp
xpyctumo 27d2f2f
test: Add some tests and debug info for windows
xpyctumo cecef1b
test: add test with traits and global functions
xpyctumo 1e07120
fix(test): trying to pass windows tests
xpyctumo 081a665
fix(test): trying to pass windows tests via timeout?
xpyctumo 722a944
test: Add test with Struct
xpyctumo 64087b5
test: Add test with traits in contract
xpyctumo 4faa18e
refator: split tests into files / add more tests and add coverage to …
xpyctumo a912bc6
fix(test): use valid caret index in document
xpyctumo daa8d27
fix(test): remove debug info and fix test
xpyctumo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,6 @@ yarn-error.log | |
|
||
# eslint | ||
.eslintcache | ||
|
||
# coverage | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import * as vscode from "vscode" | ||
import * as assert from "node:assert" | ||
import {BaseTestSuite} from "./BaseTestSuite" | ||
import type {TestCase} from "./TestParser" | ||
|
||
suite("Signatures Test Suite", () => { | ||
const testSuite = new (class extends BaseTestSuite { | ||
public async getSignature(input: string): Promise<vscode.SignatureHelp> { | ||
const textWithoutCaret = input.replace("<caret>", "") | ||
await this.replaceDocumentText(textWithoutCaret) | ||
|
||
const caretIndex = input.indexOf("<caret>") | ||
if (caretIndex === -1) { | ||
throw new Error("No <caret> marker found in input") | ||
} | ||
|
||
const position = this.document.positionAt(caretIndex) | ||
this.editor.selection = new vscode.Selection(position, position) | ||
this.editor.revealRange(new vscode.Range(position, position)) | ||
|
||
return vscode.commands.executeCommand<vscode.SignatureHelp>( | ||
"vscode.executeSignatureHelpProvider", | ||
this.document.uri, | ||
position, | ||
) | ||
} | ||
|
||
protected runTest(testFile: string, testCase: TestCase): void { | ||
test(`Signature: ${testCase.name}`, async () => { | ||
const signature = await this.getSignature(testCase.input) | ||
console.log("signature") | ||
console.log(JSON.stringify(signature)) | ||
const items = signature.signatures.map(item => { | ||
const label = item.label | ||
if (item.activeParameter !== undefined) { | ||
const activeParamLabel = item.parameters[item.activeParameter]?.label ?? "" | ||
return `${activeParamLabel.toString()}\n${label}` | ||
} | ||
return "" | ||
}) | ||
const expected = testCase.expected.split("\n").filter((line: string) => line !== "") | ||
if (BaseTestSuite.UPDATE_SNAPSHOTS) { | ||
this.updates.push({ | ||
filePath: testFile, | ||
testName: testCase.name, | ||
actual: items.join("\n"), | ||
}) | ||
} else { | ||
assert.deepStrictEqual(items.sort(), expected.sort()) | ||
} | ||
}) | ||
} | ||
})() | ||
|
||
suiteSetup(async function () { | ||
this.timeout(10_000) | ||
await testSuite.suiteSetup() | ||
}) | ||
|
||
setup(async () => testSuite.setup()) | ||
teardown(async () => testSuite.teardown()) | ||
suiteTeardown(() => testSuite.suiteTeardown()) | ||
|
||
testSuite.runTestsFromDirectory("signatures") | ||
}) |
153 changes: 153 additions & 0 deletions
153
server/src/e2e/suite/testcases/signatures/contract.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
======================================================================== | ||
Basic Function with Multiple Parameters | ||
======================================================================== | ||
primitive Int; | ||
primitive String; | ||
|
||
struct User { | ||
name: String; | ||
age: Int; | ||
} | ||
|
||
contract Foo { | ||
fun baz(user: User, action: String, value: Int) { | ||
// ... | ||
} | ||
|
||
init() { | ||
self.baz(user, "update", <caret>); | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
value: Int | ||
fun baz(user: User, action: String, value: Int) | ||
|
||
======================================================================== | ||
Function Overloading | ||
======================================================================== | ||
primitive Int; | ||
primitive String; | ||
|
||
contract Foo { | ||
fun add(a: Int, b: Int): Int { | ||
return a + b; | ||
} | ||
|
||
fun add(a: String, b: String): String { | ||
return a + b; | ||
} | ||
|
||
init() { | ||
self.add("hello", <caret>); | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
b: Int | ||
fun add(a: Int, b: Int) | ||
|
||
======================================================================== | ||
Nested Function Calls | ||
======================================================================== | ||
primitive Int; | ||
primitive String; | ||
|
||
contract Foo { | ||
fun multiply(a: Int, b: Int): Int { | ||
return a * b; | ||
} | ||
|
||
fun calculate(x: Int, y: Int, z: Int): Int { | ||
return x + self.multiply(y, z); | ||
} | ||
|
||
init() { | ||
self.calculate(10, <caret>); | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
y: Int | ||
fun calculate(x: Int, y: Int, z: Int) | ||
|
||
======================================================================== | ||
Nested Function Calls - 2 | ||
======================================================================== | ||
primitive Int; | ||
|
||
contract Foo { | ||
fun double(x: Int): Int { | ||
return x * 2; | ||
} | ||
|
||
fun triple(x: Int): Int { | ||
return x * 3; | ||
} | ||
|
||
init() { | ||
self.double(self.triple(<caret>)); | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
x: Int | ||
fun triple(x: Int) | ||
|
||
======================================================================== | ||
Promt first arg while second is filled | ||
======================================================================== | ||
primitive Int; | ||
|
||
contract Foo { | ||
fun add(a: Int, b: Int): Int { | ||
return a + b; | ||
} | ||
|
||
init() { | ||
self.add(<caret>, 2); | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
a: Int | ||
fun add(a: Int, b: Int) | ||
|
||
======================================================================== | ||
Global function with Map | ||
======================================================================== | ||
primitive Int; | ||
primitive String; | ||
|
||
struct Key { | ||
id: Int; | ||
name: String; | ||
} | ||
|
||
get fun globalFunc(map: Map<Key, Int>) { | ||
// ... | ||
} | ||
|
||
contract Foo { | ||
init() { | ||
let key = Key { id: 1, name: "Test" }; | ||
let map = emptyMap(); | ||
globalFunc(<caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
map: Map | ||
fun globalFunc(map: Map) | ||
|
||
======================================================================== | ||
Global function with String | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But function takes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added also for |
||
======================================================================== | ||
primitive Int; | ||
|
||
fun globalFunc(input: Int): Int { | ||
return input; | ||
} | ||
|
||
contract A { | ||
init() { | ||
globalFunc(<caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
input: Int | ||
fun globalFunc(input: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
======================================================================== | ||
initOf with one argument | ||
======================================================================== | ||
primitive Int; | ||
|
||
contract ContractA { | ||
init(a: Int) { | ||
|
||
} | ||
} | ||
|
||
contract ContractB { | ||
init() { | ||
initOf ContractA(<caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
a: Int | ||
init(a: Int) | ||
|
||
======================================================================== | ||
initOf with many arguments | ||
======================================================================== | ||
primitive Int; | ||
|
||
contract ContractA { | ||
init(a: Int, b: Int, c: Int) { | ||
// ... | ||
} | ||
} | ||
|
||
contract ContractB { | ||
init() { | ||
initOf ContractA(<caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
a: Int | ||
init(a: Int, b: Int, c: Int) | ||
|
||
======================================================================== | ||
initOf with many arguments (first is filled) | ||
======================================================================== | ||
primitive Int; | ||
|
||
contract ContractA { | ||
init(a: Int, b: Int, c: Int) { | ||
// ... | ||
} | ||
} | ||
|
||
contract ContractB { | ||
init() { | ||
initOf ContractA(42, <caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
b: Int | ||
init(a: Int, b: Int, c: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
======================================================================== | ||
Set Map (Key) | ||
======================================================================== | ||
primitive Int; | ||
extends mutates fun set(self: map<K, V>, key: K, val: V); | ||
|
||
contract A { | ||
init() { | ||
let fizz: map<Int, Int> = emptyMap(); | ||
|
||
fizz.set(<caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
key: K | ||
fun set(self: map<K, V>, key: K, val: V) | ||
|
||
======================================================================== | ||
Set Map (Value) | ||
======================================================================== | ||
primitive Int; | ||
extends mutates fun set(self: map<K, V>, key: K, val: V); | ||
|
||
contract A { | ||
init() { | ||
let fizz: map<Int, Int> = emptyMap(); | ||
|
||
fizz.set(42, <caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
val: V | ||
fun set(self: map<K, V>, key: K, val: V) | ||
|
||
======================================================================== | ||
Get value from Map | ||
======================================================================== | ||
primitive Int; | ||
extends fun get(self: map<K, V>, key: K): V?; | ||
contract A { | ||
init() { | ||
let fizz: map<Int, Int> = emptyMap(); | ||
|
||
fizz.get(<caret>); | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
key: K | ||
fun get(self: map<K, V>, key: K) | ||
|
||
======================================================================== | ||
Replace value map by key (caret on key) | ||
======================================================================== | ||
primitive Int; | ||
extends mutates fun replace(self: map<K, V>, key: K, val: V): Bool; | ||
contract A { | ||
init() { | ||
let fizz: map<Int, Int> = emptyMap(); | ||
|
||
fizz.replace(<caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
key: K | ||
fun replace(self: map<K, V>, key: K, val: V) | ||
|
||
======================================================================== | ||
Replace value map by key (caret on value) | ||
======================================================================== | ||
primitive Int; | ||
extends mutates fun replace(self: map<K, V>, key: K, val: V): Bool; | ||
contract A { | ||
init() { | ||
let fizz: map<Int, Int> = emptyMap(); | ||
|
||
fizz.replace(42, <caret>) | ||
} | ||
} | ||
------------------------------------------------------------------------ | ||
val: V | ||
fun replace(self: map<K, V>, key: K, val: V) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's remove debug statements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, of course.
It was just to see why tests were failing CI on Windows. Already removed because the tests are fixed.