From 18b7454987064d4df32e31ff9acb6ba0a39f87da Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 14:57:13 +0300 Subject: [PATCH 01/10] test: Add tests for signatureHelp --- server/src/e2e/suite/signatures.test.ts | 63 ++++ .../suite/testcases/signatures/contract.test | 279 ++++++++++++++++++ 2 files changed, 342 insertions(+) create mode 100644 server/src/e2e/suite/signatures.test.ts create mode 100644 server/src/e2e/suite/testcases/signatures/contract.test diff --git a/server/src/e2e/suite/signatures.test.ts b/server/src/e2e/suite/signatures.test.ts new file mode 100644 index 00000000..b0fe7313 --- /dev/null +++ b/server/src/e2e/suite/signatures.test.ts @@ -0,0 +1,63 @@ +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 { + const textWithoutCaret = input.replace("", "") + await this.replaceDocumentText(textWithoutCaret) + + const caretIndex = input.indexOf("") + if (caretIndex === -1) { + throw new Error("No 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.executeSignatureHelpProvider", + this.document.uri, + position, + ) + } + + protected runTest(testFile: string, testCase: TestCase): void { + test(`Signature: ${testCase.name}`, async () => { + const signature = await this.getSignature(testCase.input) + 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") +}) diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test new file mode 100644 index 00000000..fa2cf041 --- /dev/null +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -0,0 +1,279 @@ +======================================================================== +Basic Function with Multiple Parameters +======================================================================== +primitive Int; +primitive String; + +struct User { + first_name: String; + last_name: String; + age: Int; +} + +contract Foo { + + fun bar(a: Int, b: String, c: User) { + return a + 42; + } + + init() { + self.bar(1000, ); + } +} +------------------------------------------------------------------------ +b: String +fun bar(a: Int, b: String, c: User) + +======================================================================== +Basic Function with Multiple Parameters - 2 +======================================================================== +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", ); + } +} +------------------------------------------------------------------------ +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", ); + } +} +------------------------------------------------------------------------ +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, ); + } +} +------------------------------------------------------------------------ +y: Int +fun calculate(x: Int, y: Int, z: Int) + +======================================================================== +Function with Optional Parameters +======================================================================== +primitive Int; + +contract Foo { + fun sum(a: Int, b: Int = 10, c: Int = 20): Int { + return a + b + c; + } + + init() { + self.sum(5, ); + } +} +------------------------------------------------------------------------ +b: Int +fun sum(a: Int, b: Int, c: Int) + +======================================================================== +Default Parameter Values +======================================================================== +primitive Int; + +contract Foo { + fun configure(a: Int, b: Int = 42, c: Int = 100): Int { + return a + b + c; + } + + init() { + self.configure(10, ); + } +} +------------------------------------------------------------------------ +b: Int +fun configure(a: Int, b: Int, c: Int) + +======================================================================== +Chained Function Calls +======================================================================== +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()); + } +} +------------------------------------------------------------------------ +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(, 2); + } +} +------------------------------------------------------------------------ +a: Int +fun add(a: Int, b: Int) + +======================================================================== +Map with Complex Key Types +======================================================================== +primitive Int; +primitive String; + +struct Key { + id: Int; + name: String; +} + +contract Foo { + fun processComplexMap(map: Map) { + // ... + } + + init() { + let key = Key { id: 1, name: "Test" }; + let map = emptyMap(); + self.processComplexMap(); + } +} +------------------------------------------------------------------------ +map: Map +fun processComplexMap(map: Map) + +======================================================================== +Set Map (Key) +======================================================================== +primitive Int; +extends mutates fun set(self: map, key: K, val: V); + +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.set() + } +} +------------------------------------------------------------------------ +key: K +fun set(self: map, key: K, val: V) + +======================================================================== +Set Map (Value) +======================================================================== +primitive Int; +extends mutates fun set(self: map, key: K, val: V); + +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.set(42, ) + } +} +------------------------------------------------------------------------ +val: V +fun set(self: map, key: K, val: V) + +======================================================================== +Get value from Map +======================================================================== +primitive Int; +extends fun get(self: map, key: K): V?; +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.get(); + } +} +------------------------------------------------------------------------ +key: K +fun get(self: map, key: K) + +======================================================================== +Replace value map by key (caret on key) +======================================================================== +primitive Int; +extends mutates fun replace(self: map, key: K, val: V): Bool; +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.replace() + } +} +------------------------------------------------------------------------ +key: K +fun replace(self: map, key: K, val: V) + +======================================================================== +Replace value map by key (caret on value) +======================================================================== +primitive Int; +extends mutates fun replace(self: map, key: K, val: V): Bool; +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.replace(42, ) + } +} +------------------------------------------------------------------------ +val: V +fun replace(self: map, key: K, val: V) From 27d2f2ffc015487088e85de8f01a008f3c50ce8d Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 16:46:46 +0300 Subject: [PATCH 02/10] test: Add some tests and debug info for windows --- ...gnatures.test.ts => signatureHelp.test.ts} | 2 + .../suite/testcases/signatures/contract.test | 70 ++++++------------- 2 files changed, 25 insertions(+), 47 deletions(-) rename server/src/e2e/suite/{signatures.test.ts => signatureHelp.test.ts} (96%) diff --git a/server/src/e2e/suite/signatures.test.ts b/server/src/e2e/suite/signatureHelp.test.ts similarity index 96% rename from server/src/e2e/suite/signatures.test.ts rename to server/src/e2e/suite/signatureHelp.test.ts index b0fe7313..bdc29435 100644 --- a/server/src/e2e/suite/signatures.test.ts +++ b/server/src/e2e/suite/signatureHelp.test.ts @@ -28,6 +28,8 @@ suite("Signatures Test Suite", () => { 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) { diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test index fa2cf041..0e891d4c 100644 --- a/server/src/e2e/suite/testcases/signatures/contract.test +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -94,24 +94,6 @@ contract Foo { y: Int fun calculate(x: Int, y: Int, z: Int) -======================================================================== -Function with Optional Parameters -======================================================================== -primitive Int; - -contract Foo { - fun sum(a: Int, b: Int = 10, c: Int = 20): Int { - return a + b + c; - } - - init() { - self.sum(5, ); - } -} ------------------------------------------------------------------------- -b: Int -fun sum(a: Int, b: Int, c: Int) - ======================================================================== Default Parameter Values ======================================================================== @@ -131,7 +113,7 @@ b: Int fun configure(a: Int, b: Int, c: Int) ======================================================================== -Chained Function Calls +Nested Function Calls ======================================================================== primitive Int; @@ -149,8 +131,8 @@ contract Foo { } } ------------------------------------------------------------------------ -x: Int -fun triple(x: Int) +y: Int +fun calculate(x: Int, y: Int, z: Int) ======================================================================== Promt first arg while second is filled @@ -170,32 +152,6 @@ contract Foo { a: Int fun add(a: Int, b: Int) -======================================================================== -Map with Complex Key Types -======================================================================== -primitive Int; -primitive String; - -struct Key { - id: Int; - name: String; -} - -contract Foo { - fun processComplexMap(map: Map) { - // ... - } - - init() { - let key = Key { id: 1, name: "Test" }; - let map = emptyMap(); - self.processComplexMap(); - } -} ------------------------------------------------------------------------- -map: Map -fun processComplexMap(map: Map) - ======================================================================== Set Map (Key) ======================================================================== @@ -277,3 +233,23 @@ contract A { ------------------------------------------------------------------------ val: V fun replace(self: map, key: K, val: V) + +======================================================================== +External Contract Initialization +======================================================================== +primitive Int; + +contract ContractA { + init(a: Int) { + + } +} + +contract ContractB { + init() { + initOf ContractA() + } +} +------------------------------------------------------------------------ +a: Int +init(a: Int) From cecef1b3caa3457311fe88a916d661ca9ec6fd07 Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 16:59:00 +0300 Subject: [PATCH 03/10] test: add test with traits and global functions --- .../suite/testcases/signatures/contract.test | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test index 0e891d4c..cc49eab5 100644 --- a/server/src/e2e/suite/testcases/signatures/contract.test +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -4,32 +4,6 @@ Basic Function with Multiple Parameters primitive Int; primitive String; -struct User { - first_name: String; - last_name: String; - age: Int; -} - -contract Foo { - - fun bar(a: Int, b: String, c: User) { - return a + 42; - } - - init() { - self.bar(1000, ); - } -} ------------------------------------------------------------------------- -b: String -fun bar(a: Int, b: String, c: User) - -======================================================================== -Basic Function with Multiple Parameters - 2 -======================================================================== -primitive Int; -primitive String; - struct User { name: String; age: Int; @@ -94,24 +68,6 @@ contract Foo { y: Int fun calculate(x: Int, y: Int, z: Int) -======================================================================== -Default Parameter Values -======================================================================== -primitive Int; - -contract Foo { - fun configure(a: Int, b: Int = 42, c: Int = 100): Int { - return a + b + c; - } - - init() { - self.configure(10, ); - } -} ------------------------------------------------------------------------- -b: Int -fun configure(a: Int, b: Int, c: Int) - ======================================================================== Nested Function Calls ======================================================================== @@ -253,3 +209,47 @@ contract ContractB { ------------------------------------------------------------------------ a: Int init(a: Int) + +======================================================================== +Global function with Map +======================================================================== +primitive Int; +primitive String; + +struct Key { + id: Int; + name: String; +} + +get fun globalFunc(map: Map) { + // ... +} + +contract Foo { + init() { + let key = Key { id: 1, name: "Test" }; + let map = emptyMap(); + globalFunc() + } +} +------------------------------------------------------------------------ +map: Map +fun globalFunc(map: Map) + +======================================================================== +Global function with String +======================================================================== +primitive Int; + +fun globalFunc(input: Int): Int { + return input; +} + +contract A { + init() { + globalFunc() + } +} +------------------------------------------------------------------------ +input: Int +fun globalFunc(input: Int) From 1e0712052131166b0b6697b2b4e7cd5eb48598fa Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 17:05:43 +0300 Subject: [PATCH 04/10] fix(test): trying to pass windows tests --- server/src/e2e/suite/signatureHelp.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/src/e2e/suite/signatureHelp.test.ts b/server/src/e2e/suite/signatureHelp.test.ts index bdc29435..524c8b01 100644 --- a/server/src/e2e/suite/signatureHelp.test.ts +++ b/server/src/e2e/suite/signatureHelp.test.ts @@ -18,6 +18,8 @@ suite("Signatures Test Suite", () => { this.editor.selection = new vscode.Selection(position, position) this.editor.revealRange(new vscode.Range(position, position)) + await this.editor.document.save() + return vscode.commands.executeCommand( "vscode.executeSignatureHelpProvider", this.document.uri, From 081a665b03857fefc8c61ecb24471b564b8c73cf Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 17:12:04 +0300 Subject: [PATCH 05/10] fix(test): trying to pass windows tests via timeout? --- server/src/e2e/suite/signatureHelp.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/e2e/suite/signatureHelp.test.ts b/server/src/e2e/suite/signatureHelp.test.ts index 524c8b01..6103b79d 100644 --- a/server/src/e2e/suite/signatureHelp.test.ts +++ b/server/src/e2e/suite/signatureHelp.test.ts @@ -18,7 +18,7 @@ suite("Signatures Test Suite", () => { this.editor.selection = new vscode.Selection(position, position) this.editor.revealRange(new vscode.Range(position, position)) - await this.editor.document.save() + await new Promise(resolve => setTimeout(resolve, 1000)) return vscode.commands.executeCommand( "vscode.executeSignatureHelpProvider", From 722a944a68c1b5ceea6e973250e49442a7f7d7c5 Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 17:25:28 +0300 Subject: [PATCH 06/10] test: Add test with Struct --- server/src/e2e/suite/signatureHelp.test.ts | 2 -- .../suite/testcases/signatures/contract.test | 20 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/server/src/e2e/suite/signatureHelp.test.ts b/server/src/e2e/suite/signatureHelp.test.ts index 6103b79d..bdc29435 100644 --- a/server/src/e2e/suite/signatureHelp.test.ts +++ b/server/src/e2e/suite/signatureHelp.test.ts @@ -18,8 +18,6 @@ suite("Signatures Test Suite", () => { this.editor.selection = new vscode.Selection(position, position) this.editor.revealRange(new vscode.Range(position, position)) - await new Promise(resolve => setTimeout(resolve, 1000)) - return vscode.commands.executeCommand( "vscode.executeSignatureHelpProvider", this.document.uri, diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test index cc49eab5..94652a92 100644 --- a/server/src/e2e/suite/testcases/signatures/contract.test +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -253,3 +253,23 @@ contract A { ------------------------------------------------------------------------ input: Int fun globalFunc(input: Int) + +======================================================================== +Struct Key +======================================================================== +primitive Int; +primitive String; + +struct Person { + age: Int; + name: String; +} + +contract Foo { + init() { + const userA = Person{age:,} + } +} +------------------------------------------------------------------------ +age: Int +Person{ age: Int, name: String } From 64087b58ca441a345600759e14b3fbdd6f11b0f0 Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 18:11:32 +0300 Subject: [PATCH 07/10] test: Add test with traits in contract --- .../e2e/suite/testcases/signatures/contract.test | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test index 94652a92..30c29671 100644 --- a/server/src/e2e/suite/testcases/signatures/contract.test +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -273,3 +273,19 @@ contract Foo { ------------------------------------------------------------------------ age: Int Person{ age: Int, name: String } + +======================================================================== +Use Contract with Trait +======================================================================== +trait Random { + abstract fun bar(a: Int): Bool; +} + +contract ContractA with Random { + fun test() { + self.bar(); + } +} +------------------------------------------------------------------------ +a: Int +fun bar(a: Int) From 4faa18e2a8f087c0d7028e710a6b8d2f554d69f8 Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 18:43:30 +0300 Subject: [PATCH 08/10] refator: split tests into files / add more tests and add coverage to .gitignore file --- .gitignore | 3 + .../suite/testcases/signatures/contract.test | 144 +----------------- .../suite/testcases/signatures/initOf.test | 59 +++++++ .../e2e/suite/testcases/signatures/map.test | 81 ++++++++++ .../suite/testcases/signatures/struct.test | 62 ++++++++ .../e2e/suite/testcases/signatures/trait.test | 47 ++++++ 6 files changed, 255 insertions(+), 141 deletions(-) create mode 100644 server/src/e2e/suite/testcases/signatures/initOf.test create mode 100644 server/src/e2e/suite/testcases/signatures/map.test create mode 100644 server/src/e2e/suite/testcases/signatures/struct.test create mode 100644 server/src/e2e/suite/testcases/signatures/trait.test diff --git a/.gitignore b/.gitignore index 7524e243..a0369ff1 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ yarn-error.log # eslint .eslintcache + +# coverage +coverage/ diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test index 30c29671..785322c1 100644 --- a/server/src/e2e/suite/testcases/signatures/contract.test +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -69,7 +69,7 @@ y: Int fun calculate(x: Int, y: Int, z: Int) ======================================================================== -Nested Function Calls +Nested Function Calls - 2 ======================================================================== primitive Int; @@ -87,8 +87,8 @@ contract Foo { } } ------------------------------------------------------------------------ -y: Int -fun calculate(x: Int, y: Int, z: Int) +x: Int +fun triple(x: Int) ======================================================================== Promt first arg while second is filled @@ -108,108 +108,6 @@ contract Foo { a: Int fun add(a: Int, b: Int) -======================================================================== -Set Map (Key) -======================================================================== -primitive Int; -extends mutates fun set(self: map, key: K, val: V); - -contract A { - init() { - let fizz: map = emptyMap(); - - fizz.set() - } -} ------------------------------------------------------------------------- -key: K -fun set(self: map, key: K, val: V) - -======================================================================== -Set Map (Value) -======================================================================== -primitive Int; -extends mutates fun set(self: map, key: K, val: V); - -contract A { - init() { - let fizz: map = emptyMap(); - - fizz.set(42, ) - } -} ------------------------------------------------------------------------- -val: V -fun set(self: map, key: K, val: V) - -======================================================================== -Get value from Map -======================================================================== -primitive Int; -extends fun get(self: map, key: K): V?; -contract A { - init() { - let fizz: map = emptyMap(); - - fizz.get(); - } -} ------------------------------------------------------------------------- -key: K -fun get(self: map, key: K) - -======================================================================== -Replace value map by key (caret on key) -======================================================================== -primitive Int; -extends mutates fun replace(self: map, key: K, val: V): Bool; -contract A { - init() { - let fizz: map = emptyMap(); - - fizz.replace() - } -} ------------------------------------------------------------------------- -key: K -fun replace(self: map, key: K, val: V) - -======================================================================== -Replace value map by key (caret on value) -======================================================================== -primitive Int; -extends mutates fun replace(self: map, key: K, val: V): Bool; -contract A { - init() { - let fizz: map = emptyMap(); - - fizz.replace(42, ) - } -} ------------------------------------------------------------------------- -val: V -fun replace(self: map, key: K, val: V) - -======================================================================== -External Contract Initialization -======================================================================== -primitive Int; - -contract ContractA { - init(a: Int) { - - } -} - -contract ContractB { - init() { - initOf ContractA() - } -} ------------------------------------------------------------------------- -a: Int -init(a: Int) - ======================================================================== Global function with Map ======================================================================== @@ -253,39 +151,3 @@ contract A { ------------------------------------------------------------------------ input: Int fun globalFunc(input: Int) - -======================================================================== -Struct Key -======================================================================== -primitive Int; -primitive String; - -struct Person { - age: Int; - name: String; -} - -contract Foo { - init() { - const userA = Person{age:,} - } -} ------------------------------------------------------------------------- -age: Int -Person{ age: Int, name: String } - -======================================================================== -Use Contract with Trait -======================================================================== -trait Random { - abstract fun bar(a: Int): Bool; -} - -contract ContractA with Random { - fun test() { - self.bar(); - } -} ------------------------------------------------------------------------- -a: Int -fun bar(a: Int) diff --git a/server/src/e2e/suite/testcases/signatures/initOf.test b/server/src/e2e/suite/testcases/signatures/initOf.test new file mode 100644 index 00000000..e9d5d7da --- /dev/null +++ b/server/src/e2e/suite/testcases/signatures/initOf.test @@ -0,0 +1,59 @@ +======================================================================== +initOf with one argument +======================================================================== +primitive Int; + +contract ContractA { + init(a: Int) { + + } +} + +contract ContractB { + init() { + initOf ContractA() + } +} +------------------------------------------------------------------------ +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() + } +} +------------------------------------------------------------------------ +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, ) + } +} +------------------------------------------------------------------------ +b: Int +init(a: Int, b: Int, c: Int) diff --git a/server/src/e2e/suite/testcases/signatures/map.test b/server/src/e2e/suite/testcases/signatures/map.test new file mode 100644 index 00000000..6d3fbb3b --- /dev/null +++ b/server/src/e2e/suite/testcases/signatures/map.test @@ -0,0 +1,81 @@ +======================================================================== +Set Map (Key) +======================================================================== +primitive Int; +extends mutates fun set(self: map, key: K, val: V); + +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.set() + } +} +------------------------------------------------------------------------ +key: K +fun set(self: map, key: K, val: V) + +======================================================================== +Set Map (Value) +======================================================================== +primitive Int; +extends mutates fun set(self: map, key: K, val: V); + +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.set(42, ) + } +} +------------------------------------------------------------------------ +val: V +fun set(self: map, key: K, val: V) + +======================================================================== +Get value from Map +======================================================================== +primitive Int; +extends fun get(self: map, key: K): V?; +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.get(); + } +} +------------------------------------------------------------------------ +key: K +fun get(self: map, key: K) + +======================================================================== +Replace value map by key (caret on key) +======================================================================== +primitive Int; +extends mutates fun replace(self: map, key: K, val: V): Bool; +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.replace() + } +} +------------------------------------------------------------------------ +key: K +fun replace(self: map, key: K, val: V) + +======================================================================== +Replace value map by key (caret on value) +======================================================================== +primitive Int; +extends mutates fun replace(self: map, key: K, val: V): Bool; +contract A { + init() { + let fizz: map = emptyMap(); + + fizz.replace(42, ) + } +} +------------------------------------------------------------------------ +val: V +fun replace(self: map, key: K, val: V) diff --git a/server/src/e2e/suite/testcases/signatures/struct.test b/server/src/e2e/suite/testcases/signatures/struct.test new file mode 100644 index 00000000..3b4d35ee --- /dev/null +++ b/server/src/e2e/suite/testcases/signatures/struct.test @@ -0,0 +1,62 @@ +======================================================================== +Struct Key +======================================================================== +primitive Int; +primitive String; + +struct Person { + age: Int; + name: String; +} + +contract Foo { + init() { + const userA = Person{age:,} + } +} +------------------------------------------------------------------------ +age: Int +Person{ age: Int, name: String } + +======================================================================== +Struct Key (second value) TODO: fix #252 +======================================================================== +primitive Int; +primitive String; + +struct Person { + age: Int; + name: String; +} + +contract Foo { + init() { + const userA = Person{age:42, name: } + } +} +------------------------------------------------------------------------ +name: String +Person{ age: Int, name: String } + +======================================================================== +Struct Multiline +======================================================================== +primitive Int; +primitive String; + +struct Person { + age: Int; + name: String; +} + +contract Foo { + init() { + const userA = Person{ + age:, + name: "A" + } + } +} +------------------------------------------------------------------------ +age: Int +Person{ age: Int, name: String } diff --git a/server/src/e2e/suite/testcases/signatures/trait.test b/server/src/e2e/suite/testcases/signatures/trait.test new file mode 100644 index 00000000..4dd3dd9d --- /dev/null +++ b/server/src/e2e/suite/testcases/signatures/trait.test @@ -0,0 +1,47 @@ +======================================================================== +Use Contract with Trait (1 argument) +======================================================================== +trait Random { + abstract fun bar(a: Int): Bool; +} + +contract ContractA with Random { + fun test() { + self.bar(); + } +} +------------------------------------------------------------------------ +a: Int +fun bar(a: Int) + +======================================================================== +Use Contract with Trait (2 argument) +======================================================================== +trait Random { + abstract fun bar(a: Int, b: Int): Bool; +} + +contract ContractA with Random { + fun test() { + self.bar(); + } +} +------------------------------------------------------------------------ +a: Int +fun bar(a: Int, b: Int) + +======================================================================== +Use Contract with Trait (2 argument, first filled) +======================================================================== +trait Random { + abstract fun bar(a: Int, b: Int): Bool; +} + +contract ContractA with Random { + fun test() { + self.bar(42, ); + } +} +------------------------------------------------------------------------ +b: Int +fun bar(a: Int, b: Int) From a912bc6da57530abb49c29ec67f9aa1aaf686eff Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:07:56 +0300 Subject: [PATCH 09/10] fix(test): use valid caret index in document --- server/src/e2e/suite/signatureHelp.test.ts | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/server/src/e2e/suite/signatureHelp.test.ts b/server/src/e2e/suite/signatureHelp.test.ts index bdc29435..bcaec755 100644 --- a/server/src/e2e/suite/signatureHelp.test.ts +++ b/server/src/e2e/suite/signatureHelp.test.ts @@ -6,22 +6,38 @@ import type {TestCase} from "./TestParser" suite("Signatures Test Suite", () => { const testSuite = new (class extends BaseTestSuite { public async getSignature(input: string): Promise { - const textWithoutCaret = input.replace("", "") - await this.replaceDocumentText(textWithoutCaret) + await this.editor.edit(builder => { + const fullRange = new vscode.Range( + this.document.lineAt(0).range.start, + this.document.lineAt(this.document.lineCount - 1).range.end, + ) + builder.delete(fullRange) + builder.insert(this.document.positionAt(0), input) + }) + + const editorText = this.document.getText() + const caretIndex = editorText.indexOf("") - const caretIndex = input.indexOf("") if (caretIndex === -1) { throw new Error("No 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)) + const caretPosition = this.document.positionAt(caretIndex) + + await this.editor.edit(builder => { + const caretRange = this.document.getWordRangeAtPosition(caretPosition, //) + if (caretRange) { + builder.delete(caretRange) + } + }) + + this.editor.selection = new vscode.Selection(caretPosition, caretPosition) + this.editor.revealRange(new vscode.Range(caretPosition, caretPosition)) return vscode.commands.executeCommand( "vscode.executeSignatureHelpProvider", this.document.uri, - position, + caretPosition, ) } From daa8d27164bd9bf89bb82c49274e347ac579cec0 Mon Sep 17 00:00:00 2001 From: xpyctumo <30053565+xpyctumo@users.noreply.github.com> Date: Mon, 17 Feb 2025 23:15:26 +0300 Subject: [PATCH 10/10] fix(test): remove debug info and fix test --- server/src/e2e/suite/signatureHelp.test.ts | 2 -- .../suite/testcases/signatures/contract.test | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server/src/e2e/suite/signatureHelp.test.ts b/server/src/e2e/suite/signatureHelp.test.ts index bcaec755..1454a2a9 100644 --- a/server/src/e2e/suite/signatureHelp.test.ts +++ b/server/src/e2e/suite/signatureHelp.test.ts @@ -44,8 +44,6 @@ suite("Signatures Test Suite", () => { 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) { diff --git a/server/src/e2e/suite/testcases/signatures/contract.test b/server/src/e2e/suite/testcases/signatures/contract.test index 785322c1..d10361a0 100644 --- a/server/src/e2e/suite/testcases/signatures/contract.test +++ b/server/src/e2e/suite/testcases/signatures/contract.test @@ -137,6 +137,24 @@ fun globalFunc(map: Map) ======================================================================== Global function with String ======================================================================== +primitive String; + +fun globalFunc(input: String): String { + return input; +} + +contract A { + init() { + globalFunc() + } +} +------------------------------------------------------------------------ +input: String +fun globalFunc(input: String) + +======================================================================== +Global function with Int +======================================================================== primitive Int; fun globalFunc(input: Int): Int {