Skip to content

Commit 188004b

Browse files
authored
Merge pull request #118 from xushiwei/q
x/test: fallback type []map[string]string
2 parents 847a6b0 + c192cf2 commit 188004b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

test/match.go

Lines changed: 12 additions & 0 deletions
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 toSliceAny[T basetype](val []map[string]T) []any {
44+
ret := make([]any, len(val))
45+
for i, v := range val {
46+
ret[i] = toMapAny(v)
47+
}
48+
return ret
49+
}
50+
4351
func tryToMapAny(val any) (ret map[string]any, ok bool) {
4452
v := reflect.ValueOf(val)
4553
return castMapAny(v)
@@ -388,6 +396,10 @@ retry:
388396
expected = toMapAny(ev)
389397
goto retry
390398

399+
case []map[string]string:
400+
expected = toSliceAny(ev)
401+
goto retry
402+
391403
// other types:
392404
default:
393405
if v, ok := tryToMapAny(expected); ok {

0 commit comments

Comments
 (0)