Skip to content

Commit

Permalink
test: example with delimiters disabled (#395)
Browse files Browse the repository at this point in the history
Demonstrate delimiter behavior described in
#393
  • Loading branch information
jazanne authored Oct 5, 2023
1 parent e2663b1 commit 2ad4e60
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions search/matcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,48 @@ func TestElementMatcher_FindMatches(t *testing.T) {
}

func TestMatcher_MatchElement(t *testing.T) {
const FLAG_KEY = "testflag"

specs := []struct {
name string
expected bool
line string
matcher Matcher
flagKey string
}{
{
name: "match found",
expected: true,
line: "var flagKey = 'testflag'",
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", ",'\"", []string{"testflag"}, map[string][]string{"testflag": {"testFlag"}})}},
flagKey: "testflag",
},
{
name: "no match found",
expected: false,
line: "var flagKey = 'testflag'",
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", ",'\"", []string{"anotherflag"}, map[string][]string{"anotherflag": {"anotherFlag"}})}},
flagKey: "testflag",
},
{
name: "doesn't match when delimiters aren't present",
expected: false,
line: "var TEST_FLAG",
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", "'", []string{"TEST_FLAG"}, map[string][]string{"testflag": {}})}},
flagKey: "TEST_FLAG",
},
{
// This example is equivalent to setting `defaultsDisabled: true` in delimiters configuration
name: "matches without delimiters",
expected: true,
line: "var TEST_FLAG",
matcher: Matcher{Elements: []ElementMatcher{NewElementMatcher("projKey", "", "", []string{"TEST_FLAG"}, map[string][]string{"testflag": {}})}},
flagKey: "TEST_FLAG",
},
}

for _, tt := range specs {
tt := tt
t.Run(tt.name, func(t *testing.T) {
require.Equal(t, tt.expected, tt.matcher.MatchElement(tt.line, FLAG_KEY))
require.Equal(t, tt.expected, tt.matcher.MatchElement(tt.line, tt.flagKey))
})
}
}

0 comments on commit 2ad4e60

Please sign in to comment.