forked from qt-creator/qt-creator
C++: fix code completion: casting inside parentheses
Included unit tests. Task-number: QTCREATORBUG-8368 Change-Id: I1b04124bc2c9eac050cfb2e6d3a5c1aca5311f4b Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
committed by
Erik Verbruggen
parent
d9571f2ecd
commit
31ce303ee7
@@ -152,6 +152,87 @@ void CppToolsPlugin::test_completion_forward_declarations_present()
|
||||
QCOMPARE(completions, expected);
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_inside_parentheses_c_style_conversion()
|
||||
{
|
||||
TestData data;
|
||||
data.srcText = "\n"
|
||||
"class Base\n"
|
||||
"{\n"
|
||||
" int i_base;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"class Derived : public Base\n"
|
||||
"{\n"
|
||||
" int i_derived;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void fun()\n"
|
||||
"{\n"
|
||||
" Base *b = new Derived;\n"
|
||||
" if (1)\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
QString txt = QLatin1String("((Derived *)b)->");
|
||||
change.insert(data.pos, txt);
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += txt.length();
|
||||
|
||||
QStringList completions = getCompletions(data);
|
||||
|
||||
QCOMPARE(completions.size(), 4);
|
||||
QVERIFY(completions.contains(QLatin1String("Derived")));
|
||||
QVERIFY(completions.contains(QLatin1String("Base")));
|
||||
QVERIFY(completions.contains(QLatin1String("i_derived")));
|
||||
QVERIFY(completions.contains(QLatin1String("i_base")));
|
||||
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_inside_parentheses_cast_operator_conversion()
|
||||
{
|
||||
TestData data;
|
||||
data.srcText = "\n"
|
||||
"class Base\n"
|
||||
"{\n"
|
||||
" int i_base;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"class Derived : public Base\n"
|
||||
"{\n"
|
||||
" int i_derived;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void fun()\n"
|
||||
"{\n"
|
||||
" Base *b = new Derived;\n"
|
||||
" if (1)\n"
|
||||
" @\n"
|
||||
"}\n"
|
||||
;
|
||||
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
QString txt = QLatin1String("(static_cast<Derived *>(b))->");
|
||||
change.insert(data.pos, txt);
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += txt.length();
|
||||
|
||||
QStringList completions = getCompletions(data);
|
||||
|
||||
QCOMPARE(completions.size(), 4);
|
||||
QVERIFY(completions.contains(QLatin1String("Derived")));
|
||||
QVERIFY(completions.contains(QLatin1String("Base")));
|
||||
QVERIFY(completions.contains(QLatin1String("i_derived")));
|
||||
QVERIFY(completions.contains(QLatin1String("i_base")));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_basic_1()
|
||||
{
|
||||
TestData data;
|
||||
|
||||
@@ -90,6 +90,8 @@ private slots:
|
||||
void test_codegen_definition_middle_member();
|
||||
|
||||
void test_completion_forward_declarations_present();
|
||||
void test_completion_inside_parentheses_c_style_conversion();
|
||||
void test_completion_inside_parentheses_cast_operator_conversion();
|
||||
void test_completion_basic_1();
|
||||
void test_completion_template_1();
|
||||
void test_completion_template_2();
|
||||
|
||||
Reference in New Issue
Block a user