From af77c97394221fc54fdcf9a5599fe09cd141b306 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sun, 15 Jan 2017 21:01:13 -0500 Subject: [PATCH] test that non-adjacent inserts make a single change operation --- test/src/test_Buffer.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/src/test_Buffer.cc b/test/src/test_Buffer.cc index d20aa00..b5cb554 100644 --- a/test/src/test_Buffer.cc +++ b/test/src/test_Buffer.cc @@ -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()); +}