mirror of
https://github.com/wailsapp/wails.git
synced 2026-03-15 07:05:50 +01:00
* enumsort: enumsort * enumsort: update changelog * Add tests for enum ordering fix Tests added: - EnumOrderingTest: Verifies multiple enums are output in alphabetical order - EnumElementOrderingTest: Verifies enum elements are sorted by TSName - TSNameEnumElementOrderingTest: Verifies TSName() interface enums are also sorted 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Lea Anthony <lea.anthony@gmail.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
85 lines
2 KiB
Go
85 lines
2 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{}
|
|
enums []interface{}
|
|
exemptions []interface{}
|
|
want string
|
|
shouldError bool
|
|
TsGenerationOptionsTest
|
|
}
|
|
|
|
type TsGenerationOptionsTest struct {
|
|
TsPrefix string
|
|
TsSuffix string
|
|
TsOutputType string
|
|
}
|
|
|
|
func TestBindings_GenerateModels(t *testing.T) {
|
|
|
|
tests := []BindingTest{
|
|
EscapedNameTest,
|
|
ImportedStructTest,
|
|
ImportedSliceTest,
|
|
ImportedMapTest,
|
|
ImportedEnumTest,
|
|
NestedFieldTest,
|
|
NonStringMapKeyTest,
|
|
SingleFieldTest,
|
|
MultistructTest,
|
|
EmptyStructTest,
|
|
GeneratedJsEntityTest,
|
|
GeneratedJsEntityWithIntEnumTest,
|
|
GeneratedJsEntityWithStringEnumTest,
|
|
GeneratedJsEntityWithEnumTsName,
|
|
GeneratedJsEntityWithNestedStructInterfacesTest,
|
|
AnonymousSubStructTest,
|
|
AnonymousSubStructMultiLevelTest,
|
|
GeneratedJsEntityWithNestedStructTest,
|
|
EntityWithDiffNamespacesTest,
|
|
SpecialCharacterFieldTest,
|
|
WithoutFieldsTest,
|
|
NoFieldTagsTest,
|
|
Generics1Test,
|
|
Generics2Test,
|
|
IgnoredTest,
|
|
DeepElementsTest,
|
|
// PR #4664: Enum ordering tests
|
|
EnumOrderingTest,
|
|
EnumElementOrderingTest,
|
|
TSNameEnumElementOrderingTest,
|
|
}
|
|
|
|
testLogger := &logger.Logger{}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
b := binding.NewBindings(testLogger, tt.structs, tt.exemptions, false, tt.enums)
|
|
for _, s := range tt.structs {
|
|
err := b.Add(s)
|
|
require.NoError(t, err)
|
|
}
|
|
b.SetTsPrefix(tt.TsPrefix)
|
|
b.SetTsSuffix(tt.TsSuffix)
|
|
b.SetOutputType(tt.TsOutputType)
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
}
|