terminal/new: index tests

This commit is contained in:
Mitchell Hashimoto
2024-02-25 21:15:57 -08:00
parent 0cbed73ff0
commit cc324b0cb7
3 changed files with 165 additions and 1 deletions

View File

@ -4265,6 +4265,7 @@ test "Terminal: reverseIndex outside left/right margins" {
}
}
// X
test "Terminal: index" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
@ -4280,6 +4281,7 @@ test "Terminal: index" {
}
}
// X
test "Terminal: index from the bottom" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
@ -4299,6 +4301,7 @@ test "Terminal: index from the bottom" {
}
}
// X
test "Terminal: index outside of scrolling region" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
@ -4310,6 +4313,7 @@ test "Terminal: index outside of scrolling region" {
try testing.expectEqual(@as(usize, 1), t.screen.cursor.y);
}
// X
test "Terminal: index from the bottom outside of scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
@ -4328,6 +4332,7 @@ test "Terminal: index from the bottom outside of scroll region" {
}
}
// X
test "Terminal: index no scroll region, top of screen" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
@ -4344,6 +4349,7 @@ test "Terminal: index no scroll region, top of screen" {
}
}
// X
test "Terminal: index bottom of primary screen" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
@ -4386,6 +4392,7 @@ test "Terminal: index bottom of primary screen background sgr" {
}
}
// X
test "Terminal: index inside scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
@ -4423,6 +4430,7 @@ test "Terminal: index bottom of scroll region" {
}
}
// X
test "Terminal: index bottom of primary screen with scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
@ -4444,6 +4452,7 @@ test "Terminal: index bottom of primary screen with scroll region" {
}
}
// X
test "Terminal: index outside left/right margin" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 5);

View File

@ -143,7 +143,7 @@ pub fn cursorDown(self: *Screen) void {
// We move the offset into our page list to the next row and then
// get the pointers to the row/cell and set all the cursor state up.
const page_offset = self.cursor.page_offset.forward(1).?;
const page_rac = page_offset.rowAndCell(0);
const page_rac = page_offset.rowAndCell(self.cursor.x);
self.cursor.page_offset = page_offset;
self.cursor.page_row = page_rac.row;
self.cursor.page_cell = page_rac.cell;

View File

@ -2824,6 +2824,161 @@ test "Terminal: reverseIndex outside top/bottom margins" {
}
}
test "Terminal: index" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
defer t.deinit(alloc);
try t.index();
try t.print('A');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\nA", str);
}
}
test "Terminal: index from the bottom" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
defer t.deinit(alloc);
t.setCursorPos(5, 1);
try t.print('A');
t.cursorLeft(1); // undo moving right from 'A'
try t.index();
try t.print('B');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n\n\nA\nB", str);
}
}
test "Terminal: index outside of scrolling region" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
defer t.deinit(alloc);
try testing.expectEqual(@as(usize, 0), t.screen.cursor.y);
t.setTopAndBottomMargin(2, 5);
try t.index();
try testing.expectEqual(@as(usize, 1), t.screen.cursor.y);
}
test "Terminal: index from the bottom outside of scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 2, 5);
defer t.deinit(alloc);
t.setTopAndBottomMargin(1, 2);
t.setCursorPos(5, 1);
try t.print('A');
try t.index();
try t.print('B');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n\n\n\nAB", str);
}
}
test "Terminal: index no scroll region, top of screen" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
try t.print('A');
try t.index();
try t.print('X');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("A\n X", str);
}
}
test "Terminal: index bottom of primary screen" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setCursorPos(5, 1);
try t.print('A');
try t.index();
try t.print('X');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n\n\nA\n X", str);
}
}
test "Terminal: index inside scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setTopAndBottomMargin(1, 3);
try t.print('A');
try t.index();
try t.print('X');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("A\n X", str);
}
}
test "Terminal: index bottom of primary screen with scroll region" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);
defer t.deinit(alloc);
t.setTopAndBottomMargin(1, 3);
t.setCursorPos(3, 1);
try t.print('A');
t.setCursorPos(5, 1);
try t.index();
try t.index();
try t.index();
try t.print('X');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n\nA\n\nX", str);
}
}
test "Terminal: index outside left/right margin" {
const alloc = testing.allocator;
var t = try init(alloc, 10, 5);
defer t.deinit(alloc);
t.setTopAndBottomMargin(1, 3);
t.scrolling_region.left = 3;
t.scrolling_region.right = 5;
t.setCursorPos(3, 3);
try t.print('A');
t.setCursorPos(3, 1);
try t.index();
try t.print('X');
{
const str = try t.plainString(testing.allocator);
defer testing.allocator.free(str);
try testing.expectEqualStrings("\n\nX A", str);
}
}
test "Terminal: cursorUp basic" {
const alloc = testing.allocator;
var t = try init(alloc, 5, 5);