diff --git a/cmd/genbindings/clang2il.go b/cmd/genbindings/clang2il.go index 6883e2b6..bf3147ce 100644 --- a/cmd/genbindings/clang2il.go +++ b/cmd/genbindings/clang2il.go @@ -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])) diff --git a/cmd/genbindings/clang2il_test.go b/cmd/genbindings/clang2il_test.go new file mode 100644 index 00000000..6c2d32f2 --- /dev/null +++ b/cmd/genbindings/clang2il_test.go @@ -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) + } + } +}