2024-08-18 07:01:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseTypeString(t *testing.T) {
|
|
|
|
type testCase struct {
|
|
|
|
input string
|
|
|
|
expectReturn CppParameter
|
|
|
|
expectParams []CppParameter
|
2024-08-19 07:11:19 +00:00
|
|
|
expectErr bool
|
2024-08-18 07:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cases := []testCase{
|
|
|
|
testCase{
|
|
|
|
input: "void (bool)",
|
|
|
|
expectReturn: CppParameter{ParameterType: "void"},
|
|
|
|
expectParams: []CppParameter{
|
|
|
|
CppParameter{ParameterType: "bool"},
|
|
|
|
},
|
|
|
|
},
|
2024-08-19 07:11:19 +00:00
|
|
|
testCase{
|
|
|
|
input: "bool (QList<QPair<Foo, Bar>>, QString)",
|
|
|
|
/*
|
|
|
|
expectReturn: CppParameter{ParameterType: "bool"},
|
|
|
|
expectParams: []CppParameter{
|
|
|
|
CppParameter{ParameterType: "QList<QPair<Foo, Bar>>"},
|
|
|
|
CppParameter{ParameterType: "QString"},
|
|
|
|
},
|
|
|
|
*/
|
|
|
|
expectErr: true,
|
|
|
|
},
|
2024-08-18 07:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
|
|
|
r, p, err := parseTypeString(tc.input)
|
|
|
|
|
2024-08-19 07:11:19 +00:00
|
|
|
if tc.expectErr {
|
|
|
|
if err == nil {
|
|
|
|
t.Errorf("Test %q got error=nil but it was expected to fail", tc.input)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Test %q got error %v", tc.input, err)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if !reflect.DeepEqual(r, tc.expectReturn) {
|
|
|
|
t.Errorf("Test %q\n-got return=%#v\n-expected =%#v", tc.input, r, tc.expectReturn)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(p, tc.expectParams) {
|
|
|
|
t.Errorf("Test %q\n-got params=%#v\n-expected =%#v", tc.input, p, tc.expectParams)
|
|
|
|
}
|
2024-08-18 07:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|