Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show First 20 Lines • Show All 700 Lines • ▼ Show 20 Line(s) | 688 | { | |||
---|---|---|---|---|---|
701 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | 701 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||
702 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | 702 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | ||
703 | 703 | | |||
704 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | 704 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||
705 | QVERIFY(type); | 705 | QVERIFY(type); | ||
706 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | 706 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||
707 | } | 707 | } | ||
708 | 708 | | |||
709 | void TestDUChain::declareTypehintIterableFunction() | ||||
710 | { | ||||
711 | //Note: in practice, Traversable is defined by php, but this interface is not loaded in this test, so define it ourselves | ||||
712 | // 0 1 2 3 | ||||
713 | // 0123456789012345678901234567890123 | ||||
714 | QByteArray method("<? interface Traversable { } function foo(iterable $i) { } "); | ||||
715 | | ||||
716 | TopDUContext* top = parse(method, DumpAll); | ||||
717 | DUChainReleaser releaseTop(top); | ||||
718 | | ||||
719 | DUChainWriteLocker lock(DUChain::lock()); | ||||
720 | | ||||
721 | QCOMPARE(top->localDeclarations().count(), 2); | ||||
722 | FunctionType::Ptr fun = top->localDeclarations().at(1)->type<FunctionType>(); | ||||
723 | QVERIFY(fun); | ||||
724 | QCOMPARE(fun->arguments().count(), 1); | ||||
725 | | ||||
726 | UnsureType::Ptr argType = UnsureType::Ptr::dynamicCast(fun->arguments().first()); | ||||
727 | QVERIFY(argType); | ||||
728 | QCOMPARE(argType->typesSize(), 2u); | ||||
729 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()); | ||||
730 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
731 | QVERIFY(argType->types()[1].abstractType().cast<StructureType>()); | ||||
732 | QCOMPARE(argType->types()[1].abstractType().cast<StructureType>()->qualifiedIdentifier(), QualifiedIdentifier("traversable")); | ||||
733 | } | ||||
734 | | ||||
709 | void TestDUChain::declareTypehintBoolFunction() | 735 | void TestDUChain::declareTypehintBoolFunction() | ||
710 | { | 736 | { | ||
711 | // 0 1 2 3 | 737 | // 0 1 2 3 | ||
712 | // 0123456789012345678901234567890123 | 738 | // 0123456789012345678901234567890123 | ||
713 | QByteArray method("<? function foo(bool $i) { } "); | 739 | QByteArray method("<? function foo(bool $i) { } "); | ||
714 | 740 | | |||
715 | TopDUContext* top = parse(method, DumpAll); | 741 | TopDUContext* top = parse(method, DumpAll); | ||
716 | DUChainReleaser releaseTop(top); | 742 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 148 Lines • ▼ Show 20 Line(s) | 878 | { | |||
865 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | 891 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||
866 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | 892 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | ||
867 | 893 | | |||
868 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | 894 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||
869 | QVERIFY(type); | 895 | QVERIFY(type); | ||
870 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | 896 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||
871 | } | 897 | } | ||
872 | 898 | | |||
899 | void TestDUChain::declareTypehintNullableIterableFunction() | ||||
900 | { | ||||
901 | //Note: in practice, Traversable is defined by php, but this interface is not loaded in this test, so define it ourselves | ||||
902 | // 0 1 2 3 | ||||
903 | // 0123456789012345678901234567890123 | ||||
904 | QByteArray method("<? interface Traversable { } function foo(?iterable $i) { } "); | ||||
905 | | ||||
906 | TopDUContext* top = parse(method, DumpAll); | ||||
907 | DUChainReleaser releaseTop(top); | ||||
908 | | ||||
909 | DUChainWriteLocker lock(DUChain::lock()); | ||||
910 | | ||||
911 | QCOMPARE(top->localDeclarations().count(), 2); | ||||
912 | FunctionType::Ptr fun = top->localDeclarations().at(1)->type<FunctionType>(); | ||||
913 | QVERIFY(fun); | ||||
914 | QCOMPARE(fun->arguments().count(), 1); | ||||
915 | | ||||
916 | UnsureType::Ptr argType = UnsureType::Ptr::dynamicCast(fun->arguments().first()); | ||||
917 | QVERIFY(argType); | ||||
918 | QCOMPARE(argType->typesSize(), 3u); | ||||
919 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()); | ||||
920 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
921 | QVERIFY(argType->types()[1].abstractType().cast<StructureType>()); | ||||
922 | QCOMPARE(argType->types()[1].abstractType().cast<StructureType>()->qualifiedIdentifier(), QualifiedIdentifier("traversable")); | ||||
923 | QVERIFY(argType->types()[2].abstractType().cast<IntegralType>()); | ||||
924 | QVERIFY(argType->types()[2].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeNull); | ||||
925 | } | ||||
926 | | ||||
873 | void TestDUChain::classImplementsInterface() | 927 | void TestDUChain::classImplementsInterface() | ||
874 | { | 928 | { | ||
875 | // 0 1 2 3 4 5 6 7 | 929 | // 0 1 2 3 4 5 6 7 | ||
876 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 930 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
877 | QByteArray method("<? interface I { } class A implements I { }"); | 931 | QByteArray method("<? interface I { } class A implements I { }"); | ||
878 | 932 | | |||
879 | TopDUContext* top = parse(method, DumpAll); | 933 | TopDUContext* top = parse(method, DumpAll); | ||
880 | DUChainReleaser releaseTop(top); | 934 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 2385 Lines • Show Last 20 Lines |