This repository has been archived by the owner on Oct 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatcher_test.go
69 lines (63 loc) · 1.76 KB
/
matcher_test.go
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
69
package charmset
import (
"testing"
"github.com/sammiq/charmset/internal"
)
func Test_and(t *testing.T) {
tests := []struct {
name string
firstMatch bool
secondMatch bool
shouldMatch bool
}{
{"should not match if both do not match", false, false, false},
{"should not match if first does not match", true, false, false},
{"not match if second does not match", false, true, false},
{"should match if both match", true, true, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
first := &internal.MockMatcher{Matches: tt.firstMatch}
second := &internal.MockMatcher{Matches: tt.secondMatch}
err := and(first, second, 42)
if tt.shouldMatch {
if err != nil {
t.Errorf("expected no error from %v and %v", tt.firstMatch, tt.secondMatch)
}
} else {
if err == nil {
t.Errorf("expected error from %v and %v", tt.firstMatch, tt.secondMatch)
}
}
})
}
}
func Test_or(t *testing.T) {
tests := []struct {
name string
firstMatch bool
secondMatch bool
shouldMatch bool
}{
{"should not match if both do not match", false, false, false},
{"should not match if first does not match", true, false, true},
{"not match if second does not match", false, true, true},
{"should match if both match", true, true, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
first := &internal.MockMatcher{Matches: tt.firstMatch}
second := &internal.MockMatcher{Matches: tt.secondMatch}
err := or(first, second, 42)
if tt.shouldMatch {
if err != nil {
t.Errorf("expected no error from %v or %v", tt.firstMatch, tt.secondMatch)
}
} else {
if err == nil {
t.Errorf("expected error from %v or %v", tt.firstMatch, tt.secondMatch)
}
}
})
}
}