Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/uses.cpp
Show First 20 Lines • Show All 384 Lines • ▼ Show 20 Line(s) | 380 | { | |||
---|---|---|---|---|---|
385 | DUChainReleaser releaseTop(top); | 385 | DUChainReleaser releaseTop(top); | ||
386 | DUChainWriteLocker lock(DUChain::lock()); | 386 | DUChainWriteLocker lock(DUChain::lock()); | ||
387 | 387 | | |||
388 | compareUses(top->localDeclarations().first(), RangeInRevision(0, 43, 0, 44)); | 388 | compareUses(top->localDeclarations().first(), RangeInRevision(0, 43, 0, 44)); | ||
389 | compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 46, 0, 50)); | 389 | compareUses(top->childContexts().first()->localDeclarations().first(), RangeInRevision(0, 46, 0, 50)); | ||
390 | compareUses(top->localDeclarations().at(1), RangeInRevision(0, 52, 0, 56)); | 390 | compareUses(top->localDeclarations().at(1), RangeInRevision(0, 52, 0, 56)); | ||
391 | } | 391 | } | ||
392 | 392 | | |||
393 | void TestUses::dynamicStaticMemberVariable() | ||||
394 | { | ||||
395 | // 0 1 2 3 4 5 6 7 | ||||
396 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||||
397 | QByteArray method("<? class A { public static $foo; } $var='foo'; A::${$var};"); | ||||
398 | TopDUContext* top = parse(method, DumpAll); | ||||
399 | DUChainReleaser releaseTop(top); | ||||
400 | DUChainWriteLocker lock(DUChain::lock()); | ||||
401 | | ||||
402 | Declaration* dec = top->localDeclarations().at(0); | ||||
403 | QCOMPARE(dec->identifier(), Identifier("a")); | ||||
404 | compareUses(dec, QList<RangeInRevision>() | ||||
405 | << RangeInRevision(0, 47, 0, 48)); | ||||
406 | | ||||
407 | dec = top->localDeclarations().at(1); | ||||
408 | QCOMPARE(dec->identifier(), Identifier("var")); | ||||
409 | compareUses(dec, QList<RangeInRevision>() | ||||
410 | << RangeInRevision(0, 52, 0, 56)); | ||||
411 | } | ||||
412 | | ||||
393 | void TestUses::constant() | 413 | void TestUses::constant() | ||
394 | { | 414 | { | ||
395 | // 0 1 2 3 4 5 6 7 | 415 | // 0 1 2 3 4 5 6 7 | ||
396 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 416 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
397 | QByteArray method("<? define('A', 'foo'); echo A;"); | 417 | QByteArray method("<? define('A', 'foo'); echo A;"); | ||
398 | TopDUContext* top = parse(method, DumpAll); | 418 | TopDUContext* top = parse(method, DumpAll); | ||
399 | DUChainReleaser releaseTop(top); | 419 | DUChainReleaser releaseTop(top); | ||
400 | DUChainWriteLocker lock(DUChain::lock()); | 420 | DUChainWriteLocker lock(DUChain::lock()); | ||
▲ Show 20 Lines • Show All 927 Lines • ▼ Show 20 Line(s) | 1346 | compareUses(dec, QList<RangeInRevision>() | |||
1328 | << RangeInRevision(3, 44, 3, 48)); | 1348 | << RangeInRevision(3, 44, 3, 48)); | ||
1329 | 1349 | | |||
1330 | dec = top->localDeclarations().at(3); | 1350 | dec = top->localDeclarations().at(3); | ||
1331 | QCOMPARE(dec->identifier(), Identifier("bar")); | 1351 | QCOMPARE(dec->identifier(), Identifier("bar")); | ||
1332 | compareUses(dec, QList<RangeInRevision>() | 1352 | compareUses(dec, QList<RangeInRevision>() | ||
1333 | << RangeInRevision(3, 38, 3, 42)); | 1353 | << RangeInRevision(3, 38, 3, 42)); | ||
1334 | } | 1354 | } | ||
1335 | 1355 | | |||
1356 | void TestUses::instanceofDynamicStaticProperty() | ||||
1357 | { | ||||
1358 | // 0 1 2 3 4 5 | ||||
1359 | // 012345678901234567890123456789012345678901234567890123456789 | ||||
1360 | TopDUContext* top = parse("<? class A { /** @var B **/ public $foo; }\n" | ||||
1361 | "class B { /** @var A **/ public $bar; }\n" | ||||
1362 | "$foo = 'foo'; $bar = 'bar';\n" | ||||
1363 | "$a = new A(); $a instanceof $a::${$foo}::${$bar}::${$foo};\n", DumpNone); | ||||
1364 | | ||||
1365 | QVERIFY(top); | ||||
1366 | DUChainReleaser releaseTop(top); | ||||
1367 | DUChainWriteLocker lock; | ||||
1368 | | ||||
1369 | QVERIFY(top->problems().isEmpty()); | ||||
1370 | | ||||
1371 | QVERIFY(!top->parentContext()); | ||||
1372 | QCOMPARE(top->childContexts().count(), 2); | ||||
1373 | QCOMPARE(top->localDeclarations().count(), 5); | ||||
1374 | | ||||
1375 | Declaration* dec = top->localDeclarations().at(0); | ||||
1376 | QCOMPARE(dec->identifier(), Identifier("a")); | ||||
1377 | compareUses(dec, QList<RangeInRevision>() | ||||
1378 | << RangeInRevision(3, 9, 3, 10)); | ||||
1379 | | ||||
1380 | dec = top->localDeclarations().at(4); | ||||
1381 | QCOMPARE(dec->identifier(), Identifier("a")); | ||||
1382 | StructureType::Ptr classType = dec->type<StructureType>(); | ||||
1383 | QVERIFY(classType); | ||||
1384 | QCOMPARE(classType->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||||
1385 | QVERIFY(classType->equals(dec->abstractType().data())); | ||||
1386 | compareUses(dec, QList<RangeInRevision>() | ||||
1387 | << RangeInRevision(3, 14, 3, 16) | ||||
1388 | << RangeInRevision(3, 28, 3, 30)); | ||||
1389 | | ||||
1390 | dec = top->localDeclarations().at(2); | ||||
1391 | QCOMPARE(dec->identifier(), Identifier("foo")); | ||||
1392 | compareUses(dec, QList<RangeInRevision>() | ||||
1393 | << RangeInRevision(3, 34, 3, 38) | ||||
1394 | << RangeInRevision(3, 52, 3, 56)); | ||||
1395 | | ||||
1396 | dec = top->localDeclarations().at(3); | ||||
1397 | QCOMPARE(dec->identifier(), Identifier("bar")); | ||||
1398 | compareUses(dec, QList<RangeInRevision>() | ||||
1399 | << RangeInRevision(3, 43, 3, 47)); | ||||
1400 | } | ||||
1401 | | ||||
1402 | void TestUses::instanceofDynamicVariableProperty() | ||||
1403 | { | ||||
1404 | // 0 1 2 3 4 5 | ||||
1405 | // 012345678901234567890123456789012345678901234567890123456789 | ||||
1406 | TopDUContext* top = parse("<? class A { /** @var B **/ public $foo; }\n" | ||||
1407 | "class B { /** @var A **/ public $bar; }\n" | ||||
1408 | "$foo = 'foo'; $bar = 'bar';\n" | ||||
1409 | "$a = new A(); $a instanceof $a->${$foo}->${$bar}->${$foo};\n", DumpNone); | ||||
1410 | | ||||
1411 | QVERIFY(top); | ||||
1412 | DUChainReleaser releaseTop(top); | ||||
1413 | DUChainWriteLocker lock; | ||||
1414 | | ||||
1415 | QVERIFY(top->problems().isEmpty()); | ||||
1416 | | ||||
1417 | QVERIFY(!top->parentContext()); | ||||
1418 | QCOMPARE(top->childContexts().count(), 2); | ||||
1419 | QCOMPARE(top->localDeclarations().count(), 5); | ||||
1420 | | ||||
1421 | Declaration* dec = top->localDeclarations().at(0); | ||||
1422 | QCOMPARE(dec->identifier(), Identifier("a")); | ||||
1423 | compareUses(dec, QList<RangeInRevision>() | ||||
kfunk: Minor, for future: you can use C++11-style initialization here: `QList<RangeInRevision>{...}`… | |||||
1424 | << RangeInRevision(3, 9, 3, 10)); | ||||
1425 | | ||||
1426 | dec = top->localDeclarations().at(4); | ||||
1427 | QCOMPARE(dec->identifier(), Identifier("a")); | ||||
1428 | StructureType::Ptr classType = dec->type<StructureType>(); | ||||
1429 | QVERIFY(classType); | ||||
1430 | QCOMPARE(classType->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||||
1431 | QVERIFY(classType->equals(dec->abstractType().data())); | ||||
1432 | compareUses(dec, QList<RangeInRevision>() | ||||
1433 | << RangeInRevision(3, 14, 3, 16) | ||||
1434 | << RangeInRevision(3, 28, 3, 30)); | ||||
1435 | | ||||
1436 | dec = top->localDeclarations().at(2); | ||||
1437 | QCOMPARE(dec->identifier(), Identifier("foo")); | ||||
1438 | compareUses(dec, QList<RangeInRevision>() | ||||
1439 | << RangeInRevision(3, 34, 3, 38) | ||||
1440 | << RangeInRevision(3, 52, 3, 56)); | ||||
1441 | | ||||
1442 | dec = top->localDeclarations().at(3); | ||||
1443 | QCOMPARE(dec->identifier(), Identifier("bar")); | ||||
1444 | compareUses(dec, QList<RangeInRevision>() | ||||
1445 | << RangeInRevision(3, 43, 3, 47)); | ||||
1446 | } | ||||
1447 | | ||||
1336 | void TestUses::instanceofPropertyArrayAccess() | 1448 | void TestUses::instanceofPropertyArrayAccess() | ||
1337 | { | 1449 | { | ||
1338 | // 0 1 2 3 4 5 | 1450 | // 0 1 2 3 4 5 | ||
1339 | // 012345678901234567890123456789012345678901234567890123456789 | 1451 | // 012345678901234567890123456789012345678901234567890123456789 | ||
1340 | TopDUContext* top = parse("<? class A { /** @var array **/ public $foo; }\n" | 1452 | TopDUContext* top = parse("<? class A { /** @var array **/ public $foo; }\n" | ||
1341 | "class B { /** @var array **/ public static $bar; }\n" | 1453 | "class B { /** @var array **/ public static $bar; }\n" | ||
1342 | "$a = new A(); $a instanceof $a->foo[0]::$bar[0]->foo;\n", DumpNone); | 1454 | "$a = new A(); $a instanceof $a->foo[0]::$bar[0]->foo;\n", DumpNone); | ||
1343 | 1455 | | |||
▲ Show 20 Lines • Show All 246 Lines • Show Last 20 Lines |
Minor, for future: you can use C++11-style initialization here: QList<RangeInRevision>{...}
More TODO: Should be a QVector<RangeInRevision> for performance reasons.