font/coretext: unit tests pass on macOS

This commit is contained in:
Mitchell Hashimoto
2024-04-04 14:46:46 -07:00
parent 1b8bae5f0a
commit 6ace9e9d19

View File

@ -345,13 +345,19 @@ test "run iterator" {
{
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 5, 0);
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
try screen.testWriteString("ABCD");
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |_| count += 1;
try testing.expectEqual(@as(usize, 1), count);
@ -359,12 +365,18 @@ test "run iterator" {
// Spaces should be part of a run
{
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString("ABCD EFG");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |_| count += 1;
try testing.expectEqual(@as(usize, 1), count);
@ -372,13 +384,19 @@ test "run iterator" {
{
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 5, 0);
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
try screen.testWriteString("A😃D");
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |_| count += 1;
try testing.expectEqual(@as(usize, 3), count);
@ -394,31 +412,49 @@ test "run iterator: empty cells with background set" {
{
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 5, 0);
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
screen.cursor.pen.bg = try terminal.color.Name.cyan.default();
screen.cursor.pen.attrs.has_bg = true;
try screen.setAttribute(.{ .direct_color_bg = .{ .r = 0xFF, .g = 0, .b = 0 } });
try screen.testWriteString("A");
// Get our first row
const row = screen.getRow(.{ .active = 0 });
row.getCellPtr(1).* = screen.cursor.pen;
row.getCellPtr(2).* = screen.cursor.pen;
{
const list_cell = screen.pages.getCell(.{ .active = .{ .x = 1 } }).?;
const cell = list_cell.cell;
cell.* = .{
.content_tag = .bg_color_rgb,
.content = .{ .color_rgb = .{ .r = 0xFF, .g = 0, .b = 0 } },
};
}
{
const list_cell = screen.pages.getCell(.{ .active = .{ .x = 2 } }).?;
const cell = list_cell.cell;
cell.* = .{
.content_tag = .bg_color_rgb,
.content = .{ .color_rgb = .{ .r = 0xFF, .g = 0, .b = 0 } },
};
}
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
// The run should have length 3 because of the two background
// cells.
try testing.expectEqual(@as(usize, 3), shaper.codepoints.items.len);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
{
const run = (try it.next(alloc)).?;
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 3), cells.len);
try testing.expectEqual(@as(usize, 1), cells.len);
}
try testing.expectEqual(@as(usize, 1), count);
{
const run = (try it.next(alloc)).?;
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 2), cells.len);
}
try testing.expect(try it.next(alloc) == null);
}
}
@ -436,13 +472,19 @@ test "shape" {
buf_idx += try std.unicode.utf8Encode(0x1F3FD, buf[buf_idx..]); // Medium skin tone
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString(buf[0..buf_idx]);
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -451,47 +493,94 @@ test "shape" {
try testing.expectEqual(@as(usize, 1), count);
}
// test "shape inconsolata ligs" {
// const testing = std.testing;
// const alloc = testing.allocator;
//
// var testdata = try testShaper(alloc);
// defer testdata.deinit();
//
// {
// var screen = try terminal.Screen.init(alloc, 3, 5, 0);
// defer screen.deinit();
// try screen.testWriteString(">=");
//
// var shaper = &testdata.shaper;
// var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
// var count: usize = 0;
// while (try it.next(alloc)) |run| {
// count += 1;
//
// const cells = try shaper.shape(run);
// try testing.expectEqual(@as(usize, 1), cells.len);
// }
// try testing.expectEqual(@as(usize, 1), count);
// }
//
// {
// var screen = try terminal.Screen.init(alloc, 3, 5, 0);
// defer screen.deinit();
// try screen.testWriteString("===");
//
// var shaper = &testdata.shaper;
// var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
// var count: usize = 0;
// while (try it.next(alloc)) |run| {
// count += 1;
//
// const cells = try shaper.shape(run);
// try testing.expectEqual(@as(usize, 1), cells.len);
// }
// try testing.expectEqual(@as(usize, 1), count);
// }
// }
// TODO(coretext)
test "shape inconsolata ligs" {
const testing = std.testing;
const alloc = testing.allocator;
var testdata = try testShaper(alloc);
defer testdata.deinit();
{
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
try screen.testWriteString(">=");
var shaper = &testdata.shaper;
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 1), cells.len);
try testing.expect(cells[0].glyph_index != null);
}
try testing.expectEqual(@as(usize, 1), count);
}
{
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
try screen.testWriteString("===");
var shaper = &testdata.shaper;
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 1), cells.len);
try testing.expect(cells[0].glyph_index != null);
}
try testing.expectEqual(@as(usize, 1), count);
}
}
test "shape monaspace ligs" {
const testing = std.testing;
const alloc = testing.allocator;
var testdata = try testShaperWithFont(alloc, .monaspace_neon);
defer testdata.deinit();
{
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
try screen.testWriteString("===");
var shaper = &testdata.shaper;
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 1), cells.len);
try testing.expect(cells[0].glyph_index != null);
}
try testing.expectEqual(@as(usize, 1), count);
}
}
test "shape emoji width" {
const testing = std.testing;
@ -501,12 +590,18 @@ test "shape emoji width" {
defer testdata.deinit();
{
var screen = try terminal.Screen.init(alloc, 3, 5, 0);
var screen = try terminal.Screen.init(alloc, 5, 3, 0);
defer screen.deinit();
try screen.testWriteString("👍");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -534,17 +629,25 @@ test "shape emoji width long" {
buf_idx += try std.unicode.utf8Encode(0xFE0F, buf[buf_idx..]); // emoji representation
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 30, 0);
var screen = try terminal.Screen.init(alloc, 30, 3, 0);
defer screen.deinit();
try screen.testWriteString(buf[0..buf_idx]);
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
const cells = try shaper.shape(run);
// screen.testWriteString isn't grapheme aware, otherwise this is two
try testing.expectEqual(@as(usize, 1), cells.len);
}
try testing.expectEqual(@as(usize, 1), count);
@ -563,13 +666,19 @@ test "shape variation selector VS15" {
buf_idx += try std.unicode.utf8Encode(0xFE0E, buf[buf_idx..]); // ZWJ to force text
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString(buf[0..buf_idx]);
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -592,13 +701,19 @@ test "shape variation selector VS16" {
buf_idx += try std.unicode.utf8Encode(0xFE0F, buf[buf_idx..]); // ZWJ to force color
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString(buf[0..buf_idx]);
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -616,23 +731,29 @@ test "shape with empty cells in between" {
defer testdata.deinit();
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 30, 0);
var screen = try terminal.Screen.init(alloc, 30, 3, 0);
defer screen.deinit();
try screen.testWriteString("A");
screen.cursor.x += 5;
screen.cursorRight(5);
try screen.testWriteString("B");
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 1), count);
try testing.expectEqual(@as(usize, 7), cells.len);
}
try testing.expectEqual(@as(usize, 1), count);
}
test "shape Chinese characters" {
@ -650,13 +771,19 @@ test "shape Chinese characters" {
buf_idx += try std.unicode.utf8Encode('a', buf[buf_idx..]);
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 30, 0);
var screen = try terminal.Screen.init(alloc, 30, 3, 0);
defer screen.deinit();
try screen.testWriteString(buf[0..buf_idx]);
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -691,22 +818,27 @@ test "shape box glyphs" {
buf_idx += try std.unicode.utf8Encode(0x2501, buf[buf_idx..]); //
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString(buf[0..buf_idx]);
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
//try testing.expectEqual(@as(u32, 2), shaper.hb_buf.getLength());
const cells = try shaper.shape(run);
try testing.expectEqual(@as(usize, 2), cells.len);
try testing.expectEqual(@as(u32, 0x2500), cells[0].glyph_index);
try testing.expectEqual(@as(u32, 0x2500), cells[0].glyph_index.?);
try testing.expectEqual(@as(u16, 0), cells[0].x);
try testing.expectEqual(@as(u32, 0x2501), cells[1].glyph_index);
try testing.expectEqual(@as(u32, 0x2501), cells[1].glyph_index.?);
try testing.expectEqual(@as(u16, 1), cells[1].x);
}
try testing.expectEqual(@as(usize, 1), count);
@ -720,7 +852,7 @@ test "shape selection boundary" {
defer testdata.deinit();
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString("a1b2c3d4e5");
@ -728,10 +860,17 @@ test "shape selection boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), .{
.start = .{ .x = 0, .y = 0 },
.end = .{ .x = screen.cols - 1, .y = 0 },
}, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
terminal.Selection.init(
screen.pages.pin(.{ .active = .{ .x = 0, .y = 0 } }).?,
screen.pages.pin(.{ .active = .{ .x = screen.pages.cols - 1, .y = 0 } }).?,
false,
),
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -744,10 +883,17 @@ test "shape selection boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), .{
.start = .{ .x = 2, .y = 0 },
.end = .{ .x = screen.cols - 1, .y = 0 },
}, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
terminal.Selection.init(
screen.pages.pin(.{ .active = .{ .x = 2, .y = 0 } }).?,
screen.pages.pin(.{ .active = .{ .x = screen.pages.cols - 1, .y = 0 } }).?,
false,
),
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -760,10 +906,17 @@ test "shape selection boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), .{
.start = .{ .x = 0, .y = 0 },
.end = .{ .x = 3, .y = 0 },
}, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
terminal.Selection.init(
screen.pages.pin(.{ .active = .{ .x = 0, .y = 0 } }).?,
screen.pages.pin(.{ .active = .{ .x = 3, .y = 0 } }).?,
false,
),
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -776,10 +929,17 @@ test "shape selection boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), .{
.start = .{ .x = 1, .y = 0 },
.end = .{ .x = 3, .y = 0 },
}, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
terminal.Selection.init(
screen.pages.pin(.{ .active = .{ .x = 1, .y = 0 } }).?,
screen.pages.pin(.{ .active = .{ .x = 3, .y = 0 } }).?,
false,
),
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -792,10 +952,17 @@ test "shape selection boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), .{
.start = .{ .x = 1, .y = 0 },
.end = .{ .x = 1, .y = 0 },
}, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
terminal.Selection.init(
screen.pages.pin(.{ .active = .{ .x = 1, .y = 0 } }).?,
screen.pages.pin(.{ .active = .{ .x = 1, .y = 0 } }).?,
false,
),
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -813,7 +980,7 @@ test "shape cursor boundary" {
defer testdata.deinit();
// Make a screen with some data
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString("a1b2c3d4e5");
@ -821,7 +988,13 @@ test "shape cursor boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -834,7 +1007,13 @@ test "shape cursor boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, 0);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
0,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -847,7 +1026,13 @@ test "shape cursor boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, 1);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
1,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -860,7 +1045,13 @@ test "shape cursor boundary" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, 9);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
9,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -886,7 +1077,13 @@ test "shape cursor boundary and colored emoji" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -899,7 +1096,13 @@ test "shape cursor boundary and colored emoji" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, 0);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
0,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -910,7 +1113,13 @@ test "shape cursor boundary and colored emoji" {
{
// Get our run iterator
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, 1);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
1,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -929,12 +1138,18 @@ test "shape cell attribute change" {
// Plain >= should shape into 1 run
{
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
var screen = try terminal.Screen.init(alloc, 10, 3, 0);
defer screen.deinit();
try screen.testWriteString(">=");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -948,11 +1163,17 @@ test "shape cell attribute change" {
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
defer screen.deinit();
try screen.testWriteString(">");
screen.cursor.pen.attrs.bold = true;
try screen.setAttribute(.{ .bold = {} });
try screen.testWriteString("=");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -965,14 +1186,19 @@ test "shape cell attribute change" {
{
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
defer screen.deinit();
screen.cursor.pen.attrs.has_fg = true;
screen.cursor.pen.fg = .{ .r = 1, .g = 2, .b = 3 };
try screen.setAttribute(.{ .direct_color_fg = .{ .r = 1, .g = 2, .b = 3 } });
try screen.testWriteString(">");
screen.cursor.pen.fg = .{ .r = 3, .g = 2, .b = 1 };
try screen.setAttribute(.{ .direct_color_fg = .{ .r = 3, .g = 2, .b = 1 } });
try screen.testWriteString("=");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -985,14 +1211,19 @@ test "shape cell attribute change" {
{
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
defer screen.deinit();
screen.cursor.pen.attrs.has_bg = true;
screen.cursor.pen.bg = .{ .r = 1, .g = 2, .b = 3 };
try screen.setAttribute(.{ .direct_color_bg = .{ .r = 1, .g = 2, .b = 3 } });
try screen.testWriteString(">");
screen.cursor.pen.bg = .{ .r = 3, .g = 2, .b = 1 };
try screen.setAttribute(.{ .direct_color_bg = .{ .r = 3, .g = 2, .b = 1 } });
try screen.testWriteString("=");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -1005,13 +1236,18 @@ test "shape cell attribute change" {
{
var screen = try terminal.Screen.init(alloc, 3, 10, 0);
defer screen.deinit();
screen.cursor.pen.attrs.has_bg = true;
screen.cursor.pen.bg = .{ .r = 1, .g = 2, .b = 3 };
try screen.setAttribute(.{ .direct_color_bg = .{ .r = 1, .g = 2, .b = 3 } });
try screen.testWriteString(">");
try screen.testWriteString("=");
var shaper = &testdata.shaper;
var it = shaper.runIterator(testdata.cache, screen.getRow(.{ .screen = 0 }), null, null);
var it = shaper.runIterator(
testdata.cache,
&screen,
screen.pages.pin(.{ .screen = .{ .y = 0 } }).?,
null,
null,
);
var count: usize = 0;
while (try it.next(alloc)) |run| {
count += 1;
@ -1035,11 +1271,23 @@ const TestShaper = struct {
}
};
const TestFont = enum {
inconsolata,
monaspace_neon,
};
/// Helper to return a fully initialized shaper.
fn testShaper(alloc: Allocator) !TestShaper {
const testFont = @import("../test.zig").fontRegular;
return try testShaperWithFont(alloc, .inconsolata);
}
fn testShaperWithFont(alloc: Allocator, font_req: TestFont) !TestShaper {
const testEmoji = @import("../test.zig").fontEmoji;
const testEmojiText = @import("../test.zig").fontEmojiText;
const testFont = switch (font_req) {
.inconsolata => @import("../test.zig").fontRegular,
.monaspace_neon => @import("../test.zig").fontMonaspaceNeon,
};
var lib = try Library.init();
errdefer lib.deinit();