Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show First 20 Lines • Show All 661 Lines • ▼ Show 20 Line(s) | 640 | { | |||
---|---|---|---|---|---|
662 | QVERIFY(fType); | 662 | QVERIFY(fType); | ||
663 | QVERIFY(StructureType::Ptr::dynamicCast(fType->returnType())); | 663 | QVERIFY(StructureType::Ptr::dynamicCast(fType->returnType())); | ||
664 | QCOMPARE(StructureType::Ptr::dynamicCast(fType->returnType())->qualifiedIdentifier(), QualifiedIdentifier("a")); | 664 | QCOMPARE(StructureType::Ptr::dynamicCast(fType->returnType())->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||
665 | 665 | | |||
666 | //function bar | 666 | //function bar | ||
667 | dec = top->localDeclarations().at(3); | 667 | dec = top->localDeclarations().at(3); | ||
668 | fType = dec->type<FunctionType>(); | 668 | fType = dec->type<FunctionType>(); | ||
669 | QVERIFY(fType); | 669 | QVERIFY(fType); | ||
670 | QVERIFY(StructureType::Ptr::dynamicCast(fType->returnType())); | 670 | QVERIFY(IntegralTypeExtended::Ptr::dynamicCast(fType->returnType())); | ||
671 | QCOMPARE(StructureType::Ptr::dynamicCast(fType->returnType())->qualifiedIdentifier(), QualifiedIdentifier("stdclass")); | 671 | QVERIFY(IntegralTypeExtended::Ptr::dynamicCast(fType->returnType())->dataType() == IntegralTypeExtended::TypeObject); | ||
672 | 672 | | |||
673 | //test hint in internal functions file of a type that is added later on | 673 | //test hint in internal functions file of a type that is added later on | ||
674 | // function | 674 | // function | ||
675 | QList<Declaration*> decs = top->findDeclarations(Identifier(QStringLiteral("should_return_exception"))); | 675 | QList<Declaration*> decs = top->findDeclarations(Identifier(QStringLiteral("should_return_exception"))); | ||
676 | QCOMPARE(decs.size(), 1); | 676 | QCOMPARE(decs.size(), 1); | ||
677 | dec = decs.first(); | 677 | dec = decs.first(); | ||
678 | fType = dec->type<FunctionType>(); | 678 | fType = dec->type<FunctionType>(); | ||
679 | QVERIFY(fType); | 679 | QVERIFY(fType); | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 765 | { | |||
776 | 776 | | |||
777 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | 777 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||
778 | QVERIFY(fun); | 778 | QVERIFY(fun); | ||
779 | IntegralType::Ptr returnType = IntegralType::Ptr::dynamicCast(fun->returnType()); | 779 | IntegralType::Ptr returnType = IntegralType::Ptr::dynamicCast(fun->returnType()); | ||
780 | QVERIFY(returnType); | 780 | QVERIFY(returnType); | ||
781 | QVERIFY(returnType->dataType() == IntegralType::TypeVoid); | 781 | QVERIFY(returnType->dataType() == IntegralType::TypeVoid); | ||
782 | } | 782 | } | ||
783 | 783 | | |||
784 | void TestDUChain::declarationReturnTypeTypehintObject() | ||||
785 | { | ||||
786 | //Typehint preferred over phpdoc preferred over inferred type | ||||
787 | QByteArray method("<? /** @return string **/ function foo(): object { return new stdClass(); }"); | ||||
788 | | ||||
789 | TopDUContext* top = parse(method, DumpNone); | ||||
790 | DUChainReleaser releaseTop(top); | ||||
791 | DUChainWriteLocker lock(DUChain::lock()); | ||||
792 | | ||||
793 | QVERIFY(!top->parentContext()); | ||||
794 | QCOMPARE(top->childContexts().count(), 2); | ||||
795 | QCOMPARE(top->localDeclarations().count(), 1); | ||||
796 | | ||||
797 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
798 | QVERIFY(fun); | ||||
799 | IntegralTypeExtended::Ptr returnType = IntegralTypeExtended::Ptr::dynamicCast(fun->returnType()); | ||||
800 | QVERIFY(returnType); | ||||
801 | QVERIFY(returnType->dataType() == IntegralTypeExtended::TypeObject); | ||||
802 | } | ||||
803 | | ||||
784 | void TestDUChain::declareTypehintFunction() | 804 | void TestDUChain::declareTypehintFunction() | ||
785 | { | 805 | { | ||
786 | // 0 1 2 3 4 5 6 7 | 806 | // 0 1 2 3 4 5 6 7 | ||
787 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 807 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
788 | QByteArray method("<? class A {} function foo(A $i) { return $i; } "); | 808 | QByteArray method("<? class A {} function foo(A $i) { return $i; } "); | ||
789 | 809 | | |||
790 | TopDUContext* top = parse(method, DumpAll); | 810 | TopDUContext* top = parse(method, DumpAll); | ||
791 | DUChainReleaser releaseTop(top); | 811 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 80 Lines • ▼ Show 20 Line(s) | 875 | { | |||
872 | QCOMPARE(arg.cast<IndexedContainer>()->typesCount(), 1); | 892 | QCOMPARE(arg.cast<IndexedContainer>()->typesCount(), 1); | ||
873 | QCOMPARE(arg.cast<IndexedContainer>()->prettyName().str(), QStringLiteral("array")); | 893 | QCOMPARE(arg.cast<IndexedContainer>()->prettyName().str(), QStringLiteral("array")); | ||
874 | 894 | | |||
875 | AbstractType::Ptr typehint = arg.cast<IndexedContainer>()->typeAt(0).abstractType(); | 895 | AbstractType::Ptr typehint = arg.cast<IndexedContainer>()->typeAt(0).abstractType(); | ||
876 | QVERIFY(typehint); | 896 | QVERIFY(typehint); | ||
877 | QCOMPARE(typehint->toString(), QStringLiteral("A")); | 897 | QCOMPARE(typehint->toString(), QStringLiteral("A")); | ||
878 | } | 898 | } | ||
879 | 899 | | |||
900 | void TestDUChain::declareTypehintObjectFunction() | ||||
901 | { | ||||
902 | // 0 1 2 3 4 5 6 7 | ||||
903 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||||
904 | QByteArray method("<? function foo(object $i) { } "); | ||||
905 | | ||||
906 | TopDUContext* top = parse(method, DumpAll); | ||||
907 | DUChainReleaser releaseTop(top); | ||||
908 | | ||||
909 | DUChainWriteLocker lock(DUChain::lock()); | ||||
910 | | ||||
911 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
912 | QVERIFY(fun); | ||||
913 | QCOMPARE(fun->arguments().count(), 1); | ||||
914 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
915 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralTypeExtended::TypeObject); | ||||
916 | | ||||
917 | IntegralTypeExtended::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralTypeExtended>(); | ||||
918 | QVERIFY(type); | ||||
919 | QVERIFY(type->dataType() == IntegralTypeExtended::TypeObject); | ||||
920 | } | ||||
921 | | ||||
880 | void TestDUChain::declareTypehintArrayFunction() | 922 | void TestDUChain::declareTypehintArrayFunction() | ||
881 | { | 923 | { | ||
882 | // 0 1 2 3 4 5 6 7 | 924 | // 0 1 2 3 4 5 6 7 | ||
883 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 925 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
884 | QByteArray method("<? function foo(array $i) { } "); | 926 | QByteArray method("<? function foo(array $i) { } "); | ||
885 | 927 | | |||
886 | TopDUContext* top = parse(method, DumpAll); | 928 | TopDUContext* top = parse(method, DumpAll); | ||
887 | DUChainReleaser releaseTop(top); | 929 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 2847 Lines • Show Last 20 Lines |