| 37 | } |
| 38 | |
| 39 | void 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 | |
| 73 | void TestContexts::testFunctionContext_data() |
| 74 | { |