summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/regexp.zig23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/regexp.zig b/src/regexp.zig
index 249763c2..97e3dc91 100644
--- a/src/regexp.zig
+++ b/src/regexp.zig
@@ -235,3 +235,26 @@ test "a \\x without two hex digits is refused, not handed to mvzr to panic on" {
var rx = try Regex.compile("\\x41");
try std.testing.expectEqual(@as(usize, 1), (try rx.find("xA", 0, 1, 2)).?.start);
}
+
+test "a repeat inside a group gives back to what follows the group" {
+ const Case = struct { pat: []const u8, text: []const u8, start: usize, end: usize };
+ for ([_]Case{
+ .{ .pat = "a+ab", .text = "aab", .start = 0, .end = 3 },
+ .{ .pat = "(a+)ab", .text = "aab", .start = 0, .end = 3 },
+ .{ .pat = "(a*)ab", .text = "aab", .start = 0, .end = 3 },
+ .{ .pat = "(.+)_area", .text = "the_total_area x", .start = 0, .end = 14 },
+ .{ .pat = "([a-z_]+)_area", .text = "the_total_area x", .start = 0, .end = 14 },
+ .{ .pat = "\\w+_area", .text = "the_total_area x", .start = 0, .end = 14 },
+ .{ .pat = "(\\w)+_area", .text = "the_total_area x", .start = 0, .end = 14 },
+ .{ .pat = "([a-z]+)_area", .text = "the_total_area x", .start = 4, .end = 14 },
+ .{ .pat = "x(ab|a)bc", .text = "xabc", .start = 0, .end = 4 },
+ }) |c| {
+ var rx = try Regex.compile(c.pat);
+ const m = (try rx.find(c.text, 0, c.text.len, c.text.len)) orelse {
+ std.debug.print("no match for {s}\n", .{c.pat});
+ return error.NoMatch;
+ };
+ try std.testing.expectEqual(c.start, m.start);
+ try std.testing.expectEqual(c.end, m.end);
+ }
+}