forked from qt-creator/qt-creator
C++: add test-case for member access replacement in completion.
Change-Id: Id5fe00b94a6622178db9bd26f54d29efe88970f7 Reviewed-by: Przemyslaw Gorszkowski <pgorszkowski@gmail.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
@@ -72,7 +72,7 @@ struct TestCase
|
||||
QTextDocument *doc;
|
||||
};
|
||||
|
||||
static QStringList getCompletions(TestCase &data)
|
||||
static QStringList getCompletions(TestCase &data, bool *replaceAccessOperator = 0)
|
||||
{
|
||||
QStringList completions;
|
||||
|
||||
@@ -86,13 +86,16 @@ static QStringList getCompletions(TestCase &data)
|
||||
IAssistProposalModel *model = proposal->model();
|
||||
if (!model)
|
||||
return completions;
|
||||
BasicProposalItemListModel *listmodel = dynamic_cast<BasicProposalItemListModel *>(model);
|
||||
CppAssistProposalModel *listmodel = dynamic_cast<CppAssistProposalModel *>(model);
|
||||
if (!listmodel)
|
||||
return completions;
|
||||
|
||||
for (int i = 0; i < listmodel->size(); ++i)
|
||||
completions << listmodel->text(i);
|
||||
|
||||
if (replaceAccessOperator)
|
||||
*replaceAccessOperator = listmodel->m_replaceDotForArrow;
|
||||
|
||||
return completions;
|
||||
}
|
||||
|
||||
@@ -1288,3 +1291,30 @@ void CppToolsPlugin::test_completion_instantiate_nested_of_nested_class_when_enc
|
||||
QVERIFY(completions.contains(QLatin1String("Foo")));
|
||||
QVERIFY(completions.contains(QLatin1String("foo_i")));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_member_access_operator_1()
|
||||
{
|
||||
TestCase data;
|
||||
data.srcText = "\n"
|
||||
"struct S { void t(); };\n"
|
||||
"void f() { S *s;\n"
|
||||
"@\n"
|
||||
"}\n"
|
||||
;
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
QString txt = QLatin1String("s.");
|
||||
change.insert(data.pos, txt);
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += txt.length();
|
||||
|
||||
bool replaceAccessOperator = false;
|
||||
QStringList completions = getCompletions(data, &replaceAccessOperator);
|
||||
|
||||
QCOMPARE(completions.size(), 2);
|
||||
QVERIFY(completions.contains(QLatin1String("S")));
|
||||
QVERIFY(completions.contains(QLatin1String("t")));
|
||||
QVERIFY(replaceAccessOperator);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user