-
Notifications
You must be signed in to change notification settings - Fork 0
/
pattern_equals_test.go
49 lines (41 loc) · 1.41 KB
/
pattern_equals_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
package hypermatch
import (
"gotest.tools/v3/assert"
"testing"
)
func TestCompilePatternEquals(t *testing.T) {
test := []testTable{
{input: "hallo", shouldMatch: []string{"hallo"}, shouldNotMatch: []string{"", "halloo", "halo"}},
{input: "welt", shouldMatch: []string{"welt"}, shouldNotMatch: []string{"", "weltt"}},
}
for _, tt := range test {
start := newNfaStep()
fm := compilePatternEquals(start, str2value(tt.input, nil, nil), nil)
for _, m := range tt.shouldMatch {
target := transitionNfa(start, str2value(m, nil, nil), nil)
assert.Check(t, len(target) > 0, "expected match '%s' with pattern '%s'", m, tt.input)
assert.Check(t, fm == target[0], "expected match '%s' with pattern '%s'", m, tt.input)
}
for _, n := range tt.shouldNotMatch {
target := transitionNfa(start, str2value(n, nil, nil), nil)
assert.Check(t, len(target) == 0, "expected not to match '%s' with pattern '%s'", n, tt.input)
}
}
}
func TestValidatePatternEquals_EmptyValue(t *testing.T) {
pattern := &Pattern{
Type: PatternEquals,
}
err := validatePatternEquals(pattern)
assert.ErrorContains(t, err, "[equals] must contain a value")
}
func TestValidatePatternEquals_SubPatterns(t *testing.T) {
pattern := &Pattern{
Type: PatternEquals,
Sub: []Pattern{
{Type: PatternEquals, Value: "subpattern"},
},
}
err := validatePatternEquals(pattern)
assert.ErrorContains(t, err, "[equals] must contain a value")
}