diff --git a/v3/internal/parser/bindings_test.go b/v3/internal/parser/bindings_test.go index 6d91460be..7907ae36f 100644 --- a/v3/internal/parser/bindings_test.go +++ b/v3/internal/parser/bindings_test.go @@ -2,11 +2,12 @@ package parser import ( "embed" - "github.com/google/go-cmp/cmp" "io/fs" "os" "path/filepath" "testing" + + "github.com/google/go-cmp/cmp" ) //go:embed testdata @@ -623,6 +624,48 @@ func TestGenerateBindings(t *testing.T) { useIDs: false, useTypescript: true, }, + { + name: "function_single_context", + dir: "testdata/function_single_context", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_single_context/frontend/bindings/main/GreetService.js"), + }, + }, + useIDs: true, + }, + { + name: "function_single_context", + dir: "testdata/function_single_context", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_single_context/frontend/bindings/main/GreetService.name.js"), + }, + }, + useIDs: false, + }, + { + name: "function single - Typescript - CallByID", + dir: "testdata/function_single_context", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_single_context/frontend/bindings/main/GreetService.ts"), + }, + }, + useIDs: true, + useTypescript: true, + }, + { + name: "function single - Typescript - CallByName", + dir: "testdata/function_single_context", + want: map[string]map[string]string{ + "main": { + "GreetService": getFile("testdata/function_single_context/frontend/bindings/main/GreetService.name.ts"), + }, + }, + useIDs: false, + useTypescript: true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js index 755148ee4..6e4ed88f9 100644 --- a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js +++ b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.js @@ -13,13 +13,3 @@ import {Call} from '@wailsio/runtime'; export async function Greet(name) { return Call.ByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); } - -/** - * Greet someone - * @function GreetWithContext - * @param name {string} - * @returns {Promise} - **/ -export async function GreetWithContext(name) { - return Call.ByID(1310150960, ...Array.prototype.slice.call(arguments, 0)); -} diff --git a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js index e08e79d39..020458d0b 100644 --- a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js +++ b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.js @@ -13,13 +13,3 @@ import {Call} from '@wailsio/runtime'; export async function Greet(name) { return Call.ByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); } - -/** - * Greet someone - * @function GreetWithContext - * @param name {string} - * @returns {Promise} - **/ -export async function GreetWithContext(name) { - return Call.ByName("main.GreetService.GreetWithContext", ...Array.prototype.slice.call(arguments, 0)); -} diff --git a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.ts b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.ts index 3e3d1aa9e..e7884a90c 100644 --- a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.ts +++ b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.name.ts @@ -7,8 +7,3 @@ export async function Greet(name: string) : Promise { return Call.ByName("main.GreetService.Greet", name); } -// Greet someone -export async function GreetWithContext(name: string) : Promise { - return Call.ByName("main.GreetService.GreetWithContext", name); -} - diff --git a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.ts b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.ts index a252570c5..497e17d2b 100644 --- a/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.ts +++ b/v3/internal/parser/testdata/function_single/frontend/bindings/main/GreetService.ts @@ -7,8 +7,3 @@ export async function Greet(name: string) : Promise { return Call.ByID(1411160069, name); } -// Greet someone -export async function GreetWithContext(name: string) : Promise { - return Call.ByID(1310150960, name); -} - diff --git a/v3/internal/parser/testdata/function_single/main.go b/v3/internal/parser/testdata/function_single/main.go index c42e1c871..8bb48f4e2 100644 --- a/v3/internal/parser/testdata/function_single/main.go +++ b/v3/internal/parser/testdata/function_single/main.go @@ -1,7 +1,6 @@ package main import ( - "context" _ "embed" "log" @@ -19,11 +18,6 @@ func (*GreetService) Greet(name string) string { return "Hello " + name } -// Greet someone -func (*GreetService) GreetWithContext(ctx context.Context, name string) string { - return "Hello " + name -} - func NewGreetService() *GreetService { return &GreetService{} } diff --git a/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.js b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.js new file mode 100644 index 000000000..755148ee4 --- /dev/null +++ b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.js @@ -0,0 +1,25 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {Call} from '@wailsio/runtime'; + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export async function Greet(name) { + return Call.ByID(1411160069, ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * Greet someone + * @function GreetWithContext + * @param name {string} + * @returns {Promise} + **/ +export async function GreetWithContext(name) { + return Call.ByID(1310150960, ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.name.js b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.name.js new file mode 100644 index 000000000..e08e79d39 --- /dev/null +++ b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.name.js @@ -0,0 +1,25 @@ +// @ts-check +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {Call} from '@wailsio/runtime'; + +/** + * Greet someone + * @function Greet + * @param name {string} + * @returns {Promise} + **/ +export async function Greet(name) { + return Call.ByName("main.GreetService.Greet", ...Array.prototype.slice.call(arguments, 0)); +} + +/** + * Greet someone + * @function GreetWithContext + * @param name {string} + * @returns {Promise} + **/ +export async function GreetWithContext(name) { + return Call.ByName("main.GreetService.GreetWithContext", ...Array.prototype.slice.call(arguments, 0)); +} diff --git a/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.name.ts b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.name.ts new file mode 100644 index 000000000..3e3d1aa9e --- /dev/null +++ b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.name.ts @@ -0,0 +1,14 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {Call} from '@wailsio/runtime'; +// Greet someone +export async function Greet(name: string) : Promise { + return Call.ByName("main.GreetService.Greet", name); +} + +// Greet someone +export async function GreetWithContext(name: string) : Promise { + return Call.ByName("main.GreetService.GreetWithContext", name); +} + diff --git a/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.ts b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.ts new file mode 100644 index 000000000..a252570c5 --- /dev/null +++ b/v3/internal/parser/testdata/function_single_context/frontend/bindings/main/GreetService.ts @@ -0,0 +1,14 @@ +// Cynhyrchwyd y ffeil hon yn awtomatig. PEIDIWCH Â MODIWL +// This file is automatically generated. DO NOT EDIT + +import {Call} from '@wailsio/runtime'; +// Greet someone +export async function Greet(name: string) : Promise { + return Call.ByID(1411160069, name); +} + +// Greet someone +export async function GreetWithContext(name: string) : Promise { + return Call.ByID(1310150960, name); +} + diff --git a/v3/internal/parser/testdata/function_single_context/main.go b/v3/internal/parser/testdata/function_single_context/main.go new file mode 100644 index 000000000..c42e1c871 --- /dev/null +++ b/v3/internal/parser/testdata/function_single_context/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "context" + _ "embed" + "log" + + "github.com/wailsapp/wails/v3/pkg/application" +) + +// GreetService is great +type GreetService struct { + SomeVariable int + lowerCase string +} + +// Greet someone +func (*GreetService) Greet(name string) string { + return "Hello " + name +} + +// Greet someone +func (*GreetService) GreetWithContext(ctx context.Context, name string) string { + return "Hello " + name +} + +func NewGreetService() *GreetService { + return &GreetService{} +} + +func main() { + app := application.New(application.Options{ + Bind: []interface{}{ + NewGreetService(), + }, + }) + + app.NewWebviewWindow() + + err := app.Run() + + if err != nil { + log.Fatal(err) + } + +}