jes/test/src/test_Buffer.cc

44 lines
1.3 KiB
C++

#include "gtest/gtest.h"
#include "Buffer.h"
#include "TestSupport.h"
#include "Path.h"
TEST(BufferTest, writes_an_identical_file_to_what_is_loaded_if_no_changes_were_performed)
{
const char * files_to_test[] = {
"test/files/empty.txt",
"test/files/line_endings/cr_format.txt",
"test/files/line_endings/crlf_format.txt",
"test/files/line_endings/lf_format.txt",
"test/files/no_eol_at_eof.txt",
};
for (auto e : files_to_test)
{
Buffer b;
ASSERT_TRUE(b.load_from_file(e));
ASSERT_TRUE(b.write_to_file("test/tmp/f"));
ASSERT_TRUE(Path::is_file("test/tmp/f"));
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();
ASSERT_EQ((uint32_t)'H', **cursor);
cursor->go_up();
ASSERT_EQ((uint32_t)'H', **cursor);
cursor->go_right();
ASSERT_EQ((uint32_t)'e', **cursor);
cursor->go_down();
ASSERT_EQ((uint32_t)'h', **cursor);
cursor->go_left();
ASSERT_EQ((uint32_t)'T', **cursor);
cursor->go_left();
ASSERT_EQ((uint32_t)'T', **cursor);
cursor->go_down();
ASSERT_EQ((uint32_t)'T', **cursor);
}