fix(goctl): dart gen user defined struct array (#1620)

This commit is contained in:
Fyn
2022-03-07 14:11:47 +08:00
committed by GitHub
parent 68a81fea8a
commit 365c569d7c
3 changed files with 38 additions and 5 deletions

View File

@@ -37,3 +37,35 @@ func Test_getPropertyFromMember(t *testing.T) {
})
}
}
func Test_specTypeToDart(t *testing.T) {
tests := []struct {
name string
specType spec.Type
want string
wantErr bool
}{
{
name: "[]string should return List<String>",
specType: spec.ArrayType{RawName: "[]string", Value: spec.PrimitiveType{RawName: "string"}},
want: "List<String>",
},
{
name: "[]Foo should return List<Foo>",
specType: spec.ArrayType{RawName: "[]Foo", Value: spec.DefineStruct{RawName: "Foo"}},
want: "List<Foo>",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := specTypeToDart(tt.specType)
if (err != nil) != tt.wantErr {
t.Errorf("specTypeToDart() error = %v, wantErr %v", err, tt.wantErr)
return
}
if got != tt.want {
t.Errorf("specTypeToDart() = %v, want %v", got, tt.want)
}
})
}
}