add tests for modifying uncommitted insert change units
This commit is contained in:
parent
4e03fbc3de
commit
edf29f0bac
@ -280,3 +280,50 @@ TEST(BufferTest, erase_chunks_are_coalesced_within_a_change_operation)
|
||||
EXPECT_EQ(C('e'), **it);
|
||||
EXPECT_EQ(ss("abcdef\n"), b.get_string());
|
||||
}
|
||||
|
||||
TEST(BufferTest, erases_in_uncommitted_insert_units_modify_the_insert_units)
|
||||
{
|
||||
std::string s("abcdef\n");
|
||||
Buffer b((const uint8_t *)&s[0], s.size());
|
||||
auto it = b.add_cursor();
|
||||
|
||||
it->go_right_in_line(false);
|
||||
b.enter_insert_mode();
|
||||
b.insert_code_point(*it, C('1'));
|
||||
b.insert_code_point(*it, C('2'));
|
||||
b.insert_code_point(*it, C('3'));
|
||||
it->go_left_in_line();
|
||||
b.erase_code_point(*it);
|
||||
b.exit_insert_mode();
|
||||
EXPECT_EQ(1u, b.m_change_operations.size());
|
||||
EXPECT_EQ(ss("a12bcdef\n"), b.get_string());
|
||||
EXPECT_EQ(C('b'), **it);
|
||||
|
||||
b.undo();
|
||||
EXPECT_EQ(ss("abcdef\n"), b.get_string());
|
||||
EXPECT_EQ(C('b'), **it);
|
||||
|
||||
b.redo();
|
||||
EXPECT_EQ(ss("a12bcdef\n"), b.get_string());
|
||||
EXPECT_EQ(C('b'), **it);
|
||||
}
|
||||
|
||||
TEST(BufferTest, a_insert_change_unit_is_dropped_if_everything_in_it_is_erased_before_committing)
|
||||
{
|
||||
std::string s("abc\n");
|
||||
Buffer b((const uint8_t *)&s[0], s.size());
|
||||
auto it = b.add_cursor();
|
||||
|
||||
it->go_right_in_line(false);
|
||||
b.enter_insert_mode();
|
||||
b.insert_code_point(*it, C('1'));
|
||||
b.insert_code_point(*it, C('2'));
|
||||
it->go_left_in_line();
|
||||
b.erase_code_point(*it); /* backspace */
|
||||
it->go_left_in_line();
|
||||
b.erase_code_point(*it); /* backspace */
|
||||
b.exit_insert_mode();
|
||||
EXPECT_EQ(ss("abc\n"), b.get_string());
|
||||
EXPECT_EQ(0u, b.m_change_operations.size());
|
||||
EXPECT_EQ(C('b'), **it);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user