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/regression.zigmodified+17-17
Changes to tests/regression.zig
@@ -10,7 +10,7 @@ const RegexError = @import("regex").RegexError;
1010
1111test "regression: $0 replacement expands to full match" {
1212 const allocator = std.testing.allocator;
13 var regex = try Regex.compile(allocator, "\\d+");
13 var regex = try Regex.compile(allocator, std.testing.io, "\\d+");
1414 defer regex.deinit();
1515
1616 const result = try regex.replace(allocator, "abc 123 def", "[$0]");
@@ -20,7 +20,7 @@ test "regression: $0 replacement expands to full match" {
2020
2121test "regression: $0 replacement with captures" {
2222 const allocator = std.testing.allocator;
23 var regex = try Regex.compile(allocator, "(\\w+)@(\\w+)");
23 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+)@(\\w+)");
2424 defer regex.deinit();
2525
2626 const result = try regex.replace(allocator, "email: user@host ok", "match=$0,user=$1,host=$2");
@@ -30,7 +30,7 @@ test "regression: $0 replacement with captures" {
3030
3131test "regression: $0 in replaceAll" {
3232 const allocator = std.testing.allocator;
33 var regex = try Regex.compile(allocator, "\\w+");
33 var regex = try Regex.compile(allocator, std.testing.io, "\\w+");
3434 defer regex.deinit();
3535
3636 const result = try regex.replaceAll(allocator, "a b c", "[$0]");
@@ -42,7 +42,7 @@ test "regression: $0 in replaceAll" {
4242
4343test "regression: case-insensitive backreference" {
4444 const allocator = std.testing.allocator;
45 var regex = try Regex.compileWithFlags(allocator, "(\\w+) \\1", .{ .case_insensitive = true });
45 var regex = try Regex.compileWithFlags(allocator, std.testing.io, "(\\w+) \\1", .{ .case_insensitive = true });
4646 defer regex.deinit();
4747
4848 try std.testing.expect(try regex.isMatch("hello HELLO"));
@@ -52,7 +52,7 @@ test "regression: case-insensitive backreference" {
5252
5353test "regression: case-sensitive backreference rejects case mismatch" {
5454 const allocator = std.testing.allocator;
55 var regex = try Regex.compile(allocator, "(\\w+) \\1");
55 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1");
5656 defer regex.deinit();
5757
5858 try std.testing.expect(!try regex.isMatch("hello HELLO"));
@@ -63,19 +63,19 @@ test "regression: case-sensitive backreference rejects case mismatch" {
6363
6464test "regression: {10,5} is rejected as invalid" {
6565 const allocator = std.testing.allocator;
66 const result = Regex.compile(allocator, "a{10,5}");
66 const result = Regex.compile(allocator, std.testing.io, "a{10,5}");
6767 try std.testing.expectError(RegexError.InvalidQuantifier, result);
6868}
6969
7070test "regression: {5,3} is rejected" {
7171 const allocator = std.testing.allocator;
72 const result = Regex.compile(allocator, "x{5,3}");
72 const result = Regex.compile(allocator, std.testing.io, "x{5,3}");
7373 try std.testing.expectError(RegexError.InvalidQuantifier, result);
7474}
7575
7676test "regression: {3,3} is accepted (min == max)" {
7777 const allocator = std.testing.allocator;
78 var regex = try Regex.compile(allocator, "a{3,3}");
78 var regex = try Regex.compile(allocator, std.testing.io, "a{3,3}");
7979 defer regex.deinit();
8080
8181 try std.testing.expect(try regex.isMatch("aaa"));
@@ -86,7 +86,7 @@ test "regression: {3,3} is accepted (min == max)" {
8686
8787test "regression: {0,3} matches 0 to 3 occurrences" {
8888 const allocator = std.testing.allocator;
89 var regex = try Regex.compile(allocator, "^a{0,3}$");
89 var regex = try Regex.compile(allocator, std.testing.io, "^a{0,3}$");
9090 defer regex.deinit();
9191
9292 try std.testing.expect(try regex.isMatch(""));
@@ -98,9 +98,9 @@ test "regression: {0,3} matches 0 to 3 occurrences" {
9898
9999test "regression: {0,1} is equivalent to ?" {
100100 const allocator = std.testing.allocator;
101 var regex1 = try Regex.compile(allocator, "^ab{0,1}c$");
101 var regex1 = try Regex.compile(allocator, std.testing.io, "^ab{0,1}c$");
102102 defer regex1.deinit();
103 var regex2 = try Regex.compile(allocator, "^ab?c$");
103 var regex2 = try Regex.compile(allocator, std.testing.io, "^ab?c$");
104104 defer regex2.deinit();
105105
106106 const inputs = [_][]const u8{ "ac", "abc", "abbc", "" };
@@ -111,7 +111,7 @@ test "regression: {0,1} is equivalent to ?" {
111111
112112test "regression: {0,0} matches empty only" {
113113 const allocator = std.testing.allocator;
114 var regex = try Regex.compile(allocator, "^a{0,0}b$");
114 var regex = try Regex.compile(allocator, std.testing.io, "^a{0,0}b$");
115115 defer regex.deinit();
116116
117117 try std.testing.expect(try regex.isMatch("b"));
@@ -123,7 +123,7 @@ test "regression: {0,0} matches empty only" {
123123test "regression: prefix optimization finds match after false prefix start" {
124124 const allocator = std.testing.allocator;
125125 // Pattern with prefix "ab" - but first "ab" at position 0 doesn't complete the full match
126 var regex = try Regex.compile(allocator, "abc\\d+");
126 var regex = try Regex.compile(allocator, std.testing.io, "abc\\d+");
127127 defer regex.deinit();
128128
129129 // "ab" appears at position 0, but "abc" + digits is only at position 5
@@ -141,7 +141,7 @@ test "regression: prefix optimization finds match after false prefix start" {
141141test "regression: backtrack step counter resets between positions" {
142142 const allocator = std.testing.allocator;
143143 // This pattern uses backtracking via backreference.
144 var regex = try Regex.compile(allocator, "(\\w+) \\1");
144 var regex = try Regex.compile(allocator, std.testing.io, "(\\w+) \\1");
145145 defer regex.deinit();
146146
147147 // Verify basic backreference works
@@ -161,7 +161,7 @@ test "regression: backtrack step counter resets between positions" {
161161
162162test "regression: deinit on regex that was never used" {
163163 const allocator = std.testing.allocator;
164 var regex = try Regex.compile(allocator, "test");
164 var regex = try Regex.compile(allocator, std.testing.io, "test");
165165 regex.deinit();
166166 // Should not crash - just testing that deinit works without any find/match calls
167167}
@@ -169,12 +169,12 @@ test "regression: deinit on regex that was never used" {
169169test "regression: double pattern compile and deinit" {
170170 const allocator = std.testing.allocator;
171171 {
172 var regex = try Regex.compile(allocator, "abc");
172 var regex = try Regex.compile(allocator, std.testing.io, "abc");
173173 defer regex.deinit();
174174 try std.testing.expect(try regex.isMatch("abc"));
175175 }
176176 {
177 var regex = try Regex.compile(allocator, "def");
177 var regex = try Regex.compile(allocator, std.testing.io, "def");
178178 defer regex.deinit();
179179 try std.testing.expect(try regex.isMatch("def"));
180180 }