-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatcher.go
More file actions
68 lines (55 loc) · 1.18 KB
/
matcher.go
File metadata and controls
68 lines (55 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package sqlmock
import (
"reflect"
)
// anyArg marks a wildcard argument matcher.
type anyArg struct{}
// AnyArg returns a wildcard matcher that accepts any argument value.
func AnyArg() any {
return anyArg{}
}
type anyArgOf struct {
typ reflect.Type
}
// AnyArgOf returns a wildcard matcher that accepts values of type T.
//
// AnyArgOf[any]() is not supported because it cannot derive a concrete type;
// use AnyArg() for unconstrained wildcard matching.
func AnyArgOf[T any]() any {
var zero T
typ := reflect.TypeOf(zero)
if typ == nil {
panic("sqlmock: AnyArgOf[any]() is invalid, use AnyArg() instead")
}
return anyArgOf{
typ: typ,
}
}
// matchArgs compares expected and actual arguments with wildcard support.
func matchArgs(expected, actual []any) bool {
if len(expected) == 0 {
return true
}
if len(expected) != len(actual) {
return false
}
for i := range expected {
switch exp := expected[i].(type) {
case anyArg:
continue
case anyArgOf:
if actual[i] == nil {
return false
}
if reflect.TypeOf(actual[i]) != exp.typ {
return false
}
continue
default:
if expected[i] != actual[i] {
return false
}
}
}
return true
}