| 209 | } |
| 210 | |
| 211 | void executeCompletionPriorityTest(const QString& code, const CompletionPriorityItems& expectedCompletionItems, |
| 212 | const ClangCodeCompletionContext::ContextFilters& filters = NoMacroOrBuiltin) |
| 213 | { |
| 214 | TestFile file(code, QStringLiteral("cpp")); |
| 215 | QVERIFY(file.parseAndWait(TopDUContext::AllDeclarationsContextsUsesAndAST)); |
| 216 | DUChainReadLocker lock; |
| 217 | auto top = file.topContext(); |
| 218 | QVERIFY(top); |
| 219 | const ParseSessionData::Ptr sessionData(dynamic_cast<ParseSessionData*>(top->ast().data())); |
| 220 | QVERIFY(sessionData); |
| 221 | |
| 222 | // don't hold DUChain lock when constructing ClangCodeCompletionContext |
| 223 | lock.unlock(); |
| 224 | |
| 225 | auto context = createContext(top, sessionData, expectedCompletionItems.position); |
| 226 | context->setFilters(filters); |
| 227 | |
| 228 | lock.lock(); |
| 229 | auto tester = ClangCodeCompletionItemTester(context); |
| 230 | |
| 231 | for(const auto& declaration : expectedCompletionItems.completions){ |
| 232 | qDebug() << "verifying declaration:" << declaration.name; |
| 233 | |
| 234 | const auto declarationItem = tester.findItem(declaration.name); |
| 235 | if (!declarationItem || !declarationItem->declaration()) { |
| 236 | qDebug() << "names of all completion-items:" << tester.names; |
| 237 | } |
| 238 | QVERIFY(declarationItem); |
| 239 | QVERIFY(declarationItem->declaration()); |
| 240 | |
| 241 | auto matchQuality = tester.itemData(declarationItem, KTextEditor::CodeCompletionModel::Name, KTextEditor::CodeCompletionModel::MatchQuality).toInt(); |
| 242 | auto inheritanceDepth = declarationItem->inheritanceDepth(); |
| 243 | |
| 244 | if (!declaration.failMessage.isEmpty()) { |
| 245 | QEXPECT_FAIL("", declaration.failMessage.toUtf8().constData(), Continue); |
| 246 | } |
| 247 | QVERIFY2(matchQuality == declaration.matchQuality && inheritanceDepth == declaration.inheritanceDepth, |
| 248 | qPrintable(QStringLiteral("%1 == %2 && %3 == %4") |
| 249 | .arg(matchQuality) |
| 250 | .arg(declaration.matchQuality) |
| 251 | .arg(inheritanceDepth) |
| 252 | .arg(declaration.inheritanceDepth))); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void executeMemberAccessReplacerTest(const QString& code, const CompletionItems& expectedCompletionItems, |
| 257 | const ClangCodeCompletionContext::ContextFilters& filters = NoMacroOrBuiltin) |
no test coverage detected