Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/duchain.cpp
Show First 20 Lines • Show All 472 Lines • ▼ Show 20 Line(s) | 419 | { | |||
---|---|---|---|---|---|
473 | QVERIFY(var); | 473 | QVERIFY(var); | ||
474 | QCOMPARE(var->identifier(), Identifier("boo")); | 474 | QCOMPARE(var->identifier(), Identifier("boo")); | ||
475 | QCOMPARE(var->accessPolicy(), Declaration::Public); | 475 | QCOMPARE(var->accessPolicy(), Declaration::Public); | ||
476 | QCOMPARE(var->isStatic(), false); | 476 | QCOMPARE(var->isStatic(), false); | ||
477 | QVERIFY(var->type<IntegralType>()); | 477 | QVERIFY(var->type<IntegralType>()); | ||
478 | QVERIFY(var->type<IntegralType>()->dataType() == IntegralType::TypeInt); | 478 | QVERIFY(var->type<IntegralType>()->dataType() == IntegralType::TypeInt); | ||
479 | } | 479 | } | ||
480 | 480 | | |||
481 | void TestDUChain::classMemberVarTypehint() | ||||
482 | { | ||||
483 | //Note: in practice, Traversable is defined by php, but this interface is not loaded in this test, so define it ourselves | ||||
484 | // 0 1 2 3 4 5 6 7 | ||||
485 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||||
486 | QByteArray method("<? interface Traversable { } class A { public iterable $foo; protected A $bar; private static ?string $baz; public int $boo = 1; }"); | ||||
487 | | ||||
488 | TopDUContext* top = parse(method, DumpNone); | ||||
489 | DUChainReleaser releaseTop(top); | ||||
490 | DUChainWriteLocker lock(DUChain::lock()); | ||||
491 | | ||||
492 | QVERIFY(!top->parentContext()); | ||||
493 | QCOMPARE(top->childContexts().count(), 2); | ||||
494 | | ||||
495 | DUContext* contextClassA = top->childContexts().at(1); | ||||
496 | | ||||
497 | QCOMPARE(top->localDeclarations().count(), 2); | ||||
498 | Declaration* dec = top->localDeclarations().at(1); | ||||
499 | QCOMPARE(dec->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||||
500 | QCOMPARE(dec->isDefinition(), true); | ||||
501 | QCOMPARE(dec->logicalInternalContext(top), contextClassA); | ||||
502 | | ||||
503 | QCOMPARE(contextClassA->localScopeIdentifier(), QualifiedIdentifier("a")); | ||||
504 | QCOMPARE(contextClassA->childContexts().count(), 0); | ||||
505 | QCOMPARE(contextClassA->localDeclarations().count(), 4); | ||||
506 | | ||||
507 | TypePtr<UnsureType> ut; | ||||
508 | | ||||
509 | //$foo | ||||
510 | ClassMemberDeclaration* var = dynamic_cast<ClassMemberDeclaration*>(contextClassA->localDeclarations().first()); | ||||
511 | QVERIFY(var); | ||||
512 | QCOMPARE(var->identifier(), Identifier("foo")); | ||||
513 | QCOMPARE(var->accessPolicy(), Declaration::Public); | ||||
514 | QCOMPARE(var->isStatic(), false); | ||||
515 | QVERIFY(var->type<UnsureType>()); | ||||
516 | | ||||
517 | ut = var->type<UnsureType>(); | ||||
518 | QVERIFY(ut); | ||||
519 | QCOMPARE(2u, ut->typesSize()); | ||||
520 | | ||||
521 | QVERIFY(ut->types()[0].type<IntegralType>()); | ||||
522 | QVERIFY(ut->types()[0].type<IntegralType>()->dataType() == IntegralType::TypeArray); | ||||
523 | | ||||
524 | QVERIFY(ut->types()[1].type<StructureType>()); | ||||
525 | QVERIFY(ut->types()[1].type<StructureType>()->declaration(top)); | ||||
526 | QCOMPARE(ut->types()[1].type<StructureType>()->declaration(top)->qualifiedIdentifier(), QualifiedIdentifier("traversable")); | ||||
527 | | ||||
528 | //$bar | ||||
529 | var = dynamic_cast<ClassMemberDeclaration*>(contextClassA->localDeclarations().at(1)); | ||||
530 | QVERIFY(var); | ||||
531 | QCOMPARE(var->identifier(), Identifier("bar")); | ||||
532 | QCOMPARE(var->accessPolicy(), Declaration::Protected); | ||||
533 | QCOMPARE(var->isStatic(), false); | ||||
534 | StructureType::Ptr type = var->type<StructureType>(); | ||||
535 | QVERIFY(type); | ||||
536 | QCOMPARE(type->qualifiedIdentifier(), QualifiedIdentifier("a")); | ||||
537 | | ||||
538 | //$baz | ||||
539 | var = dynamic_cast<ClassMemberDeclaration*>(contextClassA->localDeclarations().at(2)); | ||||
540 | QVERIFY(var); | ||||
541 | QCOMPARE(var->identifier(), Identifier("baz")); | ||||
542 | QCOMPARE(var->accessPolicy(), Declaration::Private); | ||||
543 | QCOMPARE(var->isStatic(), true); | ||||
544 | QVERIFY(var->type<UnsureType>()); | ||||
545 | ut = var->type<UnsureType>(); | ||||
546 | QVERIFY(ut); | ||||
547 | QCOMPARE(2u, ut->typesSize()); | ||||
548 | | ||||
549 | QVERIFY(ut->types()[0].type<IntegralType>()); | ||||
550 | QVERIFY(ut->types()[0].type<IntegralType>()->dataType() == IntegralType::TypeString); | ||||
551 | | ||||
552 | QVERIFY(ut->types()[1].type<IntegralType>()); | ||||
553 | QVERIFY(ut->types()[1].type<IntegralType>()->dataType() == IntegralType::TypeNull); | ||||
554 | | ||||
555 | //$boo | ||||
556 | var = dynamic_cast<ClassMemberDeclaration*>(contextClassA->localDeclarations().at(3)); | ||||
557 | QVERIFY(var); | ||||
558 | QCOMPARE(var->identifier(), Identifier("boo")); | ||||
559 | QCOMPARE(var->accessPolicy(), Declaration::Public); | ||||
560 | QCOMPARE(var->isStatic(), false); | ||||
561 | QVERIFY(var->type<IntegralType>()); | ||||
562 | QVERIFY(var->type<IntegralType>()->dataType() == IntegralType::TypeInt); | ||||
563 | } | ||||
564 | | ||||
481 | void TestDUChain::classMemberVarAfterUse() | 565 | void TestDUChain::classMemberVarAfterUse() | ||
482 | { | 566 | { | ||
483 | // 0 1 2 3 4 5 6 7 | 567 | // 0 1 2 3 4 5 6 7 | ||
484 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 568 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
485 | QByteArray method("<?php class B { function x() { $this->a = 1; } public $a = 1; }"); | 569 | QByteArray method("<?php class B { function x() { $this->a = 1; } public $a = 1; }"); | ||
486 | 570 | | |||
487 | TopDUContext* top = parse(method, DumpNone); | 571 | TopDUContext* top = parse(method, DumpNone); | ||
488 | DUChainReleaser releaseTop(top); | 572 | DUChainReleaser releaseTop(top); | ||
▲ Show 20 Lines • Show All 3181 Lines • ▼ Show 20 Line(s) | |||||
3670 | 3754 | | |||
3671 | void TestDUChain::varStatic() | 3755 | void TestDUChain::varStatic() | ||
3672 | { | 3756 | { | ||
3673 | //bug: https://bugs.kde.org/244076 | 3757 | //bug: https://bugs.kde.org/244076 | ||
3674 | 3758 | | |||
3675 | // 0 1 2 3 4 5 6 7 | 3759 | // 0 1 2 3 4 5 6 7 | ||
3676 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | 3760 | // 01234567890123456789012345678901234567890123456789012345678901234567890123456789 | ||
3677 | TopDUContext* top = parse("<?php\n" | 3761 | TopDUContext* top = parse("<?php\n" | ||
3678 | "class c { static a = 1; static function foo() {} }\n" | 3762 | "class c { const a = 1; static function foo() {} }\n" | ||
3679 | "$o = 'c';\n" | 3763 | "$o = 'c';\n" | ||
3680 | "$o::a;\n" | 3764 | "$o::a;\n" | ||
3681 | "$o::foo();\n" | 3765 | "$o::foo();\n" | ||
3682 | , DumpNone); | 3766 | , DumpNone); | ||
3683 | QVERIFY(top); | 3767 | QVERIFY(top); | ||
3684 | DUChainReleaser releaseTop(top); | 3768 | DUChainReleaser releaseTop(top); | ||
3685 | DUChainWriteLocker lock; | 3769 | DUChainWriteLocker lock; | ||
3686 | QVERIFY(top->problems().empty()); | 3770 | QVERIFY(top->problems().empty()); | ||
▲ Show 20 Lines • Show All 520 Lines • Show Last 20 Lines |