diff --git a/v3/examples/plain/main.go b/v3/examples/plain/main.go index 42cf49b49..9a965e485 100644 --- a/v3/examples/plain/main.go +++ b/v3/examples/plain/main.go @@ -17,7 +17,7 @@ func main() { }, }) // Create window - app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ + myWindow := app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{ Title: "Plain Bundle", CSS: `body { background-color: rgba(255, 255, 255, 0); font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif; user-select: none; -ms-user-select: none; -webkit-user-select: none; } .main { color: white; margin: 20%; }`, Mac: application.MacWindow{ @@ -25,7 +25,6 @@ func main() { Backdrop: application.MacBackdropTranslucent, TitleBar: application.MacTitleBarHiddenInsetUnified, }, - URL: "/", Assets: application.AssetOptions{ Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { diff --git a/v3/internal/parser/parser.go b/v3/internal/parser/parser.go index a9ddab3f2..5c8a4c617 100644 --- a/v3/internal/parser/parser.go +++ b/v3/internal/parser/parser.go @@ -295,8 +295,6 @@ func (p *Project) parseBoundStructMethods(name string, pkg *ParsedPackage) error method := &BoundMethod{ Name: funcDecl.Name.Name, DocComment: funcDecl.Doc.Text(), - Inputs: make([]*Parameter, 0), - Outputs: make([]*Parameter, 0), } if funcDecl.Type.Params != nil { diff --git a/v3/internal/parser/parser_external_packages_test.go b/v3/internal/parser/parser_external_packages_test.go new file mode 100644 index 000000000..9e0970147 --- /dev/null +++ b/v3/internal/parser/parser_external_packages_test.go @@ -0,0 +1,28 @@ +package parser + +import ( + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestExternalPackages(t *testing.T) { + tests := []struct { + name string + dir string + wantBoundMethods map[string]map[string][]*BoundMethod + wantErr bool + }{} + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got, err := ParseProject(tt.dir) + if (err != nil) != tt.wantErr { + t.Errorf("ParseDirectory() error = %v, wantErr %v", err, tt.wantErr) + return + } + if diff := cmp.Diff(tt.wantBoundMethods, got.BoundMethods); diff != "" { + t.Errorf("ParseDirectory() failed:\n" + diff) + } + }) + } +} diff --git a/v3/internal/parser/parser_types_test.go b/v3/internal/parser/parser_types_test.go index 0a49be04c..3c4c144c6 100644 --- a/v3/internal/parser/parser_types_test.go +++ b/v3/internal/parser/parser_types_test.go @@ -738,7 +738,6 @@ func TestParseDirectory(t *testing.T) { }, }, }, - Outputs: []*Parameter{}, }, { Name: "PointerMapIntInt", @@ -757,7 +756,6 @@ func TestParseDirectory(t *testing.T) { }, }, }, - Outputs: []*Parameter{}, }, { Name: "MapIntPointerInt", @@ -776,7 +774,6 @@ func TestParseDirectory(t *testing.T) { }, }, }, - Outputs: []*Parameter{}, }, { Name: "MapIntSliceInt", @@ -795,7 +792,6 @@ func TestParseDirectory(t *testing.T) { }, }, }, - Outputs: []*Parameter{}, }, { Name: "MapIntSliceIntInMapIntSliceIntOut", @@ -841,25 +837,84 @@ func TestParseDirectory(t *testing.T) { }, }, }, - Outputs: []*Parameter{}, }, }, }, }, wantErr: false, }, - //{ - // name: "should find multiple bound services", - // dir: "testdata/struct_literal_multiple", - // //wantModels: []string{"main.GreetService", "main.OtherService"}, - // wantErr: false, - //}, - //{ - // name: "should find multiple bound services over multiple files", - // dir: "testdata/struct_literal_multiple_files", - // //wantModels: []string{"main.GreetService", "main.OtherService"}, - // wantErr: false, - //}, + { + name: "should find multiple bound services", + dir: "testdata/struct_literal_multiple", + wantBoundMethods: map[string]map[string][]*BoundMethod{ + "main": { + "GreetService": { + { + Name: "Greet", + DocComment: "", + Inputs: []*Parameter{ + { + Name: "name", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + }, + }, + "OtherService": { + { + Name: "Hello", + }, + }, + }, + }, + wantErr: false, + }, + { + name: "should find multiple bound services over multiple files", + dir: "testdata/struct_literal_multiple_files", + wantBoundMethods: map[string]map[string][]*BoundMethod{ + "main": { + "GreetService": { + { + Name: "Greet", + DocComment: "", + Inputs: []*Parameter{ + { + Name: "name", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + Outputs: []*Parameter{ + { + Name: "", + Type: &ParameterType{ + Name: "string", + }, + }, + }, + }, + }, + "OtherService": { + { + Name: "Hello", + }, + }, + }, + }, + wantErr: false, + }, //{ // name: "should find multiple bound services over multiple packages", // dir: "testdata/struct_literal_multiple_other", diff --git a/v3/internal/parser/testdata/struct_literal_multiple/main.go b/v3/internal/parser/testdata/struct_literal_multiple/main.go index 125aad612..fb555d79f 100644 --- a/v3/internal/parser/testdata/struct_literal_multiple/main.go +++ b/v3/internal/parser/testdata/struct_literal_multiple/main.go @@ -20,6 +20,8 @@ type OtherService struct { t int } +func (o *OtherService) Hello() {} + func main() { app := application.New(application.Options{ Bind: []interface{}{ diff --git a/v3/internal/parser/testdata/struct_literal_multiple_files/other.go b/v3/internal/parser/testdata/struct_literal_multiple_files/other.go index c6e16377f..ad5e661ef 100644 --- a/v3/internal/parser/testdata/struct_literal_multiple_files/other.go +++ b/v3/internal/parser/testdata/struct_literal_multiple_files/other.go @@ -3,3 +3,5 @@ package main type OtherService struct { t int } + +func (o *OtherService) Hello() {}