| 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ |
| 6 | |
| 7 | import ( |
| 8 | "reflectscip-go gomod github.com/golang/go/src go1.21 reflect/" |
| 9 | "regexp/syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/" |
| 10 | "slicesscip-go gomod github.com/golang/go/src go1.21 slices/" |
| 11 | "stringsscip-go gomod github.com/golang/go/src go1.21 strings/" |
| 12 | "testingscip-go gomod github.com/golang/go/src go1.21 testing/" |
| 13 | "unicode/utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/" |
| 14 | ) |
| 15 | |
| 16 | var goodRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/goodRe. = []string{ |
| 17 | ``, |
| 18 | `.`, |
| 19 | `^.$`, |
| 20 | `a`, |
| 21 | `a*`, |
| 22 | `a+`, |
| 23 | `a?`, |
| 24 | `a|b`, |
| 25 | `a*|b*`, |
| 26 | `(a*|b)(c*|d)`, |
| 27 | `[a-z]`, |
| 28 | `[a-abc-c\-\]\[]`, |
| 29 | `[a-z]+`, |
| 30 | `[abc]`, |
| 31 | `[^1234]`, |
| 32 | `[^\n]`, |
| 33 | `\!\\`, |
| 34 | } |
| 35 | |
| 36 | type stringErrorscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/stringError# struct { |
| 37 | rescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/stringError#re. string |
| 38 | errscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/stringError#err. string |
| 39 | } |
| 40 | |
| 41 | var badRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/badRe. = []stringErrorscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/stringError#{ |
| 42 | {`*`, "missing argument to repetition operator: `*`"}, |
| 43 | {`+`, "missing argument to repetition operator: `+`"}, |
| 44 | {`?`, "missing argument to repetition operator: `?`"}, |
| 45 | {`(abc`, "missing closing ): `(abc`"}, |
| 46 | {`abc)`, "unexpected ): `abc)`"}, |
| 47 | {`x[a-z`, "missing closing ]: `[a-z`"}, |
| 48 | {`[z-a]`, "invalid character class range: `z-a`"}, |
| 49 | {`abc\`, "trailing backslash at end of expression"}, |
| 50 | {`a**`, "invalid nested repetition operator: `**`"}, |
| 51 | {`a*+`, "invalid nested repetition operator: `*+`"}, |
| 52 | {`\x`, "invalid escape sequence: `\\x`"}, |
| 53 | {stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().(`\pL`, 27000), "expression too large"}, |
| 54 | } |
| 55 | |
| 56 | func compileTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileTest().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#, expr string, error string) *Regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp# { |
| 57 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(expr) |
| 58 | if error == "" && err != nil { |
| 59 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().("compiling `", expr, "`; unexpected error: ", err.Error()) |
| 60 | } |
| 61 | if error != "" && err == nil { |
| 62 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().("compiling `", expr, "`; missing error") |
| 63 | } else if error != "" && !stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Containsscip-go gomod github.com/golang/go/src go1.21 strings/Contains().(err.Error(), error) { |
| 64 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().("compiling `", expr, "`; wrong error: ", err.Error(), "; want ", error) |
| 65 | } |
| 66 | return re |
| 67 | } |
| 68 | |
| 69 | func TestGoodCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestGoodCompile().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 70 | for i := 0; i < len(goodRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/goodRe.); i++ { |
| 71 | compileTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileTest().(t, goodRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/goodRe.[i], "") |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | func TestBadCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestBadCompile().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 76 | for i := 0; i < len(badRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/badRe.); i++ { |
| 77 | compileTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileTest().(t, badRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/badRe.[i].rescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/stringError#re., badRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/badRe.[i].errscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/stringError#err.) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | func matchTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/matchTest().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#, test *FindTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#) { |
| 82 | re := compileTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileTest().(t, test.patscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#pat., "") |
| 83 | if re == nil { |
| 84 | return |
| 85 | } |
| 86 | m := re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(test.textscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#text.) |
| 87 | if m != (len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) { |
| 88 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("MatchString failure on %s: %t should be %t", test, m, len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) |
| 89 | } |
| 90 | // now try bytes |
| 91 | m = re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().([]byte(test.textscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#text.)) |
| 92 | if m != (len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) { |
| 93 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Match failure on %s: %t should be %t", test, m, len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | func TestMatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestMatch().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 98 | for _, test := range findTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/findTests. { |
| 99 | matchTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/matchTest().(t, &test) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | func matchFunctionTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/matchFunctionTest().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#, test *FindTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#) { |
| 104 | m, err := MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MatchString().(test.patscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#pat., test.textscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#text.) |
| 105 | if err == nil { |
| 106 | return |
| 107 | } |
| 108 | if m != (len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) { |
| 109 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Match failure on %s: %t should be %t", test, m, len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func TestMatchFunctionscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestMatchFunction().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 114 | for _, test := range findTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/findTests. { |
| 115 | matchFunctionTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/matchFunctionTest().(t, &test) |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | func copyMatchTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/copyMatchTest().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#, test *FindTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#) { |
| 120 | re := compileTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileTest().(t, test.patscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#pat., "") |
| 121 | if re == nil { |
| 122 | return |
| 123 | } |
| 124 | m1 := re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(test.textscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#text.) |
| 125 | m2 := re.Copyscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Copy().().MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(test.textscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#text.) |
| 126 | if m1 != m2 { |
| 127 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Copied Regexp match failure on %s: original gave %t; copy gave %t; should be %t", |
| 128 | test, m1, m2, len(test.matchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/FindTest#matches.) > 0) |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | func TestCopyMatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestCopyMatch().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 133 | for _, test := range findTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/findTests. { |
| 134 | copyMatchTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/copyMatchTest().(t, &test) |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | type ReplaceTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest# struct { |
| 139 | patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. string |
| 140 | } |
| 141 | |
| 142 | var replaceTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceTests. = []ReplaceTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#{ |
| 143 | // Test empty input and/or replacement, with pattern that matches the empty string. |
| 144 | {"", "", "", ""}, |
| 145 | {"", "x", "", "x"}, |
| 146 | {"", "", "abc", "abc"}, |
| 147 | {"", "x", "abc", "xaxbxcx"}, |
| 148 | |
| 149 | // Test empty input and/or replacement, with pattern that does not match the empty string. |
| 150 | {"b", "", "", ""}, |
| 151 | {"b", "x", "", ""}, |
| 152 | {"b", "", "abc", "ac"}, |
| 153 | {"b", "x", "abc", "axc"}, |
| 154 | {"y", "", "", ""}, |
| 155 | {"y", "x", "", ""}, |
| 156 | {"y", "", "abc", "abc"}, |
| 157 | {"y", "x", "abc", "abc"}, |
| 158 | |
| 159 | // Multibyte characters -- verify that we don't try to match in the middle |
| 160 | // of a character. |
| 161 | {"[a-c]*", "x", "\u65e5", "x\u65e5x"}, |
| 162 | {"[^\u65e5]", "x", "abc\u65e5def", "xxx\u65e5xxx"}, |
| 163 | |
| 164 | // Start and end of a string. |
| 165 | {"^[a-c]*", "x", "abcdabc", "xdabc"}, |
| 166 | {"[a-c]*$", "x", "abcdabc", "abcdx"}, |
| 167 | {"^[a-c]*$", "x", "abcdabc", "abcdabc"}, |
| 168 | {"^[a-c]*", "x", "abc", "x"}, |
| 169 | {"[a-c]*$", "x", "abc", "x"}, |
| 170 | {"^[a-c]*$", "x", "abc", "x"}, |
| 171 | {"^[a-c]*", "x", "dabce", "xdabce"}, |
| 172 | {"[a-c]*$", "x", "dabce", "dabcex"}, |
| 173 | {"^[a-c]*$", "x", "dabce", "dabce"}, |
| 174 | {"^[a-c]*", "x", "", "x"}, |
| 175 | {"[a-c]*$", "x", "", "x"}, |
| 176 | {"^[a-c]*$", "x", "", "x"}, |
| 177 | |
| 178 | {"^[a-c]+", "x", "abcdabc", "xdabc"}, |
| 179 | {"[a-c]+$", "x", "abcdabc", "abcdx"}, |
| 180 | {"^[a-c]+$", "x", "abcdabc", "abcdabc"}, |
| 181 | {"^[a-c]+", "x", "abc", "x"}, |
| 182 | {"[a-c]+$", "x", "abc", "x"}, |
| 183 | {"^[a-c]+$", "x", "abc", "x"}, |
| 184 | {"^[a-c]+", "x", "dabce", "dabce"}, |
| 185 | {"[a-c]+$", "x", "dabce", "dabce"}, |
| 186 | {"^[a-c]+$", "x", "dabce", "dabce"}, |
| 187 | {"^[a-c]+", "x", "", ""}, |
| 188 | {"[a-c]+$", "x", "", ""}, |
| 189 | {"^[a-c]+$", "x", "", ""}, |
| 190 | |
| 191 | // Other cases. |
| 192 | {"abc", "def", "abcdefg", "defdefg"}, |
| 193 | {"bc", "BC", "abcbcdcdedef", "aBCBCdcdedef"}, |
| 194 | {"abc", "", "abcdabc", "d"}, |
| 195 | {"x", "xXx", "xxxXxxx", "xXxxXxxXxXxXxxXxxXx"}, |
| 196 | {"abc", "d", "", ""}, |
| 197 | {"abc", "d", "abc", "d"}, |
| 198 | {".+", "x", "abc", "x"}, |
| 199 | {"[a-c]*", "x", "def", "xdxexfx"}, |
| 200 | {"[a-c]+", "x", "abcbcdcdedef", "xdxdedef"}, |
| 201 | {"[a-c]*", "x", "abcbcdcdedef", "xdxdxexdxexfx"}, |
| 202 | |
| 203 | // Substitutions |
| 204 | {"a+", "($0)", "banana", "b(a)n(a)n(a)"}, |
| 205 | {"a+", "(${0})", "banana", "b(a)n(a)n(a)"}, |
| 206 | {"a+", "(${0})$0", "banana", "b(a)an(a)an(a)a"}, |
| 207 | {"a+", "(${0})$0", "banana", "b(a)an(a)an(a)a"}, |
| 208 | {"hello, (.+)", "goodbye, ${1}", "hello, world", "goodbye, world"}, |
| 209 | {"hello, (.+)", "goodbye, $1x", "hello, world", "goodbye, "}, |
| 210 | {"hello, (.+)", "goodbye, ${1}x", "hello, world", "goodbye, worldx"}, |
| 211 | {"hello, (.+)", "<$0><$1><$2><$3>", "hello, world", "<hello, world><world><><>"}, |
| 212 | {"hello, (?P<noun>.+)", "goodbye, $noun!", "hello, world", "goodbye, world!"}, |
| 213 | {"hello, (?P<noun>.+)", "goodbye, ${noun}", "hello, world", "goodbye, world"}, |
| 214 | {"(?P<x>hi)|(?P<x>bye)", "$x$x$x", "hi", "hihihi"}, |
| 215 | {"(?P<x>hi)|(?P<x>bye)", "$x$x$x", "bye", "byebyebye"}, |
| 216 | {"(?P<x>hi)|(?P<x>bye)", "$xyz", "hi", ""}, |
| 217 | {"(?P<x>hi)|(?P<x>bye)", "${x}yz", "hi", "hiyz"}, |
| 218 | {"(?P<x>hi)|(?P<x>bye)", "hello $$x", "hi", "hello $x"}, |
| 219 | {"a+", "${oops", "aaa", "${oops"}, |
| 220 | {"a+", "$$", "aaa", "$"}, |
| 221 | {"a+", "$", "aaa", "$"}, |
| 222 | |
| 223 | // Substitution when subexpression isn't found |
| 224 | {"(x)?", "$1", "123", "123"}, |
| 225 | {"abc", "$1", "123", "123"}, |
| 226 | |
| 227 | // Substitutions involving a (x){0} |
| 228 | {"(a)(b){0}(c)", ".$1|$3.", "xacxacx", "x.a|c.x.a|c.x"}, |
| 229 | {"(a)(((b))){0}c", ".$1.", "xacxacx", "x.a.x.a.x"}, |
| 230 | {"((a(b){0}){3}){5}(h)", "y caramb$2", "say aaaaaaaaaaaaaaaah", "say ay caramba"}, |
| 231 | {"((a(b){0}){3}){5}h", "y caramb$2", "say aaaaaaaaaaaaaaaah", "say ay caramba"}, |
| 232 | } |
| 233 | |
| 234 | var replaceLiteralTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceLiteralTests. = []ReplaceTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#{ |
| 235 | // Substitutions |
| 236 | {"a+", "($0)", "banana", "b($0)n($0)n($0)"}, |
| 237 | {"a+", "(${0})", "banana", "b(${0})n(${0})n(${0})"}, |
| 238 | {"a+", "(${0})$0", "banana", "b(${0})$0n(${0})$0n(${0})$0"}, |
| 239 | {"a+", "(${0})$0", "banana", "b(${0})$0n(${0})$0n(${0})$0"}, |
| 240 | {"hello, (.+)", "goodbye, ${1}", "hello, world", "goodbye, ${1}"}, |
| 241 | {"hello, (?P<noun>.+)", "goodbye, $noun!", "hello, world", "goodbye, $noun!"}, |
| 242 | {"hello, (?P<noun>.+)", "goodbye, ${noun}", "hello, world", "goodbye, ${noun}"}, |
| 243 | {"(?P<x>hi)|(?P<x>bye)", "$x$x$x", "hi", "$x$x$x"}, |
| 244 | {"(?P<x>hi)|(?P<x>bye)", "$x$x$x", "bye", "$x$x$x"}, |
| 245 | {"(?P<x>hi)|(?P<x>bye)", "$xyz", "hi", "$xyz"}, |
| 246 | {"(?P<x>hi)|(?P<x>bye)", "${x}yz", "hi", "${x}yz"}, |
| 247 | {"(?P<x>hi)|(?P<x>bye)", "hello $$x", "hi", "hello $$x"}, |
| 248 | {"a+", "${oops", "aaa", "${oops"}, |
| 249 | {"a+", "$$", "aaa", "$$"}, |
| 250 | {"a+", "$", "aaa", "$"}, |
| 251 | } |
| 252 | |
| 253 | type ReplaceFuncTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest# struct { |
| 254 | patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#pattern. string |
| 255 | replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#replacement. func(string) string |
| 256 | inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#input., outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#output. string |
| 257 | } |
| 258 | |
| 259 | var replaceFuncTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests. = []ReplaceFuncTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#{ |
| 260 | {"[a-c]", func(sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests:s. string) string { return "x" + sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests:s. + "y" }, "defabcdef", "defxayxbyxcydef"}, |
| 261 | {"[a-c]+", func(sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests:s. string) string { return "x" + sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests:s. + "y" }, "defabcdef", "defxabcydef"}, |
| 262 | {"[a-c]*", func(sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests:s. string) string { return "x" + sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests:s. + "y" }, "defabcdef", "xydxyexyfxabcydxyexyfxy"}, |
| 263 | } |
| 264 | |
| 265 | func TestReplaceAllscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestReplaceAll().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 266 | for _, tc := range replaceTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceTests. { |
| 267 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern.) |
| 268 | if err != nil { |
| 269 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Unexpected error compiling %q: %v", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., err) |
| 270 | continue |
| 271 | } |
| 272 | actual := re.ReplaceAllStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllString().(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement.) |
| 273 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. { |
| 274 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceAllString(%q,%q) = %q; want %q", |
| 275 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output.) |
| 276 | } |
| 277 | // now try bytes |
| 278 | actual = string(re.ReplaceAllscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAll().([]byte(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input.), []byte(tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement.))) |
| 279 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. { |
| 280 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceAll(%q,%q) = %q; want %q", |
| 281 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output.) |
| 282 | } |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | func TestReplaceAllLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestReplaceAllLiteral().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 287 | // Run ReplaceAll tests that do not have $ expansions. |
| 288 | for _, tc := range replaceTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceTests. { |
| 289 | if stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Containsscip-go gomod github.com/golang/go/src go1.21 strings/Contains().(tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., "$") { |
| 290 | continue |
| 291 | } |
| 292 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern.) |
| 293 | if err != nil { |
| 294 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Unexpected error compiling %q: %v", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., err) |
| 295 | continue |
| 296 | } |
| 297 | actual := re.ReplaceAllLiteralStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllLiteralString().(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement.) |
| 298 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. { |
| 299 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceAllLiteralString(%q,%q) = %q; want %q", |
| 300 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output.) |
| 301 | } |
| 302 | // now try bytes |
| 303 | actual = string(re.ReplaceAllLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllLiteral().([]byte(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input.), []byte(tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement.))) |
| 304 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. { |
| 305 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceAllLiteral(%q,%q) = %q; want %q", |
| 306 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output.) |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // Run literal-specific tests. |
| 311 | for _, tc := range replaceLiteralTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceLiteralTests. { |
| 312 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern.) |
| 313 | if err != nil { |
| 314 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Unexpected error compiling %q: %v", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., err) |
| 315 | continue |
| 316 | } |
| 317 | actual := re.ReplaceAllLiteralStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllLiteralString().(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement.) |
| 318 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. { |
| 319 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceAllLiteralString(%q,%q) = %q; want %q", |
| 320 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output.) |
| 321 | } |
| 322 | // now try bytes |
| 323 | actual = string(re.ReplaceAllLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllLiteral().([]byte(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input.), []byte(tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement.))) |
| 324 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output. { |
| 325 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceAllLiteral(%q,%q) = %q; want %q", |
| 326 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#replacement., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceTest#output.) |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | func TestReplaceAllFuncscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestReplaceAllFunc().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 332 | for _, tc := range replaceFuncTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/replaceFuncTests. { |
| 333 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#pattern.) |
| 334 | if err != nil { |
| 335 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Unexpected error compiling %q: %v", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#pattern., err) |
| 336 | continue |
| 337 | } |
| 338 | actual := re.ReplaceAllStringFuncscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllStringFunc().(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#input., tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#replacement.) |
| 339 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#output. { |
| 340 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceFunc(%q,fn) = %q; want %q", |
| 341 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#input., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#output.) |
| 342 | } |
| 343 | // now try bytes |
| 344 | actual = string(re.ReplaceAllFuncscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllFunc().([]byte(tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#input.), func(s []byte) []byte { return []byte(tc.replacementscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#replacement.(string(s))) })) |
| 345 | if actual != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#output. { |
| 346 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q.ReplaceFunc(%q,fn) = %q; want %q", |
| 347 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#pattern., tc.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#input., actual, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/ReplaceFuncTest#output.) |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | type MetaTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest# struct { |
| 353 | patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern., outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#output., literalscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#literal. string |
| 354 | isLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#isLiteral. bool |
| 355 | } |
| 356 | |
| 357 | var metaTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/metaTests. = []MetaTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#{ |
| 358 | {``, ``, ``, true}, |
| 359 | {`foo`, `foo`, `foo`, true}, |
| 360 | {`日本語+`, `日本語\+`, `日本語`, false}, |
| 361 | {`foo\.\$`, `foo\\\.\\\$`, `foo.$`, true}, // has meta but no operator |
| 362 | {`foo.\$`, `foo\.\\\$`, `foo`, false}, // has escaped operators and real operators |
| 363 | {`!@#$%^&*()_+-=[{]}\|,<.>/?~`, `!@#\$%\^&\*\(\)_\+-=\[\{\]\}\\\|,<\.>/\?~`, `!@#`, false}, |
| 364 | } |
| 365 | |
| 366 | var literalPrefixTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/literalPrefixTests. = []MetaTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#{ |
| 367 | // See golang.org/issue/11175. |
| 368 | // output is unused. |
| 369 | {`^0^0$`, ``, `0`, false}, |
| 370 | {`^0^`, ``, ``, false}, |
| 371 | {`^0$`, ``, `0`, true}, |
| 372 | {`$0^`, ``, ``, false}, |
| 373 | {`$0$`, ``, ``, false}, |
| 374 | {`^^0$$`, ``, ``, false}, |
| 375 | {`^$^$`, ``, ``, false}, |
| 376 | {`$$0^^`, ``, ``, false}, |
| 377 | {`a\x{fffd}b`, ``, `a`, false}, |
| 378 | {`\x{fffd}b`, ``, ``, false}, |
| 379 | {"\ufffd", ``, ``, false}, |
| 380 | } |
| 381 | |
| 382 | func TestQuoteMetascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestQuoteMeta().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 383 | for _, tc := range metaTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/metaTests. { |
| 384 | // Verify that QuoteMeta returns the expected string. |
| 385 | quoted := QuoteMetascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/QuoteMeta().(tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern.) |
| 386 | if quoted != tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#output. { |
| 387 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("QuoteMeta(`%s`) = `%s`; want `%s`", |
| 388 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern., quoted, tc.outputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#output.) |
| 389 | continue |
| 390 | } |
| 391 | |
| 392 | // Verify that the quoted string is in fact treated as expected |
| 393 | // by Compile -- i.e. that it matches the original, unquoted string. |
| 394 | if tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern. != "" { |
| 395 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(quoted) |
| 396 | if err != nil { |
| 397 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("Unexpected error compiling QuoteMeta(`%s`): %v", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern., err) |
| 398 | continue |
| 399 | } |
| 400 | src := "abc" + tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern. + "def" |
| 401 | repl := "xyz" |
| 402 | replaced := re.ReplaceAllStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllString().(src, repl) |
| 403 | expected := "abcxyzdef" |
| 404 | if replaced != expected { |
| 405 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("QuoteMeta(`%s`).Replace(`%s`,`%s`) = `%s`; want `%s`", |
| 406 | tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern., src, repl, replaced, expected) |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | func TestLiteralPrefixscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestLiteralPrefix().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 413 | for _, tc := range append(metaTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/metaTests., literalPrefixTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/literalPrefixTests....) { |
| 414 | // Literal method needs to scan the pattern. |
| 415 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().(tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern.) |
| 416 | str, complete := re.LiteralPrefixscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#LiteralPrefix().() |
| 417 | if complete != tc.isLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#isLiteral. { |
| 418 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("LiteralPrefix(`%s`) = %t; want %t", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern., complete, tc.isLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#isLiteral.) |
| 419 | } |
| 420 | if str != tc.literalscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#literal. { |
| 421 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("LiteralPrefix(`%s`) = `%s`; want `%s`", tc.patternscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#pattern., str, tc.literalscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MetaTest#literal.) |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | type subexpIndexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex# struct { |
| 427 | namescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#name. string |
| 428 | indexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#index. int |
| 429 | } |
| 430 | |
| 431 | type subexpCasescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase# struct { |
| 432 | inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#input. string |
| 433 | numscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#num. int |
| 434 | namesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#names. []string |
| 435 | indicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#indices. []subexpIndexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex# |
| 436 | } |
| 437 | |
| 438 | var emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices. = []subexpIndexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#{{"", -1}, {"missing", -1}} |
| 439 | |
| 440 | var subexpCasesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCases. = []subexpCasescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#{ |
| 441 | {``, 0, nil, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 442 | {`.*`, 0, nil, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 443 | {`abba`, 0, nil, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 444 | {`ab(b)a`, 1, []string{"", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 445 | {`ab(.*)a`, 1, []string{"", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 446 | {`(.*)ab(.*)a`, 2, []string{"", "", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 447 | {`(.*)(ab)(.*)a`, 3, []string{"", "", "", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 448 | {`(.*)((a)b)(.*)a`, 4, []string{"", "", "", "", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 449 | {`(.*)(\(ab)(.*)a`, 3, []string{"", "", "", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 450 | {`(.*)(\(a\)b)(.*)a`, 3, []string{"", "", "", ""}, emptySubexpIndicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/emptySubexpIndices.}, |
| 451 | {`(?P<foo>.*)(?P<bar>(a)b)(?P<foo>.*)a`, 4, []string{"", "foo", "bar", "", "foo"}, []subexpIndexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#{{"", -1}, {"missing", -1}, {"foo", 1}, {"bar", 2}}}, |
| 452 | } |
| 453 | |
| 454 | func TestSubexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestSubexp().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 455 | for _, c := range subexpCasesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCases. { |
| 456 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().(c.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#input.) |
| 457 | n := re.NumSubexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#NumSubexp().() |
| 458 | if n != c.numscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#num. { |
| 459 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q: NumSubexp = %d, want %d", c.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#input., n, c.numscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#num.) |
| 460 | continue |
| 461 | } |
| 462 | names := re.SubexpNamesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#SubexpNames().() |
| 463 | if len(names) != 1+n { |
| 464 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q: len(SubexpNames) = %d, want %d", c.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#input., len(names), n) |
| 465 | continue |
| 466 | } |
| 467 | if c.namesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#names. != nil { |
| 468 | for i := 0; i < 1+n; i++ { |
| 469 | if names[i] != c.namesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#names.[i] { |
| 470 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q: SubexpNames[%d] = %q, want %q", c.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#input., i, names[i], c.namesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#names.[i]) |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | for _, subexp := range c.indicesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#indices. { |
| 475 | index := re.SubexpIndexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#SubexpIndex().(subexp.namescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#name.) |
| 476 | if index != subexp.indexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#index. { |
| 477 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%q: SubexpIndex(%q) = %d, want %d", c.inputscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpCase#input., subexp.namescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#name., index, subexp.indexscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/subexpIndex#index.) |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | var splitTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests. = []struct { |
| 484 | sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:s. string |
| 485 | rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r. string |
| 486 | nscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:n. int |
| 487 | outscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:out. []string |
| 488 | }{ |
| 489 | {"foo:and:bar", ":", -1, []string{"foo", "and", "bar"}}, |
| 490 | {"foo:and:bar", ":", 1, []string{"foo:and:bar"}}, |
| 491 | {"foo:and:bar", ":", 2, []string{"foo", "and:bar"}}, |
| 492 | {"foo:and:bar", "foo", -1, []string{"", ":and:bar"}}, |
| 493 | {"foo:and:bar", "bar", -1, []string{"foo:and:", ""}}, |
| 494 | {"foo:and:bar", "baz", -1, []string{"foo:and:bar"}}, |
| 495 | {"baabaab", "a", -1, []string{"b", "", "b", "", "b"}}, |
| 496 | {"baabaab", "a*", -1, []string{"b", "b", "b"}}, |
| 497 | {"baabaab", "ba*", -1, []string{"", "", "", ""}}, |
| 498 | {"foobar", "f*b*", -1, []string{"", "o", "o", "a", "r"}}, |
| 499 | {"foobar", "f+.*b+", -1, []string{"", "ar"}}, |
| 500 | {"foobooboar", "o{2}", -1, []string{"f", "b", "boar"}}, |
| 501 | {"a,b,c,d,e,f", ",", 3, []string{"a", "b", "c,d,e,f"}}, |
| 502 | {"a,b,c,d,e,f", ",", 0, nil}, |
| 503 | {",", ",", -1, []string{"", ""}}, |
| 504 | {",,,", ",", -1, []string{"", "", "", ""}}, |
| 505 | {"", ",", -1, []string{""}}, |
| 506 | {"", ".*", -1, []string{""}}, |
| 507 | {"", ".+", -1, []string{""}}, |
| 508 | {"", "", -1, []string{}}, |
| 509 | {"foobar", "", -1, []string{"f", "o", "o", "b", "a", "r"}}, |
| 510 | {"abaabaccadaaae", "a*", 5, []string{"", "b", "b", "c", "cadaaae"}}, |
| 511 | {":x:y:z:", ":", -1, []string{"", "x", "y", "z", ""}}, |
| 512 | } |
| 513 | |
| 514 | func TestSplitscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestSplit().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 515 | for i, test := range splitTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests. { |
| 516 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r.) |
| 517 | if err != nil { |
| 518 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("#%d: %q: compile error: %s", i, test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r., err.Error()) |
| 519 | continue |
| 520 | } |
| 521 | |
| 522 | split := re.Splitscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Split().(test.sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:s., test.nscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:n.) |
| 523 | if !slicesscip-go gomod github.com/golang/go/src go1.21 slices/.Equalscip-go gomod github.com/golang/go/src go1.21 slices/Equal().(split, test.outscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:out.) { |
| 524 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("#%d: %q: got %q; want %q", i, test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r., split, test.outscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:out.) |
| 525 | } |
| 526 | |
| 527 | if QuoteMetascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/QuoteMeta().(test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r.) == test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r. { |
| 528 | strsplit := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.SplitNscip-go gomod github.com/golang/go/src go1.21 strings/SplitN().(test.sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:s., test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r., test.nscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:n.) |
| 529 | if !slicesscip-go gomod github.com/golang/go/src go1.21 slices/.Equalscip-go gomod github.com/golang/go/src go1.21 slices/Equal().(split, strsplit) { |
| 530 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("#%d: Split(%q, %q, %d): regexp vs strings mismatch\nregexp=%q\nstrings=%q", i, test.sscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:s., test.rscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:r., test.nscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/splitTests:n., split, strsplit) |
| 531 | } |
| 532 | } |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | // The following sequence of Match calls used to panic. See issue #12980. |
| 537 | func TestParseAndCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestParseAndCompile().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 538 | expr := "a$" |
| 539 | s := "a\nb" |
| 540 | |
| 541 | for i, tc := range []struct { |
| 542 | reFlags syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Flagsscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Flags# |
| 543 | expMatch bool |
| 544 | }{ |
| 545 | {syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Perlscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Perl. | syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.OneLinescip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/OneLine., false}, |
| 546 | {syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Perlscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Perl. &^ syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.OneLinescip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/OneLine., true}, |
| 547 | } { |
| 548 | parsed, err := syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Parsescip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Parse().(expr, tc.reFlags) |
| 549 | if err != nil { |
| 550 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("%d: parse: %v", i, err) |
| 551 | } |
| 552 | re, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(parsed.Stringscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Regexp#String().()) |
| 553 | if err != nil { |
| 554 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("%d: compile: %v", i, err) |
| 555 | } |
| 556 | if match := re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(s); match != tc.expMatch { |
| 557 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("%d: %q.MatchString(%q)=%t; expected=%t", i, re, s, match, tc.expMatch) |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | // Check that one-pass cutoff does trigger. |
| 563 | func TestOnePassCutoffscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestOnePassCutoff().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 564 | re, err := syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Parsescip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Parse().(`^x{1,1000}y{1,1000}$`, syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Perlscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Perl.) |
| 565 | if err != nil { |
| 566 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("parse: %v", err) |
| 567 | } |
| 568 | p, err := syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Compilescip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Compile().(re.Simplifyscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Regexp#Simplify().()) |
| 569 | if err != nil { |
| 570 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("compile: %v", err) |
| 571 | } |
| 572 | if compileOnePassscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileOnePass().(p) != nil { |
| 573 | t.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("makeOnePass succeeded; wanted nil") |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | // Check that the same machine can be used with the standard matcher |
| 578 | // and then the backtracker when there are no captures. |
| 579 | func TestSwitchBacktrackscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestSwitchBacktrack().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 580 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().(`a|b`) |
| 581 | long := make([]byte, maxBacktrackVectorscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/maxBacktrackVector.+1) |
| 582 | |
| 583 | // The following sequence of Match calls used to panic. See issue #10319. |
| 584 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(long) // triggers standard matcher |
| 585 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(long[:1]) // triggers backtracker |
| 586 | } |
| 587 | |
| 588 | func BenchmarkFindscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkFind().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 589 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 590 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a+b+") |
| 591 | wantSubs := "aaabb" |
| 592 | s := []byte("acbb" + wantSubs + "dd") |
| 593 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 594 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.21 testing/B#ReportAllocs().() |
| 595 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 596 | subs := re.Findscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Find().(s) |
| 597 | if string(subs) != wantSubs { |
| 598 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("Find(%q) = %q; want %q", s, subs, wantSubs) |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | func BenchmarkFindAllNoMatchesscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkFindAllNoMatches().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 604 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a+b+") |
| 605 | s := []byte("acddee") |
| 606 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.21 testing/B#ReportAllocs().() |
| 607 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#ResetTimer().() |
| 608 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 609 | all := re.FindAllscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#FindAll().(s, -1) |
| 610 | if all != nil { |
| 611 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("FindAll(%q) = %q; want nil", s, all) |
| 612 | } |
| 613 | } |
| 614 | } |
| 615 | |
| 616 | func BenchmarkFindStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkFindString().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 617 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 618 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a+b+") |
| 619 | wantSubs := "aaabb" |
| 620 | s := "acbb" + wantSubs + "dd" |
| 621 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 622 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.21 testing/B#ReportAllocs().() |
| 623 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 624 | subs := re.FindStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#FindString().(s) |
| 625 | if subs != wantSubs { |
| 626 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("FindString(%q) = %q; want %q", s, subs, wantSubs) |
| 627 | } |
| 628 | } |
| 629 | } |
| 630 | |
| 631 | func BenchmarkFindSubmatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkFindSubmatch().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 632 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 633 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a(a+b+)b") |
| 634 | wantSubs := "aaabb" |
| 635 | s := []byte("acbb" + wantSubs + "dd") |
| 636 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 637 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.21 testing/B#ReportAllocs().() |
| 638 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 639 | subs := re.FindSubmatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#FindSubmatch().(s) |
| 640 | if string(subs[0]) != wantSubs { |
| 641 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("FindSubmatch(%q)[0] = %q; want %q", s, subs[0], wantSubs) |
| 642 | } |
| 643 | if string(subs[1]) != "aab" { |
| 644 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("FindSubmatch(%q)[1] = %q; want %q", s, subs[1], "aab") |
| 645 | } |
| 646 | } |
| 647 | } |
| 648 | |
| 649 | func BenchmarkFindStringSubmatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkFindStringSubmatch().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 650 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 651 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a(a+b+)b") |
| 652 | wantSubs := "aaabb" |
| 653 | s := "acbb" + wantSubs + "dd" |
| 654 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 655 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.21 testing/B#ReportAllocs().() |
| 656 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 657 | subs := re.FindStringSubmatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#FindStringSubmatch().(s) |
| 658 | if subs[0] != wantSubs { |
| 659 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("FindStringSubmatch(%q)[0] = %q; want %q", s, subs[0], wantSubs) |
| 660 | } |
| 661 | if subs[1] != "aab" { |
| 662 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("FindStringSubmatch(%q)[1] = %q; want %q", s, subs[1], "aab") |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | func BenchmarkLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkLiteral().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 668 | x := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().("x", 50) + "y" |
| 669 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 670 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("y") |
| 671 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 672 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 673 | if !re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(x) { |
| 674 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("no match!") |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | |
| 679 | func BenchmarkNotLiteralscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkNotLiteral().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 680 | x := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().("x", 50) + "y" |
| 681 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 682 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().(".y") |
| 683 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 684 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 685 | if !re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(x) { |
| 686 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("no match!") |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | func BenchmarkMatchClassscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkMatchClass().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 692 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 693 | x := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().("xxxx", 20) + "w" |
| 694 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("[abcdw]") |
| 695 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 696 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 697 | if !re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(x) { |
| 698 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("no match!") |
| 699 | } |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | func BenchmarkMatchClass_InRangescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkMatchClass_InRange().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 704 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 705 | // 'b' is between 'a' and 'c', so the charclass |
| 706 | // range checking is no help here. |
| 707 | x := stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().("bbbb", 20) + "c" |
| 708 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("[ac]") |
| 709 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 710 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 711 | if !re.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(x) { |
| 712 | b.Fatalfscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatalf().("no match!") |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | |
| 717 | func BenchmarkReplaceAllscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkReplaceAll().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 718 | x := "abcdefghijklmnopqrstuvwxyz" |
| 719 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 720 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("[cjrw]") |
| 721 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 722 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 723 | re.ReplaceAllStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#ReplaceAllString().(x, "") |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | func BenchmarkAnchoredLiteralShortNonMatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkAnchoredLiteralShortNonMatch().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 728 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 729 | x := []byte("abcdefghijklmnopqrstuvwxyz") |
| 730 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^zbc(d|e)") |
| 731 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 732 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 733 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | func BenchmarkAnchoredLiteralLongNonMatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkAnchoredLiteralLongNonMatch().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 738 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 739 | x := []byte("abcdefghijklmnopqrstuvwxyz") |
| 740 | for i := 0; i < 15; i++ { |
| 741 | x = append(x, x...) |
| 742 | } |
| 743 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^zbc(d|e)") |
| 744 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 745 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 746 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | func BenchmarkAnchoredShortMatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkAnchoredShortMatch().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 751 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 752 | x := []byte("abcdefghijklmnopqrstuvwxyz") |
| 753 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^.bc(d|e)") |
| 754 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 755 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 756 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 757 | } |
| 758 | } |
| 759 | |
| 760 | func BenchmarkAnchoredLongMatchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkAnchoredLongMatch().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 761 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 762 | x := []byte("abcdefghijklmnopqrstuvwxyz") |
| 763 | for i := 0; i < 15; i++ { |
| 764 | x = append(x, x...) |
| 765 | } |
| 766 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^.bc(d|e)") |
| 767 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 768 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 769 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 770 | } |
| 771 | } |
| 772 | |
| 773 | func BenchmarkOnePassShortAscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkOnePassShortA().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 774 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 775 | x := []byte("abcddddddeeeededd") |
| 776 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^.bc(d|e)*$") |
| 777 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 778 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 779 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | func BenchmarkNotOnePassShortAscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkNotOnePassShortA().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 784 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 785 | x := []byte("abcddddddeeeededd") |
| 786 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().(".bc(d|e)*$") |
| 787 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 788 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 789 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | func BenchmarkOnePassShortBscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkOnePassShortB().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 794 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 795 | x := []byte("abcddddddeeeededd") |
| 796 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^.bc(?:d|e)*$") |
| 797 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 798 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 799 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 800 | } |
| 801 | } |
| 802 | |
| 803 | func BenchmarkNotOnePassShortBscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkNotOnePassShortB().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 804 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 805 | x := []byte("abcddddddeeeededd") |
| 806 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().(".bc(?:d|e)*$") |
| 807 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 808 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 809 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | func BenchmarkOnePassLongPrefixscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkOnePassLongPrefix().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 814 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 815 | x := []byte("abcdefghijklmnopqrstuvwxyz") |
| 816 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^abcdefghijklmnopqrstuvwxyz.*$") |
| 817 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 818 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 819 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | func BenchmarkOnePassLongNotPrefixscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkOnePassLongNotPrefix().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 824 | b.StopTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StopTimer().() |
| 825 | x := []byte("abcdefghijklmnopqrstuvwxyz") |
| 826 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("^.bcdefghijklmnopqrstuvwxyz.*$") |
| 827 | b.StartTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#StartTimer().() |
| 828 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 829 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | func BenchmarkMatchParallelSharedscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkMatchParallelShared().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 834 | x := []byte("this is a long line that contains foo bar baz") |
| 835 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("foo (ba+r)? baz") |
| 836 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#ResetTimer().() |
| 837 | b.RunParallelscip-go gomod github.com/golang/go/src go1.21 testing/B#RunParallel().(func(pb *testingscip-go gomod github.com/golang/go/src go1.21 testing/.PBscip-go gomod github.com/golang/go/src go1.21 testing/PB#) { |
| 838 | for pb.Nextscip-go gomod github.com/golang/go/src go1.21 testing/PB#Next().() { |
| 839 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 840 | } |
| 841 | }) |
| 842 | } |
| 843 | |
| 844 | func BenchmarkMatchParallelCopiedscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkMatchParallelCopied().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 845 | x := []byte("this is a long line that contains foo bar baz") |
| 846 | re := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("foo (ba+r)? baz") |
| 847 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#ResetTimer().() |
| 848 | b.RunParallelscip-go gomod github.com/golang/go/src go1.21 testing/B#RunParallel().(func(pb *testingscip-go gomod github.com/golang/go/src go1.21 testing/.PBscip-go gomod github.com/golang/go/src go1.21 testing/PB#) { |
| 849 | re := re.Copyscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Copy().() |
| 850 | for pb.Nextscip-go gomod github.com/golang/go/src go1.21 testing/PB#Next().() { |
| 851 | re.Matchscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#Match().(x) |
| 852 | } |
| 853 | }) |
| 854 | } |
| 855 | |
| 856 | var sinkscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/sink. string |
| 857 | |
| 858 | func BenchmarkQuoteMetaAllscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkQuoteMetaAll().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 859 | specials := make([]byte, 0) |
| 860 | for i := byte(0); i < utf8scip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/.RuneSelfscip-go gomod github.com/golang/go/src go1.21 `unicode/utf8`/RuneSelf.; i++ { |
| 861 | if specialscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/special().(i) { |
| 862 | specials = append(specials, i) |
| 863 | } |
| 864 | } |
| 865 | s := string(specials) |
| 866 | b.SetBytesscip-go gomod github.com/golang/go/src go1.21 testing/B#SetBytes().(int64(len(s))) |
| 867 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#ResetTimer().() |
| 868 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 869 | sinkscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/sink. = QuoteMetascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/QuoteMeta().(s) |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | func BenchmarkQuoteMetaNonescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkQuoteMetaNone().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 874 | s := "abcdefghijklmnopqrstuvwxyz" |
| 875 | b.SetBytesscip-go gomod github.com/golang/go/src go1.21 testing/B#SetBytes().(int64(len(s))) |
| 876 | b.ResetTimerscip-go gomod github.com/golang/go/src go1.21 testing/B#ResetTimer().() |
| 877 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 878 | sinkscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/sink. = QuoteMetascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/QuoteMeta().(s) |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | var compileBenchDatascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileBenchData. = []struct{ namescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileBenchData:name., rescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileBenchData:re. string }{ |
| 883 | {"Onepass", `^a.[l-nA-Cg-j]?e$`}, |
| 884 | {"Medium", `^((a|b|[d-z0-9])*(日){4,5}.)+$`}, |
| 885 | {"Hard", stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().(`((abc)*|`, 50) + stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().(`)`, 50)}, |
| 886 | } |
| 887 | |
| 888 | func BenchmarkCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/BenchmarkCompile().(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 889 | for _, data := range compileBenchDatascip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileBenchData. { |
| 890 | b.Runscip-go gomod github.com/golang/go/src go1.21 testing/B#Run().(data.namescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileBenchData:name., func(b *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Bscip-go gomod github.com/golang/go/src go1.21 testing/B#) { |
| 891 | b.ReportAllocsscip-go gomod github.com/golang/go/src go1.21 testing/B#ReportAllocs().() |
| 892 | for i := 0; i < b.Nscip-go gomod github.com/golang/go/src go1.21 testing/B#N.; i++ { |
| 893 | if _, err := Compilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Compile().(data.rescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileBenchData:re.); err != nil { |
| 894 | b.Fatalscip-go gomod github.com/golang/go/src go1.21 testing/common#Fatal().(err) |
| 895 | } |
| 896 | } |
| 897 | }) |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | func TestDeepEqualscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestDeepEqual().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 902 | re1 := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a.*b.*c.*d") |
| 903 | re2 := MustCompilescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/MustCompile().("a.*b.*c.*d") |
| 904 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(re1, re2) { // has always been true, since Go 1. |
| 905 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("DeepEqual(re1, re2) = false, want true") |
| 906 | } |
| 907 | |
| 908 | re1.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().("abcdefghijklmn") |
| 909 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(re1, re2) { |
| 910 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("DeepEqual(re1, re2) = false, want true") |
| 911 | } |
| 912 | |
| 913 | re2.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().("abcdefghijklmn") |
| 914 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(re1, re2) { |
| 915 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("DeepEqual(re1, re2) = false, want true") |
| 916 | } |
| 917 | |
| 918 | re2.MatchStringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MatchString().(stringsscip-go gomod github.com/golang/go/src go1.21 strings/.Repeatscip-go gomod github.com/golang/go/src go1.21 strings/Repeat().("abcdefghijklmn", 100)) |
| 919 | if !reflectscip-go gomod github.com/golang/go/src go1.21 reflect/.DeepEqualscip-go gomod github.com/golang/go/src go1.21 reflect/DeepEqual().(re1, re2) { |
| 920 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("DeepEqual(re1, re2) = false, want true") |
| 921 | } |
| 922 | } |
| 923 | |
| 924 | var minInputLenTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests. = []struct { |
| 925 | Regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests:Regexp. string |
| 926 | minscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests:min. int |
| 927 | }{ |
| 928 | {``, 0}, |
| 929 | {`a`, 1}, |
| 930 | {`aa`, 2}, |
| 931 | {`(aa)a`, 3}, |
| 932 | {`(?:aa)a`, 3}, |
| 933 | {`a?a`, 1}, |
| 934 | {`(aaa)|(aa)`, 2}, |
| 935 | {`(aa)+a`, 3}, |
| 936 | {`(aa)*a`, 1}, |
| 937 | {`(aa){3,5}`, 6}, |
| 938 | {`[a-z]`, 1}, |
| 939 | {`日`, 3}, |
| 940 | } |
| 941 | |
| 942 | func TestMinInputLenscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestMinInputLen().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 943 | for _, tt := range minInputLenTestsscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests. { |
| 944 | re, _ := syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Parsescip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Parse().(tt.Regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests:Regexp., syntaxscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/.Perlscip-go gomod github.com/golang/go/src go1.21 `regexp/syntax`/Perl.) |
| 945 | m := minInputLenscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLen().(re) |
| 946 | if m != tt.minscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests:min. { |
| 947 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("regexp %#q has minInputLen %d, should be %d", tt.Regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests:Regexp., m, tt.minscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/minInputLenTests:min.) |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | func TestUnmarshalTextscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/TestUnmarshalText().(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 953 | unmarshaled := new(Regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#) |
| 954 | for i := range goodRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/goodRe. { |
| 955 | re := compileTestscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/compileTest().(t, goodRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/goodRe.[i], "") |
| 956 | marshaled, err := re.MarshalTextscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#MarshalText().() |
| 957 | if err != nil { |
| 958 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("regexp %#q failed to marshal: %s", re, err) |
| 959 | continue |
| 960 | } |
| 961 | if err := unmarshaled.UnmarshalTextscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#UnmarshalText().(marshaled); err != nil { |
| 962 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("regexp %#q failed to unmarshal: %s", re, err) |
| 963 | continue |
| 964 | } |
| 965 | if unmarshaled.Stringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#String().() != goodRescip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/goodRe.[i] { |
| 966 | t.Errorfscip-go gomod github.com/golang/go/src go1.21 testing/common#Errorf().("UnmarshalText returned unexpected value: %s", unmarshaled.Stringscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#String().()) |
| 967 | } |
| 968 | } |
| 969 | t.Runscip-go gomod github.com/golang/go/src go1.21 testing/T#Run().("invalid pattern", func(t *testingscip-go gomod github.com/golang/go/src go1.21 testing/.Tscip-go gomod github.com/golang/go/src go1.21 testing/T#) { |
| 970 | re := new(Regexpscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#) |
| 971 | err := re.UnmarshalTextscip-go gomod github.com/grafana/regexp . `github.com/grafana/regexp`/Regexp#UnmarshalText().([]byte(`\`)) |
| 972 | if err == nil { |
| 973 | t.Errorscip-go gomod github.com/golang/go/src go1.21 testing/common#Error().("unexpected success") |
| 974 | } |
| 975 | }) |
| 976 | } |