| 1 | package regexp2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/ |
| 2 | |
| 3 | import ( |
| 4 | "testingscip-go gomod github.com/golang/go/src go1.13 testing/" |
| 5 | ) |
| 6 | |
| 7 | func TestRE2CompatCapturescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2CompatCapture().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 8 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`re(?P<a>2)`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 9 | if m, err := r.FindStringMatchscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#FindStringMatch().("blahre2blah"); m == nil { |
| 10 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 11 | } else if err != nil { |
| 12 | t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Unexpected error: %v", err) |
| 13 | } else { |
| 14 | g := m.GroupByNamescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Match#GroupByName().("a") |
| 15 | if want, got := "2", g.Stringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Capture#String().(); want != got { |
| 16 | t.Fatalfscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatalf().("Wanted %v got %v", want, got) |
| 17 | } |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | func TestRE2CompatCapture_Invalidscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2CompatCapture_Invalid().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 22 | bogus := []string{ |
| 23 | `(?P<name>a`, |
| 24 | `(?P<name>`, |
| 25 | `(?P<name`, |
| 26 | `(?P<x y>a)`, |
| 27 | `(?P<>a)`, |
| 28 | } |
| 29 | for _, inp := range bogus { |
| 30 | t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(inp, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 31 | r, err := Compilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Compile().(inp, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 32 | if err == nil { |
| 33 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected failure to parse") |
| 34 | } |
| 35 | if r != nil { |
| 36 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("expected regexp to be nil") |
| 37 | } |
| 38 | }) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | func TestRE2NamedAsciiscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2NamedAscii().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 43 | table := []struct { |
| 44 | nm string |
| 45 | pos string |
| 46 | neg string |
| 47 | }{ |
| 48 | {nm: "alnum", pos: "1", neg: "!"}, |
| 49 | {nm: "alpha", pos: "g", neg: "0"}, |
| 50 | {nm: "blank", pos: " ", neg: "_"}, |
| 51 | {nm: "ascii", pos: "*", neg: "\x8f"}, |
| 52 | {nm: "cntrl", pos: "\t", neg: "A"}, |
| 53 | {nm: "graph", pos: "!", neg: " "}, |
| 54 | {nm: "lower", pos: "a", neg: "A"}, |
| 55 | {nm: "print", pos: " ", neg: "\r"}, |
| 56 | {nm: "punct", pos: "@", neg: "A"}, |
| 57 | {nm: "space", pos: " ", neg: "A"}, |
| 58 | {nm: "digit", pos: "1", neg: "A"}, |
| 59 | {nm: "upper", pos: "A", neg: "a"}, |
| 60 | {nm: "word", pos: "_", neg: "-"}, |
| 61 | {nm: "xdigit", pos: "A", neg: "G"}, |
| 62 | } |
| 63 | |
| 64 | for _, row := range table { |
| 65 | t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(row.nm, func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 66 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`[[:`+row.nm+`:]]`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 67 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(row.pos); !m { |
| 68 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 69 | } |
| 70 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(row.neg); m { |
| 71 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 72 | } |
| 73 | }) |
| 74 | t.Runscip-go gomod github.com/golang/go/src go1.13 testing/T#Run().(row.nm+" negate", func(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 75 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`[[:^`+row.nm+`:]]`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 76 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(row.neg); !m { |
| 77 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 78 | } |
| 79 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(row.pos); m { |
| 80 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 81 | } |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | } |
| 86 | func TestRE2NamedAscii_Concatscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2NamedAscii_Concat().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 87 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`[[:digit:]a]`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 88 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("b"); m { |
| 89 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 90 | } |
| 91 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("a"); !m { |
| 92 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 93 | } |
| 94 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("["); m { |
| 95 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 96 | } |
| 97 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("5"); !m { |
| 98 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | func TestRE2Dollar_Singlelinescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2Dollar_Singleline().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 103 | // PCRE allows for \n after the $ and RE2 doesn't |
| 104 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`^ac$\n`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 105 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("ac"); m { |
| 106 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 107 | } |
| 108 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("ac\n"); m { |
| 109 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | func TestRE2Dollar_Multilinescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2Dollar_Multiline().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 114 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`^ac$\n`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.|Multilinescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Multiline.) |
| 115 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("ac"); m { |
| 116 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 117 | } |
| 118 | if m, err := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("ac\n"); err != nil { |
| 119 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().(err) |
| 120 | } else if !m { |
| 121 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | func TestRE2ExtendedZeroscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2ExtendedZero().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 126 | notZero := "߀" // \u07c0 |
| 127 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`^\d$`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 128 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(notZero); m { |
| 129 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 130 | } |
| 131 | |
| 132 | r = MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`^\D$`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 133 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(notZero); !m { |
| 134 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | func TestRegularExtendedZeroscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRegularExtendedZero().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 139 | notZero := "߀" // \u07c0 |
| 140 | |
| 141 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`^\d$`, 0) |
| 142 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(notZero); !m { |
| 143 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 144 | } |
| 145 | |
| 146 | r = MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`^\D$`, 0) |
| 147 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().(notZero); m { |
| 148 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | func TestRE2Wordscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2Word().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 153 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\w`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 154 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("å"); m { |
| 155 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 156 | } |
| 157 | |
| 158 | r = MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\W`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 159 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("å"); !m { |
| 160 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 161 | } |
| 162 | |
| 163 | } |
| 164 | |
| 165 | func TestRegularWordscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRegularWord().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 166 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\w`, 0) |
| 167 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("å"); !m { |
| 168 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 169 | } |
| 170 | r = MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\W`, 0) |
| 171 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("å"); m { |
| 172 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | func TestRE2Spacescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRE2Space().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 177 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\s`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 178 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("\x0b"); m { |
| 179 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 180 | } |
| 181 | r = MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\S`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 182 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("\x0b"); !m { |
| 183 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | func TestRegularSpacescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestRegularSpace().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 188 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\s`, 0) |
| 189 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("\x0b"); !m { |
| 190 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 191 | } |
| 192 | r = MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`\S`, 0) |
| 193 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("\x0b"); m { |
| 194 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | func TestEscapeLiteralDefaultsscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/TestEscapeLiteralDefaults().(t *testingscip-go gomod github.com/golang/go/src go1.13 testing/.Tscip-go gomod github.com/golang/go/src go1.13 testing/T#) { |
| 199 | _, err := Compilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Compile().(`a\_test`, 0) |
| 200 | if err == nil { |
| 201 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected compile fail") |
| 202 | } |
| 203 | |
| 204 | r := MustCompilescip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/MustCompile().(`a\_test`, RE2scip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/RE2.) |
| 205 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("a_test"); !m { |
| 206 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected match") |
| 207 | } |
| 208 | if m, _ := r.MatchStringscip-go gomod github.com/dlclark/regexp2 . `github.com/dlclark/regexp2`/Regexp#MatchString().("a\\_test"); m { |
| 209 | t.Fatalscip-go gomod github.com/golang/go/src go1.13 testing/common#Fatal().("Expected no match") |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | func TestRE2EndZ_Singleline(t *testing.T) { |
| 215 | // PCRE allows for \n after the $ and RE2 doesn't |
| 216 | r := MustCompile(`^ac$\Z`, RE2|Debug) |
| 217 | if m, _ := r.MatchString("ac"); m { |
| 218 | t.Fatal("Expected no match") |
| 219 | } |
| 220 | if m, _ := r.MatchString("ac\n"); m { |
| 221 | t.Fatal("Expected no match") |
| 222 | } |
| 223 | }*/ |