add(test): cell conversion to ansi enhanced strings
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 45s
Some checks failed
Zig Project Action / Lint, Spell-check and test zig project (push) Failing after 45s
This commit is contained in:
44
src/cell.zig
44
src/cell.zig
@@ -19,3 +19,47 @@ pub fn reset(this: *Cell) void {
|
||||
pub fn value(this: Cell, writer: anytype) !void {
|
||||
try this.style.value(writer, this.cp);
|
||||
}
|
||||
|
||||
test "ascii styled text" {
|
||||
const cells: [4]Cell = .{
|
||||
.{ .cp = 'Y', .style = .{ .fg = .green, .bg = .grey, .emphasis = &.{} } },
|
||||
.{ .cp = 'v', .style = .{ .emphasis = &.{ .bold, .underline } } },
|
||||
.{ .cp = 'e', .style = .{ .emphasis = &.{.italic} } },
|
||||
.{ .cp = 's', .style = .{ .fg = .light_green, .bg = .black, .emphasis = &.{.underline} } },
|
||||
};
|
||||
|
||||
var string = std.ArrayList(u8).init(std.testing.allocator);
|
||||
defer string.deinit();
|
||||
|
||||
const writer = string.writer();
|
||||
for (cells) |cell| {
|
||||
try cell.value(writer);
|
||||
}
|
||||
try std.testing.expectEqualSlices(
|
||||
u8,
|
||||
"\x1b[38;5;10;48;5;8;59mY\x1b[0m\x1b[39;49;59;1;4mv\x1b[0m\x1b[39;49;59;3me\x1b[0m\x1b[38;5;2;48;5;16;59;4ms\x1b[0m",
|
||||
string.items,
|
||||
);
|
||||
}
|
||||
|
||||
test "utf-8 styled text" {
|
||||
const cells: [4]Cell = .{
|
||||
.{ .cp = '╭', .style = .{ .fg = .green, .bg = .grey, .emphasis = &.{} } },
|
||||
.{ .cp = '─', .style = .{ .emphasis = &.{} } },
|
||||
.{ .cp = '┄', .style = .{ .emphasis = &.{} } },
|
||||
.{ .cp = '┘', .style = .{ .fg = .light_green, .bg = .black, .emphasis = &.{.underline} } },
|
||||
};
|
||||
|
||||
var string = std.ArrayList(u8).init(std.testing.allocator);
|
||||
defer string.deinit();
|
||||
|
||||
const writer = string.writer();
|
||||
for (cells) |cell| {
|
||||
try cell.value(writer);
|
||||
}
|
||||
try std.testing.expectEqualSlices(
|
||||
u8,
|
||||
"\x1b[38;5;10;48;5;8;59m╭\x1b[0m\x1b[39;49;59m─\x1b[0m\x1b[39;49;59m┄\x1b[0m\x1b[38;5;2;48;5;16;59;4m┘\x1b[0m",
|
||||
string.items,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user