Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Context not available. | |||||
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() | ||
Context not available. | |||||
701 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | 706 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||
702 | } | 707 | } | ||
703 | 708 | | |||
709 | void TestDUChain::declareTypehintIterableFunction() | ||||
710 | { | ||||
711 | // 0 1 2 3 | ||||
712 | // 0123456789012345678901234567890123 | ||||
713 | QByteArray method("<? function foo(iterable $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::TypeMixed); | ||||
725 | | ||||
726 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
727 | QVERIFY(type); | ||||
728 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||||
729 | } | ||||
730 | | ||||
731 | void TestDUChain::declareTypehintBoolFunction() | ||||
732 | { | ||||
733 | // 0 1 2 3 | ||||
734 | // 0123456789012345678901234567890123 | ||||
735 | QByteArray method("<? function foo(bool $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::TypeBoolean); | ||||
747 | | ||||
748 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
749 | QVERIFY(type); | ||||
750 | QVERIFY(type->dataType() == IntegralType::TypeBoolean); | ||||
751 | } | ||||
752 | | ||||
753 | void TestDUChain::declareTypehintFloatFunction() | ||||
754 | { | ||||
755 | // 0 1 2 3 | ||||
756 | // 0123456789012345678901234567890123 | ||||
757 | QByteArray method("<? function foo(float $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::TypeFloat); | ||||
769 | | ||||
770 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
771 | QVERIFY(type); | ||||
772 | QVERIFY(type->dataType() == IntegralType::TypeFloat); | ||||
773 | } | ||||
774 | | ||||
775 | void TestDUChain::declareTypehintIntFunction() | ||||
776 | { | ||||
777 | // 0 1 2 3 | ||||
778 | // 0123456789012345678901234567890123 | ||||
779 | QByteArray method("<? function foo(int $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::TypeInt); | ||||
791 | | ||||
792 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
793 | QVERIFY(type); | ||||
794 | QVERIFY(type->dataType() == IntegralType::TypeInt); | ||||
795 | } | ||||
796 | | ||||
797 | void TestDUChain::declareTypehintStringFunction() | ||||
798 | { | ||||
799 | // 0 1 2 3 | ||||
800 | // 0123456789012345678901234567890123 | ||||
801 | QByteArray method("<? function foo(string $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 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
812 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeString); | ||||
813 | | ||||
814 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
815 | QVERIFY(type); | ||||
816 | QVERIFY(type->dataType() == IntegralType::TypeString); | ||||
817 | } | ||||
818 | | ||||
819 | void TestDUChain::declareOptionalTypehintArrayFunction() | ||||
820 | { | ||||
821 | // 0 1 2 3 | ||||
822 | // 0123456789012345678901234567890123 | ||||
823 | QByteArray method("<? function foo(?array $i) { } "); | ||||
824 | | ||||
825 | TopDUContext* top = parse(method, DumpAll); | ||||
826 | DUChainReleaser releaseTop(top); | ||||
827 | | ||||
828 | DUChainWriteLocker lock(DUChain::lock()); | ||||
829 | | ||||
830 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
831 | QVERIFY(fun); | ||||
832 | QCOMPARE(fun->arguments().count(), 1); | ||||
833 | | ||||
834 | UnsureType::Ptr argType = UnsureType::Ptr::dynamicCast(fun->arguments().first()); | ||||
835 | QVERIFY(argType); | ||||
836 | QCOMPARE(argType->typesSize(), 2u); | ||||
837 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()); | ||||
838 | QVERIFY(argType->types()[0].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
839 | QVERIFY(argType->types()[1].abstractType().cast<IntegralType>()); | ||||
840 | QVERIFY(argType->types()[1].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeNull); | ||||
841 | | ||||
842 | UnsureType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<UnsureType>(); | ||||
843 | QVERIFY(type); | ||||
844 | QCOMPARE(type->typesSize(), 2u); | ||||
845 | QVERIFY(type->types()[0].abstractType().cast<IntegralType>()); | ||||
846 | QVERIFY(type->types()[0].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
847 | QVERIFY(type->types()[1].abstractType().cast<IntegralType>()); | ||||
848 | QVERIFY(type->types()[1].abstractType().cast<IntegralType>()->dataType() == IntegralType::TypeNull); | ||||
849 | } | ||||
850 | | ||||
851 | void TestDUChain::declareTypehintWithPhpdocFunction() | ||||
852 | { | ||||
853 | // 0 1 2 3 | ||||
854 | // 0123456789012345678901234567890123 | ||||
855 | QByteArray method("<? /**\n * @param string $i\n */ function foo(int $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::TypeInt); | ||||
867 | | ||||
868 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
869 | QVERIFY(type); | ||||
870 | QVERIFY(type->dataType() == IntegralType::TypeInt); | ||||
871 | } | ||||
872 | | ||||
873 | void TestDUChain::declareOptionalTypehintCallableFunction() | ||||
874 | { | ||||
875 | // 0 1 2 3 | ||||
876 | // 0123456789012345678901234567890123 | ||||
877 | QByteArray method("<? function foo(?callable $i) { } "); | ||||
878 | | ||||
879 | TopDUContext* top = parse(method, DumpAll); | ||||
880 | DUChainReleaser releaseTop(top); | ||||
881 | | ||||
882 | DUChainWriteLocker lock(DUChain::lock()); | ||||
883 | | ||||
884 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
885 | QVERIFY(fun); | ||||
886 | QCOMPARE(fun->arguments().count(), 1); | ||||
887 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
888 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeMixed); | ||||
889 | | ||||
890 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
891 | QVERIFY(type); | ||||
892 | QVERIFY(type->dataType() == IntegralType::TypeMixed); | ||||
893 | } | ||||
894 | | ||||
704 | void TestDUChain::classImplementsInterface() | 895 | void TestDUChain::classImplementsInterface() | ||
705 | { | 896 | { | ||
706 | // 0 1 2 3 4 5 6 7 | 897 | // 0 1 2 3 4 5 6 7 | ||
Context not available. |