Skip to content

Commit 2ad4e60

Browse files
authored
test: example with delimiters disabled (#395)
Demonstrate delimiter behavior described in #393
1 parent e2663b1 commit 2ad4e60

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

search/matcher_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,48 @@ func TestElementMatcher_FindMatches(t *testing.T) {
2929
}
3030

3131
func TestMatcher_MatchElement(t *testing.T) {
32-
const FLAG_KEY = "testflag"
33-
3432
specs := []struct {
3533
name string
3634
expected bool
3735
line string
3836
matcher Matcher
37+
flagKey string
3938
}{
4039
{
4140
name: "match found",
4241
expected: true,
4342
line: "var flagKey = 'testflag'",
4443
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", ",'\"", []string{"testflag"}, map[string][]string{"testflag": {"testFlag"}})}},
44+
flagKey: "testflag",
4545
},
4646
{
4747
name: "no match found",
4848
expected: false,
4949
line: "var flagKey = 'testflag'",
5050
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", ",'\"", []string{"anotherflag"}, map[string][]string{"anotherflag": {"anotherFlag"}})}},
51+
flagKey: "testflag",
52+
},
53+
{
54+
name: "doesn't match when delimiters aren't present",
55+
expected: false,
56+
line: "var TEST_FLAG",
57+
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", "'", []string{"TEST_FLAG"}, map[string][]string{"testflag": {}})}},
58+
flagKey: "TEST_FLAG",
59+
},
60+
{
61+
// This example is equivalent to setting `defaultsDisabled: true` in delimiters configuration
62+
name: "matches without delimiters",
63+
expected: true,
64+
line: "var TEST_FLAG",
65+
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", "", []string{"TEST_FLAG"}, map[string][]string{"testflag": {}})}},
66+
flagKey: "TEST_FLAG",
5167
},
5268
}
5369

5470
for _, tt := range specs {
5571
tt := tt
5672
t.Run(tt.name, func(t *testing.T) {
57-
require.Equal(t, tt.expected, tt.matcher.MatchElement(tt.line, FLAG_KEY))
73+
require.Equal(t, tt.expected, tt.matcher.MatchElement(tt.line, tt.flagKey))
5874
})
5975
}
6076
}

0 commit comments

Comments
 (0)