From a7a4341f79c449303ca5254b1d784e75012bd94d Mon Sep 17 00:00:00 2001 From: Gjergji Ramku Date: Fri, 17 May 2024 10:32:54 +0200 Subject: [PATCH] Special chars bindings unit tests (#3485) * JSON fields that start with special characters generate wrong typescript bindings * Update changelong --- .../binding/binding_test/binding_test.go | 1 + .../binding_variablespecialcharacter_test.go | 32 +++++++++++++++++++ website/src/pages/changelog.mdx | 1 + 3 files changed, 34 insertions(+) create mode 100644 v2/internal/binding/binding_test/binding_variablespecialcharacter_test.go diff --git a/v2/internal/binding/binding_test/binding_test.go b/v2/internal/binding/binding_test/binding_test.go index 6d643b92d..947c3b08a 100644 --- a/v2/internal/binding/binding_test/binding_test.go +++ b/v2/internal/binding/binding_test/binding_test.go @@ -48,6 +48,7 @@ func TestBindings_GenerateModels(t *testing.T) { AnonymousSubStructMultiLevelTest, GeneratedJsEntityWithNestedStructTest, EntityWithDiffNamespaces, + SpecialCharacterFieldTest, } testLogger := &logger.Logger{} diff --git a/v2/internal/binding/binding_test/binding_variablespecialcharacter_test.go b/v2/internal/binding/binding_test/binding_variablespecialcharacter_test.go new file mode 100644 index 000000000..7dbe72350 --- /dev/null +++ b/v2/internal/binding/binding_test/binding_variablespecialcharacter_test.go @@ -0,0 +1,32 @@ +package binding_test + +type SpecialCharacterField struct { + ID string `json:"@ID,omitempty"` +} + +func (s SpecialCharacterField) Get() SpecialCharacterField { + return s +} + +var SpecialCharacterFieldTest = BindingTest{ + name: "SpecialCharacterField", + structs: []interface{}{ + &SpecialCharacterField{}, + }, + exemptions: nil, + shouldError: false, + want: ` +export namespace binding_test { + export class SpecialCharacterField { + "@ID"?: string; + static createFrom(source: any = {}) { + return new SpecialCharacterField(source); + } + constructor(source: any = {}) { + if ('string' === typeof source) source = JSON.parse(source); + this["@ID"] = source["@ID"]; + } + } +} +`, +} diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index facd68f39..58a63d837 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Support for compiling with `libwebkit2gtk-4.1` instead of `4.0` to support latest Ubuntu release by [atterpac](https://github.com/atterpac) in [#3465](https://github.com/wailsapp/wails/pull/3465) +- Unit test for fix [#3476](https://github.com/wailsapp/wails/pull/3476) by [gjergj](https://github.com/Gjergj) in [#3485](https://github.com/wailsapp/wails/pull/3485) ### Changed - Updated several broken links in the "How Does It Work?" page on the website. Changed by [@oguz-yilmaz](https://github.com/oguz-yilmaz) in [PR #3469](https://github.com/wailsapp/wails/pull/3469)