Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show All 22 Lines | |||||
23 | #include <language/duchain/parsingenvironment.h> | 23 | #include <language/duchain/parsingenvironment.h> | ||
24 | #include <language/duchain/problem.h> | 24 | #include <language/duchain/problem.h> | ||
25 | #include <language/duchain/duchain.h> | 25 | #include <language/duchain/duchain.h> | ||
26 | #include <language/duchain/duchainlock.h> | 26 | #include <language/duchain/duchainlock.h> | ||
27 | #include <language/duchain/topducontext.h> | 27 | #include <language/duchain/topducontext.h> | ||
28 | #include <language/duchain/types/functiontype.h> | 28 | #include <language/duchain/types/functiontype.h> | ||
29 | #include <language/duchain/types/integraltype.h> | 29 | #include <language/duchain/types/integraltype.h> | ||
30 | #include <language/duchain/types/unsuretype.h> | 30 | #include <language/duchain/types/unsuretype.h> | ||
31 | #include <language/duchain/types/arraytype.h> | ||||
31 | #include <language/duchain/namespacealiasdeclaration.h> | 32 | #include <language/duchain/namespacealiasdeclaration.h> | ||
32 | #include <language/editor/documentrange.h> | 33 | #include <language/editor/documentrange.h> | ||
33 | 34 | | |||
34 | #include <interfaces/icore.h> | 35 | #include <interfaces/icore.h> | ||
35 | #include <interfaces/ilanguagecontroller.h> | 36 | #include <interfaces/ilanguagecontroller.h> | ||
36 | #include <interfaces/icompletionsettings.h> | 37 | #include <interfaces/icompletionsettings.h> | ||
37 | 38 | | |||
38 | #include "helper.h" | 39 | #include "helper.h" | ||
39 | 40 | | |||
40 | #include "../declarations/classdeclaration.h" | 41 | #include "../declarations/classdeclaration.h" | ||
41 | #include "../declarations/classmethoddeclaration.h" | 42 | #include "../declarations/classmethoddeclaration.h" | ||
42 | #include "../declarations/functiondeclaration.h" | 43 | #include "../declarations/functiondeclaration.h" | ||
43 | #include "../declarations/variabledeclaration.h" | 44 | #include "../declarations/variabledeclaration.h" | ||
44 | 45 | | |||
45 | #include "../types/structuretype.h" | 46 | #include "../types/structuretype.h" | ||
46 | #include "../types/integraltypeextended.h" | 47 | #include "../types/integraltypeextended.h" | ||
47 | #include "../types/indexedcontainer.h" | | |||
48 | 48 | | |||
49 | #include <QStandardPaths> | 49 | #include <QStandardPaths> | ||
50 | 50 | | |||
51 | using namespace KDevelop; | 51 | using namespace KDevelop; | ||
52 | using namespace Php; | 52 | using namespace Php; | ||
53 | 53 | | |||
54 | QTEST_MAIN(Php::TestDUChain) | 54 | QTEST_MAIN(Php::TestDUChain) | ||
55 | 55 | | |||
▲ Show 20 Lines • Show All 951 Lines • ▼ Show 20 Line(s) | 999 | { | |||
1007 | DUChainWriteLocker lock(DUChain::lock()); | 1007 | DUChainWriteLocker lock(DUChain::lock()); | ||
1008 | 1008 | | |||
1009 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | 1009 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||
1010 | QVERIFY(fun); | 1010 | QVERIFY(fun); | ||
1011 | QCOMPARE(fun->arguments().count(), 1); | 1011 | QCOMPARE(fun->arguments().count(), 1); | ||
1012 | 1012 | | |||
1013 | AbstractType::Ptr arg = fun->arguments().first(); | 1013 | AbstractType::Ptr arg = fun->arguments().first(); | ||
1014 | QVERIFY(arg); | 1014 | QVERIFY(arg); | ||
1015 | QVERIFY(arg.cast<IndexedContainer>()); | 1015 | QVERIFY(arg.cast<KDevelop::ArrayType>()); | ||
1016 | QCOMPARE(arg.cast<IndexedContainer>()->typesCount(), 1); | | |||
1017 | QCOMPARE(arg.cast<IndexedContainer>()->prettyName().str(), QStringLiteral("array")); | | |||
1018 | 1016 | | |||
1019 | AbstractType::Ptr typehint = arg.cast<IndexedContainer>()->typeAt(0).abstractType(); | 1017 | AbstractType::Ptr typehint = arg.cast<KDevelop::ArrayType>()->elementType(); | ||
1020 | QVERIFY(typehint); | 1018 | QVERIFY(typehint); | ||
1021 | QVERIFY(IntegralType::Ptr::dynamicCast(typehint)); | 1019 | QVERIFY(IntegralType::Ptr::dynamicCast(typehint)); | ||
1022 | QVERIFY(IntegralType::Ptr::dynamicCast(typehint)->dataType() == IntegralType::TypeMixed); | 1020 | QVERIFY(IntegralType::Ptr::dynamicCast(typehint)->dataType() == IntegralType::TypeMixed); | ||
1023 | } | 1021 | } | ||
1024 | 1022 | | |||
1025 | void TestDUChain::declareTypehintVariadicFunction() | 1023 | void TestDUChain::declareTypehintVariadicFunction() | ||
1026 | { | 1024 | { | ||
1027 | // 0 1 2 3 4 5 6 7 | 1025 | // 0 1 2 3 4 5 6 7 | ||
1028 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 1026 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
1029 | QByteArray method("<? class A {} function foo(A ...$i) { } "); | 1027 | QByteArray method("<? class A {} function foo(A ...$i) { } "); | ||
1030 | 1028 | | |||
1031 | TopDUContext* top = parse(method, DumpAll); | 1029 | TopDUContext* top = parse(method, DumpAll); | ||
1032 | DUChainReleaser releaseTop(top); | 1030 | DUChainReleaser releaseTop(top); | ||
1033 | 1031 | | |||
1034 | DUChainWriteLocker lock(DUChain::lock()); | 1032 | DUChainWriteLocker lock(DUChain::lock()); | ||
1035 | 1033 | | |||
1036 | FunctionType::Ptr fun = top->localDeclarations().at(1)->type<FunctionType>(); | 1034 | FunctionType::Ptr fun = top->localDeclarations().at(1)->type<FunctionType>(); | ||
1037 | QVERIFY(fun); | 1035 | QVERIFY(fun); | ||
1038 | QCOMPARE(fun->arguments().count(), 1); | 1036 | QCOMPARE(fun->arguments().count(), 1); | ||
1039 | 1037 | | |||
1040 | AbstractType::Ptr arg = fun->arguments().first(); | 1038 | AbstractType::Ptr arg = fun->arguments().first(); | ||
1041 | QVERIFY(arg); | 1039 | QVERIFY(arg); | ||
1042 | QVERIFY(arg.cast<IndexedContainer>()); | 1040 | QVERIFY(arg.cast<KDevelop::ArrayType>()); | ||
1043 | QCOMPARE(arg.cast<IndexedContainer>()->typesCount(), 1); | | |||
1044 | QCOMPARE(arg.cast<IndexedContainer>()->prettyName().str(), QStringLiteral("array")); | | |||
1045 | 1041 | | |||
1046 | AbstractType::Ptr typehint = arg.cast<IndexedContainer>()->typeAt(0).abstractType(); | 1042 | AbstractType::Ptr typehint = arg.cast<KDevelop::ArrayType>()->elementType(); | ||
1047 | QVERIFY(typehint); | 1043 | QVERIFY(typehint); | ||
1048 | QCOMPARE(typehint->toString(), QStringLiteral("A")); | 1044 | QCOMPARE(typehint->toString(), QStringLiteral("A")); | ||
1049 | } | 1045 | } | ||
1050 | 1046 | | |||
1051 | void TestDUChain::declareTypehintObjectFunction() | 1047 | void TestDUChain::declareTypehintObjectFunction() | ||
1052 | { | 1048 | { | ||
1053 | // 0 1 2 3 4 5 6 7 | 1049 | // 0 1 2 3 4 5 6 7 | ||
1054 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 1050 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
▲ Show 20 Lines • Show All 1679 Lines • ▼ Show 20 Line(s) | 2712 | { | |||
2734 | 2730 | | |||
2735 | DUContext* fooCtx = top->childContexts().first()->childContexts().last(); | 2731 | DUContext* fooCtx = top->childContexts().first()->childContexts().last(); | ||
2736 | QVERIFY(fooCtx->owner()); | 2732 | QVERIFY(fooCtx->owner()); | ||
2737 | 2733 | | |||
2738 | QCOMPARE(aDec->uses().size(), 1); | 2734 | QCOMPARE(aDec->uses().size(), 1); | ||
2739 | QCOMPARE(aDec->uses().begin()->size(), 4); | 2735 | QCOMPARE(aDec->uses().begin()->size(), 4); | ||
2740 | } | 2736 | } | ||
2741 | 2737 | | |||
2738 | void TestDUChain::foreachArray() | ||||
2739 | { | ||||
2740 | { | ||||
2741 | QByteArray code = "<?\n" | ||||
2742 | "class Foo {};\n" | ||||
2743 | "/// @param Foo[]\n" | ||||
2744 | "function bar($a) {\n" | ||||
2745 | " foreach($a as $e){ $e; }\n" | ||||
2746 | "}\n"; | ||||
2747 | TopDUContext* top = parse(code, DumpNone); | ||||
2748 | DUChainReleaser releaseTop(top); | ||||
2749 | DUChainWriteLocker lock(DUChain::lock()); | ||||
2750 | | ||||
2751 | DUContext* barContext = top->childContexts().last(); | ||||
2752 | QCOMPARE(barContext->localScopeIdentifier(), QualifiedIdentifier("bar")); | ||||
2753 | | ||||
2754 | Declaration* eDec = barContext->localDeclarations().first(); | ||||
2755 | QCOMPARE(eDec->qualifiedIdentifier(), QualifiedIdentifier("bar::e")); | ||||
2756 | QVERIFY(eDec->type<StructureType>()); | ||||
2757 | QCOMPARE(eDec->type<StructureType>()->qualifiedIdentifier(), QualifiedIdentifier("foo")); | ||||
2758 | } | ||||
2759 | } | ||||
2760 | | ||||
2742 | void TestDUChain::returnThis() | 2761 | void TestDUChain::returnThis() | ||
2743 | { | 2762 | { | ||
2744 | QByteArray code("<? class A { \n/**\n * @return $this\n */\npublic function x() {} } "); | 2763 | QByteArray code("<? class A { \n/**\n * @return $this\n */\npublic function x() {} } "); | ||
2745 | TopDUContext* top = parse(code, DumpAST); | 2764 | TopDUContext* top = parse(code, DumpAST); | ||
2746 | DUChainReleaser releaseTop(top); | 2765 | DUChainReleaser releaseTop(top); | ||
2747 | DUChainWriteLocker lock(DUChain::lock()); | 2766 | DUChainWriteLocker lock(DUChain::lock()); | ||
2748 | 2767 | | |||
2749 | Declaration* dec = top->childContexts().first()->localDeclarations().first(); | 2768 | Declaration* dec = top->childContexts().first()->localDeclarations().first(); | ||
▲ Show 20 Lines • Show All 1438 Lines • Show Last 20 Lines |