forked from qt-creator/qt-creator
C++: Fix code completion for nested classes
Fix code completion for nested classes when enclosing is template class. Unit tests Task-number: QTCREATORBUG-8245 (only standalone) Change-Id: Ib31ad4b799db927b56debd4dc3e7403404c1839d Reviewed-by: hjk <qthjk@ovi.com>
This commit is contained in:
committed by
hjk
parent
17748280e8
commit
b1199ef0cc
@@ -1176,3 +1176,87 @@ void CppToolsPlugin::test_completion_enclosing_template_class_data()
|
||||
QTest::newRow("case: nested template class with enclosing template class")
|
||||
<< code << completions;
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_instantiate_nested_class_when_enclosing_is_template()
|
||||
{
|
||||
TestData data;
|
||||
data.srcText = "\n"
|
||||
"struct Foo \n"
|
||||
"{\n"
|
||||
" int foo_i;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"template <typename T>\n"
|
||||
"struct Enclosing\n"
|
||||
"{\n"
|
||||
" struct Nested\n"
|
||||
" {\n"
|
||||
" T nested_t;\n"
|
||||
" } nested;\n"
|
||||
"\n"
|
||||
" T enclosing_t;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"Enclosing<Foo> enclosing;\n"
|
||||
"@\n"
|
||||
;
|
||||
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
QString txt = QLatin1String("enclosing.nested.nested_t.");
|
||||
change.insert(data.pos, txt);
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += txt.length();
|
||||
|
||||
QStringList completions = getCompletions(data);
|
||||
|
||||
QCOMPARE(completions.size(), 2);
|
||||
QVERIFY(completions.contains(QLatin1String("Foo")));
|
||||
QVERIFY(completions.contains(QLatin1String("foo_i")));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_instantiate_nested_of_nested_class_when_enclosing_is_template()
|
||||
{
|
||||
TestData data;
|
||||
data.srcText = "\n"
|
||||
"struct Foo \n"
|
||||
"{\n"
|
||||
" int foo_i;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"template <typename T>\n"
|
||||
"struct Enclosing\n"
|
||||
"{\n"
|
||||
" struct Nested\n"
|
||||
" {\n"
|
||||
" T nested_t;\n"
|
||||
" struct NestedNested\n"
|
||||
" {\n"
|
||||
" T nestedNested_t;\n"
|
||||
" } nestedNested;\n"
|
||||
" } nested;\n"
|
||||
"\n"
|
||||
" T enclosing_t;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"Enclosing<Foo> enclosing;\n"
|
||||
"@\n"
|
||||
;
|
||||
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
QString txt = QLatin1String("enclosing.nested.nestedNested.nestedNested_t.");
|
||||
change.insert(data.pos, txt);
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += txt.length();
|
||||
|
||||
QStringList completions = getCompletions(data);
|
||||
|
||||
QCOMPARE(completions.size(), 2);
|
||||
QVERIFY(completions.contains(QLatin1String("Foo")));
|
||||
QVERIFY(completions.contains(QLatin1String("foo_i")));
|
||||
}
|
||||
|
||||
@@ -110,6 +110,8 @@ private slots:
|
||||
void test_completion_cyclic_inheritance_data();
|
||||
void test_completion_enclosing_template_class();
|
||||
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();
|
||||
|
||||
private:
|
||||
void test_completion();
|
||||
|
||||
Reference in New Issue
Block a user