Add test for snippets with overlapping fields

See 4e1cdb4c9e for details.
This commit is contained in:
Allan Odgaard
2014-03-06 11:15:34 +07:00
parent 337dc1a221
commit c7ae7d1337
2 changed files with 50 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
#include <editor/editor.h>
void test_repopulating_mirrors ()
{
static std::string const plistSrc = "{ content = \"${1/.+/-/}${1:x}${1/.+/-/}\"; }";
ng::buffer_t buf;
ng::editor_t editor(buf);
editor.snippet_dispatch(boost::get<plist::dictionary_t>(plist::parse(plistSrc)), std::map<std::string, std::string>());
OAK_ASSERT_EQ(editor.as_string(), "-x-");
OAK_ASSERT_EQ(to_s(editor.ranges()), "[1-2]");
editor.perform(ng::kDeleteSelection);
OAK_ASSERT_EQ(editor.as_string(), "");
OAK_ASSERT_EQ(to_s(editor.ranges()), "[0]");
editor.insert("y");
OAK_ASSERT_EQ(editor.as_string(), "-y-");
OAK_ASSERT_EQ(to_s(editor.ranges()), "[2]");
}

View File

@@ -100,3 +100,32 @@ void test_indent_replace_soft_tabs ()
s.replace(s.fields[1]->range, "int");
OAK_ASSERT_EQ(s.text, "- (int)method:(id)anArgument\n {\n return nil;\n }");
}
void test_repopulating_mirrors ()
{
std::string src = "${1/.+/-/}${1:x}${1/.+/-/}";
snippet::snippet_t s = snippet::parse(src, std::map<std::string, std::string>(), "" /* indent string */, text::indent_t(2, 2, false), NULL /* run command callback */);
OAK_ASSERT_EQ(s.text, "-x-");
OAK_ASSERT_EQ(s.fields.size(), 2);
OAK_ASSERT_EQ(s.fields[0]->range.from.offset, 3);
OAK_ASSERT_EQ(s.fields[0]->range.to.offset, 3);
OAK_ASSERT_EQ(s.fields[1]->range.from.offset, 1);
OAK_ASSERT_EQ(s.fields[1]->range.to.offset, 2);
s.replace(s.fields[1]->range, "");
OAK_ASSERT_EQ(s.text, "");
OAK_ASSERT_EQ(s.fields.size(), 2);
OAK_ASSERT_EQ(s.fields[0]->range.from.offset, 0);
OAK_ASSERT_EQ(s.fields[0]->range.to.offset, 0);
OAK_ASSERT_EQ(s.fields[1]->range.from.offset, 0);
OAK_ASSERT_EQ(s.fields[1]->range.to.offset, 0);
auto res = s.replace(s.fields[1]->range, "y");
OAK_ASSERT_EQ(s.text, "-y-");
OAK_ASSERT_EQ(s.fields.size(), 2);
OAK_ASSERT_EQ(s.fields[0]->range.from.offset, 3);
OAK_ASSERT_EQ(s.fields[0]->range.to.offset, 3);
OAK_ASSERT_EQ(s.fields[1]->range.from.offset, 1);
OAK_ASSERT_EQ(s.fields[1]->range.to.offset, 2);
}