add PieceTable::Cursor::operator*(), add unit test

This commit is contained in:
Josh Holtrop 2016-08-04 22:38:18 -04:00
parent abf853e1ba
commit f6338da8d0
2 changed files with 14 additions and 0 deletions

View File

@ -63,6 +63,12 @@ public:
/** Virtual column (0 based). */
uint32_t column;
uint32_t operator*() const
{
/* TODO: Use Encoding */
return piece->start[offset];
}
};
PieceTable(const uint8_t * file_buffer, unsigned long file_buffer_size);

View File

@ -21,3 +21,11 @@ TEST(BufferTest, writes_an_identical_file_to_what_is_loaded_if_no_changes_were_p
TestSupport::compare_files(e, "test/tmp/f");
}
}
TEST(BufferTest, allows_navigating_using_cursors)
{
Buffer b;
ASSERT_TRUE(b.load_from_file("test/files/line_endings/lf_format.txt"));
std::shared_ptr<PieceTable::Cursor> cursor = b.piece_table->add_cursor();
EXPECT_EQ((uint32_t)'H', **cursor);
}