Improved tests

Signed-off-by: Marco Pracucci <marco@pracucci.com>
pull/14173/head
Marco Pracucci 6 months ago
parent 78fdd2188d
commit a0807733be
No known key found for this signature in database
GPG Key ID: 74C1BD403D2DF9B5

@ -389,9 +389,8 @@ func optimizeConcatRegex(r *syntax.Regexp) (prefix, suffix string, contains []st
} }
// If contains any literal which is not a prefix/suffix, we keep track of // If contains any literal which is not a prefix/suffix, we keep track of
// all the ones which are case sensitive. // all the ones which are case-sensitive.
for i := 1; i < len(sub)-1; i++ { for i := 1; i < len(sub)-1; i++ {
// TODO if it's case insensitive we should return an contains list or is it safe to keep searching for case sensitive ones?
if sub[i].Op == syntax.OpLiteral && (sub[i].Flags&syntax.FoldCase) == 0 { if sub[i].Op == syntax.OpLiteral && (sub[i].Flags&syntax.FoldCase) == 0 {
contains = append(contains, string(sub[i].Rune)) contains = append(contains, string(sub[i].Rune))
} }

@ -84,11 +84,12 @@ var (
// Concat of literals and wildcards. // Concat of literals and wildcards.
".*-.*-.*-.*-.*", ".*-.*-.*-.*-.*",
"(.+)-(.+)-(.+)-(.+)-(.+)", "(.+)-(.+)-(.+)-(.+)-(.+)",
"((.*))-((.*))-((.*))-((.*))-((.*))", "((.*))(?i:f)((.*))o((.*))o((.*))",
"((.*))f((.*))(?i:o)((.*))o((.*))",
} }
values = []string{ values = []string{
"foo", " foo bar", "bar", "buzz\nbar", "bar foo", "bfoo", "\n", "\nfoo", "foo\n", "hello foo world", "hello foo\n world", "", "foo", " foo bar", "bar", "buzz\nbar", "bar foo", "bfoo", "\n", "\nfoo", "foo\n", "hello foo world", "hello foo\n world", "",
"FOO", "Foo", "OO", "Oo", "\nfoo\n", strings.Repeat("f", 20), "prometheus", "prometheus_api_v1", "prometheus_api_v1_foo", "FOO", "Foo", "fOo", "foO", "OO", "Oo", "\nfoo\n", strings.Repeat("f", 20), "prometheus", "prometheus_api_v1", "prometheus_api_v1_foo",
"10.0.1.20", "10.0.2.10", "10.0.3.30", "10.0.4.40", "10.0.1.20", "10.0.2.10", "10.0.3.30", "10.0.4.40",
"foofoo0", "foofoo", "😀foo0", "foofoo0", "foofoo", "😀foo0",

Loading…
Cancel
Save