summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/regexp.zig17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/regexp.zig b/src/regexp.zig
index 97e3dc91..64e1d75a 100644
--- a/src/regexp.zig
+++ b/src/regexp.zig
@@ -258,3 +258,20 @@ test "a repeat inside a group gives back to what follows the group" {
try std.testing.expectEqual(c.end, m.end);
}
}
+
+test "`$` may end any alternative, not only the last" {
+ const Case = struct { pat: []const u8, text: []const u8, start: usize, end: usize };
+ for ([_]Case{
+ .{ .pat = "h$|zz", .text = "xh", .start = 1, .end = 2 },
+ .{ .pat = "zz|h$", .text = "xh", .start = 1, .end = 2 },
+ .{ .pat = "h$|zz", .text = "hx zz", .start = 3, .end = 5 },
+ .{ .pat = "(h$|zz)", .text = "xh", .start = 1, .end = 2 },
+ }) |c| {
+ var rx = try Regex.compile(c.pat);
+ const m = (try rx.find(c.text, 0, c.text.len, c.text.len)).?;
+ try std.testing.expectEqual(c.start, m.start);
+ try std.testing.expectEqual(c.end, m.end);
+ }
+ var only = try Regex.compile("h$|zz");
+ try std.testing.expectEqual(null, try only.find("hx", 0, 2, 2));
+}