Add unit tests for BufferView moving cursor to top/middle/bottom of screen

This commit is contained in:
Josh Holtrop 2018-03-26 11:17:34 -04:00
parent c72308c9c3
commit 7637c3ae21

View File

@ -823,3 +823,67 @@ TEST(BufferViewTest, moving_cursor_screen_row_down_jumps_past_wrapped_tab)
EXPECT_EQ(C('f'), **iterator); EXPECT_EQ(C('f'), **iterator);
EXPECT_EQ(3, bv.cursor_screen_row()); EXPECT_EQ(3, bv.cursor_screen_row());
} }
TEST(BufferViewTest, moves_cursor_to_top_middle_or_bottom_of_screen_contents_when_file_fits_on_screen)
{
static const char data[] =
"0abcdefghijklmnopqrstuvwxyz\n"
"1abcdefghijklmnopqrstuvwxyz\n"
"2abcdefghijklmnopqrstuvwxyz\n"
"3abcdefghijklmnopqrstuvwxyz\n"
"4abcdefghijklmnopqrstuvwxyz\n"
"5abcdefghijklmnopqrstuvwxyz\n"
"6abcdefghijklmnopqrstuvwxyz\n";
auto b = std::make_shared<Buffer>((const uint8_t *)data, strlen(data));
auto iterator = b->add_cursor();
BufferView bv(b, iterator, Cwd);
bv.set_scroll_offset(1);
bv.resize(50, 50);
bv.update();
EXPECT_EQ(C('0'), **iterator);
EXPECT_EQ(0, bv.cursor_screen_row());
bv.cursor_move(BufferView::CursorMovement::BOTTOM_OF_SCREEN, 0u, false);
bv.update();
EXPECT_EQ(C('6'), **iterator);
EXPECT_EQ(6, bv.cursor_screen_row());
bv.cursor_move(BufferView::CursorMovement::MIDDLE_OF_SCREEN, 0u, false);
bv.update();
EXPECT_EQ(C('3'), **iterator);
EXPECT_EQ(3, bv.cursor_screen_row());
bv.cursor_move(BufferView::CursorMovement::TOP_OF_SCREEN, 0u, false);
bv.update();
EXPECT_EQ(C('0'), **iterator);
EXPECT_EQ(0, bv.cursor_screen_row());
}
TEST(BufferViewTest, moves_cursor_to_top_middle_or_bottom_of_screen_contents_when_file_does_not_fit_on_screen)
{
static const char data[] =
"0abcdefghijklmnopqrstuvwxyz\n"
"1abcdefghijklmnopqrstuvwxyz\n"
"2abcdefghijklmnopqrstuvwxyz\n"
"3abcdefghijklmnopqrstuvwxyz\n"
"4abcdefghijklmnopqrstuvwxyz\n"
"5abcdefghijklmnopqrstuvwxyz\n"
"6abcdefghijklmnopqrstuvwxyz\n";
auto b = std::make_shared<Buffer>((const uint8_t *)data, strlen(data));
auto iterator = b->add_cursor();
BufferView bv(b, iterator, Cwd);
bv.set_scroll_offset(1);
bv.resize(20, 8);
bv.update();
EXPECT_EQ(C('0'), **iterator);
EXPECT_EQ(0, bv.cursor_screen_row());
bv.cursor_move(BufferView::CursorMovement::BOTTOM_OF_SCREEN, 0u, false);
bv.update();
EXPECT_EQ(C('3'), **iterator);
EXPECT_EQ(6, bv.cursor_screen_row());
bv.cursor_move(BufferView::CursorMovement::MIDDLE_OF_SCREEN, 0u, false);
bv.update();
EXPECT_EQ(C('2'), **iterator);
EXPECT_EQ(4, bv.cursor_screen_row());
bv.cursor_move(BufferView::CursorMovement::TOP_OF_SCREEN, 0u, false);
bv.update();
EXPECT_EQ(C('t'), **iterator);
EXPECT_EQ(1, bv.cursor_screen_row());
}