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/backreferences.zigmodified+23-23
Changes to tests/backreferences.zig
@@ -5,7 +5,7 @@ const Regex = @import("regex").Regex;
55
66test "backreference: simple capture group replacement" {
77 const allocator = std.testing.allocator;
8 var regex = try Regex.compile(allocator, "(\\w+)");
8 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)");
99 defer regex.deinit();
1010
1111 const result = try regex.replace(allocator, "hello", "$1!");
@@ -16,7 +16,7 @@ test "backreference: simple capture group replacement" {
1616
1717test "backreference: swap two words" {
1818 const allocator = std.testing.allocator;
19 var regex = try Regex.compile(allocator, "(\\w+) (\\w+)");
19 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) (\\w+)");
2020 defer regex.deinit();
2121
2222 const result = try regex.replace(allocator, "hello world", "$2 $1");
@@ -27,7 +27,7 @@ test "backreference: swap two words" {
2727
2828test "backreference: repeat capture" {
2929 const allocator = std.testing.allocator;
30 var regex = try Regex.compile(allocator, "(\\w+)");
30 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)");
3131 defer regex.deinit();
3232
3333 const result = try regex.replace(allocator, "test", "$1-$1");
@@ -38,7 +38,7 @@ test "backreference: repeat capture" {
3838
3939test "backreference: multiple captures" {
4040 const allocator = std.testing.allocator;
41 var regex = try Regex.compile(allocator, "(\\d+)-(\\d+)-(\\d+)");
41 var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)-(\\d+)-(\\d+)");
4242 defer regex.deinit();
4343
4444 const result = try regex.replace(allocator, "2025-10-26", "$3/$2/$1");
@@ -49,7 +49,7 @@ test "backreference: multiple captures" {
4949
5050test "backreference: escaped dollar sign" {
5151 const allocator = std.testing.allocator;
52 var regex = try Regex.compile(allocator, "(\\d+)");
52 var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)");
5353 defer regex.deinit();
5454
5555 const result = try regex.replace(allocator, "100", "$$$1");
@@ -60,7 +60,7 @@ test "backreference: escaped dollar sign" {
6060
6161test "backreference: replaceAll with captures" {
6262 const allocator = std.testing.allocator;
63 var regex = try Regex.compile(allocator, "(\\w+)@(\\w+)");
63 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(\\w+)");
6464 defer regex.deinit();
6565
6666 const result = try regex.replaceAll(allocator, "user@example and admin@test", "$1 at $2");
@@ -71,7 +71,7 @@ test "backreference: replaceAll with captures" {
7171
7272test "backreference: extract and format phone numbers" {
7373 const allocator = std.testing.allocator;
74 var regex = try Regex.compile(allocator, "(\\d{3})-(\\d{3})-(\\d{4})");
74 var regex = try Regex.compile(allocator, std.testing.io, "(\\d{3})-(\\d{3})-(\\d{4})");
7575 defer regex.deinit();
7676
7777 const result = try regex.replace(allocator, "555-123-4567", "($1) $2-$3");
@@ -82,7 +82,7 @@ test "backreference: extract and format phone numbers" {
8282
8383test "backreference: reformat dates" {
8484 const allocator = std.testing.allocator;
85 var regex = try Regex.compile(allocator, "(\\d{4})-(\\d{2})-(\\d{2})");
85 var regex = try Regex.compile(allocator, std.testing.io, "(\\d{4})-(\\d{2})-(\\d{2})");
8686 defer regex.deinit();
8787
8888 const result = try regex.replaceAll(allocator, "2025-10-26 and 2024-12-31", "$2/$3/$1");
@@ -93,7 +93,7 @@ test "backreference: reformat dates" {
9393
9494test "backreference: wrap matches in tags" {
9595 const allocator = std.testing.allocator;
96 var regex = try Regex.compile(allocator, "(\\w+)");
96 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)");
9797 defer regex.deinit();
9898
9999 const result = try regex.replaceAll(allocator, "hello world", "<b>$1</b>");
@@ -104,7 +104,7 @@ test "backreference: wrap matches in tags" {
104104
105105test "backreference: invalid capture index" {
106106 const allocator = std.testing.allocator;
107 var regex = try Regex.compile(allocator, "(\\w+)");
107 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)");
108108 defer regex.deinit();
109109
110110 // Only one capture group, $2 should be treated as literal
@@ -116,7 +116,7 @@ test "backreference: invalid capture index" {
116116
117117test "backreference: nested captures" {
118118 const allocator = std.testing.allocator;
119 var regex = try Regex.compile(allocator, "((\\w+)@(\\w+))");
119 var regex = try Regex.compile(allocator, std.testing.io, "((\\w+)@(\\w+))");
120120 defer regex.deinit();
121121
122122 const result = try regex.replace(allocator, "user@example.com", "Email: $1 (user=$2, domain=$3)");
@@ -127,7 +127,7 @@ test "backreference: nested captures" {
127127
128128test "backreference: quote words" {
129129 const allocator = std.testing.allocator;
130 var regex = try Regex.compile(allocator, "\\b(\\w+)\\b");
130 var regex = try Regex.compile(allocator, std.testing.io, "\\b(\\w+)\\b");
131131 defer regex.deinit();
132132
133133 const result = try regex.replaceAll(allocator, "hello world", "'$1'");
@@ -138,7 +138,7 @@ test "backreference: quote words" {
138138
139139test "backreference: transform case context" {
140140 const allocator = std.testing.allocator;
141 var regex = try Regex.compile(allocator, "(Mr|Mrs|Ms) (\\w+)");
141 var regex = try Regex.compile(allocator, std.testing.io, "(Mr|Mrs|Ms) (\\w+)");
142142 defer regex.deinit();
143143
144144 const result = try regex.replace(allocator, "Hello Mr Smith", "$1. $2");
@@ -151,7 +151,7 @@ test "backreference: transform case context" {
151151
152152test "pattern backreference: basic \\1" {
153153 const allocator = std.testing.allocator;
154 var regex = try Regex.compile(allocator, "(\\w+) \\1");
154 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1");
155155 defer regex.deinit();
156156
157157 // Should match repeated words
@@ -171,7 +171,7 @@ test "pattern backreference: basic \\1" {
171171
172172test "pattern backreference: multiple captures" {
173173 const allocator = std.testing.allocator;
174 var regex = try Regex.compile(allocator, "(\\w+) (\\w+) \\1 \\2");
174 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) (\\w+) \\1 \\2");
175175 defer regex.deinit();
176176
177177 try std.testing.expect(try regex.isMatch("foo bar foo bar"));
@@ -191,7 +191,7 @@ test "pattern backreference: multiple captures" {
191191
192192test "pattern backreference: with quantifiers" {
193193 const allocator = std.testing.allocator;
194 var regex = try Regex.compile(allocator, "(\\d+)\\+\\1");
194 var regex = try Regex.compile(allocator, std.testing.io, "(\\d+)\\+\\1");
195195 defer regex.deinit();
196196
197197 // Match patterns like "5+5", "123+123"
@@ -202,7 +202,7 @@ test "pattern backreference: with quantifiers" {
202202
203203test "pattern backreference: HTML tag matching" {
204204 const allocator = std.testing.allocator;
205 var regex = try Regex.compile(allocator, "<(\\w+)>.*</\\1>");
205 var regex = try Regex.compile(allocator, std.testing.io, "<(\\w+)>.*</\\1>");
206206 defer regex.deinit();
207207
208208 // Match matching HTML tags
@@ -213,7 +213,7 @@ test "pattern backreference: HTML tag matching" {
213213
214214test "pattern backreference: case sensitive" {
215215 const allocator = std.testing.allocator;
216 var regex = try Regex.compile(allocator, "(\\w+) \\1");
216 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1");
217217 defer regex.deinit();
218218
219219 // Backreferences should be case sensitive
@@ -223,7 +223,7 @@ test "pattern backreference: case sensitive" {
223223
224224test "pattern backreference: nested groups" {
225225 const allocator = std.testing.allocator;
226 var regex = try Regex.compile(allocator, "((\\w)\\w)\\2");
226 var regex = try Regex.compile(allocator, std.testing.io, "((\\w)\\w)\\2");
227227 defer regex.deinit();
228228
229229 // \\2 refers to second group (single char), so "aba" should match:
@@ -246,7 +246,7 @@ test "pattern backreference: nested groups" {
246246
247247test "pattern backreference: with alternation" {
248248 const allocator = std.testing.allocator;
249 var regex = try Regex.compile(allocator, "(a|b)\\1");
249 var regex = try Regex.compile(allocator, std.testing.io, "(a|b)\\1");
250250 defer regex.deinit();
251251
252252 try std.testing.expect(try regex.isMatch("aa"));
@@ -257,7 +257,7 @@ test "pattern backreference: with alternation" {
257257
258258test "pattern backreference: multiple in same pattern" {
259259 const allocator = std.testing.allocator;
260 var regex = try Regex.compile(allocator, "(\\w)\\1\\1");
260 var regex = try Regex.compile(allocator, std.testing.io, "(\\w)\\1\\1");
261261 defer regex.deinit();
262262
263263 // Match three of the same character
@@ -269,7 +269,7 @@ test "pattern backreference: multiple in same pattern" {
269269
270270test "pattern backreference: findAll" {
271271 const allocator = std.testing.allocator;
272 var regex = try Regex.compile(allocator, "(\\w+) \\1");
272 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1");
273273 defer regex.deinit();
274274
275275 const matches = try regex.findAll(allocator, "foo foo bar bar baz qux");
@@ -288,7 +288,7 @@ test "pattern backreference: findAll" {
288288
289289test "pattern backreference: quoted strings" {
290290 const allocator = std.testing.allocator;
291 var regex = try Regex.compile(allocator, "(['\"]).*\\1");
291 var regex = try Regex.compile(allocator, std.testing.io, "(['\"]).*\\1");
292292 defer regex.deinit();
293293
294294 // Match quoted strings with same quote type