360
360
void TestCppCodeCompletion::testMemberAccess()
362
QByteArray method = "template<class T1, class T2> class T { public: T1 ta(); class U { public: class V{ }; }; }; class X { public: X(){}; int a(int a, T<int,int> b); int b;}; T<int,int> t; X* getX() { }";
362
QByteArray method = "template<class T1, class T2> class T { public: T1 ta(); class U { public: class V{ }; }; };"
363
"class X { public: X(){}; int a(int a, T<int,int> b); int b;};"
366
"class Z { public: Z() = delete; static int a(int b); };";
363
367
TopDUContext* top = parse(method, DumpNone);
365
369
DUChainWriteLocker lock(DUChain::lock());
381
385
CompletionItemTester testColons2(top->childContexts()[ctxt], "T::U::");
382
386
QCOMPARE(testColons2.names, QStringList() << "V");
383
387
QCOMPARE(testColons2.completionContext->accessType(), Cpp::CodeCompletionContext::StaticMemberChoose);
388
CompletionItemTester testDeleted(top->childContexts()[ctxt], "Z::");
389
QCOMPARE(testDeleted.names, QStringList() << "a");
390
QCOMPARE(testDeleted.completionContext->accessType(), Cpp::CodeCompletionContext::StaticMemberChoose);
1031
void TestCppCodeCompletion::testConstructorUsageCompletion_data()
1033
QTest::addColumn<QString>("code"); // existing source code
1034
QTest::addColumn<QStringList>("args"); // completion arguments
1035
QTest::addColumn<QStringList>("not_args"); // forbidden completion arguments
1037
// only the default constructor is present
1038
QTest::newRow("only default")
1039
<< "class A { A(); };"
1040
<< (QStringList() << "()")
1042
// the default constructor and one overload
1043
QTest::newRow("Default and int")
1044
<< "class A { A(); A(int); };"
1045
<< (QStringList() << "()" << "(int)")
1047
// the default constructor and two overloads
1048
QTest::newRow("Default, int and float")
1049
<< "class A { A(); A(int); A(float); };"
1050
<< (QStringList() << "()" << "(int)" << "(float)")
1052
// deleted default constructor and two overloads
1053
QTest::newRow("no default, int and float")
1054
<< "class A { A() = delete; A(int); A(float); };"
1055
<< (QStringList() << "(int)" << "(float)")
1056
<< (QStringList() << "()");
1057
// the default and copy constructors are present
1058
QTest::newRow("default and copy")
1059
<< "class A { A(); A(const A&); };"
1060
<< (QStringList() << "()" << "(const A&)")
1062
// the default and copy constructors are deleted
1063
QTest::newRow("default and copy")
1064
<< "class A { A() = delete; A(const A&) = delete; };"
1066
<< (QStringList() << "()" << "(const A&)");
1067
// the default and copy constructors are deleted, but another one is present
1068
QTest::newRow("default and copy")
1069
<< "class A { A() = delete; A(const A&) = delete; A(int); };"
1070
<< (QStringList() << "(int)")
1071
<< (QStringList() << "()" << "(const A&)");
1074
void TestCppCodeCompletion::testConstructorUsageCompletion()
1076
QFETCH(QString, code);
1077
QFETCH(QStringList, args);
1078
QFETCH(QStringList, not_args);
1080
TopDUContext* context = parse( code.toAscii(), DumpNone /*DumpDUChain | DumpAST */);
1081
DUChainWriteLocker lock(DUChain::lock());
1083
CompletionItemTester tester(context, "void k() { A *a = new A(");
1085
QStringList foundargs;
1086
for (int i = 0; i < tester.items.count(); i++)
1087
foundargs << tester.itemData(i, KTextEditor::CodeCompletionModel::Arguments).toString();
1088
qDebug() << foundargs << args << not_args;
1089
foreach(const QString &arg, args)
1090
QVERIFY(foundargs.contains(arg));
1091
foreach(const QString &arg, not_args)
1092
QVERIFY(!foundargs.contains(arg));
1024
1097
void TestCppCodeCompletion::testParentConstructor_data()
1026
1099
QTest::addColumn<QString>("code"); // existing source code
3101
3174
codeToArgList.insert("void foo(int arg[][1]){}", "(int arg[][1])");
3102
3175
codeToArgList.insert("void foo(int arg[1][1]){}", "(int arg[1][1])");
3103
3176
codeToArgList.insert("void foo(int arg[][1][1]){}", "(int arg[][1][1])");
3177
codeToArgList.insert("void foo(void){}", "(void)");
3178
codeToArgList.insert("void foo(int){}", "(int)");
3104
3179
QMap< QByteArray, QString >::const_iterator it = codeToArgList.constBegin();
3105
3180
while (it != codeToArgList.constEnd()){
3106
3181
qDebug() << "input function is:" << it.key();