| 534 | } |
| 535 | |
| 536 | void TestDUChain::testNamespace() |
| 537 | { |
| 538 | TestFile file("namespace foo { struct bar { int baz; }; }\n" |
| 539 | "int main() { foo::bar myBar; }\n", QStringLiteral("cpp")); |
| 540 | QVERIFY(file.parseAndWait()); |
| 541 | |
| 542 | DUChainReadLocker lock; |
| 543 | QVERIFY(file.topContext()); |
| 544 | QCOMPARE(file.topContext()->localDeclarations().size(), 2); |
| 545 | auto fooDecl = file.topContext()->localDeclarations().first(); |
| 546 | QVERIFY(fooDecl->internalContext()); |
| 547 | QCOMPARE(fooDecl->internalContext()->localDeclarations().size(), 1); |
| 548 | |
| 549 | DUContext* top = file.topContext().data(); |
| 550 | DUContext* mainCtx = file.topContext()->childContexts().last(); |
| 551 | |
| 552 | auto foo = top->localDeclarations().first(); |
| 553 | QCOMPARE(foo->qualifiedIdentifier().toString(), QString("foo")); |
| 554 | |
| 555 | DUContext* fooCtx = file.topContext()->childContexts().first(); |
| 556 | QCOMPARE(fooCtx->localScopeIdentifier().toString(), QString("foo")); |
| 557 | QCOMPARE(fooCtx->scopeIdentifier(true).toString(), QString("foo")); |
| 558 | QCOMPARE(fooCtx->localDeclarations().size(), 1); |
| 559 | auto bar = fooCtx->localDeclarations().first(); |
| 560 | QCOMPARE(bar->qualifiedIdentifier().toString(), QString("foo::bar")); |
| 561 | QCOMPARE(fooCtx->childContexts().size(), 1); |
| 562 | |
| 563 | DUContext* barCtx = fooCtx->childContexts().first(); |
| 564 | QCOMPARE(barCtx->localScopeIdentifier().toString(), QString("bar")); |
| 565 | QCOMPARE(barCtx->scopeIdentifier(true).toString(), QString("foo::bar")); |
| 566 | QCOMPARE(barCtx->localDeclarations().size(), 1); |
| 567 | auto baz = barCtx->localDeclarations().first(); |
| 568 | QCOMPARE(baz->qualifiedIdentifier().toString(), QString("foo::bar::baz")); |
| 569 | |
| 570 | for (auto ctx : {top, mainCtx}) { |
| 571 | QCOMPARE(ctx->findDeclarations(QualifiedIdentifier(u"foo")).size(), 1); |
| 572 | QCOMPARE(ctx->findDeclarations(QualifiedIdentifier(u"foo::bar")).size(), 1); |
| 573 | QCOMPARE(ctx->findDeclarations(QualifiedIdentifier(u"foo::bar::baz")).size(), 1); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | void TestDUChain::testAutoTypeDeduction() |
| 578 | { |
nothing calls this directly
no test coverage detected