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

Method testFunctionContext

plugins/qmljs/duchain/tests/test_qmljscontexts.cpp:39–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

37}
38
39void TestContexts::testFunctionContext()
40{
41 QFETCH(QString, code);
42 QFETCH(RangeInRevision, argCtxRange);
43 QFETCH(RangeInRevision, bodyCtxRange);
44
45 const auto random = QRandomGenerator::global()->generate();
46 const IndexedString file(QUrl(QStringLiteral("file:///internal/%1-functionContext.js").arg(random)));
47 ParseSession session(file, code, 0);
48 QVERIFY(session.ast());
49 QCOMPARE(session.language().dialect(), QmlJS::Dialect::JavaScript);
50
51 DeclarationBuilder builder(&session);
52 ReferencedTopDUContext top = builder.build(file, session.ast());
53 QVERIFY(top);
54
55 DUChainReadLocker lock;
56
57 QCOMPARE(top->type(), DUContext::Global);
58
59 // the function arguments (containing the prototype context and the function body)
60 QCOMPARE(top->childContexts().count(), 3); // module, exports, the function
61
62 DUContext* argCtx = top->childContexts().at(2);
63 QCOMPARE(argCtx->type(), DUContext::Function);
64 QCOMPARE(argCtx->range(), argCtxRange);
65 QCOMPARE(argCtx->childContexts().size(), 2); // The prototype context then the body context
66
67 DUContext* bodyCtx = argCtx->childContexts().at(1);
68 QVERIFY(bodyCtx);
69 QCOMPARE(bodyCtx->type(), DUContext::Other);
70 QCOMPARE(bodyCtx->range(), bodyCtxRange);
71}
72
73void TestContexts::testFunctionContext_data()
74{

Callers

nothing calls this directly

Calls 11

childContextsMethod · 0.80
QUrlClass · 0.50
generateMethod · 0.45
astMethod · 0.45
languageMethod · 0.45
buildMethod · 0.45
typeMethod · 0.45
countMethod · 0.45
atMethod · 0.45
rangeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected