forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/2.6'
This commit is contained in:
@@ -121,6 +121,40 @@ static void setup(TestData *data)
|
||||
data->doc = data->editor->document();
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_forward_declarations_present()
|
||||
{
|
||||
TestData data;
|
||||
data.srcText = "\n"
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
" struct Bar;\n"
|
||||
" int i;\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"struct Foo::Bar \n"
|
||||
"{\n"
|
||||
" Bar() {}\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"@\n"
|
||||
"// padding so we get the scope right\n";
|
||||
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
change.insert(data.pos, "Foo::Bar::");
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += 10;
|
||||
|
||||
QStringList expected;
|
||||
expected.append("Bar");
|
||||
|
||||
QStringList completions = getCompletions(data);
|
||||
|
||||
QCOMPARE(completions, expected);
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_basic_1()
|
||||
{
|
||||
TestData data;
|
||||
@@ -196,3 +230,172 @@ void CppToolsPlugin::test_completion_template_1()
|
||||
QVERIFY(!completions.contains("f"));
|
||||
QVERIFY(!completions.contains("func"));
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_template_as_base()
|
||||
{
|
||||
QFETCH(QByteArray, code);
|
||||
QFETCH(QStringList, expectedCompletions);
|
||||
|
||||
TestData data;
|
||||
data.srcText = code;
|
||||
setup(&data);
|
||||
|
||||
Utils::ChangeSet change;
|
||||
change.insert(data.pos, "c.");
|
||||
QTextCursor cursor(data.doc);
|
||||
change.apply(&cursor);
|
||||
data.pos += 2;
|
||||
|
||||
QStringList actualCompletions = getCompletions(data);
|
||||
actualCompletions.sort();
|
||||
expectedCompletions.sort();
|
||||
|
||||
QCOMPARE(actualCompletions, expectedCompletions);
|
||||
}
|
||||
|
||||
void CppToolsPlugin::test_completion_template_as_base_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("code");
|
||||
QTest::addColumn<QStringList>("expectedCompletions");
|
||||
|
||||
QByteArray code;
|
||||
QStringList completions;
|
||||
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"template <class T> class Other : public T { int otherMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" Other<Data> c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Other");
|
||||
completions.append("otherMember");
|
||||
QTest::newRow("case: base as template directly") << code << completions;
|
||||
|
||||
|
||||
completions.clear();
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"template <class T> class Other : public T { int otherMember; };\n"
|
||||
"template <class T> class More : public Other<T> { int moreMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" More<Data> c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Other");
|
||||
completions.append("otherMember");
|
||||
completions.append("More");
|
||||
completions.append("moreMember");
|
||||
QTest::newRow("case: base as class template") << code << completions;
|
||||
|
||||
|
||||
completions.clear();
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"template <class T> class Other : public T { int otherMember; };\n"
|
||||
"template <class T> class More : public ::Other<T> { int moreMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" More<Data> c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Other");
|
||||
completions.append("otherMember");
|
||||
completions.append("More");
|
||||
completions.append("moreMember");
|
||||
QTest::newRow("case: base as globally qualified class template") << code << completions;
|
||||
|
||||
|
||||
completions.clear();
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"namespace NS {\n"
|
||||
"template <class T> class Other : public T { int otherMember; };\n"
|
||||
"}\n"
|
||||
"template <class T> class More : public NS::Other<T> { int moreMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" More<Data> c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Other");
|
||||
completions.append("otherMember");
|
||||
completions.append("More");
|
||||
completions.append("moreMember");
|
||||
QTest::newRow("case: base as namespace qualified class template") << code << completions;
|
||||
|
||||
|
||||
completions.clear();
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"namespace NS {\n"
|
||||
"template <class T> class Delegate { typedef Data<T> Type; };\n"
|
||||
"}\n"
|
||||
"template <class T> class Final : public NS::Delegate<T>::Type { int finalMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" Final<Data> c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Final");
|
||||
completions.append("finalMember");
|
||||
QTest::newRow("case: base as nested template name") << code << completions;
|
||||
|
||||
|
||||
completions.clear();
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"namespace NS {\n"
|
||||
"template <class T> class Delegate { typedef Data<T> Type; };\n"
|
||||
"}\n"
|
||||
"class Final : public NS::Delegate<Data>::Type { int finalMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" Final c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Final");
|
||||
completions.append("finalMember");
|
||||
QTest::newRow("case: base as nested template name in non-template") << code << completions;
|
||||
|
||||
completions.clear();
|
||||
code = "\n"
|
||||
"class Data { int dataMember; };\n"
|
||||
"namespace NS {\n"
|
||||
"template <class T> class Other : public T { int otherMember; };\n"
|
||||
"}\n"
|
||||
"class Final : public NS::Other<Data> { int finalMember; };\n"
|
||||
"\n"
|
||||
"void func() {\n"
|
||||
" Final c;\n"
|
||||
" @\n"
|
||||
" // padding so we get the scope right\n"
|
||||
"}";
|
||||
completions.append("Data");
|
||||
completions.append("dataMember");
|
||||
completions.append("Final");
|
||||
completions.append("finalMember");
|
||||
completions.append("Other");
|
||||
completions.append("otherMember");
|
||||
QTest::newRow("case: base as template name in non-template") << code << completions;
|
||||
}
|
||||
|
||||
@@ -90,8 +90,11 @@ private slots:
|
||||
void test_codegen_definition_last_member();
|
||||
void test_codegen_definition_middle_member();
|
||||
|
||||
void test_completion_forward_declarations_present();
|
||||
void test_completion_basic_1();
|
||||
void test_completion_template_1();
|
||||
void test_completion_template_as_base();
|
||||
void test_completion_template_as_base_data();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user