Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/tests/test_codecompletion.cpp
Context not available. | |||||
188 | template<typename CustomTestFunction = NoopTestFunction> | 188 | template<typename CustomTestFunction = NoopTestFunction> | ||
---|---|---|---|---|---|
189 | void executeCompletionTest(const QString& code, const CompletionItems& expectedCompletionItems, | 189 | void executeCompletionTest(const QString& code, const CompletionItems& expectedCompletionItems, | ||
190 | const ClangCodeCompletionContext::ContextFilters& filters = NoMacroOrBuiltin, | 190 | const ClangCodeCompletionContext::ContextFilters& filters = NoMacroOrBuiltin, | ||
191 | CustomTestFunction customTestFunction = {}) | 191 | CustomTestFunction customTestFunction = {}, | ||
192 | QString fileExtension = QStringLiteral("cpp")) | ||||
192 | { | 193 | { | ||
193 | TestFile file(code, QStringLiteral("cpp")); | 194 | TestFile file(code, fileExtension); | ||
194 | QVERIFY(file.parseAndWait(TopDUContext::AllDeclarationsContextsUsesAndAST)); | 195 | QVERIFY(file.parseAndWait(TopDUContext::AllDeclarationsContextsUsesAndAST)); | ||
195 | executeCompletionTest(file.topContext(), expectedCompletionItems, filters, customTestFunction); | 196 | executeCompletionTest(file.topContext(), expectedCompletionItems, filters, customTestFunction); | ||
196 | } | 197 | } | ||
Context not available. | |||||
504 | << CompletionItems{{3, 17}, { "Head", "Tail", "my_class" }}; | 505 | << CompletionItems{{3, 17}, { "Head", "Tail", "my_class" }}; | ||
505 | } | 506 | } | ||
506 | 507 | | |||
508 | | ||||
509 | void TestCodeCompletion::testClangCodeCompletionType() | ||||
510 | { | ||||
511 | QFETCH(QString, fileExtension); | ||||
512 | QFETCH(QString, code); | ||||
513 | QFETCH(CompletionItems, expectedItems); | ||||
514 | QFETCH(QString, expedtedItem); | ||||
515 | QFETCH(QString, expectedType); | ||||
516 | | ||||
517 | auto executeItem = [=] (const ClangCodeCompletionItemTester& tester) { | ||||
518 | auto item = tester.findItem(expedtedItem); | ||||
519 | QVERIFY(item); | ||||
520 | auto declaration = item->declaration(); | ||||
521 | QVERIFY(declaration); | ||||
522 | QCOMPARE(declaration->abstractType()->toString(), expectedType); | ||||
523 | }; | ||||
524 | | ||||
525 | executeCompletionTest(code, expectedItems, NoMacroOrBuiltin, executeItem, fileExtension); | ||||
526 | } | ||||
527 | | ||||
528 | void TestCodeCompletion::testClangCodeCompletionType_data() | ||||
529 | { | ||||
530 | QTest::addColumn<QString>("fileExtension"); | ||||
531 | QTest::addColumn<QString>("code"); | ||||
532 | QTest::addColumn<CompletionItems>("expectedItems"); | ||||
533 | QTest::addColumn<QString>("expedtedItem"); | ||||
534 | QTest::addColumn<QString>("expectedType"); | ||||
535 | | ||||
536 | QTest::newRow("bug409041") | ||||
537 | << "c" | ||||
538 | << "typedef struct { int bitmask[1]; } bitmask_a;\n" | ||||
539 | "typedef struct { int bitmask[6]; } bitmask_c;\n" | ||||
540 | "typedef union { bitmask_c bitmask; } bitmask_union;\n" | ||||
541 | "int main() { bitmask_union u;\n" | ||||
542 | "u. \n " | ||||
543 | << CompletionItems{{4, 2}, { "bitmask" }} | ||||
544 | << "bitmask" | ||||
545 | << "bitmask_c"; | ||||
546 | } | ||||
547 | | ||||
507 | void TestCodeCompletion::testReplaceMemberAccess() | 548 | void TestCodeCompletion::testReplaceMemberAccess() | ||
508 | { | 549 | { | ||
509 | QFETCH(QString, code); | 550 | QFETCH(QString, code); | ||
Context not available. |