~ubuntu-branches/ubuntu/trusty/kdevelop-php/trusty-proposed

« back to all changes in this revision

Viewing changes to duchain/tests/duchain.cpp

  • Committer: Package Import Robot
  • Author(s): Rohan Garg
  • Date: 2012-04-15 21:59:13 UTC
  • mfrom: (1.2.13) (5.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20120415215913-m3fxrx7yn0oxlpjk
Tags: 1.3.1-0ubuntu1
* New upstream bugfix release
* Added watch file

Show diffs side-by-side

added added

removed removed

Lines of Context:
1999
1999
    QCOMPARE(top->problems().at(1)->finalLocation().start.line, 3);
2000
2000
}
2001
2001
 
 
2002
void TestDUChain::declareMemberOutOfClass2()
 
2003
{
 
2004
    // see also: https://bugs.kde.org/show_bug.cgi?id=283356
 
2005
    //               0         1         2         3         4         5         6         7
 
2006
    //               01234567890123456789012345678901234567890123456789012345678901234567890123456789
 
2007
    QByteArray code("<? $a = new A();\n"
 
2008
                    // allowed, should re-use existing declaration
 
2009
                    "$a->x = 1;\n"
 
2010
                    "class A { var $x = 1; }");
 
2011
    TopDUContext* top = parse(code, DumpAST);
 
2012
    QVERIFY(top);
 
2013
    // update
 
2014
    top = parse(code, DumpNone, top->url().str(), ReferencedTopDUContext(top));
 
2015
    DUChainReleaser releaseTop(top);
 
2016
    DUChainWriteLocker lock;
 
2017
 
 
2018
    QVERIFY(top->problems().isEmpty());
 
2019
 
 
2020
    QList<Declaration*> decs = top->findLocalDeclarations(Identifier("a"));
 
2021
    QCOMPARE(decs.size(), 2);
 
2022
    {
 
2023
        Declaration *dec = decs.first();
 
2024
        QVERIFY(dynamic_cast<VariableDeclaration*>(dec));
 
2025
        QVERIFY(dec->type<StructureType>());
 
2026
        QVERIFY(dec->type<StructureType>()->declaration(top)->identifier().nameEquals(Identifier("a")));
 
2027
    }
 
2028
    {
 
2029
        Declaration *dec = decs.last();
 
2030
        QVERIFY(dynamic_cast<ClassDeclaration*>(dec));
 
2031
        QVERIFY(dec->type<StructureType>());
 
2032
        QVERIFY(dec->type<StructureType>()->declaration(top)->identifier().nameEquals(Identifier("a")));
 
2033
    }
 
2034
 
 
2035
    { // check if x got declared
 
2036
        QList<Declaration*> decs = top->childContexts().first()->findDeclarations(Identifier("x"));
 
2037
        // the type of both assignments to $bar->asdf are the same, hence it should only be declared once
 
2038
        QCOMPARE(decs.size(), 1);
 
2039
        ClassMemberDeclaration* cmdec = dynamic_cast<ClassMemberDeclaration*>(decs.first());
 
2040
        QVERIFY(cmdec);
 
2041
        QVERIFY(cmdec->accessPolicy() == Declaration::Public);
 
2042
        QVERIFY(!cmdec->isStatic());
 
2043
        QVERIFY(cmdec->type<IntegralType>());
 
2044
        QCOMPARE(cmdec->type<IntegralType>()->dataType(), (uint) IntegralType::TypeInt);
 
2045
    }
 
2046
}
 
2047
 
2002
2048
void TestDUChain::declareMemberInClassMethod()
2003
2049
{
2004
2050
    QByteArray code("<? class foo { private $priv = 0; protected $prot = 0; } class bar extends foo {\n"
2761
2807
    QVERIFY(top->problems().isEmpty());
2762
2808
}
2763
2809
 
 
2810
namespace QTest {
 
2811
  template<>
 
2812
  char* toString(const KDevelop::CursorInRevision& c)
 
2813
  {
 
2814
    return qstrdup(
 
2815
        QString("(%1, %2)")
 
2816
        .arg(QTest::toString(c.line))
 
2817
        .arg(QTest::toString(c.column))
 
2818
        .toLocal8Bit().constData());
 
2819
  }
 
2820
  template<>
 
2821
  char* toString(const KDevelop::RangeInRevision& r)
 
2822
  {
 
2823
    return qstrdup(
 
2824
        QString("[%1, %2]")
 
2825
        .arg(QTest::toString(r.start))
 
2826
        .arg(QTest::toString(r.end))
 
2827
        .toLocal8Bit().constData());
 
2828
  }
 
2829
}
 
2830
 
 
2831
void TestDUChain::bug296709()
 
2832
{
 
2833
    // see also: https://bugs.kde.org/show_bug.cgi?id=296709
 
2834
    //               0         1         2         3         4         5         6         7
 
2835
    //               01234567890123456789012345678901234567890123456789012345678901234567890123456789
 
2836
    TopDUContext* top = parse(
 
2837
                    "<?php\n"
 
2838
                    "foreach(array() as $a) {\n"
 
2839
                    "  $a[0] = 1;\n"
 
2840
                    "}\n", DumpAll);
 
2841
    QVERIFY(top);
 
2842
    DUChainReleaser releaseTop(top);
 
2843
    DUChainWriteLocker lock;
 
2844
    QVERIFY(top->problems().isEmpty());
 
2845
    QList< Declaration* > decs = top->findLocalDeclarations(Identifier("a"));
 
2846
    QCOMPARE(decs.size(), 1);
 
2847
    QCOMPARE(decs.at(0)->range(), RangeInRevision(1, 19, 1, 21));
 
2848
    QCOMPARE(decs.at(0)->uses().count(), 1);
 
2849
    QCOMPARE(decs.at(0)->uses().begin()->count(), 1);
 
2850
    QCOMPARE(decs.at(0)->uses().begin()->first(), RangeInRevision(2, 2, 2, 4));
 
2851
}
 
2852
 
2764
2853
#include "duchain.moc"