Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Context not available. | |||||
566 | QVERIFY(/* func b (self) */ ctx->localDeclarations().at(1)->type<FunctionType>().data() == ctx->owner()->abstractType().data()); | 566 | QVERIFY(/* func b (self) */ ctx->localDeclarations().at(1)->type<FunctionType>().data() == ctx->owner()->abstractType().data()); | ||
---|---|---|---|---|---|
567 | } | 567 | } | ||
568 | 568 | | |||
569 | void TestDUChain::declarationReturnTypeTypehint() | ||||
570 | { | ||||
571 | //Typehint preferred over phpdoc preferred over inferred type | ||||
572 | QByteArray method("<? /** @return string **/ function foo(): bool { return 5; }"); | ||||
573 | | ||||
574 | TopDUContext* top = parse(method, DumpNone); | ||||
575 | DUChainReleaser releaseTop(top); | ||||
576 | DUChainWriteLocker lock(DUChain::lock()); | ||||
577 | | ||||
578 | QVERIFY(!top->parentContext()); | ||||
579 | QCOMPARE(top->childContexts().count(), 2); | ||||
580 | QCOMPARE(top->localDeclarations().count(), 1); | ||||
581 | | ||||
582 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
583 | QVERIFY(fun); | ||||
584 | IntegralType::Ptr returnType = IntegralType::Ptr::dynamicCast(fun->returnType()); | ||||
585 | QVERIFY(returnType); | ||||
586 | QVERIFY(returnType->dataType() == IntegralType::TypeBoolean); | ||||
587 | } | ||||
588 | | ||||
589 | void TestDUChain::declarationReturnTypeTypehintVoid() | ||||
590 | { | ||||
591 | //Typehint preferred over phpdoc preferred over inferred type | ||||
592 | QByteArray method("<? /** @return string **/ function foo(): void { return 5; }"); | ||||
593 | | ||||
594 | TopDUContext* top = parse(method, DumpNone); | ||||
595 | DUChainReleaser releaseTop(top); | ||||
596 | DUChainWriteLocker lock(DUChain::lock()); | ||||
597 | | ||||
598 | QVERIFY(!top->parentContext()); | ||||
599 | QCOMPARE(top->childContexts().count(), 2); | ||||
600 | QCOMPARE(top->localDeclarations().count(), 1); | ||||
601 | | ||||
602 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
603 | QVERIFY(fun); | ||||
604 | IntegralType::Ptr returnType = IntegralType::Ptr::dynamicCast(fun->returnType()); | ||||
605 | QVERIFY(returnType); | ||||
606 | QVERIFY(returnType->dataType() == IntegralType::TypeVoid); | ||||
607 | } | ||||
608 | | ||||
569 | void TestDUChain::declareTypehintFunction() | 609 | void TestDUChain::declareTypehintFunction() | ||
570 | { | 610 | { | ||
571 | // 0 1 2 3 4 5 6 7 | 611 | // 0 1 2 3 4 5 6 7 | ||
Context not available. |