| 64 | } |
| 65 | |
| 66 | void TestDeclarations::testFunction() |
| 67 | { |
| 68 | const IndexedString file(QUrl(QStringLiteral("file:///internal/functionArgs.js"))); |
| 69 | // 0 1 2 3 |
| 70 | // 01234567890123456789012345678901234567890 |
| 71 | ParseSession session(file, "/**\n * some comment\n */\n" |
| 72 | "function foo(arg1, arg2, arg3) { var i = 0; }", 0); |
| 73 | QVERIFY(session.ast()); |
| 74 | QVERIFY(session.problems().isEmpty()); |
| 75 | QCOMPARE(session.language().dialect(), QmlJS::Dialect::JavaScript); |
| 76 | |
| 77 | DeclarationBuilder builder(&session); |
| 78 | ReferencedTopDUContext top = builder.build(file, session.ast()); |
| 79 | QVERIFY(top); |
| 80 | |
| 81 | DUChainReadLocker lock; |
| 82 | |
| 83 | QCOMPARE(top->localDeclarations().size(), 3); // module, exports and foo |
| 84 | |
| 85 | FunctionDeclaration* fooDec = dynamic_cast<FunctionDeclaration*>(top->localDeclarations().at(2)); |
| 86 | QVERIFY(fooDec); |
| 87 | QCOMPARE(fooDec->range(), RangeInRevision(3, 9, 3, 12)); |
| 88 | QCOMPARE(QString::fromUtf8(fooDec->comment()), QString("some comment")); |
| 89 | |
| 90 | QVERIFY(fooDec->internalContext()); |
| 91 | DUContext* argCtx = fooDec->internalContext(); |
| 92 | QCOMPARE(argCtx->localDeclarations().size(), 3); |
| 93 | |
| 94 | Declaration* arg1 = argCtx->localDeclarations().at(0); |
| 95 | QCOMPARE(arg1->identifier().toString(), QString("arg1")); |
| 96 | QCOMPARE(arg1->range(), RangeInRevision(3, 13, 3, 17)); |
| 97 | |
| 98 | Declaration* arg2 = argCtx->localDeclarations().at(1); |
| 99 | QCOMPARE(arg2->identifier().toString(), QString("arg2")); |
| 100 | QCOMPARE(arg2->range(), RangeInRevision(3, 19, 3, 23)); |
| 101 | |
| 102 | Declaration* arg3 = argCtx->localDeclarations().at(2); |
| 103 | QCOMPARE(arg3->identifier().toString(), QString("arg3")); |
| 104 | QCOMPARE(arg3->range(), RangeInRevision(3, 25, 3, 29)); |
| 105 | |
| 106 | FunctionType::Ptr funType = fooDec->type<FunctionType>(); |
| 107 | QVERIFY(funType); |
| 108 | QVERIFY(funType->returnType().dynamicCast<IntegralType>()); |
| 109 | QCOMPARE(funType->returnType().dynamicCast<IntegralType>()->dataType(), (uint)IntegralType::TypeVoid); |
| 110 | |
| 111 | QCOMPARE(argCtx->childContexts().size(), 2); |
| 112 | DUContext* bodyCtx = argCtx->childContexts().at(1); |
| 113 | QVERIFY(bodyCtx); |
| 114 | QVERIFY(bodyCtx->findDeclarations(arg1->identifier()).contains(arg1)); |
| 115 | QVERIFY(bodyCtx->findDeclarations(arg2->identifier()).contains(arg2)); |
| 116 | QVERIFY(bodyCtx->findDeclarations(arg3->identifier()).contains(arg3)); |
| 117 | |
| 118 | QCOMPARE(bodyCtx->localDeclarations().count(), 1); |
| 119 | } |
| 120 | |
| 121 | void TestDeclarations::testQMLId() |
| 122 | { |
nothing calls this directly
no test coverage detected