-
Notifications
You must be signed in to change notification settings - Fork 2
/
matchers_test.go
40 lines (29 loc) · 943 Bytes
/
matchers_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
package quasar
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRegexMatcherCanMatch(t *testing.T) {
matcher := NewRegexMatcher("^(?i)(hi|hello|sup|hey), I'm (?P<name>(.*))$")
msg := Message{Payload: "hey, I'm Kyle"}
match := matcher.Match(msg)
assert.NotNil(t, match)
assert.Contains(t, match, "name")
assert.Equal(t, match["name"], "Kyle")
}
func TestRegexMatcherWillReturnNilForNoMatch(t *testing.T) {
matcher := NewRegexMatcher("^(?i)(hi|hello|sup|hey), I'm (?P<name>(.*))$")
msg := Message{Payload: "nonsense"}
match := matcher.Match(msg)
assert.Nil(t, match)
}
func TestRegexMatcherCanFindOneOutOfMany(t *testing.T) {
matcher := NewRegexMatcher(
"^(?i)hi, I'm (?P<name>(.*))$",
"^testing (?P<thing>(.*))$")
msg := Message{Payload: "testing something"}
match := matcher.Match(msg)
assert.NotNil(t, match)
assert.Contains(t, match, "thing")
assert.Equal(t, match["thing"], "something")
}