test that non-adjacent inserts make a single change operation

This commit is contained in:
Josh Holtrop 2017-01-15 21:01:13 -05:00
parent 2e2cdfdb81
commit af77c97394

View File

@ -327,3 +327,31 @@ TEST(BufferTest, a_insert_change_unit_is_dropped_if_everything_in_it_is_erased_b
EXPECT_EQ(0u, b.m_change_operations.size());
EXPECT_EQ(C('b'), **it);
}
TEST(BufferTest, non_adjacent_inserts_in_insert_mode_create_a_single_change_operation)
{
std::string s("abc\n");
Buffer b((const uint8_t *)&s[0], s.size());
auto it = b.add_cursor();
b.enter_insert_mode();
b.insert_code_point(*it, C('1'));
it->go_right_in_line(false);
b.insert_code_point(*it, C('2'));
b.exit_insert_mode();
EXPECT_EQ(ss("1a2bc\n"), b.get_string());
b.undo();
EXPECT_EQ(ss("abc\n"), b.get_string());
it->go_right_in_line(false);
b.enter_insert_mode();
b.insert_code_point(*it, C('3'));
it->go_start_of_line();
b.insert_code_point(*it, C('4'));
b.exit_insert_mode();
EXPECT_EQ(ss("4ab3c\n"), b.get_string());
b.undo();
EXPECT_EQ("abc\n", b.get_string());
}