forked from maksymgaraiev/orwell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch_test.go
More file actions
37 lines (35 loc) · 796 Bytes
/
match_test.go
File metadata and controls
37 lines (35 loc) · 796 Bytes
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
package orwell
import (
"regexp"
"testing"
)
func TestApplyMatch(t *testing.T) {
r := &match{regexp: regexp.MustCompile("^te[s]t"), msg: "Regexp test"}
t.Run("Nil value", func(t *testing.T) {
if err := r.Apply(nil); err != nil {
t.Error("Expected valid")
}
})
t.Run("Valid string", func(t *testing.T) {
if err := r.Apply("test"); err != nil {
t.Error("Expected valid")
}
})
t.Run("Invalid string", func(t *testing.T) {
if err := r.Apply(" tet"); err == nil {
t.Error("Expected error")
}
})
t.Run("Valid Pointer", func(t *testing.T) {
s := "test2"
if err := r.Apply(&s); err != nil {
t.Error("Expected valid")
}
})
t.Run("Invalid Pointer", func(t *testing.T) {
s := "2test"
if err := r.Apply(&s); err == nil {
t.Error("Expected error")
}
})
}