5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-02 23:02:19 +08:00

Fixed generated typescript type for []byte. (#701)

This commit is contained in:
Alexander Hudek 2021-05-01 23:08:49 -04:00 committed by GitHub
parent 6b919808c9
commit 0966c96ef0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 0 deletions

View File

@ -144,6 +144,8 @@ func goTypeToJSDocType(input string) string {
return "number"
case input == "bool":
return "boolean"
case input == "[]byte":
return "string"
case strings.HasPrefix(input, "[]"):
arrayType := goTypeToJSDocType(input[2:])
return "Array.<" + arrayType + ">"

View File

@ -0,0 +1,87 @@
package binding
import (
"testing"
)
func Test_goTypeToJSDocType(t *testing.T) {
tests := []struct {
name string
input string
want string
}{
{
name: "string",
input: "string",
want: "string",
},
{
name: "error",
input: "error",
want: "Error",
},
{
name: "int",
input: "int",
want: "number",
},
{
name: "int32",
input: "int32",
want: "number",
},
{
name: "uint",
input: "uint",
want: "number",
},
{
name: "uint32",
input: "uint32",
want: "number",
},
{
name: "float32",
input: "float32",
want: "number",
},
{
name: "float64",
input: "float64",
want: "number",
},
{
name: "bool",
input: "bool",
want: "boolean",
},
{
name: "[]byte",
input: "[]byte",
want: "string",
},
{
name: "[]int",
input: "[]int",
want: "Array.<number>",
},
{
name: "[]bool",
input: "[]bool",
want: "Array.<boolean>",
},
{
name: "anything else",
input: "foo",
want: "any",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := goTypeToJSDocType(tt.input); got != tt.want {
t.Errorf("goTypeToJSDocType() = %v, want %v", got, tt.want)
}
})
}
}