ReviewOS

also looking at this

zig-utils/zig-regex

Port to latest zig-master

#2
Closed armagidon-exception wants to merge main into main
53 files +1149 -1017
tests/advanced_edge_cases.zigmodified+24-24
Changes to tests/advanced_edge_cases.zig
@@ -10,7 +10,7 @@ const RegexError = @import("regex").RegexError;
1010
1111test "advanced: positive lookahead basic" {
1212 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)");
1414 defer regex.deinit();
1515
1616 // "foobar" should match "foo" (lookahead is zero-width)
@@ -28,7 +28,7 @@ test "advanced: positive lookahead basic" {
2828
2929test "advanced: negative lookahead basic" {
3030 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)");
3232 defer regex.deinit();
3333
3434 // "foobaz" should match "foo" (bar not following)
@@ -41,7 +41,7 @@ test "advanced: negative lookahead basic" {
4141
4242test "advanced: lookahead is zero-width" {
4343 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");
4545 defer regex.deinit();
4646
4747 // Lookahead doesn't consume, so "bar" after it should match the same "bar"
@@ -52,7 +52,7 @@ test "advanced: lookahead is zero-width" {
5252
5353test "advanced: positive lookbehind" {
5454 const allocator = std.testing.allocator;
55 var regex = try Regex.compile(allocator, "(?<=@)\\w+");
55 var regex = try Regex.compile(allocator, std.testing.io, "(?<=@)\\w+");
5656 defer regex.deinit();
5757
5858 if (try regex.find("user@domain")) |match| {
@@ -66,7 +66,7 @@ test "advanced: positive lookbehind" {
6666
6767test "advanced: negative lookbehind" {
6868 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+");
7070 defer regex.deinit();
7171
7272 if (try regex.find("abc")) |match| {
@@ -82,7 +82,7 @@ test "advanced: negative lookbehind" {
8282
8383test "advanced: backreference repeated word" {
8484 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");
8686 defer regex.deinit();
8787
8888 try std.testing.expect(try regex.isMatch("the the"));
@@ -92,7 +92,7 @@ test "advanced: backreference repeated word" {
9292
9393test "advanced: backreference HTML tag matching" {
9494 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>");
9696 defer regex.deinit();
9797
9898 try std.testing.expect(try regex.isMatch("<b>bold</b>"));
@@ -104,7 +104,7 @@ test "advanced: backreference HTML tag matching" {
104104
105105test "advanced: non-capturing group doesn't affect capture numbering" {
106106 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)");
108108 defer regex.deinit();
109109
110110 if (try regex.find("abcdef")) |match| {
@@ -121,7 +121,7 @@ test "advanced: non-capturing group doesn't affect capture numbering" {
121121
122122test "advanced: non-capturing with alternation" {
123123 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");
125125 defer regex.deinit();
126126
127127 try std.testing.expect(try regex.isMatch("catfish"));
@@ -131,7 +131,7 @@ test "advanced: non-capturing with alternation" {
131131
132132test "advanced: mixed capturing and non-capturing" {
133133 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+)");
135135 defer regex.deinit();
136136
137137 if (try regex.find("hello world")) |match| {
@@ -149,7 +149,7 @@ test "advanced: mixed capturing and non-capturing" {
149149
150150test "advanced: named capture python style" {
151151 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})");
153153 defer regex.deinit();
154154
155155 if (try regex.find("date: 2024-01 ok")) |match| {
@@ -166,7 +166,7 @@ test "advanced: named capture python style" {
166166
167167test "advanced: named capture angle bracket style" {
168168 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+)");
170170 defer regex.deinit();
171171
172172 if (try regex.find("John Doe")) |match| {
@@ -184,7 +184,7 @@ test "advanced: named capture angle bracket style" {
184184
185185test "advanced: anchored pattern with captures" {
186186 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+)$");
188188 defer regex.deinit();
189189
190190 if (try regex.find("hello world")) |match| {
@@ -202,7 +202,7 @@ test "advanced: anchored pattern with captures" {
202202
203203test "advanced: case insensitive find with captures" {
204204 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 });
206206 defer regex.deinit();
207207
208208 if (try regex.find("HELLO WORLD")) |match| {
@@ -221,7 +221,7 @@ test "advanced: case insensitive find with captures" {
221221
222222test "advanced: IPv4 address pattern" {
223223 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}");
225225 defer regex.deinit();
226226
227227 try std.testing.expect(try regex.isMatch("192.168.1.1"));
@@ -231,7 +231,7 @@ test "advanced: IPv4 address pattern" {
231231
232232test "advanced: hex color pattern" {
233233 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}");
235235 defer regex.deinit();
236236
237237 try std.testing.expect(try regex.isMatch("#ff0000"));
@@ -241,7 +241,7 @@ test "advanced: hex color pattern" {
241241
242242test "advanced: semver pattern" {
243243 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+)");
245245 defer regex.deinit();
246246
247247 if (try regex.find("version 1.2.3-beta")) |match| {
@@ -259,7 +259,7 @@ test "advanced: semver pattern" {
259259
260260test "advanced: log line pattern" {
261261 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+(.+)");
263263 defer regex.deinit();
264264
265265 if (try regex.find("[ERROR] Something went wrong")) |match| {
@@ -275,7 +275,7 @@ test "advanced: log line pattern" {
275275
276276test "advanced: URL extraction" {
277277 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._/-]+");
279279 defer regex.deinit();
280280
281281 if (try regex.find("visit http://example.com/path today")) |match| {
@@ -291,7 +291,7 @@ test "advanced: URL extraction" {
291291
292292test "advanced: iterator over empty result" {
293293 const allocator = std.testing.allocator;
294 var regex = try Regex.compile(allocator, "xyz");
294 var regex = try Regex.compile(allocator, std.testing.io, "xyz");
295295 defer regex.deinit();
296296
297297 var iter = regex.iterator("hello world");
@@ -301,7 +301,7 @@ test "advanced: iterator over empty result" {
301301
302302test "advanced: iterator collects all matches" {
303303 const allocator = std.testing.allocator;
304 var regex = try Regex.compile(allocator, "\\d+");
304 var regex = try Regex.compile(allocator, std.testing.io, "\\d+");
305305 defer regex.deinit();
306306
307307 var iter = regex.iterator("a1b23c456");
@@ -320,7 +320,7 @@ test "advanced: iterator collects all matches" {
320320
321321test "advanced: multiline with captures" {
322322 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 });
324324 defer regex.deinit();
325325
326326 const matches = try regex.findAll(allocator, "key1: val\nkey2: val");
@@ -343,7 +343,7 @@ test "advanced: multiline with captures" {
343343
344344test "advanced: match at very start of input" {
345345 const allocator = std.testing.allocator;
346 var regex = try Regex.compile(allocator, "\\d+");
346 var regex = try Regex.compile(allocator, std.testing.io, "\\d+");
347347 defer regex.deinit();
348348
349349 if (try regex.find("123abc")) |match| {
@@ -358,7 +358,7 @@ test "advanced: match at very start of input" {
358358
359359test "advanced: match consuming entire input" {
360360 const allocator = std.testing.allocator;
361 var regex = try Regex.compile(allocator, "\\w+");
361 var regex = try Regex.compile(allocator, std.testing.io, "\\w+");
362362 defer regex.deinit();
363363
364364 if (try regex.find("hello")) |match| {