Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show All 38 Lines | |||||
39 | 39 | | |||
40 | #include "../declarations/classdeclaration.h" | 40 | #include "../declarations/classdeclaration.h" | ||
41 | #include "../declarations/classmethoddeclaration.h" | 41 | #include "../declarations/classmethoddeclaration.h" | ||
42 | #include "../declarations/functiondeclaration.h" | 42 | #include "../declarations/functiondeclaration.h" | ||
43 | #include "../declarations/variabledeclaration.h" | 43 | #include "../declarations/variabledeclaration.h" | ||
44 | 44 | | |||
45 | #include "../types/structuretype.h" | 45 | #include "../types/structuretype.h" | ||
46 | #include "../types/integraltypeextended.h" | 46 | #include "../types/integraltypeextended.h" | ||
47 | #include "../types/indexedcontainer.h" | ||||
47 | 48 | | |||
48 | #include <QStandardPaths> | 49 | #include <QStandardPaths> | ||
49 | 50 | | |||
50 | using namespace KDevelop; | 51 | using namespace KDevelop; | ||
51 | using namespace Php; | 52 | using namespace Php; | ||
52 | 53 | | |||
53 | QTEST_MAIN(Php::TestDUChain) | 54 | QTEST_MAIN(Php::TestDUChain) | ||
54 | 55 | | |||
▲ Show 20 Lines • Show All 570 Lines • ▼ Show 20 Line(s) | 613 | { | |||
625 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | 626 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||
626 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeArray); | 627 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeArray); | ||
627 | 628 | | |||
628 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | 629 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||
629 | QVERIFY(type); | 630 | QVERIFY(type); | ||
630 | QVERIFY(type->dataType() == IntegralType::TypeArray); | 631 | QVERIFY(type->dataType() == IntegralType::TypeArray); | ||
631 | } | 632 | } | ||
632 | 633 | | |||
634 | void TestDUChain::declareTypehintVariadicFunction() | ||||
635 | { | ||||
636 | // 0 1 2 3 4 5 6 7 | ||||
637 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||||
638 | QByteArray method("<? class A {} function foo(A ...$i) { } "); | ||||
639 | | ||||
640 | TopDUContext* top = parse(method, DumpAll); | ||||
641 | DUChainReleaser releaseTop(top); | ||||
642 | | ||||
643 | DUChainWriteLocker lock(DUChain::lock()); | ||||
644 | | ||||
645 | FunctionType::Ptr fun = top->localDeclarations().at(1)->type<FunctionType>(); | ||||
646 | QVERIFY(fun); | ||||
647 | QCOMPARE(fun->arguments().count(), 1); | ||||
648 | | ||||
649 | AbstractType::Ptr arg = fun->arguments().first(); | ||||
650 | QVERIFY(arg); | ||||
651 | QVERIFY(arg.cast<IndexedContainer>()); | ||||
652 | QCOMPARE(arg.cast<IndexedContainer>()->typesCount(), 1); | ||||
653 | QCOMPARE(arg.cast<IndexedContainer>()->prettyName().str(), QStringLiteral("array")); | ||||
654 | | ||||
655 | AbstractType::Ptr typehint = arg.cast<IndexedContainer>()->typeAt(0).abstractType(); | ||||
656 | QVERIFY(typehint); | ||||
657 | QCOMPARE(typehint->toString(), QStringLiteral("A")); | ||||
658 | } | ||||
659 | | ||||
633 | void TestDUChain::declareTypehintArrayFunction() | 660 | void TestDUChain::declareTypehintArrayFunction() | ||
634 | { | 661 | { | ||
635 | // 0 1 2 3 4 5 6 7 | 662 | // 0 1 2 3 4 5 6 7 | ||
636 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 663 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
637 | QByteArray method("<? function foo(array $i) { } "); | 664 | QByteArray method("<? function foo(array $i) { } "); | ||
638 | 665 | | |||
639 | TopDUContext* top = parse(method, DumpAll); | 666 | TopDUContext* top = parse(method, DumpAll); | ||
640 | DUChainReleaser releaseTop(top); | 667 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 2399 Lines • ▼ Show 20 Line(s) | 3054 | { | |||
3040 | QVERIFY(top->problems().isEmpty()); | 3067 | QVERIFY(top->problems().isEmpty()); | ||
3041 | QCOMPARE(top->localDeclarations().count(),1); | 3068 | QCOMPARE(top->localDeclarations().count(),1); | ||
3042 | 3069 | | |||
3043 | Declaration* dec = top->localDeclarations().at(0); | 3070 | Declaration* dec = top->localDeclarations().at(0); | ||
3044 | ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(dec); | 3071 | ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(dec); | ||
3045 | QCOMPARE(classDec->uses().count(),1); | 3072 | QCOMPARE(classDec->uses().count(),1); | ||
3046 | } | 3073 | } | ||
3047 | 3074 | | |||
3075 | void TestDUChain::functionArgumentUnpacking_data() | ||||
3076 | { | ||||
3077 | QTest::addColumn<QString>("code"); | ||||
3078 | | ||||
3079 | QTest::newRow("unpackVariable") << QStringLiteral("<? $a = [ 1,2 ];\n$b = [ 3,4 ];\nfunction aaa($c,$d,$e,$f) { }\naaa(...$a, ...$b);\n"); | ||||
3080 | | ||||
3081 | QTest::newRow("unpackLiteral") << QStringLiteral("<? function aaa($c,$d,$e,$f) { }\naaa(...[1,2], ...[3,4]);\n"); | ||||
3082 | | ||||
3083 | QTest::newRow("unpackFunction") << QStringLiteral("<? function bbb() { return [1,2,3,4]; }\nfunction aaa($c,$d,$e,$f) { }\naaa(...bbb());\n"); | ||||
3084 | } | ||||
3085 | | ||||
3048 | void TestDUChain::functionArgumentUnpacking() | 3086 | void TestDUChain::functionArgumentUnpacking() | ||
3049 | { | 3087 | { | ||
3050 | // 0 1 2 3 4 5 6 7 | 3088 | QFETCH(QString, code); | ||
3051 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | | |||
3052 | QByteArray method("<?php\n" | | |||
3053 | "$a = [ 1,2 ];\n" | | |||
3054 | "$b = [ 3,4 ];\n" | | |||
3055 | "function aaa($c,$d,$e,$f) { }\n" | | |||
3056 | "aaa(...$a, ...$b);\n"); | | |||
3057 | 3089 | | |||
3058 | TopDUContext* top = parse(method); | 3090 | TopDUContext* top = parse(code.toUtf8(), DumpNone); | ||
3059 | QVERIFY(top); | 3091 | QVERIFY(top); | ||
3060 | DUChainReleaser releaseTop(top); | 3092 | DUChainReleaser releaseTop(top); | ||
3061 | DUChainWriteLocker lock(DUChain::lock()); | 3093 | DUChainWriteLocker lock(DUChain::lock()); | ||
3062 | 3094 | | |||
3063 | QVERIFY(top->problems().isEmpty()); | 3095 | QVERIFY(top->problems().isEmpty()); | ||
3064 | QCOMPARE(top->localDeclarations().count(),3); | | |||
3065 | } | 3096 | } |