2024-08-18 07:01:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2024-08-28 05:59:21 +00:00
|
|
|
func TestParseMethodTypes(t *testing.T) {
|
2024-08-18 07:01:49 +00:00
|
|
|
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{
|
2024-08-28 05:59:21 +00:00
|
|
|
input: "bool (QList<QPair<Foo, Bar>>, QString)",
|
|
|
|
expectReturn: CppParameter{ParameterType: "bool"},
|
|
|
|
expectParams: []CppParameter{
|
|
|
|
CppParameter{ParameterType: "QList<QPair<Foo, Bar>>"},
|
|
|
|
CppParameter{ParameterType: "QString"},
|
|
|
|
},
|
|
|
|
// expectErr: true,
|
|
|
|
},
|
|
|
|
testCase{
|
|
|
|
input: "bool (QList<QWidget*>)",
|
|
|
|
expectReturn: CppParameter{ParameterType: "bool"},
|
|
|
|
expectParams: []CppParameter{
|
|
|
|
CppParameter{ParameterType: "QList<QWidget*>"},
|
|
|
|
},
|
2024-08-19 07:11:19 +00:00
|
|
|
},
|
2024-08-18 07:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range cases {
|
2024-09-07 03:24:57 +00:00
|
|
|
r, p, _ /* isConst */, err := parseTypeString(tc.input)
|
2024-08-18 07:01:49 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-08-28 05:59:21 +00:00
|
|
|
|
|
|
|
func TestParseInnerListTypes(t *testing.T) {
|
|
|
|
l := parseSingleTypeString(`QList<QWidget*>`)
|
|
|
|
|
|
|
|
tok, ok := l.QListOf()
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
t.Fatal("expected QListOf")
|
|
|
|
}
|
|
|
|
|
|
|
|
if !tok.Pointer {
|
|
|
|
t.Error("expected pointer")
|
|
|
|
}
|
|
|
|
|
|
|
|
if tok.ParameterType != "QWidget" {
|
|
|
|
t.Errorf("expected QWidget, got %q", tok.ParameterType)
|
|
|
|
}
|
|
|
|
}
|
2024-08-28 06:22:05 +00:00
|
|
|
|
|
|
|
func TestPointerDepth(t *testing.T) {
|
|
|
|
for _, testCase := range []string{`char**`, `char * *`} {
|
|
|
|
l := parseSingleTypeString(testCase)
|
|
|
|
if l.ParameterType != "char" {
|
|
|
|
t.Error("expected char")
|
|
|
|
}
|
|
|
|
if !l.Pointer {
|
|
|
|
t.Error("expected pointer")
|
|
|
|
}
|
|
|
|
if l.PointerCount != 2 {
|
|
|
|
t.Errorf("expected pointerCount=2, got %d", l.PointerCount)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|