terminal: test REP

This commit is contained in:
Mitchell Hashimoto
2023-10-11 17:23:27 -07:00
parent d6f7b45a64
commit 96546af475
2 changed files with 100 additions and 4 deletions

View File

@@ -856,11 +856,10 @@ fn clearWideSpacerHead(self: *Terminal) void {
}
/// Print the previous printed character a repeated amount of times.
pub fn printRepeat(self: *Terminal, count: usize) !void {
// TODO: test
pub fn printRepeat(self: *Terminal, count_req: usize) !void {
if (self.previous_char) |c| {
var i: usize = 0;
while (i < count) : (i += 1) try self.print(c);
const count = @max(count_req, 1);
for (0..count) |_| try self.print(c);
}
}
@@ -6082,3 +6081,47 @@ test "Terminal: tabClear all" {
try t.horizontalTab();
try testing.expectEqual(@as(usize, 29), t.screen.cursor.x);
}
test "Terminal: printRepeat simple" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString("A");
try t.printRepeat(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("AA", str);
}
}
test "Terminal: printRepeat wrap" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printString(" A");
try t.printRepeat(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings(" A\nA", str);
}
}
test "Terminal: printRepeat no previous character" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.printRepeat(1);
{
var str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("", str);
}
}