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/lookbehind.zigmodified+11-11
Changes to tests/lookbehind.zig
@@ -3,7 +3,7 @@ const Regex = @import("regex").Regex;
33
44test "positive lookbehind: basic (?<=...)" {
55 const allocator = std.testing.allocator;
6 var regex = try Regex.compile(allocator, "(?<=foo)bar");
6 var regex = try Regex.compile(allocator, std.testing.io, "(?<=foo)bar");
77 defer regex.deinit();
88
99 // Should match "bar" only when preceded by "foo"
@@ -25,7 +25,7 @@ test "positive lookbehind: basic (?<=...)" {
2525
2626test "positive lookbehind: at start of pattern" {
2727 const allocator = std.testing.allocator;
28 var regex = try Regex.compile(allocator, "(?<=foo)bar");
28 var regex = try Regex.compile(allocator, std.testing.io, "(?<=foo)bar");
2929 defer regex.deinit();
3030
3131 try std.testing.expect(try regex.isMatch("foobar"));
@@ -34,7 +34,7 @@ test "positive lookbehind: at start of pattern" {
3434
3535test "positive lookbehind: with alternation" {
3636 const allocator = std.testing.allocator;
37 var regex = try Regex.compile(allocator, "(?<=foo|baz)bar");
37 var regex = try Regex.compile(allocator, std.testing.io, "(?<=foo|baz)bar");
3838 defer regex.deinit();
3939
4040 try std.testing.expect(try regex.isMatch("foobar"));
@@ -44,7 +44,7 @@ test "positive lookbehind: with alternation" {
4444
4545test "negative lookbehind: basic (?<!...)" {
4646 const allocator = std.testing.allocator;
47 var regex = try Regex.compile(allocator, "(?<!foo)bar");
47 var regex = try Regex.compile(allocator, std.testing.io, "(?<!foo)bar");
4848 defer regex.deinit();
4949
5050 // Should match "bar" when NOT preceded by "foo"
@@ -62,7 +62,7 @@ test "negative lookbehind: basic (?<!...)" {
6262
6363test "negative lookbehind: at string start" {
6464 const allocator = std.testing.allocator;
65 var regex = try Regex.compile(allocator, "(?<!x)bar");
65 var regex = try Regex.compile(allocator, std.testing.io, "(?<!x)bar");
6666 defer regex.deinit();
6767
6868 // "bar" at start should match (nothing before it, so not preceded by 'x')
@@ -78,7 +78,7 @@ test "negative lookbehind: at string start" {
7878
7979test "lookbehind with literal characters" {
8080 const allocator = std.testing.allocator;
81 var regex = try Regex.compile(allocator, "(?<=\\$)\\d+");
81 var regex = try Regex.compile(allocator, std.testing.io, "(?<=\\$)\\d+");
8282 defer regex.deinit();
8383
8484 // Match digits preceded by dollar sign
@@ -95,7 +95,7 @@ test "lookbehind with literal characters" {
9595
9696test "lookbehind: zero-width assertion" {
9797 const allocator = std.testing.allocator;
98 var regex = try Regex.compile(allocator, "(?<=a)b");
98 var regex = try Regex.compile(allocator, std.testing.io, "(?<=a)b");
9999 defer regex.deinit();
100100
101101 if (try regex.find("ab")) |match| {
@@ -112,7 +112,7 @@ test "lookbehind: zero-width assertion" {
112112
113113test "combined lookahead and lookbehind" {
114114 const allocator = std.testing.allocator;
115 var regex = try Regex.compile(allocator, "(?<=foo)bar(?=baz)");
115 var regex = try Regex.compile(allocator, std.testing.io, "(?<=foo)bar(?=baz)");
116116 defer regex.deinit();
117117
118118 try std.testing.expect(try regex.isMatch("foobarbaz"));
@@ -132,7 +132,7 @@ test "combined lookahead and lookbehind" {
132132
133133test "lookbehind with capture groups" {
134134 const allocator = std.testing.allocator;
135 var regex = try Regex.compile(allocator, "(?<=@)(\\w+)");
135 var regex = try Regex.compile(allocator, std.testing.io, "(?<=@)(\\w+)");
136136 defer regex.deinit();
137137
138138 if (try regex.find("@username")) |match| {
@@ -148,7 +148,7 @@ test "lookbehind with capture groups" {
148148
149149test "multiple lookbehinds" {
150150 const allocator = std.testing.allocator;
151 var regex = try Regex.compile(allocator, "(?<=a)(?<=ab)c");
151 var regex = try Regex.compile(allocator, std.testing.io, "(?<=a)(?<=ab)c");
152152 defer regex.deinit();
153153
154154 try std.testing.expect(try regex.isMatch("abc"));
@@ -157,7 +157,7 @@ test "multiple lookbehinds" {
157157
158158test "lookbehind in findAll" {
159159 const allocator = std.testing.allocator;
160 var regex = try Regex.compile(allocator, "(?<=\\s)\\w+");
160 var regex = try Regex.compile(allocator, std.testing.io, "(?<=\\s)\\w+");
161161 defer regex.deinit();
162162
163163 const matches = try regex.findAll(allocator, "hello world foo bar");