Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show First 20 Lines • Show All 1561 Lines • ▼ Show 20 Line(s) | |||||
1562 | void TestDUChain::fileConst() | 1562 | void TestDUChain::fileConst() | ||
1563 | { | 1563 | { | ||
1564 | QFETCH(QString, code); | 1564 | QFETCH(QString, code); | ||
1565 | QFETCH(int, problems); | 1565 | QFETCH(int, problems); | ||
1566 | QFETCH(uint, dataType); | 1566 | QFETCH(uint, dataType); | ||
1567 | 1567 | | |||
1568 | code.prepend("<?php "); | 1568 | code.prepend("<?php "); | ||
1569 | 1569 | | |||
1570 | DUChainWriteLocker lock; | ||||
1570 | TopDUContext* top = parse(code.toUtf8(), DumpNone); | 1571 | TopDUContext* top = parse(code.toUtf8(), DumpNone); | ||
1571 | QVERIFY(top); | 1572 | QVERIFY(top); | ||
1572 | DUChainReleaser releaseTop(top); | 1573 | DUChainReleaser releaseTop(top); | ||
1573 | DUChainWriteLocker lock; | | |||
1574 | 1574 | | |||
1575 | QCOMPARE(top->problems().count(), problems); | 1575 | QCOMPARE(top->problems().count(), problems); | ||
1576 | 1576 | | |||
1577 | QList< Declaration* > decs = top->findDeclarations(QualifiedIdentifier(QStringLiteral("C"))); | 1577 | QList< Declaration* > decs = top->findDeclarations(QualifiedIdentifier(QStringLiteral("C"))); | ||
1578 | QCOMPARE(decs.count(), 1); | 1578 | QCOMPARE(decs.count(), 1); | ||
1579 | IntegralType::Ptr type = decs.first()->abstractType().cast<IntegralType>(); | 1579 | IntegralType::Ptr type = decs.first()->abstractType().cast<IntegralType>(); | ||
1580 | QVERIFY(type); | 1580 | QVERIFY(type); | ||
1581 | QCOMPARE(type->dataType(), dataType); | 1581 | QCOMPARE(type->dataType(), dataType); | ||
▲ Show 20 Lines • Show All 1597 Lines • ▼ Show 20 Line(s) | 3161 | { | |||
3179 | QCOMPARE(top->childContexts().at(0)->localScopeIdentifier().toString(), QString("string")); | 3179 | QCOMPARE(top->childContexts().at(0)->localScopeIdentifier().toString(), QString("string")); | ||
3180 | 3180 | | |||
3181 | QCOMPARE(top->localDeclarations().size(), 1); | 3181 | QCOMPARE(top->localDeclarations().size(), 1); | ||
3182 | QCOMPARE(top->localDeclarations().at(0)->kind(), Declaration::Namespace); | 3182 | QCOMPARE(top->localDeclarations().at(0)->kind(), Declaration::Namespace); | ||
3183 | } | 3183 | } | ||
3184 | 3184 | | |||
3185 | void TestDUChain::useNamespace() | 3185 | void TestDUChain::useNamespace() | ||
3186 | { | 3186 | { | ||
3187 | DUChainWriteLocker lock; | ||||
3188 | | ||||
3187 | // 0 1 2 3 4 5 6 7 | 3189 | // 0 1 2 3 4 5 6 7 | ||
3188 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 3190 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
3189 | TopDUContext* top = parse("<?php\n" | 3191 | TopDUContext* top = parse("<?php\n" | ||
3190 | "namespace ns1\\ns2 {\n" | 3192 | "namespace ns1\\ns2 {\n" | ||
3191 | "function a(){}\n" | 3193 | "function a(){}\n" | ||
3192 | "const b = 0;\n" | 3194 | "const b = 0;\n" | ||
3193 | "class c {}\n" | 3195 | "class c {}\n" | ||
3194 | "}\n" | 3196 | "}\n" | ||
3195 | "namespace ns3\\ns4 {\n" | 3197 | "namespace ns3\\ns4 {\n" | ||
3196 | "function a(){}\n" | 3198 | "function a(){}\n" | ||
3197 | "const b = 0;\n" | 3199 | "const b = 0;\n" | ||
3198 | "class c {}\n" | 3200 | "class c {}\n" | ||
3199 | "}\n" | 3201 | "}\n" | ||
3200 | "namespace {\n" | 3202 | "namespace {\n" | ||
3201 | "use ns1\\ns2, ns3\\ns4 as ns5;\n" | 3203 | "use ns1\\ns2, ns3\\ns4 as ns5;\n" | ||
3202 | "use \\ns3\\ns4 as ns6;\n" | 3204 | "use \\ns3\\ns4 as ns6;\n" | ||
3203 | "}\n" | 3205 | "}\n" | ||
3204 | , DumpNone); | 3206 | , DumpNone); | ||
3205 | QVERIFY(top); | 3207 | QVERIFY(top); | ||
3206 | DUChainReleaser releaseTop(top); | 3208 | DUChainReleaser releaseTop(top); | ||
3207 | DUChainWriteLocker lock; | | |||
3208 | 3209 | | |||
3209 | QCOMPARE(top->localDeclarations().count(), 5); | 3210 | QCOMPARE(top->localDeclarations().count(), 5); | ||
3210 | 3211 | | |||
3211 | Declaration* dec = top->localDeclarations().at(2); | 3212 | Declaration* dec = top->localDeclarations().at(2); | ||
3212 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("ns2")); | 3213 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("ns2")); | ||
3213 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | 3214 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | ||
3214 | 3215 | | |||
3215 | dec = top->localDeclarations().at(3); | 3216 | dec = top->localDeclarations().at(3); | ||
3216 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("ns5")); | 3217 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("ns5")); | ||
3217 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | 3218 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | ||
3218 | 3219 | | |||
3219 | dec = top->localDeclarations().at(4); | 3220 | dec = top->localDeclarations().at(4); | ||
3220 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("ns6")); | 3221 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("ns6")); | ||
3221 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | 3222 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | ||
3222 | ///TODO: find out why this is explictly required | 3223 | ///TODO: find out why this is explictly required | ||
3223 | QVERIFY(!dynamic_cast<NamespaceAliasDeclaration*>(dec)->importIdentifier().explicitlyGlobal()); | 3224 | QVERIFY(!dynamic_cast<NamespaceAliasDeclaration*>(dec)->importIdentifier().explicitlyGlobal()); | ||
3224 | } | 3225 | } | ||
3225 | 3226 | | |||
3226 | void TestDUChain::useBaseTypeNamespace() | 3227 | void TestDUChain::useBaseTypeNamespace() | ||
3227 | { | 3228 | { | ||
3229 | DUChainWriteLocker lock; | ||||
3230 | | ||||
3228 | // 0 1 2 3 4 5 6 7 | 3231 | // 0 1 2 3 4 5 6 7 | ||
3229 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 3232 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
3230 | TopDUContext* top = parse("<?php\n" | 3233 | TopDUContext* top = parse("<?php\n" | ||
3231 | "namespace ns1\\string {\n" | 3234 | "namespace ns1\\string {\n" | ||
3232 | "function a(){}\n" | 3235 | "function a(){}\n" | ||
3233 | "const b = 0;\n" | 3236 | "const b = 0;\n" | ||
3234 | "class c {}\n" | 3237 | "class c {}\n" | ||
3235 | "}\n" | 3238 | "}\n" | ||
3236 | "namespace ns3\\iterable {\n" | 3239 | "namespace ns3\\iterable {\n" | ||
3237 | "function a(){}\n" | 3240 | "function a(){}\n" | ||
3238 | "const b = 0;\n" | 3241 | "const b = 0;\n" | ||
3239 | "class c {}\n" | 3242 | "class c {}\n" | ||
3240 | "}\n" | 3243 | "}\n" | ||
3241 | "namespace {\n" | 3244 | "namespace {\n" | ||
3242 | "use ns1\\string, ns3\\iterable;\n" | 3245 | "use ns1\\string, ns3\\iterable;\n" | ||
3243 | "}\n" | 3246 | "}\n" | ||
3244 | , DumpNone); | 3247 | , DumpNone); | ||
3245 | QVERIFY(top); | 3248 | QVERIFY(top); | ||
3246 | DUChainReleaser releaseTop(top); | 3249 | DUChainReleaser releaseTop(top); | ||
3247 | DUChainWriteLocker lock; | | |||
3248 | 3250 | | |||
3249 | QCOMPARE(top->localDeclarations().count(), 4); | 3251 | QCOMPARE(top->localDeclarations().count(), 4); | ||
3250 | 3252 | | |||
3251 | Declaration* dec = top->localDeclarations().at(2); | 3253 | Declaration* dec = top->localDeclarations().at(2); | ||
3252 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("string")); | 3254 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("string")); | ||
3253 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | 3255 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | ||
3254 | 3256 | | |||
3255 | dec = top->localDeclarations().at(3); | 3257 | dec = top->localDeclarations().at(3); | ||
3256 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("iterable")); | 3258 | QCOMPARE(dec->qualifiedIdentifier().toString(), QString("iterable")); | ||
3257 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | 3259 | QVERIFY(dynamic_cast<NamespaceAliasDeclaration*>(dec)); | ||
3258 | } | 3260 | } | ||
3259 | 3261 | | |||
3260 | void TestDUChain::useNamespaceBaseTypeAlias() | 3262 | void TestDUChain::useNamespaceBaseTypeAlias() | ||
3261 | { | 3263 | { | ||
3264 | DUChainWriteLocker lock(DUChain::lock()); | ||||
3265 | | ||||
3262 | // 0 1 2 3 4 5 6 7 | 3266 | // 0 1 2 3 4 5 6 7 | ||
3263 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 3267 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
3264 | TopDUContext* top = parse("<?php\n" | 3268 | TopDUContext* top = parse("<?php\n" | ||
3265 | "namespace ns1\\string {\n" | 3269 | "namespace ns1\\string {\n" | ||
3266 | "function a(){}\n" | 3270 | "function a(){}\n" | ||
3267 | "const b = 0;\n" | 3271 | "const b = 0;\n" | ||
3268 | "class c {}\n" | 3272 | "class c {}\n" | ||
3269 | "}\n" | 3273 | "}\n" | ||
3270 | "namespace ns3\\iterable {\n" | 3274 | "namespace ns3\\iterable {\n" | ||
3271 | "function a(){}\n" | 3275 | "function a(){}\n" | ||
3272 | "const b = 0;\n" | 3276 | "const b = 0;\n" | ||
3273 | "class c {}\n" | 3277 | "class c {}\n" | ||
3274 | "}\n" | 3278 | "}\n" | ||
3275 | "namespace {\n" | 3279 | "namespace {\n" | ||
3276 | "use ns1\\string as iterable, ns3\\iterable as bool;\n" | 3280 | "use ns1\\string as iterable, ns3\\iterable as bool;\n" | ||
3277 | "}\n" | 3281 | "}\n" | ||
3278 | , DumpNone); | 3282 | , DumpNone); | ||
3279 | QVERIFY(top); | 3283 | QVERIFY(top); | ||
3280 | DUChainReleaser releaseTop(top); | 3284 | DUChainReleaser releaseTop(top); | ||
3281 | DUChainWriteLocker lock(DUChain::lock()); | | |||
3282 | 3285 | | |||
3283 | QCOMPARE(top->problems().count(), 2); | 3286 | QCOMPARE(top->problems().count(), 2); | ||
3284 | } | 3287 | } | ||
3285 | 3288 | | |||
3286 | void TestDUChain::namespaceStaticVar() | 3289 | void TestDUChain::namespaceStaticVar() | ||
3287 | { | 3290 | { | ||
3288 | // 0 1 2 3 4 5 6 7 | 3291 | // 0 1 2 3 4 5 6 7 | ||
3289 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 3292 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Line(s) | 3372 | << (QList<TestUse>() | |||
3373 | ); | 3376 | ); | ||
3374 | } | 3377 | } | ||
3375 | 3378 | | |||
3376 | void TestDUChain::errorRecovery() | 3379 | void TestDUChain::errorRecovery() | ||
3377 | { | 3380 | { | ||
3378 | QFETCH(QString, code); | 3381 | QFETCH(QString, code); | ||
3379 | QFETCH(QList<TestUse>, usesMap); | 3382 | QFETCH(QList<TestUse>, usesMap); | ||
3380 | 3383 | | |||
3384 | DUChainWriteLocker lock; | ||||
3385 | | ||||
3381 | TopDUContext* top = parse(code.toLocal8Bit(), DumpAll); | 3386 | TopDUContext* top = parse(code.toLocal8Bit(), DumpAll); | ||
3382 | 3387 | | |||
3383 | QVERIFY(top); | 3388 | QVERIFY(top); | ||
3384 | 3389 | | |||
3385 | DUChainReleaser releaseTop(top); | 3390 | DUChainReleaser releaseTop(top); | ||
3386 | DUChainWriteLocker lock; | | |||
3387 | 3391 | | |||
3388 | foreach ( const TestUse& use, usesMap ) { | 3392 | foreach ( const TestUse& use, usesMap ) { | ||
3389 | QList< Declaration* > decs = top->findDeclarations(use.id); | 3393 | QList< Declaration* > decs = top->findDeclarations(use.id); | ||
3390 | QCOMPARE(decs.count(), 1); | 3394 | QCOMPARE(decs.count(), 1); | ||
3391 | Declaration* dec = decs.first(); | 3395 | Declaration* dec = decs.first(); | ||
3392 | QCOMPARE(dec->kind(), use.kind); | 3396 | QCOMPARE(dec->kind(), use.kind); | ||
3393 | if (use.uses) { | 3397 | if (use.uses) { | ||
3394 | QCOMPARE(dec->uses().count(), 1); | 3398 | QCOMPARE(dec->uses().count(), 1); | ||
▲ Show 20 Lines • Show All 382 Lines • Show Last 20 Lines |