mirror of
https://github.com/textmate/textmate.git
synced 2026-04-28 03:00:34 -04:00
Add test for snippets with overlapping fields
See 4e1cdb4c9e for details.
This commit is contained in:
21
Frameworks/editor/tests/t_snippets.cc
Normal file
21
Frameworks/editor/tests/t_snippets.cc
Normal 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]");
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user