genbindings/test: add simple TestParseTypeString() test case

This commit is contained in:
mappu 2024-08-18 19:01:49 +12:00
parent b3d55cc17f
commit 3ef53b4224
2 changed files with 40 additions and 1 deletions

View File

@ -404,7 +404,7 @@ func parseTypeString(typeString string) (CppParameter, []CppParameter, error) {
epos := strings.LastIndex(typeString, `)`)
if opos == -1 || epos == -1 {
return CppParameter{}, nil, fmt.Errorf("Type string %q missing brackets")
return CppParameter{}, nil, fmt.Errorf("Type string %q missing brackets", typeString)
}
returnType := parseSingleTypeString(strings.TrimSpace(typeString[0:opos]))

View File

@ -0,0 +1,39 @@
package main
import (
"reflect"
"testing"
)
func TestParseTypeString(t *testing.T) {
type testCase struct {
input string
expectReturn CppParameter
expectParams []CppParameter
}
cases := []testCase{
testCase{
input: "void (bool)",
expectReturn: CppParameter{ParameterType: "void"},
expectParams: []CppParameter{
CppParameter{ParameterType: "bool"},
},
},
}
for _, tc := range cases {
r, p, err := parseTypeString(tc.input)
if err != nil {
t.Errorf("Test %q got error %v", tc.input, err)
continue
}
if !reflect.DeepEqual(r, tc.expectReturn) {
t.Errorf("Test %q got return=%#v, expected=%#v", tc.input, r, tc.expectReturn)
}
if !reflect.DeepEqual(p, tc.expectParams) {
t.Errorf("Test %q got return=%#v, expected=%#v", tc.input, r, tc.expectReturn)
}
}
}