Skip to content

Commit 99d8ad7

Browse files
authored
Merge pull request #119 from xushiwei/q
x/test: MatchSlice
2 parents 188004b + 43ccd9a commit 99d8ad7

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

test/match.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ func toMapAny[T basetype](val map[string]T) map[string]any {
4040
return ret
4141
}
4242

43+
func toSlice(val []map[string]any) []any {
44+
ret := make([]any, len(val))
45+
for i, v := range val {
46+
ret[i] = v
47+
}
48+
return ret
49+
}
50+
4351
func toSliceAny[T basetype](val []map[string]T) []any {
4452
ret := make([]any, len(val))
4553
for i, v := range val {
@@ -129,7 +137,7 @@ func Gopt_Case_MatchMap(t CaseT, expected, got map[string]any, name ...string) {
129137
}
130138
}
131139

132-
func Gopt_Case_MatchSlice(t CaseT, expected, got []any, name ...string) {
140+
func Gopt_Case_MatchSlice[T any](t CaseT, expected []T, got []any, name ...string) {
133141
t.Helper()
134142
if len(expected) != len(got) {
135143
t.Fatalf("unmatched slice%s length - expected: %d, got: %d\n", nameCtx(name), len(expected), len(got))
@@ -287,6 +295,9 @@ retry:
287295
case *Var__3[[]string]:
288296
Gopt_Case_MatchBaseSlice(t, ev, gv.Val(), name...)
289297
return
298+
case []any:
299+
Gopt_Case_MatchSlice(t, ev, gv, name...)
300+
return
290301
}
291302
case TySet[string]:
292303
switch gv := got.(type) {
@@ -396,6 +407,9 @@ retry:
396407
expected = toMapAny(ev)
397408
goto retry
398409

410+
case []map[string]any:
411+
expected = toSlice(ev)
412+
goto retry
399413
case []map[string]string:
400414
expected = toSliceAny(ev)
401415
goto retry

0 commit comments

Comments
 (0)