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/non_capturing_groups.zigmodified+16-16
Changes to tests/non_capturing_groups.zig
@@ -5,7 +5,7 @@ const Regex = @import("regex").Regex;
55
66test "non-capturing: basic non-capturing group" {
77 const allocator = std.testing.allocator;
8 var regex = try Regex.compile(allocator, "(?:\\d+)");
8 var regex = try Regex.compile(allocator, std.testing.io, "(?:\\d+)");
99 defer regex.deinit();
1010
1111 const result = try regex.find("123");
@@ -22,7 +22,7 @@ test "non-capturing: basic non-capturing group" {
2222
2323test "non-capturing: mixed capturing and non-capturing" {
2424 const allocator = std.testing.allocator;
25 var regex = try Regex.compile(allocator, "(\\w+)@(?:\\w+)\\.(\\w+)");
25 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(?:\\w+)\\.(\\w+)");
2626 defer regex.deinit();
2727
2828 const result = try regex.find("user@example.com");
@@ -41,7 +41,7 @@ test "non-capturing: mixed capturing and non-capturing" {
4141
4242test "non-capturing: alternation in non-capturing group" {
4343 const allocator = std.testing.allocator;
44 var regex = try Regex.compile(allocator, "(?:cat|dog) (\\w+)");
44 var regex = try Regex.compile(allocator, std.testing.io, "(?:cat|dog) (\\w+)");
4545 defer regex.deinit();
4646
4747 const result1 = try regex.find("cat food");
@@ -69,7 +69,7 @@ test "non-capturing: alternation in non-capturing group" {
6969
7070test "non-capturing: nested non-capturing groups" {
7171 const allocator = std.testing.allocator;
72 var regex = try Regex.compile(allocator, "(?:(?:a|b)(?:c|d))");
72 var regex = try Regex.compile(allocator, std.testing.io, "(?:(?:a|b)(?:c|d))");
7373 defer regex.deinit();
7474
7575 try std.testing.expect(try regex.isMatch("ac"));
@@ -82,7 +82,7 @@ test "non-capturing: nested non-capturing groups" {
8282test "non-capturing: capture numbering with non-capturing groups" {
8383 const allocator = std.testing.allocator;
8484 // (a) (?:b) (c) - should have captures $1=a, $2=c (not $1=a, $2=b, $3=c)
85 var regex = try Regex.compile(allocator, "(a)(?:b)(c)");
85 var regex = try Regex.compile(allocator, std.testing.io, "(a)(?:b)(c)");
8686 defer regex.deinit();
8787
8888 const result = try regex.find("abc");
@@ -100,7 +100,7 @@ test "non-capturing: capture numbering with non-capturing groups" {
100100
101101test "non-capturing: with quantifiers" {
102102 const allocator = std.testing.allocator;
103 var regex = try Regex.compile(allocator, "(?:\\d+)+");
103 var regex = try Regex.compile(allocator, std.testing.io, "(?:\\d+)+");
104104 defer regex.deinit();
105105
106106 try std.testing.expect(try regex.isMatch("123"));
@@ -110,7 +110,7 @@ test "non-capturing: with quantifiers" {
110110test "non-capturing: complex pattern" {
111111 const allocator = std.testing.allocator;
112112 // Simplified pattern - removed [\w.] which has parsing issues
113 var regex = try Regex.compile(allocator, "(?:https?://)?([a-z]+)(?:/\\w+)*");
113 var regex = try Regex.compile(allocator, std.testing.io, "(?:https?://)?([a-z]+)(?:/\\w+)*");
114114 defer regex.deinit();
115115
116116 const result1 = try regex.find("http://example/path/to/page");
@@ -138,7 +138,7 @@ test "non-capturing: complex pattern" {
138138
139139test "non-capturing: in replacement" {
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");
@@ -149,7 +149,7 @@ test "non-capturing: in replacement" {
149149
150150test "non-capturing: multiple non-capturing with one capturing" {
151151 const allocator = std.testing.allocator;
152 var regex = try Regex.compile(allocator, "(?:a)(?:b)(c)(?:d)");
152 var regex = try Regex.compile(allocator, std.testing.io, "(?:a)(?:b)(c)(?:d)");
153153 defer regex.deinit();
154154
155155 const result = try regex.find("abcd");
@@ -166,7 +166,7 @@ test "non-capturing: multiple non-capturing with one capturing" {
166166
167167test "non-capturing: with character classes" {
168168 const allocator = std.testing.allocator;
169 var regex = try Regex.compile(allocator, "(?:[a-z]+)@(\\w+)");
169 var regex = try Regex.compile(allocator, std.testing.io, "(?:[a-z]+)@(\\w+)");
170170 defer regex.deinit();
171171
172172 const result = try regex.find("user@example");
@@ -183,7 +183,7 @@ test "non-capturing: with character classes" {
183183
184184test "non-capturing: nested capturing inside non-capturing" {
185185 const allocator = std.testing.allocator;
186 var regex = try Regex.compile(allocator, "(?:(\\d+):(\\d+))");
186 var regex = try Regex.compile(allocator, std.testing.io, "(?:(\\d+):(\\d+))");
187187 defer regex.deinit();
188188
189189 const result = try regex.find("12:30");
@@ -201,7 +201,7 @@ test "non-capturing: nested capturing inside non-capturing" {
201201
202202test "non-capturing: all groups non-capturing" {
203203 const allocator = std.testing.allocator;
204 var regex = try Regex.compile(allocator, "(?:a)(?:b)(?:c)");
204 var regex = try Regex.compile(allocator, std.testing.io, "(?:a)(?:b)(?:c)");
205205 defer regex.deinit();
206206
207207 const result = try regex.find("abc");
@@ -218,7 +218,7 @@ test "non-capturing: all groups non-capturing" {
218218
219219test "non-capturing: with anchors" {
220220 const allocator = std.testing.allocator;
221 var regex = try Regex.compile(allocator, "^(?:hello|hi) (\\w+)$");
221 var regex = try Regex.compile(allocator, std.testing.io, "^(?:hello|hi) (\\w+)$");
222222 defer regex.deinit();
223223
224224 const result = try regex.find("hello world");
@@ -237,7 +237,7 @@ test "non-capturing: with anchors" {
237237
238238test "non-capturing: replaceAll with non-capturing groups" {
239239 const allocator = std.testing.allocator;
240 var regex = try Regex.compile(allocator, "(?:the|a) (\\w+)");
240 var regex = try Regex.compile(allocator, std.testing.io, "(?:the|a) (\\w+)");
241241 defer regex.deinit();
242242
243243 const result = try regex.replaceAll(allocator, "the cat and a dog", "$1");
@@ -248,7 +248,7 @@ test "non-capturing: replaceAll with non-capturing groups" {
248248
249249test "non-capturing: empty non-capturing group" {
250250 const allocator = std.testing.allocator;
251 var regex = try Regex.compile(allocator, "a(?:)b");
251 var regex = try Regex.compile(allocator, std.testing.io, "a(?:)b");
252252 defer regex.deinit();
253253
254254 try std.testing.expect(try regex.isMatch("ab"));
@@ -258,7 +258,7 @@ test "non-capturing: verify capture count" {
258258 const allocator = std.testing.allocator;
259259
260260 // Pattern with 3 non-capturing and 2 capturing groups
261 var regex = try Regex.compile(allocator, "(?:a)(b)(?:c)(d)(?:e)");
261 var regex = try Regex.compile(allocator, std.testing.io, "(?:a)(b)(?:c)(d)(?:e)");
262262 defer regex.deinit();
263263
264264 // Should only have 2 captures, not 5