Improved tests

Signed-off-by: Marco Pracucci <marco@pracucci.com>
This commit is contained in:
Marco Pracucci 2024-06-03 11:05:20 +02:00
parent 78fdd2188d
commit a0807733be
No known key found for this signature in database
GPG Key ID: 74C1BD403D2DF9B5
2 changed files with 4 additions and 4 deletions

View File

@ -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
// all the ones which are case sensitive.
// all the ones which are case-sensitive.
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 {
contains = append(contains, string(sub[i].Rune))
}

View File

@ -84,11 +84,12 @@ var (
// Concat of literals and wildcards.
".*-.*-.*-.*-.*",
"(.+)-(.+)-(.+)-(.+)-(.+)",
"((.*))-((.*))-((.*))-((.*))-((.*))",
"((.*))(?i:f)((.*))o((.*))o((.*))",
"((.*))f((.*))(?i:o)((.*))o((.*))",
}
values = []string{
"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",
"foofoo0", "foofoo", "😀foo0",