Changeset View
Changeset View
Standalone View
Standalone View
duchain/tests/pyduchaintest.cpp
Show First 20 Lines • Show All 788 Lines • ▼ Show 20 Line(s) | 782 | { | |||
---|---|---|---|---|---|
789 | QVERIFY(m_ast); | 789 | QVERIFY(m_ast); | ||
790 | 790 | | |||
791 | DUChainReadLocker lock(DUChain::lock()); | 791 | DUChainReadLocker lock(DUChain::lock()); | ||
792 | TypeTestVisitor* visitor = new TypeTestVisitor(); | 792 | TypeTestVisitor* visitor = new TypeTestVisitor(); | ||
793 | visitor->ctx = TopDUContextPointer(ctx.data()); | 793 | visitor->ctx = TopDUContextPointer(ctx.data()); | ||
794 | visitor->searchingForType = expectedType; | 794 | visitor->searchingForType = expectedType; | ||
795 | visitor->visitCode(m_ast.data()); | 795 | visitor->visitCode(m_ast.data()); | ||
796 | QEXPECT_FAIL("lambda", "not implemented: aliasing lambdas", Continue); | 796 | QEXPECT_FAIL("lambda", "not implemented: aliasing lambdas", Continue); | ||
797 | QEXPECT_FAIL("return_builtin_iterator", "fake builtin iter()", Continue); | ||||
797 | QCOMPARE(visitor->found, true); | 798 | QCOMPARE(visitor->found, true); | ||
798 | } | 799 | } | ||
799 | 800 | | |||
800 | void PyDUChainTest::testTypes_data() | 801 | void PyDUChainTest::testTypes_data() | ||
801 | { | 802 | { | ||
802 | QTest::addColumn<QString>("code"); | 803 | QTest::addColumn<QString>("code"); | ||
803 | QTest::addColumn<QString>("expectedType"); | 804 | QTest::addColumn<QString>("expectedType"); | ||
804 | 805 | | |||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 937 | QTest::newRow("varied_args_type_1") << "def myfun(arg, *args, **kwargs): return arg\n" | |||
937 | "checkme = myfun(1, 1.5, a=str())" << "int"; | 938 | "checkme = myfun(1, 1.5, a=str())" << "int"; | ||
938 | QTest::newRow("varied_args_type_2") << "def myfun(arg, *args, **kwargs): return args[0]\n" | 939 | QTest::newRow("varied_args_type_2") << "def myfun(arg, *args, **kwargs): return args[0]\n" | ||
939 | "checkme = myfun(1, 1.5, a=str())" << "float"; | 940 | "checkme = myfun(1, 1.5, a=str())" << "float"; | ||
940 | QTest::newRow("varied_args_type_3") << "def myfun(arg, *args, **kwargs): return kwargs['a']\n" | 941 | QTest::newRow("varied_args_type_3") << "def myfun(arg, *args, **kwargs): return kwargs['a']\n" | ||
941 | "checkme = myfun(1, 1.5, a=str())" << "str"; | 942 | "checkme = myfun(1, 1.5, a=str())" << "str"; | ||
942 | 943 | | |||
943 | QTest::newRow("tuple_unsure") << "q = (3, str())\nq=(str(), 3)\ncheckme, _ = q" << "unsure (int, str)"; | 944 | QTest::newRow("tuple_unsure") << "q = (3, str())\nq=(str(), 3)\ncheckme, _ = q" << "unsure (int, str)"; | ||
944 | 945 | | |||
946 | QTest::newRow("custom_iterable") << "class Gen2:\n" | ||||
947 | " def __iter__(self): return self\n" | ||||
948 | " def __next__(self): return 'blah'\n" | ||||
949 | "for checkme in Gen2(): pass" << "str"; | ||||
950 | QTest::newRow("separate_iterator") << "class Foo:\n" | ||||
951 | " def __iter__(self): return Bar()\n" | ||||
952 | " def __next__(self): return 'blah'\n" // Not used (or shouldn't be!) | ||||
953 | "class Bar:\n" | ||||
954 | " def __next__(self): return {1}\n" | ||||
955 | "checkme = [a for a in Foo()]" << "list of set of int"; | ||||
956 | QTest::newRow("return_builtin_iterator") << "class Gen2:\n" | ||||
957 | " contents = [1, 2, 3]\n" | ||||
958 | " def __iter__(self): return iter(Gen2.contents)\n" | ||||
959 | "for checkme in Gen2(): pass" << "int"; | ||||
960 | | ||||
945 | QTest::newRow("call_class") << "class Foo:\n" | 961 | QTest::newRow("call_class") << "class Foo:\n" | ||
946 | " def __call__(self):\n" | 962 | " def __call__(self):\n" | ||
947 | " return 0\n" | 963 | " return 0\n" | ||
948 | "f = Foo()\n" | 964 | "f = Foo()\n" | ||
949 | "checkme = f()\n" << "int"; | 965 | "checkme = f()\n" << "int"; | ||
950 | QTest::newRow("classmethod") << "class Foo:\n" | 966 | QTest::newRow("classmethod") << "class Foo:\n" | ||
951 | " @classmethod\n" | 967 | " @classmethod\n" | ||
952 | " def foo(cls):\n" | 968 | " def foo(cls):\n" | ||
▲ Show 20 Lines • Show All 501 Lines • ▼ Show 20 Line(s) | 1462 | { | |||
1454 | QTest::newRow("tuple_unpack_indirect") << "c = 3, 3.5\na, b = c" << QStringList{"a", "b"} << QStringList{"int", "float"}; | 1470 | QTest::newRow("tuple_unpack_indirect") << "c = 3, 3.5\na, b = c" << QStringList{"a", "b"} << QStringList{"int", "float"}; | ||
1455 | QTest::newRow("tuple_unpack_stacked_inplace") << "a, (b, c) = 1, (2, 3.5)" << QStringList{"a", "b", "c"} | 1471 | QTest::newRow("tuple_unpack_stacked_inplace") << "a, (b, c) = 1, (2, 3.5)" << QStringList{"a", "b", "c"} | ||
1456 | << QStringList{"int", "int", "float"}; | 1472 | << QStringList{"int", "int", "float"}; | ||
1457 | QTest::newRow("tuple_unpack_stacked_indirect") << "d = 3.5, (3, 1)\na, (b, c) = d" | 1473 | QTest::newRow("tuple_unpack_stacked_indirect") << "d = 3.5, (3, 1)\na, (b, c) = d" | ||
1458 | << QStringList{"a", "b", "c"} << QStringList{"float", "int", "int"}; | 1474 | << QStringList{"a", "b", "c"} << QStringList{"float", "int", "int"}; | ||
1459 | QTest::newRow("unpack_from_list_inplace") << "a, b = [1, 2, 3]" << QStringList{"a", "b"} << QStringList{"int", "int"}; | 1475 | QTest::newRow("unpack_from_list_inplace") << "a, b = [1, 2, 3]" << QStringList{"a", "b"} << QStringList{"int", "int"}; | ||
1460 | QTest::newRow("unpack_from_list_indirect") << "c = [1, 2, 3]\na, b = c" << QStringList{"a", "b"} | 1476 | QTest::newRow("unpack_from_list_indirect") << "c = [1, 2, 3]\na, b = c" << QStringList{"a", "b"} | ||
1461 | << QStringList{"int", "int"}; | 1477 | << QStringList{"int", "int"}; | ||
1478 | QTest::newRow("unpack_custom_iterable") << | ||||
1479 | "class Foo:\n" | ||||
1480 | " def __iter__(self): return self\n" | ||||
1481 | " def __next__(self): return 1.5\n" | ||||
1482 | "a, *b = Foo()" << QStringList{"a", "b"} << QStringList {"float", "list of float"}; | ||||
1462 | QTest::newRow("for_loop_simple") << "for i in range(3): pass" << QStringList{"i"} << QStringList{"int"}; | 1483 | QTest::newRow("for_loop_simple") << "for i in range(3): pass" << QStringList{"i"} << QStringList{"int"}; | ||
1463 | QTest::newRow("for_loop_unpack") << "for a, b in [(3, 5.1)]: pass" << QStringList{"a", "b"} | 1484 | QTest::newRow("for_loop_unpack") << "for a, b in [(3, 5.1)]: pass" << QStringList{"a", "b"} | ||
1464 | << QStringList{"int", "float"}; | 1485 | << QStringList{"int", "float"}; | ||
1465 | QTest::newRow("for_loop_stacked") << "for a, (b, c) in [(1, (2, 3.5))]: pass" << QStringList{"a", "b", "c"} | 1486 | QTest::newRow("for_loop_stacked") << "for a, (b, c) in [(1, (2, 3.5))]: pass" << QStringList{"a", "b", "c"} | ||
1466 | << QStringList{"int", "int", "float"}; | 1487 | << QStringList{"int", "int", "float"}; | ||
1467 | QTest::newRow("for_loop_tuple") << "for a in 1, 2: pass" << QStringList{"a"} << QStringList{"int"}; | 1488 | QTest::newRow("for_loop_tuple") << "for a in 1, 2: pass" << QStringList{"a"} << QStringList{"int"}; | ||
1468 | QTest::newRow("for_loop_dict") << "for a in {'foo': 1}: pass" << QStringList{"a"} << QStringList{"str"}; | 1489 | QTest::newRow("for_loop_dict") << "for a in {'foo': 1}: pass" << QStringList{"a"} << QStringList{"str"}; | ||
1469 | } | 1490 | } | ||
▲ Show 20 Lines • Show All 42 Lines • Show Last 20 Lines |