Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show All 23 Lines | |||||
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/namespacealiasdeclaration.h> | 31 | #include <language/duchain/namespacealiasdeclaration.h> | ||
32 | #include <language/editor/documentrange.h> | ||||
32 | 33 | | |||
33 | #include <interfaces/icore.h> | 34 | #include <interfaces/icore.h> | ||
34 | #include <interfaces/ilanguagecontroller.h> | 35 | #include <interfaces/ilanguagecontroller.h> | ||
35 | #include <interfaces/icompletionsettings.h> | 36 | #include <interfaces/icompletionsettings.h> | ||
36 | 37 | | |||
37 | #include "helper.h" | 38 | #include "helper.h" | ||
38 | 39 | | |||
39 | #include "../declarations/classdeclaration.h" | 40 | #include "../declarations/classdeclaration.h" | ||
▲ Show 20 Lines • Show All 562 Lines • ▼ Show 20 Line(s) | 569 | { | |||
602 | QCOMPARE(top->childContexts().at(1)->localDeclarations().first()->type<StructureType>()->qualifiedIdentifier(), QualifiedIdentifier("a")); | 603 | QCOMPARE(top->childContexts().at(1)->localDeclarations().first()->type<StructureType>()->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||
603 | 604 | | |||
604 | FunctionType::Ptr fType = top->localDeclarations().at(1)->type<FunctionType>(); | 605 | FunctionType::Ptr fType = top->localDeclarations().at(1)->type<FunctionType>(); | ||
605 | QVERIFY(fType); | 606 | QVERIFY(fType); | ||
606 | QVERIFY(StructureType::Ptr::dynamicCast(fType->returnType())); | 607 | QVERIFY(StructureType::Ptr::dynamicCast(fType->returnType())); | ||
607 | QCOMPARE(StructureType::Ptr::dynamicCast(fType->returnType())->qualifiedIdentifier(), QualifiedIdentifier("a")); | 608 | QCOMPARE(StructureType::Ptr::dynamicCast(fType->returnType())->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||
608 | } | 609 | } | ||
609 | 610 | | |||
611 | void TestDUChain::declareVariadicFunction() | ||||
612 | { | ||||
613 | // 0 1 2 3 4 5 6 7 | ||||
614 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||||
615 | QByteArray method("<? function foo(...$i) { } "); | ||||
616 | | ||||
617 | TopDUContext* top = parse(method, DumpAll); | ||||
618 | DUChainReleaser releaseTop(top); | ||||
619 | | ||||
620 | DUChainWriteLocker lock(DUChain::lock()); | ||||
621 | | ||||
622 | FunctionType::Ptr fun = top->localDeclarations().first()->type<FunctionType>(); | ||||
623 | QVERIFY(fun); | ||||
624 | QCOMPARE(fun->arguments().count(), 1); | ||||
625 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())); | ||||
626 | QVERIFY(IntegralType::Ptr::dynamicCast(fun->arguments().first())->dataType() == IntegralType::TypeArray); | ||||
627 | | ||||
628 | IntegralType::Ptr type = top->childContexts().first()->localDeclarations().first()->type<IntegralType>(); | ||||
629 | QVERIFY(type); | ||||
630 | QVERIFY(type->dataType() == IntegralType::TypeArray); | ||||
631 | } | ||||
632 | | ||||
610 | void TestDUChain::declareTypehintArrayFunction() | 633 | void TestDUChain::declareTypehintArrayFunction() | ||
611 | { | 634 | { | ||
612 | // 0 1 2 3 4 5 6 7 | 635 | // 0 1 2 3 4 5 6 7 | ||
613 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 636 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
614 | QByteArray method("<? function foo(array $i) { } "); | 637 | QByteArray method("<? function foo(array $i) { } "); | ||
615 | 638 | | |||
616 | TopDUContext* top = parse(method, DumpAll); | 639 | TopDUContext* top = parse(method, DumpAll); | ||
617 | DUChainReleaser releaseTop(top); | 640 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 856 Lines • ▼ Show 20 Line(s) | 1490 | { | |||
1474 | // update top (the pointer will be the same) | 1497 | // update top (the pointer will be the same) | ||
1475 | QByteArray method2("<? $setupPage = new setupPage; $setupPage->foo();"); | 1498 | QByteArray method2("<? $setupPage = new setupPage; $setupPage->foo();"); | ||
1476 | TopDUContext* top2 = parse(method2, DumpNone, QUrl(QStringLiteral("file:///internal/testObjectWithClassName.php"))); | 1499 | TopDUContext* top2 = parse(method2, DumpNone, QUrl(QStringLiteral("file:///internal/testObjectWithClassName.php"))); | ||
1477 | QVERIFY(top2 == top); | 1500 | QVERIFY(top2 == top); | ||
1478 | } | 1501 | } | ||
1479 | 1502 | | |||
1480 | void TestDUChain::largeNumberOfDeclarations() | 1503 | void TestDUChain::largeNumberOfDeclarations() | ||
1481 | { | 1504 | { | ||
1482 | TopDUContext* top = new TopDUContext(IndexedString(QUrl(QStringLiteral("file:///internal/testurl"))), RangeInRevision(0, 0, 6000, 0), 0); | 1505 | TopDUContext* top = new TopDUContext(IndexedString(QUrl(QStringLiteral("file:///internal/testurl"))), RangeInRevision(0, 0, 6000, 0), nullptr); | ||
1483 | DUChain::self()->addDocumentChain(top); | 1506 | DUChain::self()->addDocumentChain(top); | ||
1484 | DUChainReleaser releaseTop(top); | 1507 | DUChainReleaser releaseTop(top); | ||
1485 | DUChainWriteLocker lock(DUChain::lock()); | 1508 | DUChainWriteLocker lock(DUChain::lock()); | ||
1486 | for (int i = 0; i < 6000; ++i) { | 1509 | for (int i = 0; i < 6000; ++i) { | ||
1487 | RangeInRevision newRange(i, 0, i, 1); | 1510 | RangeInRevision newRange(i, 0, i, 1); | ||
1488 | Declaration* dec = new Declaration(newRange, top); | 1511 | Declaration* dec = new Declaration(newRange, top); | ||
1489 | dec->setIdentifier(Identifier(QStringLiteral("dec%0").arg(i))); | 1512 | dec->setIdentifier(Identifier(QStringLiteral("dec%0").arg(i))); | ||
1490 | dec->setAbstractType(AbstractType::Ptr(0)); | 1513 | dec->setAbstractType(AbstractType::Ptr(nullptr)); | ||
1491 | } | 1514 | } | ||
1492 | } | 1515 | } | ||
1493 | 1516 | | |||
1494 | void TestDUChain::staticVariable() | 1517 | void TestDUChain::staticVariable() | ||
1495 | { | 1518 | { | ||
1496 | // 0 1 2 3 4 5 6 7 | 1519 | // 0 1 2 3 4 5 6 7 | ||
1497 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 1520 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
1498 | QByteArray method("<? define('AA', 0); function aaa() { static $foo; static $bar=0; static $baz='a'; static $bam=array(); static $woid=+'1'; static $a=AA; }"); | 1521 | QByteArray method("<? define('AA', 0); function aaa() { static $foo; static $bar=0; static $baz='a'; static $bam=array(); static $woid=+'1'; static $a=AA; }"); | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | 1649 | { | |||
1640 | QCOMPARE(top->localDeclarations().at(0)->internalContext()->importedParentContexts().first().context(top), | 1663 | QCOMPARE(top->localDeclarations().at(0)->internalContext()->importedParentContexts().first().context(top), | ||
1641 | top->localDeclarations().at(1)->internalContext()); | 1664 | top->localDeclarations().at(1)->internalContext()); | ||
1642 | } | 1665 | } | ||
1643 | 1666 | | |||
1644 | void TestDUChain::findDeclarations() | 1667 | void TestDUChain::findDeclarations() | ||
1645 | { | 1668 | { | ||
1646 | DUChainWriteLocker lock(DUChain::lock()); | 1669 | DUChainWriteLocker lock(DUChain::lock()); | ||
1647 | 1670 | | |||
1648 | TopDUContext* top1 = new TopDUContext(IndexedString(QUrl(QStringLiteral("file:///internal/testfile1"))), RangeInRevision(0, 0, 0, 10), 0); | 1671 | TopDUContext* top1 = new TopDUContext(IndexedString(QUrl(QStringLiteral("file:///internal/testfile1"))), RangeInRevision(0, 0, 0, 10), nullptr); | ||
1649 | DUChainReleaser releaseTop1(top1); | 1672 | DUChainReleaser releaseTop1(top1); | ||
1650 | DUChain::self()->addDocumentChain(top1); | 1673 | DUChain::self()->addDocumentChain(top1); | ||
1651 | TopDUContext* top2 = new TopDUContext(IndexedString(QUrl(QStringLiteral("file:///internal/testfile2"))), RangeInRevision(0, 0, 0, 10), 0); | 1674 | TopDUContext* top2 = new TopDUContext(IndexedString(QUrl(QStringLiteral("file:///internal/testfile2"))), RangeInRevision(0, 0, 0, 10), nullptr); | ||
1652 | DUChainReleaser releaseTop2(top2); | 1675 | DUChainReleaser releaseTop2(top2); | ||
1653 | DUChain::self()->addDocumentChain(top2); | 1676 | DUChain::self()->addDocumentChain(top2); | ||
1654 | 1677 | | |||
1655 | Declaration* declaration = new Declaration(RangeInRevision(0, 0, 0, 3), top1); | 1678 | Declaration* declaration = new Declaration(RangeInRevision(0, 0, 0, 3), top1); | ||
1656 | declaration->setIdentifier(Identifier(QStringLiteral("foo"))); | 1679 | declaration->setIdentifier(Identifier(QStringLiteral("foo"))); | ||
1657 | 1680 | | |||
1658 | QVERIFY(!top1->usingImportsCache()); | 1681 | QVERIFY(!top1->usingImportsCache()); | ||
1659 | QVERIFY(!top2->usingImportsCache()); | 1682 | QVERIFY(!top2->usingImportsCache()); | ||
▲ Show 20 Lines • Show All 1356 Lines • ▼ Show 20 Line(s) | 3027 | { | |||
3016 | 3039 | | |||
3017 | QVERIFY(top->problems().isEmpty()); | 3040 | QVERIFY(top->problems().isEmpty()); | ||
3018 | QCOMPARE(top->localDeclarations().count(),1); | 3041 | QCOMPARE(top->localDeclarations().count(),1); | ||
3019 | 3042 | | |||
3020 | Declaration* dec = top->localDeclarations().at(0); | 3043 | Declaration* dec = top->localDeclarations().at(0); | ||
3021 | ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(dec); | 3044 | ClassDeclaration* classDec = dynamic_cast<ClassDeclaration*>(dec); | ||
3022 | QCOMPARE(classDec->uses().count(),1); | 3045 | QCOMPARE(classDec->uses().count(),1); | ||
3023 | } | 3046 | } | ||
3047 | | ||||
3048 | void TestDUChain::functionArgumentUnpacking() | ||||
3049 | { | ||||
3050 | // 0 1 2 3 4 5 6 7 | ||||
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 | | ||||
3058 | TopDUContext* top = parse(method); | ||||
3059 | QVERIFY(top); | ||||
3060 | DUChainReleaser releaseTop(top); | ||||
3061 | DUChainWriteLocker lock(DUChain::lock()); | ||||
3062 | | ||||
3063 | QVERIFY(top->problems().isEmpty()); | ||||
3064 | QCOMPARE(top->localDeclarations().count(),3); | ||||
3065 | } |