mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 07:09:54 +08:00

* include ts gen pref and suff in class fields * fix nested namespaces not prefixed * add basic unit test for parent child * test for diff namespaces imports * make entityReturn type func more generic * get full entity name for TS args list * fix failing test on empty struct * wire up gen tests * remove comment * remove redundant line
67 lines
1.5 KiB
Go
67 lines
1.5 KiB
Go
package binding_test
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/wailsapp/wails/v2/internal/binding"
|
|
"github.com/wailsapp/wails/v2/internal/logger"
|
|
)
|
|
|
|
type BindingTest struct {
|
|
name string
|
|
structs []interface{}
|
|
exemptions []interface{}
|
|
want string
|
|
shouldError bool
|
|
TsGenerationOptionsTest
|
|
}
|
|
|
|
type TsGenerationOptionsTest struct {
|
|
TsPrefix string
|
|
TsSuffix string
|
|
}
|
|
|
|
func TestBindings_GenerateModels(t *testing.T) {
|
|
|
|
tests := []BindingTest{
|
|
EscapedNameTest,
|
|
ImportedStructTest,
|
|
ImportedSliceTest,
|
|
ImportedMapTest,
|
|
NestedFieldTest,
|
|
NonStringMapKeyTest,
|
|
SingleFieldTest,
|
|
MultistructTest,
|
|
EmptyStructTest,
|
|
GeneratedJsEntityTest,
|
|
AnonymousSubStructTest,
|
|
AnonymousSubStructMultiLevelTest,
|
|
GeneratedJsEntityWithNestedStructTest,
|
|
EntityWithDiffNamespaces,
|
|
}
|
|
|
|
testLogger := &logger.Logger{}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
b := binding.NewBindings(testLogger, tt.structs, tt.exemptions, false)
|
|
for _, s := range tt.structs {
|
|
err := b.Add(s)
|
|
require.NoError(t, err)
|
|
}
|
|
b.SetTsPrefix(tt.TsPrefix)
|
|
b.SetTsSuffix(tt.TsSuffix)
|
|
got, err := b.GenerateModels()
|
|
if (err != nil) != tt.shouldError {
|
|
t.Errorf("GenerateModels() error = %v, shouldError %v", err, tt.shouldError)
|
|
return
|
|
}
|
|
if !reflect.DeepEqual(strings.Fields(string(got)), strings.Fields(tt.want)) {
|
|
t.Errorf("GenerateModels() got = %v, want %v", string(got), tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|