Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show First 20 Lines • Show All 617 Lines • ▼ Show 20 Line(s) | 613 | { | |||
---|---|---|---|---|---|
618 | TopDUContext* top = parse(method, DumpAll); | 618 | TopDUContext* top = parse(method, DumpAll); | ||
619 | DUChainReleaser releaseTop(top); | 619 | DUChainReleaser releaseTop(top); | ||
620 | 620 | | |||
621 | DUChainWriteLocker lock(DUChain::lock()); | 621 | DUChainWriteLocker lock(DUChain::lock()); | ||
622 | 622 | | |||
623 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | 623 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||
624 | QVERIFY(fun); | 624 | QVERIFY(fun); | ||
625 | QCOMPARE(fun->arguments().count(), 1); | 625 | QCOMPARE(fun->arguments().count(), 1); | ||
626 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | | |||
627 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeArray); | | |||
628 | 626 | | |||
629 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | 627 | AbstractType::Ptr arg = fun->arguments().first(); | ||
630 | QVERIFY(type); | 628 | QVERIFY(arg); | ||
631 | QVERIFY(type->dataType() == IntegralType::TypeArray); | 629 | QVERIFY(arg.cast<IndexedContainer>()); | ||
630 | QCOMPARE(arg.cast<IndexedContainer>()->typesCount(), 1); | ||||
631 | QCOMPARE(arg.cast<IndexedContainer>()->prettyName().str(), QStringLiteral("array")); | ||||
632 | | ||||
633 | AbstractType::Ptr typehint = arg.cast<IndexedContainer>()->typeAt(0).abstractType(); | ||||
634 | QVERIFY(typehint); | ||||
635 | QVERIFY(IntegralType::Ptr::dynamicCast(typehint)); | ||||
636 | QVERIFY(IntegralType::Ptr::dynamicCast(typehint)->dataType() == IntegralType::TypeMixed); | ||||
632 | } | 637 | } | ||
633 | 638 | | |||
634 | void TestDUChain::declareTypehintVariadicFunction() | 639 | void TestDUChain::declareTypehintVariadicFunction() | ||
635 | { | 640 | { | ||
636 | // 0 1 2 3 4 5 6 7 | 641 | // 0 1 2 3 4 5 6 7 | ||
637 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 642 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
638 | QByteArray method("<? class A {} function foo(A ...$i) { } "); | 643 | QByteArray method("<? class A {} function foo(A ...$i) { } "); | ||
639 | 644 | | |||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | 688 | { | |||
696 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | 701 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||
697 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | 702 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | ||
698 | 703 | | |||
699 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | 704 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||
700 | QVERIFY(type); | 705 | QVERIFY(type); | ||
701 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | 706 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||
702 | } | 707 | } | ||
703 | 708 | | |||
709 | void TestDUChain::declareTypehintBoolFunction() | ||||
710 | { | ||||
711 | // 0 1 2 3 | ||||
712 | // 0123456789012345678901234567890123 | ||||
713 | QByteArray method("<? function foo(bool $i) { } "); | ||||
714 | | ||||
715 | TopDUContext* top = parse(method, DumpAll); | ||||
716 | DUChainReleaser releaseTop(top); | ||||
717 | | ||||
718 | DUChainWriteLocker lock(DUChain::lock()); | ||||
719 | | ||||
720 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
721 | QVERIFY(fun); | ||||
722 | QCOMPARE(fun->arguments().count(), 1); | ||||
723 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
724 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeBoolean); | ||||
725 | | ||||
726 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
727 | QVERIFY(type); | ||||
728 | QVERIFY(type->dataType() == IntegralType::TypeBoolean); | ||||
729 | } | ||||
730 | | ||||
731 | void TestDUChain::declareTypehintFloatFunction() | ||||
732 | { | ||||
733 | // 0 1 2 3 | ||||
734 | // 0123456789012345678901234567890123 | ||||
735 | QByteArray method("<? function foo(float $i) { } "); | ||||
736 | | ||||
737 | TopDUContext* top = parse(method, DumpAll); | ||||
738 | DUChainReleaser releaseTop(top); | ||||
739 | | ||||
740 | DUChainWriteLocker lock(DUChain::lock()); | ||||
741 | | ||||
742 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
743 | QVERIFY(fun); | ||||
744 | QCOMPARE(fun->arguments().count(), 1); | ||||
745 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
746 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeFloat); | ||||
747 | | ||||
748 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
749 | QVERIFY(type); | ||||
750 | QVERIFY(type->dataType() == IntegralType::TypeFloat); | ||||
751 | } | ||||
752 | | ||||
753 | void TestDUChain::declareTypehintIntFunction() | ||||
754 | { | ||||
755 | // 0 1 2 3 | ||||
756 | // 0123456789012345678901234567890123 | ||||
757 | QByteArray method("<? function foo(int $i) { } "); | ||||
758 | | ||||
759 | TopDUContext* top = parse(method, DumpAll); | ||||
760 | DUChainReleaser releaseTop(top); | ||||
761 | | ||||
762 | DUChainWriteLocker lock(DUChain::lock()); | ||||
763 | | ||||
764 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
765 | QVERIFY(fun); | ||||
766 | QCOMPARE(fun->arguments().count(), 1); | ||||
767 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
768 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeInt); | ||||
769 | | ||||
770 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
771 | QVERIFY(type); | ||||
772 | QVERIFY(type->dataType() == IntegralType::TypeInt); | ||||
773 | } | ||||
774 | | ||||
775 | void TestDUChain::declareTypehintStringFunction() | ||||
776 | { | ||||
777 | // 0 1 2 3 | ||||
778 | // 0123456789012345678901234567890123 | ||||
779 | QByteArray method("<? function foo(string $i) { } "); | ||||
780 | | ||||
781 | TopDUContext* top = parse(method, DumpAll); | ||||
782 | DUChainReleaser releaseTop(top); | ||||
783 | | ||||
784 | DUChainWriteLocker lock(DUChain::lock()); | ||||
785 | | ||||
786 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
787 | QVERIFY(fun); | ||||
788 | QCOMPARE(fun->arguments().count(), 1); | ||||
789 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
790 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeString); | ||||
791 | | ||||
792 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
793 | QVERIFY(type); | ||||
794 | QVERIFY(type->dataType() == IntegralType::TypeString); | ||||
795 | } | ||||
796 | | ||||
797 | void TestDUChain::declareNullableTypehintArrayFunction() | ||||
798 | { | ||||
799 | // 0 1 2 3 | ||||
800 | // 0123456789012345678901234567890123 | ||||
801 | QByteArray method("<? function foo(?array $i) { } "); | ||||
802 | | ||||
803 | TopDUContext* top = parse(method, DumpAll); | ||||
804 | DUChainReleaser releaseTop(top); | ||||
805 | | ||||
806 | DUChainWriteLocker lock(DUChain::lock()); | ||||
807 | | ||||
808 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
809 | QVERIFY(fun); | ||||
810 | QCOMPARE(fun->arguments().count(), 1); | ||||
811 | | ||||
812 | UnsureType::Ptr argType = UnsureType::Ptr::dynamicCast(fun->arguments().first()); | ||||
813 | QVERIFY(argType); | ||||
814 | QCOMPARE(argType->typesSize(), 2u); | ||||
815 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()); | ||||
816 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
817 | QVERIFY(argType->types()[1].abstractType().cast<IntegralType>()); | ||||
818 | QVERIFY(argType->types()[1].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeNull); | ||||
819 | | ||||
820 | UnsureType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<UnsureType>(); | ||||
821 | QVERIFY(type); | ||||
822 | QCOMPARE(type->typesSize(), 2u); | ||||
823 | QVERIFY(type->types()[0].abstractType().cast<IntegralType>()); | ||||
824 | QVERIFY(type->types()[0].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
825 | QVERIFY(type->types()[1].abstractType().cast<IntegralType>()); | ||||
826 | QVERIFY(type->types()[1].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeNull); | ||||
827 | } | ||||
828 | | ||||
829 | void TestDUChain::declareTypehintWithPhpdocFunction() | ||||
830 | { | ||||
831 | // 0 1 2 3 | ||||
832 | // 0123456789012345678901234567890123 | ||||
833 | QByteArray method("<? /**\n * @param string $i\n */ function foo(int $i) { } "); | ||||
834 | | ||||
835 | TopDUContext* top = parse(method, DumpAll); | ||||
836 | DUChainReleaser releaseTop(top); | ||||
837 | | ||||
838 | DUChainWriteLocker lock(DUChain::lock()); | ||||
839 | | ||||
840 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
841 | QVERIFY(fun); | ||||
842 | QCOMPARE(fun->arguments().count(), 1); | ||||
843 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
844 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeInt); | ||||
845 | | ||||
846 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
847 | QVERIFY(type); | ||||
848 | QVERIFY(type->dataType() == IntegralType::TypeInt); | ||||
849 | } | ||||
850 | | ||||
851 | void TestDUChain::declareNullableTypehintCallableFunction() | ||||
852 | { | ||||
853 | // 0 1 2 3 | ||||
854 | // 0123456789012345678901234567890123 | ||||
855 | QByteArray method("<? function foo(?callable $i) { } "); | ||||
856 | | ||||
857 | TopDUContext* top = parse(method, DumpAll); | ||||
858 | DUChainReleaser releaseTop(top); | ||||
859 | | ||||
860 | DUChainWriteLocker lock(DUChain::lock()); | ||||
861 | | ||||
862 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
863 | QVERIFY(fun); | ||||
864 | QCOMPARE(fun->arguments().count(), 1); | ||||
865 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
866 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | ||||
867 | | ||||
868 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
869 | QVERIFY(type); | ||||
870 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||||
871 | } | ||||
872 | | ||||
704 | void TestDUChain::classImplementsInterface() | 873 | void TestDUChain::classImplementsInterface() | ||
705 | { | 874 | { | ||
706 | // 0 1 2 3 4 5 6 7 | 875 | // 0 1 2 3 4 5 6 7 | ||
707 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 876 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
708 | QByteArray method("<? interface I { } class A implements I { }"); | 877 | QByteArray method("<? interface I { } class A implements I { }"); | ||
709 | 878 | | |||
710 | TopDUContext* top = parse(method, DumpAll); | 879 | TopDUContext* top = parse(method, DumpAll); | ||
711 | DUChainReleaser releaseTop(top); | 880 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 2385 Lines • Show Last 20 Lines |