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/edge_cases.zigmodified+25-25
Changes to tests/edge_cases.zig
@@ -5,7 +5,7 @@ const RegexError = @import("regex").RegexError;
55// Edge case: Empty input
66test "edge: empty input with star" {
77 const allocator = std.testing.allocator;
8 var regex = try Regex.compile(allocator, "a*");
8 var regex = try Regex.compile(allocator, std.testing.io, "a*");
99 defer regex.deinit();
1010
1111 try std.testing.expect(try regex.isMatch(""));
@@ -13,7 +13,7 @@ test "edge: empty input with star" {
1313
1414test "edge: empty input with plus should fail" {
1515 const allocator = std.testing.allocator;
16 var regex = try Regex.compile(allocator, "a+");
16 var regex = try Regex.compile(allocator, std.testing.io, "a+");
1717 defer regex.deinit();
1818
1919 try std.testing.expect(!try regex.isMatch(""));
@@ -22,7 +22,7 @@ test "edge: empty input with plus should fail" {
2222// Edge case: Single character patterns
2323test "edge: single character literal" {
2424 const allocator = std.testing.allocator;
25 var regex = try Regex.compile(allocator, "x");
25 var regex = try Regex.compile(allocator, std.testing.io, "x");
2626 defer regex.deinit();
2727
2828 try std.testing.expect(try regex.isMatch("x"));
@@ -33,7 +33,7 @@ test "edge: single character literal" {
3333// Edge case: Nested quantifiers behavior
3434test "edge: star after plus" {
3535 const allocator = std.testing.allocator;
36 var regex = try Regex.compile(allocator, "a+b*");
36 var regex = try Regex.compile(allocator, std.testing.io, "a+b*");
3737 defer regex.deinit();
3838
3939 try std.testing.expect(try regex.isMatch("a"));
@@ -44,7 +44,7 @@ test "edge: star after plus" {
4444// Edge case: Multiple alternations
4545test "edge: multiple alternations" {
4646 const allocator = std.testing.allocator;
47 var regex = try Regex.compile(allocator, "a|b|c|d");
47 var regex = try Regex.compile(allocator, std.testing.io, "a|b|c|d");
4848 defer regex.deinit();
4949
5050 try std.testing.expect(try regex.isMatch("a"));
@@ -57,7 +57,7 @@ test "edge: multiple alternations" {
5757// Edge case: Alternation with empty branch
5858test "edge: alternation with quantifiers" {
5959 const allocator = std.testing.allocator;
60 var regex = try Regex.compile(allocator, "a*|b+");
60 var regex = try Regex.compile(allocator, std.testing.io, "a*|b+");
6161 defer regex.deinit();
6262
6363 try std.testing.expect(try regex.isMatch(""));
@@ -68,7 +68,7 @@ test "edge: alternation with quantifiers" {
6868// Edge case: Complex nested groups
6969test "edge: nested groups" {
7070 const allocator = std.testing.allocator;
71 var regex = try Regex.compile(allocator, "((a))");
71 var regex = try Regex.compile(allocator, std.testing.io, "((a))");
7272 defer regex.deinit();
7373
7474 try std.testing.expect(try regex.isMatch("a"));
@@ -77,7 +77,7 @@ test "edge: nested groups" {
7777// Edge case: Character class edge cases
7878test "edge: empty character class range" {
7979 const allocator = std.testing.allocator;
80 var regex = try Regex.compile(allocator, "[a]");
80 var regex = try Regex.compile(allocator, std.testing.io, "[a]");
8181 defer regex.deinit();
8282
8383 try std.testing.expect(try regex.isMatch("a"));
@@ -86,7 +86,7 @@ test "edge: empty character class range" {
8686
8787test "edge: character class with single range" {
8888 const allocator = std.testing.allocator;
89 var regex = try Regex.compile(allocator, "[a-a]");
89 var regex = try Regex.compile(allocator, std.testing.io, "[a-a]");
9090 defer regex.deinit();
9191
9292 try std.testing.expect(try regex.isMatch("a"));
@@ -95,7 +95,7 @@ test "edge: character class with single range" {
9595
9696test "edge: negated character class matching nothing in range" {
9797 const allocator = std.testing.allocator;
98 var regex = try Regex.compile(allocator, "[^a-z]");
98 var regex = try Regex.compile(allocator, std.testing.io, "[^a-z]");
9999 defer regex.deinit();
100100
101101 try std.testing.expect(try regex.isMatch("A"));
@@ -106,7 +106,7 @@ test "edge: negated character class matching nothing in range" {
106106// Edge case: Anchors at different positions
107107test "edge: start anchor not at beginning" {
108108 const allocator = std.testing.allocator;
109 var regex = try Regex.compile(allocator, "a^b");
109 var regex = try Regex.compile(allocator, std.testing.io, "a^b");
110110 defer regex.deinit();
111111
112112 // This should not match anything since ^ is not at the start
@@ -115,7 +115,7 @@ test "edge: start anchor not at beginning" {
115115
116116test "edge: end anchor not at end" {
117117 const allocator = std.testing.allocator;
118 var regex = try Regex.compile(allocator, "a$b");
118 var regex = try Regex.compile(allocator, std.testing.io, "a$b");
119119 defer regex.deinit();
120120
121121 // This should not match anything since $ is not at the end
@@ -125,7 +125,7 @@ test "edge: end anchor not at end" {
125125// Edge case: Dot matching
126126test "edge: dot with quantifiers" {
127127 const allocator = std.testing.allocator;
128 var regex = try Regex.compile(allocator, ".*");
128 var regex = try Regex.compile(allocator, std.testing.io, ".*");
129129 defer regex.deinit();
130130
131131 try std.testing.expect(try regex.isMatch(""));
@@ -136,7 +136,7 @@ test "edge: dot with quantifiers" {
136136// Edge case: Escape sequences
137137test "edge: escaped backslash" {
138138 const allocator = std.testing.allocator;
139 var regex = try Regex.compile(allocator, "\\\\");
139 var regex = try Regex.compile(allocator, std.testing.io, "\\\\");
140140 defer regex.deinit();
141141
142142 try std.testing.expect(try regex.isMatch("\\"));
@@ -145,7 +145,7 @@ test "edge: escaped backslash" {
145145
146146test "edge: escaped dot" {
147147 const allocator = std.testing.allocator;
148 var regex = try Regex.compile(allocator, "\\.");
148 var regex = try Regex.compile(allocator, std.testing.io, "\\.");
149149 defer regex.deinit();
150150
151151 try std.testing.expect(try regex.isMatch("."));
@@ -155,7 +155,7 @@ test "edge: escaped dot" {
155155// Edge case: findAll edge cases
156156test "edge: findAll with no matches" {
157157 const allocator = std.testing.allocator;
158 var regex = try Regex.compile(allocator, "x");
158 var regex = try Regex.compile(allocator, std.testing.io, "x");
159159 defer regex.deinit();
160160
161161 const matches = try regex.findAll(allocator, "aaabbb");
@@ -166,7 +166,7 @@ test "edge: findAll with no matches" {
166166
167167test "edge: findAll with overlapping potential matches" {
168168 const allocator = std.testing.allocator;
169 var regex = try Regex.compile(allocator, "a+");
169 var regex = try Regex.compile(allocator, std.testing.io, "a+");
170170 defer regex.deinit();
171171
172172 const matches = try regex.findAll(allocator, "aaa");
@@ -186,7 +186,7 @@ test "edge: findAll with overlapping potential matches" {
186186// Edge case: replace edge cases
187187test "edge: replace with empty string" {
188188 const allocator = std.testing.allocator;
189 var regex = try Regex.compile(allocator, "a");
189 var regex = try Regex.compile(allocator, std.testing.io, "a");
190190 defer regex.deinit();
191191
192192 const result = try regex.replace(allocator, "banana", "");
@@ -197,7 +197,7 @@ test "edge: replace with empty string" {
197197
198198test "edge: replace in empty string" {
199199 const allocator = std.testing.allocator;
200 var regex = try Regex.compile(allocator, "a");
200 var regex = try Regex.compile(allocator, std.testing.io, "a");
201201 defer regex.deinit();
202202
203203 const result = try regex.replace(allocator, "", "x");
@@ -209,7 +209,7 @@ test "edge: replace in empty string" {
209209// Edge case: split edge cases
210210test "edge: split empty string" {
211211 const allocator = std.testing.allocator;
212 var regex = try Regex.compile(allocator, ",");
212 var regex = try Regex.compile(allocator, std.testing.io, ",");
213213 defer regex.deinit();
214214
215215 const parts = try regex.split(allocator, "");
@@ -221,7 +221,7 @@ test "edge: split empty string" {
221221
222222test "edge: split with no delimiter found" {
223223 const allocator = std.testing.allocator;
224 var regex = try Regex.compile(allocator, ",");
224 var regex = try Regex.compile(allocator, std.testing.io, ",");
225225 defer regex.deinit();
226226
227227 const parts = try regex.split(allocator, "hello");
@@ -234,7 +234,7 @@ test "edge: split with no delimiter found" {
234234// Edge case: Word boundaries
235235test "edge: word boundary at start" {
236236 const allocator = std.testing.allocator;
237 var regex = try Regex.compile(allocator, "\\bword");
237 var regex = try Regex.compile(allocator, std.testing.io, "\\bword");
238238 defer regex.deinit();
239239
240240 if (try regex.find("word here")) |match| {
@@ -248,7 +248,7 @@ test "edge: word boundary at start" {
248248
249249test "edge: word boundary at end" {
250250 const allocator = std.testing.allocator;
251 var regex = try Regex.compile(allocator, "word\\b");
251 var regex = try Regex.compile(allocator, std.testing.io, "word\\b");
252252 defer regex.deinit();
253253
254254 if (try regex.find("a word")) |match| {
@@ -263,7 +263,7 @@ test "edge: word boundary at end" {
263263// Edge case: Character classes with special chars
264264test "edge: whitespace character class" {
265265 const allocator = std.testing.allocator;
266 var regex = try Regex.compile(allocator, "\\s+");
266 var regex = try Regex.compile(allocator, std.testing.io, "\\s+");
267267 defer regex.deinit();
268268
269269 if (try regex.find("hello world")) |match| {
@@ -277,7 +277,7 @@ test "edge: whitespace character class" {
277277
278278test "edge: digit character class at boundaries" {
279279 const allocator = std.testing.allocator;
280 var regex = try Regex.compile(allocator, "^\\d+$");
280 var regex = try Regex.compile(allocator, std.testing.io, "^\\d+$");
281281 defer regex.deinit();
282282
283283 try std.testing.expect(try regex.isMatch("123"));