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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
// SPDX-License-Identifier: GPL-3.0-or-later
package matcher
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestTRUE(t *testing.T) {
assert.True(t, TRUE().Match(nil))
assert.True(t, TRUE().MatchString(""))
}
func TestFALSE(t *testing.T) {
assert.False(t, FALSE().Match(nil))
assert.False(t, FALSE().MatchString(""))
}
func TestAnd(t *testing.T) {
assert.Equal(t,
matcherF,
And(FALSE(), stringFullMatcher("")))
assert.Equal(t,
matcherF,
And(stringFullMatcher(""), FALSE()))
assert.Equal(t,
stringFullMatcher(""),
And(TRUE(), stringFullMatcher("")))
assert.Equal(t,
stringFullMatcher(""),
And(stringFullMatcher(""), TRUE()))
assert.Equal(t,
andMatcher{stringPartialMatcher("a"), stringPartialMatcher("b")},
And(stringPartialMatcher("a"), stringPartialMatcher("b")))
assert.Equal(t,
andMatcher{
andMatcher{stringPartialMatcher("a"), stringPartialMatcher("b")},
stringPartialMatcher("c"),
},
And(stringPartialMatcher("a"), stringPartialMatcher("b"), stringPartialMatcher("c")))
}
func TestOr(t *testing.T) {
assert.Equal(t,
stringFullMatcher(""),
Or(FALSE(), stringFullMatcher("")))
assert.Equal(t,
stringFullMatcher(""),
Or(stringFullMatcher(""), FALSE()))
assert.Equal(t,
TRUE(),
Or(TRUE(), stringFullMatcher("")))
assert.Equal(t,
TRUE(),
Or(stringFullMatcher(""), TRUE()))
assert.Equal(t,
orMatcher{stringPartialMatcher("a"), stringPartialMatcher("b")},
Or(stringPartialMatcher("a"), stringPartialMatcher("b")))
assert.Equal(t,
orMatcher{
orMatcher{stringPartialMatcher("a"), stringPartialMatcher("b")},
stringPartialMatcher("c"),
},
Or(stringPartialMatcher("a"), stringPartialMatcher("b"), stringPartialMatcher("c")))
}
func TestAndMatcher_Match(t *testing.T) {
and := andMatcher{
stringPrefixMatcher("a"),
stringSuffixMatcher("c"),
}
assert.True(t, and.Match([]byte("abc")))
assert.True(t, and.MatchString("abc"))
}
func TestOrMatcher_Match(t *testing.T) {
or := orMatcher{
stringPrefixMatcher("a"),
stringPrefixMatcher("c"),
}
assert.True(t, or.Match([]byte("aaa")))
assert.True(t, or.MatchString("ccc"))
}
func TestNegMatcher_Match(t *testing.T) {
neg := negMatcher{stringPrefixMatcher("a")}
assert.False(t, neg.Match([]byte("aaa")))
assert.True(t, neg.MatchString("ccc"))
}
|