also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -11,7 +11,7 @@ const RegexError = @import("regex").RegexError; | ||
| 11 | 11 | test "stress: empty alternation branch" { |
| 12 | 12 | const allocator = std.testing.allocator; |
| 13 | 13 | // Pattern like (|a) should match empty string or "a" |
| 14 | var regex = try Regex.compile(allocator, "^(|a)$"); | |
| 14 | var regex = try Regex.compile(allocator, std.testing.io, "^(|a)$"); | |
| 15 | 15 | defer regex.deinit(); |
| 16 | 16 | |
| 17 | 17 | try std.testing.expect(try regex.isMatch("")); |
| @@ -21,7 +21,7 @@ test "stress: empty alternation branch" { | ||
| 21 | 21 | |
| 22 | 22 | test "stress: pattern that only matches empty string" { |
| 23 | 23 | const allocator = std.testing.allocator; |
| 24 | var regex = try Regex.compile(allocator, "^$"); | |
| 24 | var regex = try Regex.compile(allocator, std.testing.io, "^$"); | |
| 25 | 25 | defer regex.deinit(); |
| 26 | 26 | |
| 27 | 27 | try std.testing.expect(try regex.isMatch("")); |
| @@ -31,7 +31,7 @@ test "stress: pattern that only matches empty string" { | ||
| 31 | 31 | |
| 32 | 32 | test "stress: dot star matches everything" { |
| 33 | 33 | const allocator = std.testing.allocator; |
| 34 | var regex = try Regex.compile(allocator, ".*"); | |
| 34 | var regex = try Regex.compile(allocator, std.testing.io, ".*"); | |
| 35 | 35 | defer regex.deinit(); |
| 36 | 36 | |
| 37 | 37 | try std.testing.expect(try regex.isMatch("")); |
| @@ -41,7 +41,7 @@ test "stress: dot star matches everything" { | ||
| 41 | 41 | |
| 42 | 42 | test "stress: single dot" { |
| 43 | 43 | const allocator = std.testing.allocator; |
| 44 | var regex = try Regex.compile(allocator, "^.$"); | |
| 44 | var regex = try Regex.compile(allocator, std.testing.io, "^.$"); | |
| 45 | 45 | defer regex.deinit(); |
| 46 | 46 | |
| 47 | 47 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -55,7 +55,7 @@ test "stress: single dot" { | ||
| 55 | 55 | |
| 56 | 56 | test "stress: {1,1} is same as no quantifier" { |
| 57 | 57 | const allocator = std.testing.allocator; |
| 58 | var regex = try Regex.compile(allocator, "^a{1,1}$"); | |
| 58 | var regex = try Regex.compile(allocator, std.testing.io, "^a{1,1}$"); | |
| 59 | 59 | defer regex.deinit(); |
| 60 | 60 | |
| 61 | 61 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -65,7 +65,7 @@ test "stress: {1,1} is same as no quantifier" { | ||
| 65 | 65 | |
| 66 | 66 | test "stress: {2,} matches 2 or more" { |
| 67 | 67 | const allocator = std.testing.allocator; |
| 68 | var regex = try Regex.compile(allocator, "^a{2,}$"); | |
| 68 | var regex = try Regex.compile(allocator, std.testing.io, "^a{2,}$"); | |
| 69 | 69 | defer regex.deinit(); |
| 70 | 70 | |
| 71 | 71 | try std.testing.expect(!try regex.isMatch("")); |
| @@ -77,7 +77,7 @@ test "stress: {2,} matches 2 or more" { | ||
| 77 | 77 | |
| 78 | 78 | test "stress: exact repeat {5}" { |
| 79 | 79 | const allocator = std.testing.allocator; |
| 80 | var regex = try Regex.compile(allocator, "^x{5}$"); | |
| 80 | var regex = try Regex.compile(allocator, std.testing.io, "^x{5}$"); | |
| 81 | 81 | defer regex.deinit(); |
| 82 | 82 | |
| 83 | 83 | try std.testing.expect(!try regex.isMatch("xxxx")); |
| @@ -87,7 +87,7 @@ test "stress: exact repeat {5}" { | ||
| 87 | 87 | |
| 88 | 88 | test "stress: mixed quantifiers in sequence" { |
| 89 | 89 | const allocator = std.testing.allocator; |
| 90 | var regex = try Regex.compile(allocator, "^a+b*c?d{2}$"); | |
| 90 | var regex = try Regex.compile(allocator, std.testing.io, "^a+b*c?d{2}$"); | |
| 91 | 91 | defer regex.deinit(); |
| 92 | 92 | |
| 93 | 93 | try std.testing.expect(try regex.isMatch("add")); |
| @@ -101,7 +101,7 @@ test "stress: mixed quantifiers in sequence" { | ||
| 101 | 101 | |
| 102 | 102 | test "stress: character class with hyphen at start" { |
| 103 | 103 | const allocator = std.testing.allocator; |
| 104 | var regex = try Regex.compile(allocator, "^[-abc]+$"); | |
| 104 | var regex = try Regex.compile(allocator, std.testing.io, "^[-abc]+$"); | |
| 105 | 105 | defer regex.deinit(); |
| 106 | 106 | |
| 107 | 107 | try std.testing.expect(try regex.isMatch("-")); |
| @@ -112,7 +112,7 @@ test "stress: character class with hyphen at start" { | ||
| 112 | 112 | |
| 113 | 113 | test "stress: character class with hyphen at end" { |
| 114 | 114 | const allocator = std.testing.allocator; |
| 115 | var regex = try Regex.compile(allocator, "^[abc-]+$"); | |
| 115 | var regex = try Regex.compile(allocator, std.testing.io, "^[abc-]+$"); | |
| 116 | 116 | defer regex.deinit(); |
| 117 | 117 | |
| 118 | 118 | try std.testing.expect(try regex.isMatch("-")); |
| @@ -121,7 +121,7 @@ test "stress: character class with hyphen at end" { | ||
| 121 | 121 | |
| 122 | 122 | test "stress: negated character class" { |
| 123 | 123 | const allocator = std.testing.allocator; |
| 124 | var regex = try Regex.compile(allocator, "^[^abc]+$"); | |
| 124 | var regex = try Regex.compile(allocator, std.testing.io, "^[^abc]+$"); | |
| 125 | 125 | defer regex.deinit(); |
| 126 | 126 | |
| 127 | 127 | try std.testing.expect(try regex.isMatch("xyz")); |
| @@ -132,7 +132,7 @@ test "stress: negated character class" { | ||
| 132 | 132 | |
| 133 | 133 | test "stress: character class with single char range" { |
| 134 | 134 | const allocator = std.testing.allocator; |
| 135 | var regex = try Regex.compile(allocator, "^[a-a]+$"); | |
| 135 | var regex = try Regex.compile(allocator, std.testing.io, "^[a-a]+$"); | |
| 136 | 136 | defer regex.deinit(); |
| 137 | 137 | |
| 138 | 138 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -142,7 +142,7 @@ test "stress: character class with single char range" { | ||
| 142 | 142 | |
| 143 | 143 | test "stress: overlapping ranges in character class" { |
| 144 | 144 | const allocator = std.testing.allocator; |
| 145 | var regex = try Regex.compile(allocator, "^[a-zA-Z]+$"); | |
| 145 | var regex = try Regex.compile(allocator, std.testing.io, "^[a-zA-Z]+$"); | |
| 146 | 146 | defer regex.deinit(); |
| 147 | 147 | |
| 148 | 148 | try std.testing.expect(try regex.isMatch("hello")); |
| @@ -154,20 +154,20 @@ test "stress: overlapping ranges in character class" { | ||
| 154 | 154 | test "stress: shorthand classes \\d \\w \\s" { |
| 155 | 155 | const allocator = std.testing.allocator; |
| 156 | 156 | { |
| 157 | var regex = try Regex.compile(allocator, "^\\d+$"); | |
| 157 | var regex = try Regex.compile(allocator, std.testing.io, "^\\d+$"); | |
| 158 | 158 | defer regex.deinit(); |
| 159 | 159 | try std.testing.expect(try regex.isMatch("12345")); |
| 160 | 160 | try std.testing.expect(!try regex.isMatch("abc")); |
| 161 | 161 | try std.testing.expect(!try regex.isMatch("")); |
| 162 | 162 | } |
| 163 | 163 | { |
| 164 | var regex = try Regex.compile(allocator, "^\\w+$"); | |
| 164 | var regex = try Regex.compile(allocator, std.testing.io, "^\\w+$"); | |
| 165 | 165 | defer regex.deinit(); |
| 166 | 166 | try std.testing.expect(try regex.isMatch("hello_123")); |
| 167 | 167 | try std.testing.expect(!try regex.isMatch("hello world")); |
| 168 | 168 | } |
| 169 | 169 | { |
| 170 | var regex = try Regex.compile(allocator, "^\\s+$"); | |
| 170 | var regex = try Regex.compile(allocator, std.testing.io, "^\\s+$"); | |
| 171 | 171 | defer regex.deinit(); |
| 172 | 172 | try std.testing.expect(try regex.isMatch(" ")); |
| 173 | 173 | try std.testing.expect(try regex.isMatch("\t\n")); |
| @@ -178,19 +178,19 @@ test "stress: shorthand classes \\d \\w \\s" { | ||
| 178 | 178 | test "stress: negated shorthand classes \\D \\W \\S" { |
| 179 | 179 | const allocator = std.testing.allocator; |
| 180 | 180 | { |
| 181 | var regex = try Regex.compile(allocator, "^\\D+$"); | |
| 181 | var regex = try Regex.compile(allocator, std.testing.io, "^\\D+$"); | |
| 182 | 182 | defer regex.deinit(); |
| 183 | 183 | try std.testing.expect(try regex.isMatch("abc")); |
| 184 | 184 | try std.testing.expect(!try regex.isMatch("123")); |
| 185 | 185 | } |
| 186 | 186 | { |
| 187 | var regex = try Regex.compile(allocator, "^\\W+$"); | |
| 187 | var regex = try Regex.compile(allocator, std.testing.io, "^\\W+$"); | |
| 188 | 188 | defer regex.deinit(); |
| 189 | 189 | try std.testing.expect(try regex.isMatch(" !@#")); |
| 190 | 190 | try std.testing.expect(!try regex.isMatch("abc")); |
| 191 | 191 | } |
| 192 | 192 | { |
| 193 | var regex = try Regex.compile(allocator, "^\\S+$"); | |
| 193 | var regex = try Regex.compile(allocator, std.testing.io, "^\\S+$"); | |
| 194 | 194 | defer regex.deinit(); |
| 195 | 195 | try std.testing.expect(try regex.isMatch("abc")); |
| 196 | 196 | try std.testing.expect(!try regex.isMatch("a b")); |
| @@ -201,7 +201,7 @@ test "stress: negated shorthand classes \\D \\W \\S" { | ||
| 201 | 201 | |
| 202 | 202 | test "stress: ^ only matches at start" { |
| 203 | 203 | const allocator = std.testing.allocator; |
| 204 | var regex = try Regex.compile(allocator, "^abc"); | |
| 204 | var regex = try Regex.compile(allocator, std.testing.io, "^abc"); | |
| 205 | 205 | defer regex.deinit(); |
| 206 | 206 | |
| 207 | 207 | try std.testing.expect(try regex.isMatch("abcdef")); |
| @@ -210,7 +210,7 @@ test "stress: ^ only matches at start" { | ||
| 210 | 210 | |
| 211 | 211 | test "stress: $ only matches at end" { |
| 212 | 212 | const allocator = std.testing.allocator; |
| 213 | var regex = try Regex.compile(allocator, "abc$"); | |
| 213 | var regex = try Regex.compile(allocator, std.testing.io, "abc$"); | |
| 214 | 214 | defer regex.deinit(); |
| 215 | 215 | |
| 216 | 216 | try std.testing.expect(try regex.isMatch("xyzabc")); |
| @@ -219,7 +219,7 @@ test "stress: $ only matches at end" { | ||
| 219 | 219 | |
| 220 | 220 | test "stress: ^$ on empty string" { |
| 221 | 221 | const allocator = std.testing.allocator; |
| 222 | var regex = try Regex.compile(allocator, "^$"); | |
| 222 | var regex = try Regex.compile(allocator, std.testing.io, "^$"); | |
| 223 | 223 | defer regex.deinit(); |
| 224 | 224 | |
| 225 | 225 | try std.testing.expect(try regex.isMatch("")); |
| @@ -228,7 +228,7 @@ test "stress: ^$ on empty string" { | ||
| 228 | 228 | |
| 229 | 229 | test "stress: word boundary \\b" { |
| 230 | 230 | const allocator = std.testing.allocator; |
| 231 | var regex = try Regex.compile(allocator, "\\bword\\b"); | |
| 231 | var regex = try Regex.compile(allocator, std.testing.io, "\\bword\\b"); | |
| 232 | 232 | defer regex.deinit(); |
| 233 | 233 | |
| 234 | 234 | try std.testing.expect(try regex.isMatch("a word here")); |
| @@ -239,7 +239,7 @@ test "stress: word boundary \\b" { | ||
| 239 | 239 | |
| 240 | 240 | test "stress: non-word boundary \\B" { |
| 241 | 241 | const allocator = std.testing.allocator; |
| 242 | var regex = try Regex.compile(allocator, "\\Bword\\B"); | |
| 242 | var regex = try Regex.compile(allocator, std.testing.io, "\\Bword\\B"); | |
| 243 | 243 | defer regex.deinit(); |
| 244 | 244 | |
| 245 | 245 | try std.testing.expect(try regex.isMatch("swordwords")); |
| @@ -251,7 +251,7 @@ test "stress: non-word boundary \\B" { | ||
| 251 | 251 | |
| 252 | 252 | test "stress: alternation with different lengths" { |
| 253 | 253 | const allocator = std.testing.allocator; |
| 254 | var regex = try Regex.compile(allocator, "^(a|bb|ccc)$"); | |
| 254 | var regex = try Regex.compile(allocator, std.testing.io, "^(a|bb|ccc)$"); | |
| 255 | 255 | defer regex.deinit(); |
| 256 | 256 | |
| 257 | 257 | try std.testing.expect(try regex.isMatch("a")); |
| @@ -263,7 +263,7 @@ test "stress: alternation with different lengths" { | ||
| 263 | 263 | |
| 264 | 264 | test "stress: nested alternation" { |
| 265 | 265 | const allocator = std.testing.allocator; |
| 266 | var regex = try Regex.compile(allocator, "^(a(b|c)d|efg)$"); | |
| 266 | var regex = try Regex.compile(allocator, std.testing.io, "^(a(b|c)d|efg)$"); | |
| 267 | 267 | defer regex.deinit(); |
| 268 | 268 | |
| 269 | 269 | try std.testing.expect(try regex.isMatch("abd")); |
| @@ -275,7 +275,7 @@ test "stress: nested alternation" { | ||
| 275 | 275 | |
| 276 | 276 | test "stress: NFA finds longest match for alternation" { |
| 277 | 277 | const allocator = std.testing.allocator; |
| 278 | var regex = try Regex.compile(allocator, "cat|catfish"); | |
| 278 | var regex = try Regex.compile(allocator, std.testing.io, "cat|catfish"); | |
| 279 | 279 | defer regex.deinit(); |
| 280 | 280 | |
| 281 | 281 | if (try regex.find("catfish")) |match| { |
| @@ -292,7 +292,7 @@ test "stress: NFA finds longest match for alternation" { | ||
| 292 | 292 | |
| 293 | 293 | test "stress: capture group with alternation - only one branch matches" { |
| 294 | 294 | const allocator = std.testing.allocator; |
| 295 | var regex = try Regex.compile(allocator, "(a)|(b)"); | |
| 295 | var regex = try Regex.compile(allocator, std.testing.io, "(a)|(b)"); | |
| 296 | 296 | defer regex.deinit(); |
| 297 | 297 | |
| 298 | 298 | if (try regex.find("b")) |match| { |
| @@ -306,7 +306,7 @@ test "stress: capture group with alternation - only one branch matches" { | ||
| 306 | 306 | |
| 307 | 307 | test "stress: nested capture groups" { |
| 308 | 308 | const allocator = std.testing.allocator; |
| 309 | var regex = try Regex.compile(allocator, "((a)(b))"); | |
| 309 | var regex = try Regex.compile(allocator, std.testing.io, "((a)(b))"); | |
| 310 | 310 | defer regex.deinit(); |
| 311 | 311 | |
| 312 | 312 | if (try regex.find("ab")) |match| { |
| @@ -325,7 +325,7 @@ test "stress: nested capture groups" { | ||
| 325 | 325 | |
| 326 | 326 | test "stress: capture with quantifier" { |
| 327 | 327 | const allocator = std.testing.allocator; |
| 328 | var regex = try Regex.compile(allocator, "(a)+"); | |
| 328 | var regex = try Regex.compile(allocator, std.testing.io, "(a)+"); | |
| 329 | 329 | defer regex.deinit(); |
| 330 | 330 | |
| 331 | 331 | if (try regex.find("aaa")) |match| { |
| @@ -341,7 +341,7 @@ test "stress: capture with quantifier" { | ||
| 341 | 341 | |
| 342 | 342 | test "stress: findAll with no matches" { |
| 343 | 343 | const allocator = std.testing.allocator; |
| 344 | var regex = try Regex.compile(allocator, "xyz"); | |
| 344 | var regex = try Regex.compile(allocator, std.testing.io, "xyz"); | |
| 345 | 345 | defer regex.deinit(); |
| 346 | 346 | |
| 347 | 347 | const matches = try regex.findAll(allocator, "abc def ghi"); |
| @@ -358,7 +358,7 @@ test "stress: findAll with no matches" { | ||
| 358 | 358 | |
| 359 | 359 | test "stress: findAll adjacent matches" { |
| 360 | 360 | const allocator = std.testing.allocator; |
| 361 | var regex = try Regex.compile(allocator, "\\d"); | |
| 361 | var regex = try Regex.compile(allocator, std.testing.io, "\\d"); | |
| 362 | 362 | defer regex.deinit(); |
| 363 | 363 | |
| 364 | 364 | const matches = try regex.findAll(allocator, "123"); |
| @@ -378,7 +378,7 @@ test "stress: findAll adjacent matches" { | ||
| 378 | 378 | |
| 379 | 379 | test "stress: findAll non-overlapping" { |
| 380 | 380 | const allocator = std.testing.allocator; |
| 381 | var regex = try Regex.compile(allocator, "aa"); | |
| 381 | var regex = try Regex.compile(allocator, std.testing.io, "aa"); | |
| 382 | 382 | defer regex.deinit(); |
| 383 | 383 | |
| 384 | 384 | const matches = try regex.findAll(allocator, "aaaa"); |
| @@ -398,7 +398,7 @@ test "stress: findAll non-overlapping" { | ||
| 398 | 398 | |
| 399 | 399 | test "stress: replace with no match returns input" { |
| 400 | 400 | const allocator = std.testing.allocator; |
| 401 | var regex = try Regex.compile(allocator, "xyz"); | |
| 401 | var regex = try Regex.compile(allocator, std.testing.io, "xyz"); | |
| 402 | 402 | defer regex.deinit(); |
| 403 | 403 | |
| 404 | 404 | const result = try regex.replace(allocator, "hello world", "!"); |
| @@ -408,7 +408,7 @@ test "stress: replace with no match returns input" { | ||
| 408 | 408 | |
| 409 | 409 | test "stress: replace with empty replacement" { |
| 410 | 410 | const allocator = std.testing.allocator; |
| 411 | var regex = try Regex.compile(allocator, "\\s+"); | |
| 411 | var regex = try Regex.compile(allocator, std.testing.io, "\\s+"); | |
| 412 | 412 | defer regex.deinit(); |
| 413 | 413 | |
| 414 | 414 | const result = try regex.replace(allocator, "hello world", ""); |
| @@ -418,7 +418,7 @@ test "stress: replace with empty replacement" { | ||
| 418 | 418 | |
| 419 | 419 | test "stress: replaceAll removes all matches" { |
| 420 | 420 | const allocator = std.testing.allocator; |
| 421 | var regex = try Regex.compile(allocator, "\\d"); | |
| 421 | var regex = try Regex.compile(allocator, std.testing.io, "\\d"); | |
| 422 | 422 | defer regex.deinit(); |
| 423 | 423 | |
| 424 | 424 | const result = try regex.replaceAll(allocator, "a1b2c3", ""); |
| @@ -428,7 +428,7 @@ test "stress: replaceAll removes all matches" { | ||
| 428 | 428 | |
| 429 | 429 | test "stress: replace with $$ escaped dollar" { |
| 430 | 430 | const allocator = std.testing.allocator; |
| 431 | var regex = try Regex.compile(allocator, "price"); | |
| 431 | var regex = try Regex.compile(allocator, std.testing.io, "price"); | |
| 432 | 432 | defer regex.deinit(); |
| 433 | 433 | |
| 434 | 434 | const result = try regex.replace(allocator, "the price is", "$$5"); |
| @@ -440,7 +440,7 @@ test "stress: replace with $$ escaped dollar" { | ||
| 440 | 440 | |
| 441 | 441 | test "stress: split with no match returns whole string" { |
| 442 | 442 | const allocator = std.testing.allocator; |
| 443 | var regex = try Regex.compile(allocator, ","); | |
| 443 | var regex = try Regex.compile(allocator, std.testing.io, ","); | |
| 444 | 444 | defer regex.deinit(); |
| 445 | 445 | |
| 446 | 446 | const parts = try regex.split(allocator, "hello"); |
| @@ -452,7 +452,7 @@ test "stress: split with no match returns whole string" { | ||
| 452 | 452 | |
| 453 | 453 | test "stress: split on every character" { |
| 454 | 454 | const allocator = std.testing.allocator; |
| 455 | var regex = try Regex.compile(allocator, ","); | |
| 455 | var regex = try Regex.compile(allocator, std.testing.io, ","); | |
| 456 | 456 | defer regex.deinit(); |
| 457 | 457 | |
| 458 | 458 | const parts = try regex.split(allocator, "a,b,c"); |
| @@ -466,7 +466,7 @@ test "stress: split on every character" { | ||
| 466 | 466 | |
| 467 | 467 | test "stress: split with regex separator" { |
| 468 | 468 | const allocator = std.testing.allocator; |
| 469 | var regex = try Regex.compile(allocator, "\\s*,\\s*"); | |
| 469 | var regex = try Regex.compile(allocator, std.testing.io, "\\s*,\\s*"); | |
| 470 | 470 | defer regex.deinit(); |
| 471 | 471 | |
| 472 | 472 | const parts = try regex.split(allocator, "a , b , c"); |
| @@ -482,7 +482,7 @@ test "stress: split with regex separator" { | ||
| 482 | 482 | |
| 483 | 483 | test "stress: escaped special characters" { |
| 484 | 484 | const allocator = std.testing.allocator; |
| 485 | var regex = try Regex.compile(allocator, "\\(\\)\\[\\]\\{\\}"); | |
| 485 | var regex = try Regex.compile(allocator, std.testing.io, "\\(\\)\\[\\]\\{\\}"); | |
| 486 | 486 | defer regex.deinit(); |
| 487 | 487 | |
| 488 | 488 | try std.testing.expect(try regex.isMatch("()[]{}")); |
| @@ -491,7 +491,7 @@ test "stress: escaped special characters" { | ||
| 491 | 491 | |
| 492 | 492 | test "stress: escaped dot matches literal dot" { |
| 493 | 493 | const allocator = std.testing.allocator; |
| 494 | var regex = try Regex.compile(allocator, "a\\.b"); | |
| 494 | var regex = try Regex.compile(allocator, std.testing.io, "a\\.b"); | |
| 495 | 495 | defer regex.deinit(); |
| 496 | 496 | |
| 497 | 497 | try std.testing.expect(try regex.isMatch("a.b")); |
| @@ -500,7 +500,7 @@ test "stress: escaped dot matches literal dot" { | ||
| 500 | 500 | |
| 501 | 501 | test "stress: escaped backslash" { |
| 502 | 502 | const allocator = std.testing.allocator; |
| 503 | var regex = try Regex.compile(allocator, "\\\\"); | |
| 503 | var regex = try Regex.compile(allocator, std.testing.io, "\\\\"); | |
| 504 | 504 | defer regex.deinit(); |
| 505 | 505 | |
| 506 | 506 | try std.testing.expect(try regex.isMatch("\\")); |
| @@ -511,7 +511,7 @@ test "stress: escaped backslash" { | ||
| 511 | 511 | |
| 512 | 512 | test "stress: match at end of long input" { |
| 513 | 513 | const allocator = std.testing.allocator; |
| 514 | var regex = try Regex.compile(allocator, "needle"); | |
| 514 | var regex = try Regex.compile(allocator, std.testing.io, "needle"); | |
| 515 | 515 | defer regex.deinit(); |
| 516 | 516 | |
| 517 | 517 | // Build a long haystack with needle at the very end |
| @@ -531,7 +531,7 @@ test "stress: match at end of long input" { | ||
| 531 | 531 | |
| 532 | 532 | test "stress: no match in long input" { |
| 533 | 533 | const allocator = std.testing.allocator; |
| 534 | var regex = try Regex.compile(allocator, "needle"); | |
| 534 | var regex = try Regex.compile(allocator, std.testing.io, "needle"); | |
| 535 | 535 | defer regex.deinit(); |
| 536 | 536 | |
| 537 | 537 | var buf: [1024]u8 = undefined; |
| @@ -544,7 +544,7 @@ test "stress: no match in long input" { | ||
| 544 | 544 | |
| 545 | 545 | test "stress: multiline ^ matches after each newline" { |
| 546 | 546 | const allocator = std.testing.allocator; |
| 547 | var regex = try Regex.compileWithFlags(allocator, "^\\w+", .{ .multiline = true }); | |
| 547 | var regex = try Regex.compileWithFlags(allocator, std.testing.io, "^\\w+", .{ .multiline = true }); | |
| 548 | 548 | defer regex.deinit(); |
| 549 | 549 | |
| 550 | 550 | const matches = try regex.findAll(allocator, "hello\nworld\nfoo"); |
| @@ -567,7 +567,7 @@ test "stress: dot does not match newline by default - find first line" { | ||
| 567 | 567 | // Without multiline, $ only matches at end of input |
| 568 | 568 | // So .+ matches "hello" but $ doesn't match at position 5 |
| 569 | 569 | // Use multiline to match lines, or just test .+ without $ |
| 570 | var regex = try Regex.compile(allocator, ".+"); | |
| 570 | var regex = try Regex.compile(allocator, std.testing.io, ".+"); | |
| 571 | 571 | defer regex.deinit(); |
| 572 | 572 | |
| 573 | 573 | if (try regex.find("hello\nworld")) |match| { |
| @@ -582,7 +582,7 @@ test "stress: dot does not match newline by default - find first line" { | ||
| 582 | 582 | |
| 583 | 583 | test "stress: dot_all makes dot match newline" { |
| 584 | 584 | const allocator = std.testing.allocator; |
| 585 | var regex = try Regex.compileWithFlags(allocator, "^.+$", .{ .dot_all = true }); | |
| 585 | var regex = try Regex.compileWithFlags(allocator, std.testing.io, "^.+$", .{ .dot_all = true }); | |
| 586 | 586 | defer regex.deinit(); |
| 587 | 587 | |
| 588 | 588 | if (try regex.find("hello\nworld")) |match| { |
| @@ -598,7 +598,7 @@ test "stress: dot_all makes dot match newline" { | ||
| 598 | 598 | |
| 599 | 599 | test "stress: case insensitive literal" { |
| 600 | 600 | const allocator = std.testing.allocator; |
| 601 | var regex = try Regex.compileWithFlags(allocator, "hello", .{ .case_insensitive = true }); | |
| 601 | var regex = try Regex.compileWithFlags(allocator, std.testing.io, "hello", .{ .case_insensitive = true }); | |
| 602 | 602 | defer regex.deinit(); |
| 603 | 603 | |
| 604 | 604 | try std.testing.expect(try regex.isMatch("HELLO")); |
| @@ -610,38 +610,38 @@ test "stress: case insensitive literal" { | ||
| 610 | 610 | |
| 611 | 611 | test "stress: unmatched closing paren" { |
| 612 | 612 | const allocator = std.testing.allocator; |
| 613 | const result = Regex.compile(allocator, "abc)"); | |
| 613 | const result = Regex.compile(allocator, std.testing.io, "abc)"); | |
| 614 | 614 | try std.testing.expectError(RegexError.UnmatchedParenthesis, result); |
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | test "stress: unmatched opening paren" { |
| 618 | 618 | const allocator = std.testing.allocator; |
| 619 | const result = Regex.compile(allocator, "(abc"); | |
| 619 | const result = Regex.compile(allocator, std.testing.io, "(abc"); | |
| 620 | 620 | try std.testing.expectError(RegexError.UnexpectedCharacter, result); |
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | test "stress: unmatched bracket" { |
| 624 | 624 | const allocator = std.testing.allocator; |
| 625 | const result = Regex.compile(allocator, "[abc"); | |
| 625 | const result = Regex.compile(allocator, std.testing.io, "[abc"); | |
| 626 | 626 | try std.testing.expectError(RegexError.UnexpectedCharacter, result); |
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | test "stress: quantifier star at start" { |
| 630 | 630 | const allocator = std.testing.allocator; |
| 631 | const result = Regex.compile(allocator, "*abc"); | |
| 631 | const result = Regex.compile(allocator, std.testing.io, "*abc"); | |
| 632 | 632 | try std.testing.expectError(RegexError.UnexpectedCharacter, result); |
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | test "stress: quantifier plus at start" { |
| 636 | 636 | const allocator = std.testing.allocator; |
| 637 | const result = Regex.compile(allocator, "+abc"); | |
| 637 | const result = Regex.compile(allocator, std.testing.io, "+abc"); | |
| 638 | 638 | try std.testing.expectError(RegexError.UnexpectedCharacter, result); |
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | test "stress: empty character class" { |
| 642 | 642 | const allocator = std.testing.allocator; |
| 643 | 643 | // [] followed by ] - parser sees empty class then stray ] |
| 644 | if (Regex.compile(allocator, "[]")) |*r| { | |
| 644 | if (Regex.compile(allocator, std.testing.io, "[]")) |*r| { | |
| 645 | 645 | var mut_r = r.*; |
| 646 | 646 | mut_r.deinit(); |
| 647 | 647 | } else |_| { |
| @@ -653,7 +653,7 @@ test "stress: empty character class" { | ||
| 653 | 653 | |
| 654 | 654 | test "stress: greedy star matches longest" { |
| 655 | 655 | const allocator = std.testing.allocator; |
| 656 | var regex = try Regex.compile(allocator, "a.*b"); | |
| 656 | var regex = try Regex.compile(allocator, std.testing.io, "a.*b"); | |
| 657 | 657 | defer regex.deinit(); |
| 658 | 658 | |
| 659 | 659 | if (try regex.find("aXXbYYb")) |match| { |
| @@ -669,7 +669,7 @@ test "stress: greedy star matches longest" { | ||
| 669 | 669 | test "stress: complex pattern with multiple features" { |
| 670 | 670 | const allocator = std.testing.allocator; |
| 671 | 671 | // Email-like pattern with captures |
| 672 | var regex = try Regex.compile(allocator, "([a-zA-Z0-9.]+)@([a-zA-Z0-9]+)\\.([a-zA-Z]{2,})"); | |
| 672 | var regex = try Regex.compile(allocator, std.testing.io, "([a-zA-Z0-9.]+)@([a-zA-Z0-9]+)\\.([a-zA-Z]{2,})"); | |
| 673 | 673 | defer regex.deinit(); |
| 674 | 674 | |
| 675 | 675 | if (try regex.find("contact: user.name@example.com today")) |match| { |
| @@ -692,7 +692,7 @@ test "stress: compile many patterns sequentially" { | ||
| 692 | 692 | |
| 693 | 693 | var i: usize = 0; |
| 694 | 694 | while (i < 100) : (i += 1) { |
| 695 | var regex = try Regex.compile(allocator, "test\\d+"); | |
| 695 | var regex = try Regex.compile(allocator, std.testing.io, "test\\d+"); | |
| 696 | 696 | defer regex.deinit(); |
| 697 | 697 | try std.testing.expect(try regex.isMatch("test123")); |
| 698 | 698 | } |