move much of the buffer layout code from BufferPane to BufferView

This commit is contained in:
josh committed 2017-08-29 23:03:49 -04:00
1 parent 545e73bd07
commit 8e0796decf
3 files changed
+209 -1

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
#include "gtest/gtest.h"
#include "BufferView.h"
static std::shared_ptr<Buffer> buffer1()
{
static const char data[] =
"0\n"
"1ab\n"
"2abc\n"
"3\n"
"4\n"
"5\n"
"6abcdefg\n"
"7\n"
"8\n"
"9abcdefghijklmno\n"
"10\n"
"11\n"
"12\n";
return std::make_shared<Buffer>((const uint8_t *)data, strlen(data));
}
class MyCharacterWidthDeterminer : public CharacterWidthDeterminer
{
int operator()(uint32_t character)
{
if (character < 32)
{
return 2;
}
else
{
return 1;
}
}
} Cwd;
static int LineNumber(const Buffer::Iterator & iterator)
{
int line_number = 0;
Buffer::Iterator i = iterator;
for (;;)
{
uint32_t c = *i;
if ((c < '0') || (c > '9'))
break;
line_number *= 10;
line_number += ((int)c - '0');
i.go_forward();
}
return line_number;
}
TEST(BufferViewTest, iterates_through_screen_lines_with_no_wrapping)
{
std::shared_ptr<Buffer> b = buffer1();
std::shared_ptr<Buffer::Iterator> iterator = b->add_iterator();
BufferView bv(b, iterator, Cwd);
bv.resize(40, 8);
int times_called = 0;
bv.iter_lines([&times_called](int row_offset, const Buffer::Iterator & iterator) -> bool {
EXPECT_EQ(times_called, LineNumber(iterator));
times_called++;
return true;
});
EXPECT_EQ(8, times_called);
}