mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 16:56:09 +03:00
renderer: matchset tests
This commit is contained in:
@ -141,3 +141,43 @@ pub const MatchSet = struct {
|
|||||||
return self.matches[self.i].contains(pt);
|
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 }));
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user