diff --git a/src/renderer/link.zig b/src/renderer/link.zig index 973ba92e8..ac4994066 100644 --- a/src/renderer/link.zig +++ b/src/renderer/link.zig @@ -141,3 +141,43 @@ pub const MatchSet = struct { return self.matches[self.i].contains(pt); } }; + +test "matchset" { + const testing = std.testing; + const alloc = testing.allocator; + + // Initialize our screen + var s = try Screen.init(alloc, 5, 5, 0); + defer s.deinit(); + const str = "1ABCD2EFGH\n3IJKL"; + try s.testWriteString(str); + + // Get a set + var set = try Set.fromConfig(alloc, &.{ + .{ + .regex = "AB", + .action = .{ .open = {} }, + .highlight = .{ .always = {} }, + }, + + .{ + .regex = "EF", + .action = .{ .open = {} }, + .highlight = .{ .always = {} }, + }, + }); + defer set.deinit(alloc); + + // Get our matches + var match = try set.matchSet(alloc, &s, .{}); + defer match.deinit(alloc); + try testing.expectEqual(@as(usize, 2), match.matches.len); + + // Test our matches + try testing.expect(!match.orderedContains(.{ .x = 0, .y = 0 })); + try testing.expect(match.orderedContains(.{ .x = 1, .y = 0 })); + try testing.expect(match.orderedContains(.{ .x = 2, .y = 0 })); + try testing.expect(!match.orderedContains(.{ .x = 3, .y = 0 })); + try testing.expect(match.orderedContains(.{ .x = 1, .y = 1 })); + try testing.expect(!match.orderedContains(.{ .x = 1, .y = 2 })); +}