| 218 | } |
| 219 | |
| 220 | void TestDUChain::testMacroDefinition() |
| 221 | { |
| 222 | QFETCH(QString, code); |
| 223 | QFETCH(QString, definition); |
| 224 | QFETCH(bool, isFunctionLike); |
| 225 | QFETCH(QVector<QString>, parameters); |
| 226 | |
| 227 | TestFile file(code, QStringLiteral("cpp")); |
| 228 | QVERIFY(file.parseAndWait()); |
| 229 | |
| 230 | DUChainReadLocker lock; |
| 231 | auto top = file.topContext(); |
| 232 | QVERIFY(top); |
| 233 | QCOMPARE(top->localDeclarations().size(), 1); |
| 234 | |
| 235 | const auto decl = top->localDeclarations().constFirst(); |
| 236 | QVERIFY(decl); |
| 237 | |
| 238 | const auto macro = dynamic_cast<const MacroDefinition*>(decl); |
| 239 | QVERIFY(macro); |
| 240 | |
| 241 | QCOMPARE(macro->definition().str(), definition); |
| 242 | |
| 243 | QCOMPARE(macro->isFunctionLike(), isFunctionLike); |
| 244 | |
| 245 | // The displayed tooltip for these incorrectly parsed macros looks good, but the bogus |
| 246 | // single macro parameter in the MacroDefinition object could cause issues in the future. |
| 247 | QEXPECT_FAIL("only_escaped_newline_in_parens(\\\n)", "difficult to parse, uncommon, not yet a problem", Continue); |
| 248 | QEXPECT_FAIL("only_comment_in_parens(/*comment*/)", "difficult to parse, uncommon, not yet a problem", Continue); |
| 249 | QCOMPARE(macro->parametersSize(), parameters.size()); |
| 250 | |
| 251 | const IndexedString* actualParam = macro->parameters(); |
| 252 | for (const auto& expectedParam : parameters) { |
| 253 | QCOMPARE(actualParam->str(), expectedParam); |
| 254 | ++actualParam; |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | void TestDUChain::testMacroDefinition_data() |
| 259 | { |
nothing calls this directly
no test coverage detected