mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-14 15:56:13 +03:00
terminal: tests for same page clone with hyperlinks
This commit is contained in:
@ -2447,6 +2447,118 @@ test "Page cloneRowFrom partial grapheme in non-copied dest region" {
|
|||||||
try testing.expectEqual(@as(usize, 2), page2.graphemeCount());
|
try testing.expectEqual(@as(usize, 2), page2.graphemeCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "Page cloneRowFrom partial hyperlink in same page copy" {
|
||||||
|
var page = try Page.init(.{ .cols = 10, .rows = 10 });
|
||||||
|
defer page.deinit();
|
||||||
|
|
||||||
|
// We need to create a hyperlink.
|
||||||
|
const hyperlink_id = try page.hyperlink_set.addContext(
|
||||||
|
page.memory,
|
||||||
|
.{ .id = .{ .implicit = 0 }, .uri = .{} },
|
||||||
|
.{ .page = &page },
|
||||||
|
);
|
||||||
|
|
||||||
|
// Write
|
||||||
|
{
|
||||||
|
const y = 0;
|
||||||
|
for (0..page.size.cols) |x| {
|
||||||
|
const rac = page.getRowAndCell(x, y);
|
||||||
|
rac.cell.* = .{
|
||||||
|
.content_tag = .codepoint,
|
||||||
|
.content = .{ .codepoint = @intCast(x + 1) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hyperlink in a single cell
|
||||||
|
{
|
||||||
|
const rac = page.getRowAndCell(7, y);
|
||||||
|
try page.setHyperlink(rac.row, rac.cell, hyperlink_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try testing.expectEqual(@as(usize, 1), page.hyperlinkCount());
|
||||||
|
|
||||||
|
// Clone into the same page
|
||||||
|
try page.clonePartialRowFrom(
|
||||||
|
&page,
|
||||||
|
page.getRow(1),
|
||||||
|
page.getRow(0),
|
||||||
|
2,
|
||||||
|
8,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Read it again
|
||||||
|
{
|
||||||
|
const y = 1;
|
||||||
|
for (0..page.size.cols) |x| {
|
||||||
|
const expected: u21 = if (x >= 2 and x < 8) @intCast(x + 1) else 0;
|
||||||
|
const rac = page.getRowAndCell(x, y);
|
||||||
|
try testing.expectEqual(expected, rac.cell.content.codepoint);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const rac = page.getRowAndCell(7, y);
|
||||||
|
try testing.expect(rac.row.hyperlink);
|
||||||
|
try testing.expect(rac.cell.hyperlink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try testing.expectEqual(@as(usize, 2), page.hyperlinkCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
test "Page cloneRowFrom partial hyperlink in same page omit" {
|
||||||
|
var page = try Page.init(.{ .cols = 10, .rows = 10 });
|
||||||
|
defer page.deinit();
|
||||||
|
|
||||||
|
// We need to create a hyperlink.
|
||||||
|
const hyperlink_id = try page.hyperlink_set.addContext(
|
||||||
|
page.memory,
|
||||||
|
.{ .id = .{ .implicit = 0 }, .uri = .{} },
|
||||||
|
.{ .page = &page },
|
||||||
|
);
|
||||||
|
|
||||||
|
// Write
|
||||||
|
{
|
||||||
|
const y = 0;
|
||||||
|
for (0..page.size.cols) |x| {
|
||||||
|
const rac = page.getRowAndCell(x, y);
|
||||||
|
rac.cell.* = .{
|
||||||
|
.content_tag = .codepoint,
|
||||||
|
.content = .{ .codepoint = @intCast(x + 1) },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hyperlink in a single cell
|
||||||
|
{
|
||||||
|
const rac = page.getRowAndCell(7, y);
|
||||||
|
try page.setHyperlink(rac.row, rac.cell, hyperlink_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try testing.expectEqual(@as(usize, 1), page.hyperlinkCount());
|
||||||
|
|
||||||
|
// Clone into the same page
|
||||||
|
try page.clonePartialRowFrom(
|
||||||
|
&page,
|
||||||
|
page.getRow(1),
|
||||||
|
page.getRow(0),
|
||||||
|
2,
|
||||||
|
6,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Read it again
|
||||||
|
{
|
||||||
|
const y = 1;
|
||||||
|
for (0..page.size.cols) |x| {
|
||||||
|
const expected: u21 = if (x >= 2 and x < 6) @intCast(x + 1) else 0;
|
||||||
|
const rac = page.getRowAndCell(x, y);
|
||||||
|
try testing.expectEqual(expected, rac.cell.content.codepoint);
|
||||||
|
}
|
||||||
|
{
|
||||||
|
const rac = page.getRowAndCell(7, y);
|
||||||
|
try testing.expect(!rac.row.hyperlink);
|
||||||
|
try testing.expect(!rac.cell.hyperlink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try testing.expectEqual(@as(usize, 1), page.hyperlinkCount());
|
||||||
|
}
|
||||||
|
|
||||||
test "Page moveCells text-only" {
|
test "Page moveCells text-only" {
|
||||||
var page = try Page.init(.{
|
var page = try Page.init(.{
|
||||||
.cols = 10,
|
.cols = 10,
|
||||||
|
@ -26,8 +26,8 @@ pub fn Offset(comptime T: type) type {
|
|||||||
|
|
||||||
/// A slice of type T that stores via a base offset and len.
|
/// A slice of type T that stores via a base offset and len.
|
||||||
pub const Slice = struct {
|
pub const Slice = struct {
|
||||||
offset: Self,
|
offset: Self = .{},
|
||||||
len: usize,
|
len: usize = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Returns a pointer to the start of the data, properly typed.
|
/// Returns a pointer to the start of the data, properly typed.
|
||||||
|
Reference in New Issue
Block a user