also looking at this
Port to latest zig-master
#2
53 files
+1149
-1017
| @@ -10,7 +10,7 @@ const RegexError = @import("regex").RegexError; | ||
| 10 | 10 | |
| 11 | 11 | test "advanced: positive lookahead basic" { |
| 12 | 12 | const allocator = std.testing.allocator; |
| 13 | var regex = try Regex.compile(allocator, "foo(?=bar)"); | |
| 13 | var regex = try Regex.compile(allocator, std.testing.io, "foo(?=bar)"); | |
| 14 | 14 | defer regex.deinit(); |
| 15 | 15 | |
| 16 | 16 | // "foobar" should match "foo" (lookahead is zero-width) |
| @@ -28,7 +28,7 @@ test "advanced: positive lookahead basic" { | ||
| 28 | 28 | |
| 29 | 29 | test "advanced: negative lookahead basic" { |
| 30 | 30 | const allocator = std.testing.allocator; |
| 31 | var regex = try Regex.compile(allocator, "foo(?!bar)"); | |
| 31 | var regex = try Regex.compile(allocator, std.testing.io, "foo(?!bar)"); | |
| 32 | 32 | defer regex.deinit(); |
| 33 | 33 | |
| 34 | 34 | // "foobaz" should match "foo" (bar not following) |
| @@ -41,7 +41,7 @@ test "advanced: negative lookahead basic" { | ||
| 41 | 41 | |
| 42 | 42 | test "advanced: lookahead is zero-width" { |
| 43 | 43 | const allocator = std.testing.allocator; |
| 44 | var regex = try Regex.compile(allocator, "foo(?=bar)bar"); | |
| 44 | var regex = try Regex.compile(allocator, std.testing.io, "foo(?=bar)bar"); | |
| 45 | 45 | defer regex.deinit(); |
| 46 | 46 | |
| 47 | 47 | // Lookahead doesn't consume, so "bar" after it should match the same "bar" |
| @@ -52,7 +52,7 @@ test "advanced: lookahead is zero-width" { | ||
| 52 | 52 | |
| 53 | 53 | test "advanced: positive lookbehind" { |
| 54 | 54 | const allocator = std.testing.allocator; |
| 55 | var regex = try Regex.compile(allocator, "(?<=@)\\w+"); | |
| 55 | var regex = try Regex.compile(allocator, std.testing.io, "(?<=@)\\w+"); | |
| 56 | 56 | defer regex.deinit(); |
| 57 | 57 | |
| 58 | 58 | if (try regex.find("user@domain")) |match| { |
| @@ -66,7 +66,7 @@ test "advanced: positive lookbehind" { | ||
| 66 | 66 | |
| 67 | 67 | test "advanced: negative lookbehind" { |
| 68 | 68 | const allocator = std.testing.allocator; |
| 69 | var regex = try Regex.compile(allocator, "(?<!\\d)\\w+"); | |
| 69 | var regex = try Regex.compile(allocator, std.testing.io, "(?<!\\d)\\w+"); | |
| 70 | 70 | defer regex.deinit(); |
| 71 | 71 | |
| 72 | 72 | if (try regex.find("abc")) |match| { |
| @@ -82,7 +82,7 @@ test "advanced: negative lookbehind" { | ||
| 82 | 82 | |
| 83 | 83 | test "advanced: backreference repeated word" { |
| 84 | 84 | const allocator = std.testing.allocator; |
| 85 | var regex = try Regex.compile(allocator, "\\b(\\w+)\\s+\\1\\b"); | |
| 85 | var regex = try Regex.compile(allocator, std.testing.io, "\\b(\\w+)\\s+\\1\\b"); | |
| 86 | 86 | defer regex.deinit(); |
| 87 | 87 | |
| 88 | 88 | try std.testing.expect(try regex.isMatch("the the")); |
| @@ -92,7 +92,7 @@ test "advanced: backreference repeated word" { | ||
| 92 | 92 | |
| 93 | 93 | test "advanced: backreference HTML tag matching" { |
| 94 | 94 | const allocator = std.testing.allocator; |
| 95 | var regex = try Regex.compile(allocator, "<(\\w+)>.*</\\1>"); | |
| 95 | var regex = try Regex.compile(allocator, std.testing.io, "<(\\w+)>.*</\\1>"); | |
| 96 | 96 | defer regex.deinit(); |
| 97 | 97 | |
| 98 | 98 | try std.testing.expect(try regex.isMatch("<b>bold</b>")); |
| @@ -104,7 +104,7 @@ test "advanced: backreference HTML tag matching" { | ||
| 104 | 104 | |
| 105 | 105 | test "advanced: non-capturing group doesn't affect capture numbering" { |
| 106 | 106 | const allocator = std.testing.allocator; |
| 107 | var regex = try Regex.compile(allocator, "(?:abc)(def)"); | |
| 107 | var regex = try Regex.compile(allocator, std.testing.io, "(?:abc)(def)"); | |
| 108 | 108 | defer regex.deinit(); |
| 109 | 109 | |
| 110 | 110 | if (try regex.find("abcdef")) |match| { |
| @@ -121,7 +121,7 @@ test "advanced: non-capturing group doesn't affect capture numbering" { | ||
| 121 | 121 | |
| 122 | 122 | test "advanced: non-capturing with alternation" { |
| 123 | 123 | const allocator = std.testing.allocator; |
| 124 | var regex = try Regex.compile(allocator, "(?:cat|dog)fish"); | |
| 124 | var regex = try Regex.compile(allocator, std.testing.io, "(?:cat|dog)fish"); | |
| 125 | 125 | defer regex.deinit(); |
| 126 | 126 | |
| 127 | 127 | try std.testing.expect(try regex.isMatch("catfish")); |
| @@ -131,7 +131,7 @@ test "advanced: non-capturing with alternation" { | ||
| 131 | 131 | |
| 132 | 132 | test "advanced: mixed capturing and non-capturing" { |
| 133 | 133 | const allocator = std.testing.allocator; |
| 134 | var regex = try Regex.compile(allocator, "(\\w+)(?:\\s+)(\\w+)"); | |
| 134 | var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)(?:\\s+)(\\w+)"); | |
| 135 | 135 | defer regex.deinit(); |
| 136 | 136 | |
| 137 | 137 | if (try regex.find("hello world")) |match| { |
| @@ -149,7 +149,7 @@ test "advanced: mixed capturing and non-capturing" { | ||
| 149 | 149 | |
| 150 | 150 | test "advanced: named capture python style" { |
| 151 | 151 | const allocator = std.testing.allocator; |
| 152 | var regex = try Regex.compile(allocator, "(?P<year>\\d{4})-(?P<month>\\d{2})"); | |
| 152 | var regex = try Regex.compile(allocator, std.testing.io, "(?P<year>\\d{4})-(?P<month>\\d{2})"); | |
| 153 | 153 | defer regex.deinit(); |
| 154 | 154 | |
| 155 | 155 | if (try regex.find("date: 2024-01 ok")) |match| { |
| @@ -166,7 +166,7 @@ test "advanced: named capture python style" { | ||
| 166 | 166 | |
| 167 | 167 | test "advanced: named capture angle bracket style" { |
| 168 | 168 | const allocator = std.testing.allocator; |
| 169 | var regex = try Regex.compile(allocator, "(?<first>\\w+)\\s(?<last>\\w+)"); | |
| 169 | var regex = try Regex.compile(allocator, std.testing.io, "(?<first>\\w+)\\s(?<last>\\w+)"); | |
| 170 | 170 | defer regex.deinit(); |
| 171 | 171 | |
| 172 | 172 | if (try regex.find("John Doe")) |match| { |
| @@ -184,7 +184,7 @@ test "advanced: named capture angle bracket style" { | ||
| 184 | 184 | |
| 185 | 185 | test "advanced: anchored pattern with captures" { |
| 186 | 186 | const allocator = std.testing.allocator; |
| 187 | var regex = try Regex.compile(allocator, "^(\\w+)\\s+(\\w+)$"); | |
| 187 | var regex = try Regex.compile(allocator, std.testing.io, "^(\\w+)\\s+(\\w+)$"); | |
| 188 | 188 | defer regex.deinit(); |
| 189 | 189 | |
| 190 | 190 | if (try regex.find("hello world")) |match| { |
| @@ -202,7 +202,7 @@ test "advanced: anchored pattern with captures" { | ||
| 202 | 202 | |
| 203 | 203 | test "advanced: case insensitive find with captures" { |
| 204 | 204 | const allocator = std.testing.allocator; |
| 205 | var regex = try Regex.compileWithFlags(allocator, "(hello) (world)", .{ .case_insensitive = true }); | |
| 205 | var regex = try Regex.compileWithFlags(allocator, std.testing.io, "(hello) (world)", .{ .case_insensitive = true }); | |
| 206 | 206 | defer regex.deinit(); |
| 207 | 207 | |
| 208 | 208 | if (try regex.find("HELLO WORLD")) |match| { |
| @@ -221,7 +221,7 @@ test "advanced: case insensitive find with captures" { | ||
| 221 | 221 | |
| 222 | 222 | test "advanced: IPv4 address pattern" { |
| 223 | 223 | const allocator = std.testing.allocator; |
| 224 | var regex = try Regex.compile(allocator, "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); | |
| 224 | var regex = try Regex.compile(allocator, std.testing.io, "\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}"); | |
| 225 | 225 | defer regex.deinit(); |
| 226 | 226 | |
| 227 | 227 | try std.testing.expect(try regex.isMatch("192.168.1.1")); |
| @@ -231,7 +231,7 @@ test "advanced: IPv4 address pattern" { | ||
| 231 | 231 | |
| 232 | 232 | test "advanced: hex color pattern" { |
| 233 | 233 | const allocator = std.testing.allocator; |
| 234 | var regex = try Regex.compile(allocator, "#[0-9a-fA-F]{6}"); | |
| 234 | var regex = try Regex.compile(allocator, std.testing.io, "#[0-9a-fA-F]{6}"); | |
| 235 | 235 | defer regex.deinit(); |
| 236 | 236 | |
| 237 | 237 | try std.testing.expect(try regex.isMatch("#ff0000")); |
| @@ -241,7 +241,7 @@ test "advanced: hex color pattern" { | ||
| 241 | 241 | |
| 242 | 242 | test "advanced: semver pattern" { |
| 243 | 243 | const allocator = std.testing.allocator; |
| 244 | var regex = try Regex.compile(allocator, "(\\d+)\\.(\\d+)\\.(\\d+)"); | |
| 244 | var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)\\.(\\d+)\\.(\\d+)"); | |
| 245 | 245 | defer regex.deinit(); |
| 246 | 246 | |
| 247 | 247 | if (try regex.find("version 1.2.3-beta")) |match| { |
| @@ -259,7 +259,7 @@ test "advanced: semver pattern" { | ||
| 259 | 259 | |
| 260 | 260 | test "advanced: log line pattern" { |
| 261 | 261 | const allocator = std.testing.allocator; |
| 262 | var regex = try Regex.compile(allocator, "\\[(\\w+)\\]\\s+(.+)"); | |
| 262 | var regex = try Regex.compile(allocator, std.testing.io, "\\[(\\w+)\\]\\s+(.+)"); | |
| 263 | 263 | defer regex.deinit(); |
| 264 | 264 | |
| 265 | 265 | if (try regex.find("[ERROR] Something went wrong")) |match| { |
| @@ -275,7 +275,7 @@ test "advanced: log line pattern" { | ||
| 275 | 275 | |
| 276 | 276 | test "advanced: URL extraction" { |
| 277 | 277 | const allocator = std.testing.allocator; |
| 278 | var regex = try Regex.compile(allocator, "https?://[a-zA-Z0-9._/-]+"); | |
| 278 | var regex = try Regex.compile(allocator, std.testing.io, "https?://[a-zA-Z0-9._/-]+"); | |
| 279 | 279 | defer regex.deinit(); |
| 280 | 280 | |
| 281 | 281 | if (try regex.find("visit http://example.com/path today")) |match| { |
| @@ -291,7 +291,7 @@ test "advanced: URL extraction" { | ||
| 291 | 291 | |
| 292 | 292 | test "advanced: iterator over empty result" { |
| 293 | 293 | const allocator = std.testing.allocator; |
| 294 | var regex = try Regex.compile(allocator, "xyz"); | |
| 294 | var regex = try Regex.compile(allocator, std.testing.io, "xyz"); | |
| 295 | 295 | defer regex.deinit(); |
| 296 | 296 | |
| 297 | 297 | var iter = regex.iterator("hello world"); |
| @@ -301,7 +301,7 @@ test "advanced: iterator over empty result" { | ||
| 301 | 301 | |
| 302 | 302 | test "advanced: iterator collects all matches" { |
| 303 | 303 | const allocator = std.testing.allocator; |
| 304 | var regex = try Regex.compile(allocator, "\\d+"); | |
| 304 | var regex = try Regex.compile(allocator, std.testing.io, "\\d+"); | |
| 305 | 305 | defer regex.deinit(); |
| 306 | 306 | |
| 307 | 307 | var iter = regex.iterator("a1b23c456"); |
| @@ -320,7 +320,7 @@ test "advanced: iterator collects all matches" { | ||
| 320 | 320 | |
| 321 | 321 | test "advanced: multiline with captures" { |
| 322 | 322 | const allocator = std.testing.allocator; |
| 323 | var regex = try Regex.compileWithFlags(allocator, "^(\\w+):", .{ .multiline = true }); | |
| 323 | var regex = try Regex.compileWithFlags(allocator, std.testing.io, "^(\\w+):", .{ .multiline = true }); | |
| 324 | 324 | defer regex.deinit(); |
| 325 | 325 | |
| 326 | 326 | const matches = try regex.findAll(allocator, "key1: val\nkey2: val"); |
| @@ -343,7 +343,7 @@ test "advanced: multiline with captures" { | ||
| 343 | 343 | |
| 344 | 344 | test "advanced: match at very start of input" { |
| 345 | 345 | const allocator = std.testing.allocator; |
| 346 | var regex = try Regex.compile(allocator, "\\d+"); | |
| 346 | var regex = try Regex.compile(allocator, std.testing.io, "\\d+"); | |
| 347 | 347 | defer regex.deinit(); |
| 348 | 348 | |
| 349 | 349 | if (try regex.find("123abc")) |match| { |
| @@ -358,7 +358,7 @@ test "advanced: match at very start of input" { | ||
| 358 | 358 | |
| 359 | 359 | test "advanced: match consuming entire input" { |
| 360 | 360 | const allocator = std.testing.allocator; |
| 361 | var regex = try Regex.compile(allocator, "\\w+"); | |
| 361 | var regex = try Regex.compile(allocator, std.testing.io, "\\w+"); | |
| 362 | 362 | defer regex.deinit(); |
| 363 | 363 | |
| 364 | 364 | if (try regex.find("hello")) |match| { |