-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatcher_test.go
118 lines (111 loc) · 2.39 KB
/
matcher_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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// Tideland Go Matcher - Unit Tests
//
// Copyright (C) 2019-2023 Frank Mueller / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.
package matcher_test
//--------------------
// IMPORTS
//--------------------
import (
"testing"
"tideland.dev/go/audit/asserts"
"tideland.dev/go/matcher"
)
//--------------------
// TESTS
//--------------------
// TestMatches tests matching string.
func TestMatches(t *testing.T) {
assert := asserts.NewTesting(t, asserts.FailStop)
tests := []struct {
name string
pattern string
value string
ignoreCase bool
out bool
}{
{
"equal pattern and string without wildcards",
"quick brown fox",
"quick brown fox",
matcher.IgnoreCase,
true,
}, {
"unequal pattern and string without wildcards",
"quick brown fox",
"lazy dog",
matcher.IgnoreCase,
false,
}, {
"matching pattern with one question mark",
"quick brown f?x",
"quick brown fox",
matcher.IgnoreCase,
true,
}, {
"matching pattern with one asterisk",
"quick*fox",
"quick brown fox",
matcher.IgnoreCase,
true,
}, {
"matching pattern with char group",
"quick brown f[ao]x",
"quick brown fox",
matcher.IgnoreCase,
true,
}, {
"not-matching pattern with char group",
"quick brown f[eiu]x",
"quick brown fox",
matcher.IgnoreCase,
false,
}, {
"matching pattern with char range",
"quick brown f[a-u]x",
"quick brown fox",
matcher.IgnoreCase,
true,
}, {
"not-matching pattern with char range",
"quick brown f[^a-u]x",
"quick brown fox",
matcher.IgnoreCase,
false,
}, {
"matching pattern with char group not ignoring care",
"quick * F[aeiou]x",
"quick * Fox",
matcher.ValidateCase,
true,
}, {
"not-matching pattern with char group not ignoring care",
"quick * F[aeiou]x",
"quick * fox",
matcher.ValidateCase,
false,
}, {
"matching pattern with escape",
"quick \\* f\\[o\\]x",
"quick * f[o]x",
matcher.IgnoreCase,
true,
}, {
"not-matching pattern with escape",
"quick \\* f\\[o\\]x",
"quick brown fox",
matcher.IgnoreCase,
false,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
defer assert.SetFailable(t)()
out := matcher.Matches(test.pattern, test.value, test.ignoreCase)
assert.Equal(out, test.out)
})
}
}
// EOF