Commit cede2947 authored by Erik Verbruggen's avatar Erik Verbruggen

C++: add test-case for member access replacement in completion.

Change-Id: Id5fe00b94a6622178db9bd26f54d29efe88970f7
Reviewed-by: default avatarPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>
Reviewed-by: default avatarNikolai Kosjar <nikolai.kosjar@digia.com>
parent 8f481715
......@@ -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);
}
......@@ -58,7 +58,6 @@
#include <coreplugin/mimedatabase.h>
#include <cppeditor/cppeditorconstants.h>
#include <texteditor/codeassist/basicproposalitem.h>
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
#include <texteditor/codeassist/genericproposal.h>
#include <texteditor/codeassist/ifunctionhintproposalmodel.h>
#include <texteditor/codeassist/functionhintproposal.h>
......@@ -91,29 +90,6 @@ struct CompleteFunctionDeclaration
Function *function;
};
// ----------------------
// CppAssistProposalModel
// ----------------------
class CppAssistProposalModel : public TextEditor::BasicProposalItemListModel
{
public:
CppAssistProposalModel()
: TextEditor::BasicProposalItemListModel()
, m_completionOperator(T_EOF_SYMBOL)
, m_replaceDotForArrow(false)
, m_typeOfExpression(new TypeOfExpression)
{
m_typeOfExpression->setExpandTemplates(true);
}
virtual bool isSortable(const QString &prefix) const;
virtual IAssistProposalItem *proposalItem(int index) const;
unsigned m_completionOperator;
bool m_replaceDotForArrow;
QSharedPointer<TypeOfExpression> m_typeOfExpression;
};
// ---------------------
// CppAssistProposalItem
// ---------------------
......
......@@ -41,10 +41,12 @@
# include <cplusplus/Symbol.h>
#endif
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
#include <texteditor/codeassist/completionassistprovider.h>
#include <texteditor/codeassist/iassistprocessor.h>
#include <texteditor/snippets/snippetassistcollector.h>
#include <texteditor/codeassist/defaultassistinterface.h>
#include <texteditor/codeassist/basicproposalitem.h>
#include <QStringList>
#include <QVariant>
......@@ -64,7 +66,26 @@ namespace CppTools {
namespace Internal {
class CppCompletionAssistInterface;
class CppAssistProposalModel;
class CppAssistProposalModel : public TextEditor::BasicProposalItemListModel
{
public:
CppAssistProposalModel()
: TextEditor::BasicProposalItemListModel()
, m_completionOperator(CPlusPlus::T_EOF_SYMBOL)
, m_replaceDotForArrow(false)
, m_typeOfExpression(new CPlusPlus::TypeOfExpression)
{
m_typeOfExpression->setExpandTemplates(true);
}
virtual bool isSortable(const QString &prefix) const;
virtual TextEditor::IAssistProposalItem *proposalItem(int index) const;
unsigned m_completionOperator;
bool m_replaceDotForArrow;
QSharedPointer<CPlusPlus::TypeOfExpression> m_typeOfExpression;
};
class InternalCompletionAssistProvider : public CppCompletionAssistProvider
{
......
......@@ -112,6 +112,7 @@ private slots:
void test_completion_enclosing_template_class_data();
void test_completion_instantiate_nested_class_when_enclosing_is_template();
void test_completion_instantiate_nested_of_nested_class_when_enclosing_is_template();
void test_completion_member_access_operator_1();
void test_format_pointerdeclaration_in_simpledeclarations();
void test_format_pointerdeclaration_in_simpledeclarations_data();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment