Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/pyduchaintest.cpp
Show First 20 Lines • Show All 1335 Lines • ▼ Show 20 Line(s) | 1335 | QTest::newRow("list_comp_other_wrong") << "def decorate(): pass\nclass A:\n @decorate\n def func(self):\n" | |||
---|---|---|---|---|---|
1336 | " [x for a in [1, 2, 3]]" << 1; | 1336 | " [x for a in [1, 2, 3]]" << 1; | ||
1337 | QTest::newRow("list_comp_staticmethod_wrong") << "class A:\n @staticmethod\n def func(cls):\n" | 1337 | QTest::newRow("list_comp_staticmethod_wrong") << "class A:\n @staticmethod\n def func(cls):\n" | ||
1338 | " [x for a in [1, 2, 3]]" << 1; | 1338 | " [x for a in [1, 2, 3]]" << 1; | ||
1339 | QTest::newRow("misplaced_return_plain") << "return" << 1; | 1339 | QTest::newRow("misplaced_return_plain") << "return" << 1; | ||
1340 | QTest::newRow("misplaced_return_value") << "return 15" << 1; | 1340 | QTest::newRow("misplaced_return_value") << "return 15" << 1; | ||
1341 | QTest::newRow("misplaced_return_class") << "class A:\n return 25" << 1; | 1341 | QTest::newRow("misplaced_return_class") << "class A:\n return 25" << 1; | ||
1342 | QTest::newRow("correct_return") << "def foo():\n return" << 0; | 1342 | QTest::newRow("correct_return") << "def foo():\n return" << 0; | ||
1343 | QTest::newRow("lambda_argument_outside") << "def bar():\n lambda foo: 3\n foo" << 1; | 1343 | QTest::newRow("lambda_argument_outside") << "def bar():\n lambda foo: 3\n foo" << 1; | ||
1344 | QTest::newRow("use_found_at_decl") << "foo = 3" << 0; | ||||
1344 | } | 1345 | } | ||
1345 | 1346 | | |||
1346 | void PyDUChainTest::testImportDeclarations_data() { | 1347 | void PyDUChainTest::testImportDeclarations_data() { | ||
1347 | QTest::addColumn<QString>("code"); | 1348 | QTest::addColumn<QString>("code"); | ||
1348 | QTest::addColumn<QStringList>("expectedDecls"); | 1349 | QTest::addColumn<QStringList>("expectedDecls"); | ||
1349 | QTest::addColumn<bool>("shouldBeAliased"); | 1350 | QTest::addColumn<bool>("shouldBeAliased"); | ||
1350 | 1351 | | |||
1351 | QTest::newRow("from_import") << "from testImportDeclarations.i import checkme" << ( QStringList() << "checkme" ) << true; | 1352 | QTest::newRow("from_import") << "from testImportDeclarations.i import checkme" << ( QStringList() << "checkme" ) << true; | ||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Line(s) | 1596 | if ( ! use_type ) { | |||
1597 | QVERIFY(type); | 1598 | QVERIFY(type); | ||
1598 | QVERIFY(type->contentType()); | 1599 | QVERIFY(type->contentType()); | ||
1599 | QCOMPARE(type->contentType().abstractType()->toString(), contenttype); | 1600 | QCOMPARE(type->contentType().abstractType()->toString(), contenttype); | ||
1600 | } | 1601 | } | ||
1601 | else { | 1602 | else { | ||
1602 | QVERIFY(decls.first()->abstractType()); | 1603 | QVERIFY(decls.first()->abstractType()); | ||
1603 | QEXPECT_FAIL("dict_of_int_call", "returnContentEqualsContentOf isn't suitable", Continue); | 1604 | QEXPECT_FAIL("dict_of_int_call", "returnContentEqualsContentOf isn't suitable", Continue); | ||
1604 | QEXPECT_FAIL("dict_from_tuples", "returnContentEqualsContentOf isn't suitable", Continue); | 1605 | QEXPECT_FAIL("dict_from_tuples", "returnContentEqualsContentOf isn't suitable", Continue); | ||
1606 | QEXPECT_FAIL("comprehension_shadowing_ms", "Nothing is foolproof to a sufficiently capable fool", Continue); | ||||
1607 | QEXPECT_FAIL("comprehension_shadowing_nest2", "See above", Continue); | ||||
1605 | QCOMPARE(decls.first()->abstractType()->toString(), contenttype); | 1608 | QCOMPARE(decls.first()->abstractType()->toString(), contenttype); | ||
1606 | } | 1609 | } | ||
1607 | } | 1610 | } | ||
1608 | 1611 | | |||
1609 | void PyDUChainTest::testContainerTypes_data() | 1612 | void PyDUChainTest::testContainerTypes_data() | ||
1610 | { | 1613 | { | ||
1611 | QTest::addColumn<QString>("code"); | 1614 | QTest::addColumn<QString>("code"); | ||
1612 | QTest::addColumn<QString>("contenttype"); | 1615 | QTest::addColumn<QString>("contenttype"); | ||
▲ Show 20 Lines • Show All 47 Lines • ▼ Show 20 Line(s) | 1646 | #endif | |||
1660 | QTest::newRow("for_loop_tuple_2") << "d = [(3, 3.5)]\nfor a, b in d:\n checkme = b" << "float" << true; | 1663 | QTest::newRow("for_loop_tuple_2") << "d = [(3, 3.5)]\nfor a, b in d:\n checkme = b" << "float" << true; | ||
1661 | QTest::newRow("for_loop_tuple_unsure") << "d = [(3, 3.5), (3.5, 3)]\nfor a, b in d:\n checkme = b" | 1664 | QTest::newRow("for_loop_tuple_unsure") << "d = [(3, 3.5), (3.5, 3)]\nfor a, b in d:\n checkme = b" | ||
1662 | << "unsure (float, int)" << true; | 1665 | << "unsure (float, int)" << true; | ||
1663 | // Proposed by Nicolás Alvarez; why not? https://bugs.kde.org/show_bug.cgi?id=359915 | 1666 | // Proposed by Nicolás Alvarez; why not? https://bugs.kde.org/show_bug.cgi?id=359915 | ||
1664 | QTest::newRow("comprehension_messy") << "users = {'a':19, 'b':42, 'c':35}\n" | 1667 | QTest::newRow("comprehension_messy") << "users = {'a':19, 'b':42, 'c':35}\n" | ||
1665 | "sorted_list = sorted(users.items(), key=lambda kv: (-kv[1], kv[0]))\n" | 1668 | "sorted_list = sorted(users.items(), key=lambda kv: (-kv[1], kv[0]))\n" | ||
1666 | "checkme = [k for r,(k,v) in enumerate(sorted_list, 1)]" << "list of str" << true; | 1669 | "checkme = [k for r,(k,v) in enumerate(sorted_list, 1)]" << "list of str" << true; | ||
1667 | QTest::newRow("comprehension_multiline") << "checkme = [a for\n a in \n (1, 2)]" << "list of int" << true; | 1670 | QTest::newRow("comprehension_multiline") << "checkme = [a for\n a in \n (1, 2)]" << "list of int" << true; | ||
1671 | QTest::newRow("comprehension_multistage") << "nested = (1, 2), (3, 4)\n" | ||||
1672 | "checkme = [foo for bar in nested for foo in bar]" << "list of int" << true; | ||||
1673 | QTest::newRow("comprehension_shadowing_ms") << "nested = (1, 2), (3, 4)\n" | ||||
1674 | "checkme = [foo for foo in nested for foo in foo]" << "list of int" << true; | ||||
1675 | QTest::newRow("comprehension_shadowing_nest1") << "nested = (1, 2), (3, 4)\n" | ||||
1676 | "checkme = [foo for foo in [foo for foo in nested]]" << "list of tuple of (int, int)" << true; | ||||
1677 | QTest::newRow("comprehension_shadowing_nest2") << "nested = (1, 2), (3, 4)\n" | ||||
1678 | "checkme = [[foo for foo in foo] for foo in nested]" << "list of list of int" << true; | ||||
1668 | // From https://bugs.kde.org/show_bug.cgi?id=359912 | 1679 | // From https://bugs.kde.org/show_bug.cgi?id=359912 | ||
1669 | QTest::newRow("subscript_multi") << | 1680 | QTest::newRow("subscript_multi") << | ||
1670 | "class Middle:\n def __getitem__(self, key):\n return str()\n" | 1681 | "class Middle:\n def __getitem__(self, key):\n return str()\n" | ||
1671 | "class Outer:\n def __getitem__(self, key):\n return Middle()\n" | 1682 | "class Outer:\n def __getitem__(self, key):\n return Middle()\n" | ||
1672 | "aaa = Outer()\ncheckme = aaa[0][0]" << "str" << true; | 1683 | "aaa = Outer()\ncheckme = aaa[0][0]" << "str" << true; | ||
1673 | QTest::newRow("subscript_func_call") << | 1684 | QTest::newRow("subscript_func_call") << | ||
1674 | "class Foo:\n def __getitem__(self, key):\n return str()\n" | 1685 | "class Foo:\n def __getitem__(self, key):\n return str()\n" | ||
1675 | "def bar():\n return Foo()\n" | 1686 | "def bar():\n return Foo()\n" | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |