Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for regex character classes #4155

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading