MCPcopy Create free account
hub / github.com/KDE/kdevelop / testNamespace

Method testNamespace

plugins/clang/tests/test_duchain.cpp:536–575  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

534}
535
536void 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
577void TestDUChain::testAutoTypeDeduction()
578{

Callers

nothing calls this directly

Calls 15

parseAndWaitMethod · 0.80
localDeclarationsMethod · 0.80
childContextsMethod · 0.80
localScopeIdentifierMethod · 0.80
scopeIdentifierMethod · 0.80
findDeclarationsMethod · 0.80
QStringClass · 0.50
QualifiedIdentifierClass · 0.50
topContextMethod · 0.45
sizeMethod · 0.45
firstMethod · 0.45
internalContextMethod · 0.45

Tested by

no test coverage detected