Changeset View
Changeset View
Standalone View
Standalone View
completion/tests/test_completion.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Line(s) | |||||
108 | ); | 108 | ); | ||
109 | 109 | | |||
110 | class TestCodeCompletionContext : public CodeCompletionContext | 110 | class TestCodeCompletionContext : public CodeCompletionContext | ||
111 | { | 111 | { | ||
112 | public: | 112 | public: | ||
113 | TestCodeCompletionContext(KDevelop::DUContextPointer context, const QString& text, const QString& followingText, const CursorInRevision &position, int depth = 0) | 113 | TestCodeCompletionContext(KDevelop::DUContextPointer context, const QString& text, const QString& followingText, const CursorInRevision &position, int depth = 0) | ||
114 | : CodeCompletionContext(context, text, followingText, position, depth) { } | 114 | : CodeCompletionContext(context, text, followingText, position, depth) { } | ||
115 | protected: | 115 | protected: | ||
116 | QList<QSet<IndexedString> > completionFiles() { | 116 | QList<QSet<IndexedString> > completionFiles() override { | ||
117 | QList<QSet<IndexedString> > ret; | 117 | QList<QSet<IndexedString> > ret; | ||
118 | QSet<IndexedString> set; | 118 | QSet<IndexedString> set; | ||
119 | set << IndexedString("file:///internal/projecttest0"); | 119 | set << IndexedString("file:///internal/projecttest0"); | ||
120 | set << IndexedString("file:///internal/projecttest1"); | 120 | set << IndexedString("file:///internal/projecttest1"); | ||
121 | ret << set; | 121 | ret << set; | ||
122 | return ret; | 122 | return ret; | ||
123 | } | 123 | } | ||
124 | }; | 124 | }; | ||
▲ Show 20 Lines • Show All 157 Lines • ▼ Show 20 Line(s) | 278 | { | |||
282 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | 282 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | ||
283 | CodeCompletionContext::FunctionCallAccess); | 283 | CodeCompletionContext::FunctionCallAccess); | ||
284 | 284 | | |||
285 | CompletionTreeItemPointer item = searchDeclaration(tester.items, top->childContexts().at(0)->localDeclarations().at(0)); | 285 | CompletionTreeItemPointer item = searchDeclaration(tester.items, top->childContexts().at(0)->localDeclarations().at(0)); | ||
286 | QVERIFY(item); | 286 | QVERIFY(item); | ||
287 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | 287 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | ||
288 | 288 | | |||
289 | QString ret; | 289 | QString ret; | ||
290 | createArgumentList(*item2, ret, 0); | 290 | createArgumentList(*item2, ret, nullptr); | ||
291 | QCOMPARE(ret, QString("(A $a, null $b = null)")); | 291 | QCOMPARE(ret, QString("(A $a, null $b = null)")); | ||
292 | } | 292 | } | ||
293 | { | 293 | { | ||
294 | PhpCompletionTester tester(top, QStringLiteral("blah; $i->foo(new A(), ")); | 294 | PhpCompletionTester tester(top, QStringLiteral("blah; $i->foo(new A(), ")); | ||
295 | QVERIFY(searchDeclaration(tester.items, top->childContexts().at(0)->localDeclarations().at(0))); | 295 | QVERIFY(searchDeclaration(tester.items, top->childContexts().at(0)->localDeclarations().at(0))); | ||
296 | } | 296 | } | ||
297 | } | 297 | } | ||
298 | 298 | | |||
▲ Show 20 Lines • Show All 903 Lines • ▼ Show 20 Line(s) | 1198 | { | |||
1202 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | 1202 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | ||
1203 | CodeCompletionContext::FunctionCallAccess); | 1203 | CodeCompletionContext::FunctionCallAccess); | ||
1204 | 1204 | | |||
1205 | CompletionTreeItemPointer item = searchDeclaration(tester.items, aCtor); | 1205 | CompletionTreeItemPointer item = searchDeclaration(tester.items, aCtor); | ||
1206 | QVERIFY(item); | 1206 | QVERIFY(item); | ||
1207 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | 1207 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | ||
1208 | 1208 | | |||
1209 | QString ret; | 1209 | QString ret; | ||
1210 | createArgumentList(*item2, ret, 0); | 1210 | createArgumentList(*item2, ret, nullptr); | ||
1211 | QCOMPARE(ret, QString("(string $bar)")); | 1211 | QCOMPARE(ret, QString("(string $bar)")); | ||
1212 | } | 1212 | } | ||
1213 | { | 1213 | { | ||
1214 | PhpCompletionTester tester(top, QStringLiteral("new B(")); | 1214 | PhpCompletionTester tester(top, QStringLiteral("new B(")); | ||
1215 | QCOMPARE(tester.completionContext->memberAccessOperation(), CodeCompletionContext::NoMemberAccess); | 1215 | QCOMPARE(tester.completionContext->memberAccessOperation(), CodeCompletionContext::NoMemberAccess); | ||
1216 | QVERIFY(tester.completionContext->parentContext()); | 1216 | QVERIFY(tester.completionContext->parentContext()); | ||
1217 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | 1217 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | ||
1218 | CodeCompletionContext::FunctionCallAccess); | 1218 | CodeCompletionContext::FunctionCallAccess); | ||
1219 | 1219 | | |||
1220 | CompletionTreeItemPointer item = searchDeclaration(tester.items, bCtor); | 1220 | CompletionTreeItemPointer item = searchDeclaration(tester.items, bCtor); | ||
1221 | QVERIFY(item); | 1221 | QVERIFY(item); | ||
1222 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | 1222 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | ||
1223 | 1223 | | |||
1224 | QString ret; | 1224 | QString ret; | ||
1225 | createArgumentList(*item2, ret, 0); | 1225 | createArgumentList(*item2, ret, nullptr); | ||
1226 | QCOMPARE(ret, QString("(bool $asdf)")); | 1226 | QCOMPARE(ret, QString("(bool $asdf)")); | ||
1227 | } | 1227 | } | ||
1228 | } | 1228 | } | ||
1229 | 1229 | | |||
1230 | void TestCompletion::chainedCalling() | 1230 | void TestCompletion::chainedCalling() | ||
1231 | { | 1231 | { | ||
1232 | // 0 1 2 3 4 5 6 7 | 1232 | // 0 1 2 3 4 5 6 7 | ||
1233 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 1233 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
Show All 23 Lines | 1253 | { | |||
1257 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | 1257 | QCOMPARE(tester.completionContext->parentContext()->memberAccessOperation(), | ||
1258 | CodeCompletionContext::FunctionCallAccess); | 1258 | CodeCompletionContext::FunctionCallAccess); | ||
1259 | 1259 | | |||
1260 | CompletionTreeItemPointer item = searchDeclaration(tester.items, top->localDeclarations().at(0)); | 1260 | CompletionTreeItemPointer item = searchDeclaration(tester.items, top->localDeclarations().at(0)); | ||
1261 | QVERIFY(item); | 1261 | QVERIFY(item); | ||
1262 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | 1262 | NormalDeclarationCompletionItem* item2 = dynamic_cast<NormalDeclarationCompletionItem*>(item.data()); | ||
1263 | 1263 | | |||
1264 | QString ret; | 1264 | QString ret; | ||
1265 | createArgumentList(*item2, ret, 0); | 1265 | createArgumentList(*item2, ret, nullptr); | ||
1266 | QCOMPARE(ret, QString("(mixed $a, int $b = 1)")); | 1266 | QCOMPARE(ret, QString("(mixed $a, int $b = 1)")); | ||
1267 | } | 1267 | } | ||
1268 | } | 1268 | } | ||
1269 | 1269 | | |||
1270 | void TestCompletion::namespaces() | 1270 | void TestCompletion::namespaces() | ||
1271 | { | 1271 | { | ||
1272 | // 0 1 2 3 4 5 6 7 | 1272 | // 0 1 2 3 4 5 6 7 | ||
1273 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 1273 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |