~ubuntu-branches/ubuntu/utopic/kdevelop-php/utopic

« back to all changes in this revision

Viewing changes to completion/tests/test_completion.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-12-20 14:59:02 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101220145902-a6cmovse1qmue52p
Tags: 1.1.80-0ubuntu1
* New upstream release
* Build-dep on kdevplatform >= 1.1.80
* Get rid of l10n packages, not relevant in Ubuntu, put locale files into main package

Show diffs side-by-side

added added

removed removed

Lines of Context:
109
109
class TestCodeCompletionContext : public CodeCompletionContext
110
110
{
111
111
public:
112
 
    TestCodeCompletionContext(KDevelop::DUContextPointer context, const QString& text, const QString& followingText, const SimpleCursor &position, int depth = 0)
113
 
            : CodeCompletionContext(context, text, followingText, position, depth) { }
 
112
    TestCodeCompletionContext(KDevelop::DUContextPointer context, const QString& text, const QString& followingText, const CursorInRevision &position, int depth = 0)
 
113
        : CodeCompletionContext(context, text, followingText, position, depth) { }
114
114
protected:
115
115
    QList<QSet<IndexedString> > completionFiles() {
116
116
        QList<QSet<IndexedString> > ret;
131
131
class PhpCompletionTester : public BasePhpCompletionTester
132
132
{
133
133
public:
134
 
    PhpCompletionTester(DUContext* context, QString text = "; ", QString followingText = "", SimpleCursor position = SimpleCursor::invalid())
 
134
    PhpCompletionTester(DUContext* context, QString text = "; ", QString followingText = "", CursorInRevision position = CursorInRevision::invalid())
135
135
        : BasePhpCompletionTester(context, text.startsWith("<?") ? text : text.prepend("<?php "), followingText, position)
136
136
    {
137
137
 
744
744
 
745
745
void TestCompletion::verifyExtendsOrImplements(const QString &codeStr, const QString &completionStr,
746
746
        ClassDeclarationData::ClassType type,
747
 
        SimpleCursor cursor,
 
747
        const CursorInRevision& cursor,
748
748
        QStringList forbiddenIdentifiers)
749
749
{
750
750
    if (cursor.isValid()) {
787
787
{
788
788
    verifyExtendsOrImplements("<?php ", "class test extends ",
789
789
                              ClassDeclarationData::Class,
790
 
                              SimpleCursor::invalid(),
 
790
                              CursorInRevision::invalid(),
791
791
                              QStringList() << "test");
792
792
 
793
793
    verifyExtendsOrImplements("<?php ", "interface test extends ",
794
794
                              ClassDeclarationData::Interface,
795
 
                              SimpleCursor::invalid(),
 
795
                              CursorInRevision::invalid(),
796
796
                              QStringList() << "test");
797
797
 
798
798
    verifyExtendsOrImplements("<?php interface blub{} ", "interface test extends blub, ",
799
799
                              ClassDeclarationData::Interface,
800
 
                              SimpleCursor::invalid(),
 
800
                              CursorInRevision::invalid(),
801
801
                              QStringList() << "test" << "blub");
802
802
}
803
803
 
807
807
    //                         012345678901234567890123456789012345678901234567890123456789
808
808
    verifyExtendsOrImplements("<?php class test {}", "class test extends ",
809
809
                              ClassDeclarationData::Class,
810
 
                              SimpleCursor(0, 16),
 
810
                              CursorInRevision(0, 16),
811
811
                              QStringList() << "test");
812
812
 
813
813
    //                         0         1         2         3         4         5
814
814
    //                         012345678901234567890123456789012345678901234567890123456789
815
815
    verifyExtendsOrImplements("<?php interface test {}", "interface test extends ",
816
816
                              ClassDeclarationData::Interface,
817
 
                              SimpleCursor(0, 20),
 
817
                              CursorInRevision(0, 20),
818
818
                              QStringList() << "test");
819
819
 
820
820
    //                         0         1         2         3         4         5
822
822
    verifyExtendsOrImplements("<?php interface blub{} interface test extends blub {}",
823
823
                              "interface test extends blub,bar, ",
824
824
                              ClassDeclarationData::Interface,
825
 
                              SimpleCursor(0, 50),
 
825
                              CursorInRevision(0, 50),
826
826
                              QStringList() << "test" << "blub");
827
827
}
828
828
 
830
830
{
831
831
    verifyExtendsOrImplements("<?php ", "class test implements ",
832
832
                              ClassDeclarationData::Interface,
833
 
                              SimpleCursor::invalid(),
 
833
                              CursorInRevision::invalid(),
834
834
                              QStringList() << "test");
835
835
    verifyExtendsOrImplements("<?php interface blub{}", " class test implements blub, ",
836
836
                              ClassDeclarationData::Interface,
837
 
                              SimpleCursor::invalid(),
 
837
                              CursorInRevision::invalid(),
838
838
                              QStringList() << "test" << "blub");
839
839
}
840
840
 
844
844
    //                         012345678901234567890123456789012345678901234567890123456789
845
845
    verifyExtendsOrImplements("<?php class test {}", "class test implements ",
846
846
                              ClassDeclarationData::Interface,
847
 
                              SimpleCursor(0, 16),
 
847
                              CursorInRevision(0, 16),
848
848
                              QStringList() << "test");
849
849
 
850
850
    //                         0         1         2         3         4         5
852
852
    verifyExtendsOrImplements("<?php interface blub{} class test implements blub {}",
853
853
                              "class test implements blub, ",
854
854
                              ClassDeclarationData::Interface,
855
 
                              SimpleCursor(0, 49),
 
855
                              CursorInRevision(0, 49),
856
856
                              QStringList() << "test" << "blub");
857
857
}
858
858
 
861
861
    verifyExtendsOrImplements("<?php interface blub{} interface bar extends blub{}",
862
862
                              "interface test extends bar, ",
863
863
                              ClassDeclarationData::Interface,
864
 
                              SimpleCursor::invalid(),
 
864
                              CursorInRevision::invalid(),
865
865
                              QStringList() << "test" << "blub" << "bar");
866
866
 
867
867
    verifyExtendsOrImplements("<?php interface blub{} interface bar extends blub{}",
868
868
                              "class test implements bar, ",
869
869
                              ClassDeclarationData::Interface,
870
 
                              SimpleCursor::invalid(),
 
870
                              CursorInRevision::invalid(),
871
871
                              QStringList() << "blub" << "bar");
872
872
}
873
873
 
1033
1033
    DUChainWriteLocker lock(DUChain::lock());
1034
1034
 
1035
1035
    QCOMPARE(top->localDeclarations().size(), 1);
1036
 
    PhpCompletionTester tester(top, "", "", SimpleCursor(0, 3));
 
1036
    PhpCompletionTester tester(top, "", "", CursorInRevision(0, 3));
1037
1037
    // function _should_ be found
1038
1038
    QVERIFY(searchDeclaration(tester.items, top->localDeclarations().first()));
1039
1039
}
1047
1047
    DUChainWriteLocker lock(DUChain::lock());
1048
1048
 
1049
1049
    QCOMPARE(top->localDeclarations().size(), 1);
1050
 
    PhpCompletionTester tester(top, "", "", SimpleCursor(0, 3));
 
1050
    PhpCompletionTester tester(top, "", "", CursorInRevision(0, 3));
1051
1051
    // class _should_ be found
1052
1052
    QVERIFY(searchDeclaration(tester.items, top->localDeclarations().first()));
1053
1053
}
1061
1061
    DUChainWriteLocker lock(DUChain::lock());
1062
1062
 
1063
1063
    QCOMPARE(top->localDeclarations().size(), 1);
1064
 
    PhpCompletionTester tester(top, "", "", SimpleCursor(0, 3));
 
1064
    PhpCompletionTester tester(top, "", "", CursorInRevision(0, 3));
1065
1065
    // constant should _not_ be found
1066
1066
    QVERIFY(!searchDeclaration(tester.items, top->localDeclarations().first()));
1067
1067
}
1075
1075
    DUChainWriteLocker lock(DUChain::lock());
1076
1076
 
1077
1077
    QCOMPARE(top->localDeclarations().size(), 1);
1078
 
    PhpCompletionTester tester(top, "", "", SimpleCursor(0, 3));
 
1078
    PhpCompletionTester tester(top, "", "", CursorInRevision(0, 3));
1079
1079
    // variable should _not_ be found
1080
1080
    QVERIFY(!searchDeclaration(tester.items, top->localDeclarations().first()));
1081
1081
}