forked from qt-creator/qt-creator
Snippets: Make it possible again to escape $fields$
Update the unit tests while at it. Add some new tests, rearrange existing ones. Change-Id: Icc2db644f8fe9752c1bf8e66b134738c27b0fb25 Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
@@ -80,6 +80,7 @@ public:
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
const QChar Snippet::kVariableDelimiter(QLatin1Char('$'));
|
||||
const QChar Snippet::kEscapeChar(QLatin1Char('\\'));
|
||||
|
||||
Snippet::Snippet(const QString &groupId, const QString &id) :
|
||||
m_isRemoved(false), m_isModified(false), m_groupId(groupId), m_id(id)
|
||||
@@ -202,6 +203,7 @@ Snippet::ParsedSnippet Snippet::parse(const QString &snippet)
|
||||
|
||||
result.success = errorMessage.isEmpty();
|
||||
if (!result.success) {
|
||||
result.text = snippet;
|
||||
result.errorMessage = errorMessage;
|
||||
return result;
|
||||
}
|
||||
@@ -254,8 +256,8 @@ Snippet::ParsedSnippet Snippet::parse(const QString &snippet)
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current == QLatin1Char('\\') && next == QLatin1Char('$')) {
|
||||
result.text.append(QLatin1Char('$'));
|
||||
if (current == kEscapeChar && (next == kEscapeChar || next == kVariableDelimiter)) {
|
||||
result.text.append(next);
|
||||
++i;
|
||||
continue;
|
||||
}
|
||||
@@ -270,7 +272,7 @@ Snippet::ParsedSnippet Snippet::parse(const QString &snippet)
|
||||
|
||||
if (!success) {
|
||||
result.ranges.clear();
|
||||
result.text = snippet;
|
||||
result.text = preprocessedSnippet;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -298,6 +300,9 @@ void Internal::TextEditorPlugin::testSnippetParsing_data()
|
||||
QTest::newRow("empty input")
|
||||
<< QString::fromLatin1("") << QString::fromLatin1("") << true
|
||||
<< (QList<int>()) << (QList<int>()) << (QList<Core::Id>());
|
||||
QTest::newRow("newline only")
|
||||
<< QString::fromLatin1("\n") << QString::fromLatin1("\n") << true
|
||||
<< (QList<int>()) << (QList<int>()) << (QList<Core::Id>());
|
||||
|
||||
QTest::newRow("simple identifier")
|
||||
<< QString::fromLatin1("$tESt$") << QString::fromLatin1("tESt") << true
|
||||
@@ -317,13 +322,17 @@ void Internal::TextEditorPlugin::testSnippetParsing_data()
|
||||
<< (QList<Core::Id>() << TCMANGLER_ID);
|
||||
|
||||
QTest::newRow("escaped string")
|
||||
<< QString::fromLatin1("\\$test\\$") << QString::fromLatin1("$test$") << true
|
||||
<< QString::fromLatin1("\\\\$test\\\\$") << QString::fromLatin1("$test$") << true
|
||||
<< (QList<int>()) << (QList<int>())
|
||||
<< (QList<Core::Id>());
|
||||
QTest::newRow("escaped escape")
|
||||
<< QString::fromLatin1("\\\\$test\\\\$") << QString::fromLatin1("\\test\\") << true
|
||||
<< (QList<int>() << 1) << (QList<int>() << 5)
|
||||
<< QString::fromLatin1("\\\\\\\\$test$\\\\\\\\") << QString::fromLatin1("\\test\\") << true
|
||||
<< (QList<int>() << 1) << (QList<int>() << 4)
|
||||
<< (QList<Core::Id>() << NOMANGLER_ID);
|
||||
QTest::newRow("broken escape")
|
||||
<< QString::fromLatin1("\\\\$test\\\\\\\\$\\\\") << QString::fromLatin1("\\$test\\\\$\\") << false
|
||||
<< (QList<int>()) << (QList<int>())
|
||||
<< (QList<Core::Id>());
|
||||
|
||||
QTest::newRow("Q_PROPERTY")
|
||||
<< QString::fromLatin1("Q_PROPERTY($type$ $name$ READ $name$ WRITE set$name:c$ NOTIFY $name$Changed)")
|
||||
@@ -332,10 +341,6 @@ void Internal::TextEditorPlugin::testSnippetParsing_data()
|
||||
<< (QList<int>() << 4 << 4 << 4 << 4 << 4)
|
||||
<< (QList<Core::Id>() << NOMANGLER_ID << NOMANGLER_ID << NOMANGLER_ID << TCMANGLER_ID << NOMANGLER_ID);
|
||||
|
||||
QTest::newRow("broken escape")
|
||||
<< QString::fromLatin1("\\\\$test\\\\$\\") << QString::fromLatin1("\\\\$test\\\\$\\") << false
|
||||
<< (QList<int>()) << (QList<int>())
|
||||
<< (QList<Core::Id>());
|
||||
QTest::newRow("open identifier")
|
||||
<< QString::fromLatin1("$test") << QString::fromLatin1("$test") << false
|
||||
<< (QList<int>()) << (QList<int>())
|
||||
@@ -360,6 +365,23 @@ void Internal::TextEditorPlugin::testSnippetParsing_data()
|
||||
<< (QList<int>() << 6 << 25)
|
||||
<< (QList<int>() << 4 << 4)
|
||||
<< (QList<Core::Id>() << NOMANGLER_ID << NOMANGLER_ID);
|
||||
|
||||
QTest::newRow("escape sequences")
|
||||
<< QString::fromLatin1("class $name$\\n"
|
||||
"{\\n"
|
||||
"public\\\\:\\n"
|
||||
"\\t$name$() {}\\n"
|
||||
"};")
|
||||
<< QString::fromLatin1("class name\n"
|
||||
"{\n"
|
||||
"public\\:\n"
|
||||
"\tname() {}\n"
|
||||
"};")
|
||||
<< true
|
||||
<< (QList<int>() << 6 << 23)
|
||||
<< (QList<int>() << 4 << 4)
|
||||
<< (QList<Core::Id>() << NOMANGLER_ID << NOMANGLER_ID);
|
||||
|
||||
}
|
||||
|
||||
void Internal::TextEditorPlugin::testSnippetParsing()
|
||||
|
@@ -79,6 +79,7 @@ public:
|
||||
QString generateTip() const;
|
||||
|
||||
static const QChar kVariableDelimiter;
|
||||
static const QChar kEscapeChar;
|
||||
|
||||
class ParsedSnippet {
|
||||
public:
|
||||
|
Reference in New Issue
Block a user