Skip to content

Commit 4aeb967

Browse files
authored
Merge pull request #2 from aalmog333/feature/new-matcher-some
add new matcher some
2 parents 8c8317b + 037aa8e commit 4aeb967

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

matcher/some.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package matcher
2+
3+
import (
4+
"github.com/riid/messenger"
5+
)
6+
7+
func Some(matchers ...messenger.Matcher) messenger.Matcher {
8+
return MatchFunc(
9+
func(e messenger.Envelope) bool {
10+
for _, m := range matchers {
11+
if m.Matches(e) {
12+
return true
13+
}
14+
}
15+
16+
return false
17+
},
18+
)
19+
}

matcher/some_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package matcher
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
8+
"github.com/riid/messenger"
9+
"github.com/riid/messenger/envelope"
10+
)
11+
12+
func TestSome(t *testing.T) {
13+
positive := &matcherStub{true}
14+
negative := &matcherStub{false}
15+
e := envelope.FromMessage([]byte{})
16+
17+
type testCase struct {
18+
matchers []messenger.Matcher
19+
expected bool
20+
}
21+
22+
suite := map[string]testCase{
23+
"no matchers": {
24+
expected: false,
25+
},
26+
"all positive matchers": {
27+
matchers: []messenger.Matcher{
28+
positive,
29+
positive,
30+
},
31+
expected: true,
32+
},
33+
"all negative matchers": {
34+
matchers: []messenger.Matcher{
35+
negative,
36+
negative,
37+
},
38+
expected: false,
39+
},
40+
"one negative matcher": {
41+
matchers: []messenger.Matcher{
42+
positive,
43+
negative,
44+
positive,
45+
},
46+
expected: true,
47+
},
48+
}
49+
50+
for name, tc := range suite {
51+
tc := tc
52+
t.Run(
53+
name, func(t *testing.T) {
54+
t.Parallel()
55+
56+
m := Some(tc.matchers...)
57+
assert.Equal(t, tc.expected, m.Matches(e))
58+
},
59+
)
60+
}
61+
}

0 commit comments

Comments
 (0)