Skip to content

Commit

Permalink
Add tests for regex character classes (#4155)
Browse files Browse the repository at this point in the history
Signed-off-by: George Robinson <[email protected]>
  • Loading branch information
grobinson-grafana authored Dec 6, 2024
1 parent 0f65e8f commit ec9a21e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
26 changes: 26 additions & 0 deletions matcher/parse/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,32 @@ func TestLexer_Scan(t *testing.T) {
columnEnd: 13,
},
}},
}, {
name: "quoted with regex digit character class",
input: "\"\\d+\"",
expected: []token{{
kind: tokenQuoted,
value: "\"\\d+\"",
position: position{
offsetStart: 0,
offsetEnd: 5,
columnStart: 0,
columnEnd: 5,
},
}},
}, {
name: "quoted with escaped regex digit character class",
input: "\"\\\\d+\"",
expected: []token{{
kind: tokenQuoted,
value: "\"\\\\d+\"",
position: position{
offsetStart: 0,
offsetEnd: 6,
columnStart: 0,
columnEnd: 6,
},
}},
}, {
name: "quoted with escaped quotes",
input: "\"hello \\\"world\\\"\"",
Expand Down
8 changes: 8 additions & 0 deletions matcher/parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ func TestMatchers(t *testing.T) {
name: "match regex in quotes",
input: "{\"foo\"=~\"[a-z]+\"}",
expected: labels.Matchers{mustNewMatcher(t, labels.MatchRegexp, "foo", "[a-z]+")},
}, {
name: "match regex digit in quotes",
input: "{\"foo\"=~\"\\\\d+\"}",
expected: labels.Matchers{mustNewMatcher(t, labels.MatchRegexp, "foo", "\\d+")},
}, {
name: "doesn't match regex in quotes",
input: "{\"foo\"!~\"[a-z]+\"}",
Expand Down Expand Up @@ -203,6 +207,10 @@ func TestMatchers(t *testing.T) {
name: "invalid escape sequence",
input: "{foo=\"bar\\w\"}",
error: "5:12: \"bar\\w\": invalid input",
}, {
name: "invalid escape sequence regex digits",
input: "{\"foo\"=~\"\\d+\"}",
error: "8:13: \"\\d+\": invalid input",
}, {
name: "no unquoted escape sequences",
input: "{foo=bar\\n}",
Expand Down

0 comments on commit ec9a21e

Please sign in to comment.