Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/testduchain.cpp
Show First 20 Lines • Show All 339 Lines • ▼ Show 20 Line(s) | |||||
340 | void TestDuchain::test_funccontexts() | 340 | void TestDuchain::test_funccontexts() | ||
341 | { | 341 | { | ||
342 | QString code("package main; type mytype int; func (i mytype) main(a, b string, c float64) (d, e int) { var f mytype; }"); | 342 | QString code("package main; type mytype int; func (i mytype) main(a, b string, c float64) (d, e int) { var f mytype; }"); | ||
343 | DUContext* context = getPackageContext(code); | 343 | DUContext* context = getPackageContext(code); | ||
344 | QVERIFY(context); | 344 | QVERIFY(context); | ||
345 | DUChainReadLocker lock; | 345 | DUChainReadLocker lock; | ||
346 | auto decls = context->findDeclarations(QualifiedIdentifier("mytype::main")); | 346 | auto decls = context->findDeclarations(QualifiedIdentifier("mytype::main")); | ||
347 | QCOMPARE(decls.size(), 1); | 347 | QCOMPARE(decls.size(), 1); | ||
348 | AbstractFunctionDeclaration* function = dynamic_cast<AbstractFunctionDeclaration*>(decls.first()); | 348 | auto function = dynamic_cast<go::GoFunctionDeclaration*>(decls.first()); | ||
349 | QVERIFY(function); | 349 | QVERIFY(function); | ||
350 | context = function->internalFunctionContext(); | 350 | context = function->internalContext(); | ||
351 | QCOMPARE(context->localDeclarations().size(), 1); | 351 | QCOMPARE(context->localDeclarations().size(), 2); | ||
352 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("i")).size(), 1); | 352 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("i")).size(), 1); | ||
353 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("a")).size(), 1); | 353 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("a")).size(), 1); | ||
354 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("b")).size(), 1); | 354 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("b")).size(), 1); | ||
355 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("c")).size(), 1); | 355 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("c")).size(), 1); | ||
356 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("d")).size(), 1); | 356 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("d")).size(), 1); | ||
357 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("e")).size(), 1); | 357 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("e")).size(), 1); | ||
358 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("f")).size(), 1); | 358 | QCOMPARE(context->findDeclarations(QualifiedIdentifier("f")).size(), 1); | ||
359 | } | 359 | } | ||
▲ Show 20 Lines • Show All 275 Lines • ▼ Show 20 Line(s) | 624 | { | |||
635 | QVERIFY(topContext.data()); | 635 | QVERIFY(topContext.data()); | ||
636 | go::UseBuilder builder2(&session); | 636 | go::UseBuilder builder2(&session); | ||
637 | builder2.buildUses(session.ast()); | 637 | builder2.buildUses(session.ast()); | ||
638 | auto packageContext = getPackageContext(topContext); | 638 | auto packageContext = getPackageContext(topContext); | ||
639 | auto context = getMainContext(packageContext); | 639 | auto context = getMainContext(packageContext); | ||
640 | DUChainReadLocker lock; | 640 | DUChainReadLocker lock; | ||
641 | 641 | | |||
642 | QCOMPARE(context->usesCount(), 1); | 642 | QCOMPARE(context->usesCount(), 1); | ||
643 | QCOMPARE(context->uses()->usedDeclaration(context->topContext()), context->parentContext()->parentContext()->localDeclarations().at(1)); | 643 | QCOMPARE(context->uses()->usedDeclaration(context->topContext()), context->parentContext()->localDeclarations().at(1)); | ||
644 | } | 644 | } | ||
645 | 645 | | |||
646 | void TestDuchain::test_functionContextIsCreatedWhenDeclaringAsMemberOfStruct_data() | 646 | void TestDuchain::test_functionContextIsCreatedWhenDeclaringAsMemberOfStruct_data() | ||
647 | { | 647 | { | ||
648 | QTest::addColumn<QString>("declaration"); | 648 | QTest::addColumn<QString>("declaration"); | ||
649 | QTest::newRow("short variable declaration") << "t := "; | 649 | QTest::newRow("short variable declaration") << "t := "; | ||
650 | QTest::newRow("variable declaration") << "var t = "; | 650 | QTest::newRow("variable declaration") << "var t = "; | ||
651 | QTest::newRow("assignment") << "t = "; | 651 | QTest::newRow("assignment") << "t = "; | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | 711 | { | |||
712 | if(!packageContext) | 712 | if(!packageContext) | ||
713 | { | 713 | { | ||
714 | return 0; | 714 | return 0; | ||
715 | } | 715 | } | ||
716 | DUChainReadLocker lock; | 716 | DUChainReadLocker lock; | ||
717 | auto decls = packageContext->findDeclarations(QualifiedIdentifier("main")); | 717 | auto decls = packageContext->findDeclarations(QualifiedIdentifier("main")); | ||
718 | if(decls.size() == 0) | 718 | if(decls.size() == 0) | ||
719 | return 0; | 719 | return 0; | ||
720 | AbstractFunctionDeclaration* function = dynamic_cast<AbstractFunctionDeclaration*>(decls.first()); | 720 | auto function = dynamic_cast<go::GoFunctionDeclaration*>(decls.first()); | ||
brauch: you can use auto | |||||
721 | if(!function) | 721 | if(!function) | ||
722 | return 0; | 722 | return 0; | ||
723 | return function->internalFunctionContext(); | 723 | return function->internalContext(); | ||
724 | } | 724 | } | ||
725 | 725 | | |||
726 | DUContext* getMainContext(const QString& code) | 726 | DUContext* getMainContext(const QString& code) | ||
727 | { | 727 | { | ||
728 | DUContext* package = getPackageContext(code); | 728 | DUContext* package = getPackageContext(code); | ||
729 | return getMainContext(package); | 729 | return getMainContext(package); | ||
730 | } | 730 | } | ||
731 | 731 | | |||
732 | 732 | |
you can use auto