Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/uses.cpp
Show First 20 Lines • Show All 915 Lines • ▼ Show 20 Line(s) | 901 | { | |||
---|---|---|---|---|---|
916 | 916 | | |||
917 | // $b | 917 | // $b | ||
918 | d = top->childContexts().at(0)->localDeclarations().at(1); | 918 | d = top->childContexts().at(0)->localDeclarations().at(1); | ||
919 | compareUses(d, RangeInRevision(0, 35, 0, 37)); | 919 | compareUses(d, RangeInRevision(0, 35, 0, 37)); | ||
920 | } | 920 | } | ||
921 | 921 | | |||
922 | void TestUses::namespaces() | 922 | void TestUses::namespaces() | ||
923 | { | 923 | { | ||
924 | DUChainWriteLocker lock; | ||||
925 | | ||||
924 | // 0 1 2 3 4 5 6 7 | 926 | // 0 1 2 3 4 5 6 7 | ||
925 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 927 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
926 | TopDUContext* top = parse("<?php\n" | 928 | TopDUContext* top = parse("<?php\n" | ||
927 | "namespace Foo\\Bar {\n" | 929 | "namespace Foo\\Bar {\n" | ||
928 | "const MyConst = 1;\n" | 930 | "const MyConst = 1;\n" | ||
929 | "$z = MyConst;\n" | 931 | "$z = MyConst;\n" | ||
930 | "function MyFunc(){}\n" | 932 | "function MyFunc(){}\n" | ||
931 | "class MyClass{ const ClassConst = 2; }\n" | 933 | "class MyClass{ const ClassConst = 2; }\n" | ||
932 | "interface MyInterface{}\n" | 934 | "interface MyInterface{}\n" | ||
933 | "}\n" | 935 | "}\n" | ||
934 | "namespace {\n" | 936 | "namespace {\n" | ||
935 | "\\Foo\\Bar\\MyConst;\n" | 937 | "\\Foo\\Bar\\MyConst;\n" | ||
936 | "\\Foo\\Bar\\MyClass::ClassConst;\n" | 938 | "\\Foo\\Bar\\MyClass::ClassConst;\n" | ||
937 | "\\Foo\\Bar\\MyFunc();\n" | 939 | "\\Foo\\Bar\\MyFunc();\n" | ||
938 | "new \\Foo\\Bar\\MyClass;\n" | 940 | "new \\Foo\\Bar\\MyClass;\n" | ||
939 | "function Func(\\Foo\\Bar\\MyClass $a){}\n" | 941 | "function Func(\\Foo\\Bar\\MyClass $a){}\n" | ||
940 | "class a extends \\Foo\\Bar\\MyClass implements \\Foo\\Bar\\MyInterface {}\n" | 942 | "class a extends \\Foo\\Bar\\MyClass implements \\Foo\\Bar\\MyInterface {}\n" | ||
941 | "}\n" | 943 | "}\n" | ||
942 | "namespace Foo {\n" | 944 | "namespace Foo {\n" | ||
943 | "}\n", DumpAll); | 945 | "}\n", DumpAll); | ||
944 | QVERIFY(top); | 946 | QVERIFY(top); | ||
945 | DUChainReleaser releaseTop(top); | 947 | DUChainReleaser releaseTop(top); | ||
946 | DUChainWriteLocker lock; | | |||
947 | 948 | | |||
948 | Declaration* dec; | 949 | Declaration* dec; | ||
949 | 950 | | |||
950 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo"))).last(); | 951 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo"))).last(); | ||
951 | QCOMPARE(dec->kind(), Declaration::Namespace); | 952 | QCOMPARE(dec->kind(), Declaration::Namespace); | ||
952 | compareUses(dec, QList<RangeInRevision>() | 953 | compareUses(dec, QList<RangeInRevision>() | ||
953 | << RangeInRevision(9, 1, 9, 4) | 954 | << RangeInRevision(9, 1, 9, 4) | ||
954 | << RangeInRevision(10, 1, 10, 4) | 955 | << RangeInRevision(10, 1, 10, 4) | ||
Show All 37 Lines | |||||
992 | compareUses(dec, RangeInRevision(10, 18, 10, 28)); | 993 | compareUses(dec, RangeInRevision(10, 18, 10, 28)); | ||
993 | 994 | | |||
994 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo::bar::myfunc"))).first(); | 995 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo::bar::myfunc"))).first(); | ||
995 | compareUses(dec, RangeInRevision(11, 9, 11, 15)); | 996 | compareUses(dec, RangeInRevision(11, 9, 11, 15)); | ||
996 | } | 997 | } | ||
997 | 998 | | |||
998 | void TestUses::useNamespace() | 999 | void TestUses::useNamespace() | ||
999 | { | 1000 | { | ||
1001 | DUChainWriteLocker lock; | ||||
1002 | | ||||
1000 | // 0 1 2 3 4 5 6 7 | 1003 | // 0 1 2 3 4 5 6 7 | ||
1001 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 1004 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
1002 | TopDUContext* top = parse("<?php\n" | 1005 | TopDUContext* top = parse("<?php\n" | ||
1003 | "namespace Foo\\Bar {class A{} function B(){} const C = 1;}\n" | 1006 | "namespace Foo\\Bar {class A{} function B(){} const C = 1;}\n" | ||
1004 | "namespace VeryLong {class A{} function B(){} const C = 1;}\n" | 1007 | "namespace VeryLong {class A{} function B(){} const C = 1;}\n" | ||
1005 | "namespace Baz {class A{} const C = 1;}\n" | 1008 | "namespace Baz {class A{} const C = 1;}\n" | ||
1006 | "namespace {\n" | 1009 | "namespace {\n" | ||
1007 | "use Foo\\Bar, VeryLong as Short;\n" | 1010 | "use Foo\\Bar, VeryLong as Short;\n" | ||
1008 | "use Baz\\A as Bazaar;\n" | 1011 | "use Baz\\A as Bazaar;\n" | ||
1009 | "new Bar\\A; Bar\\B(); Bar\\C;\n" | 1012 | "new Bar\\A; Bar\\B(); Bar\\C;\n" | ||
1010 | "new Short\\A; Short\\B(); Short\\C;\n" | 1013 | "new Short\\A; Short\\B(); Short\\C;\n" | ||
1011 | "new Bazaar;\n" | 1014 | "new Bazaar;\n" | ||
1012 | "}\n", DumpNone); | 1015 | "}\n", DumpNone); | ||
1013 | QVERIFY(top); | 1016 | QVERIFY(top); | ||
1014 | DUChainReleaser releaseTop(top); | 1017 | DUChainReleaser releaseTop(top); | ||
1015 | DUChainWriteLocker lock; | | |||
1016 | 1018 | | |||
1017 | Declaration* dec; | 1019 | Declaration* dec; | ||
1018 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo"))).first(); | 1020 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo"))).first(); | ||
1019 | QCOMPARE(dec->kind(), Declaration::Namespace); | 1021 | QCOMPARE(dec->kind(), Declaration::Namespace); | ||
1020 | compareUses(dec, RangeInRevision(5, 4, 5, 7)); | 1022 | compareUses(dec, RangeInRevision(5, 4, 5, 7)); | ||
1021 | 1023 | | |||
1022 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo::bar"))).first(); | 1024 | dec = top->findDeclarations(QualifiedIdentifier(QStringLiteral("foo::bar"))).first(); | ||
1023 | QCOMPARE(dec->kind(), Declaration::Namespace); | 1025 | QCOMPARE(dec->kind(), Declaration::Namespace); | ||
▲ Show 20 Lines • Show All 318 Lines • Show Last 20 Lines |