From 712d80cc8afe43356311c2b200e99f7e47297dc3 Mon Sep 17 00:00:00 2001 From: mlangkabel Date: Mon, 30 Sep 2019 11:45:33 +0200 Subject: [PATCH] test: clean up cxx indexer tests --- src/test/CxxParserTestSuite.h | 390 ++++++++++++++++------------------ 1 file changed, 189 insertions(+), 201 deletions(-) diff --git a/src/test/CxxParserTestSuite.h b/src/test/CxxParserTestSuite.h index 98087715..58579749 100644 --- a/src/test/CxxParserTestSuite.h +++ b/src/test/CxxParserTestSuite.h @@ -15,171 +15,6 @@ class CxxParserTestSuite: public CxxTest::TestSuite { public: - void test_cxx_parser_creates_single_node_for_all_possible_parameter_pack_expansions_of_template_function() - { - std::shared_ptr client = parseCode( - "template\n" - "T adder(T v) { return v; }\n" - "\n" - "template\n" - "T adder(T first, Args... args) { return first + adder(args...); }\n" - "\n" - "void foo() { long sum = adder(1, 2, 3, 8, 7); }\n" - ); - - TS_ASSERT(utility::containsElement( - client->functions, L"int adder>(int, ...) <5:1 <5:1 <5:3 5:7> 5:30> 5:65>" - )); - TS_ASSERT(utility::containsElement( - client->calls, L"int adder>(int, ...) -> int adder>(int, ...) <5:49 5:53>" - )); - } - - void test_record_base_class_of_implicit_template_class_specialization() - { - std::shared_ptr client = parseCode( - "template\n" - "class VectorBase {}; \n" - "\n" - "template\n" - "class Vector2 : public VectorBase { void foo(); }; \n" - "\n" - "typedef Vector2 Vec2f; \n" - "\n" - "Vec2f v; \n" - ); - - TS_ASSERT(utility::containsElement( - client->inheritances, L"Vector2 -> VectorBase <5:24 5:33>" - )); - } - - void test_cxx_parser_skips_implicit_template_method_definition_of_implicit_template_class_instantiation() - { - std::shared_ptr client = parseCode( - "template \n" - "class A\n" - "{\n" - "public:\n" - " template \n" - " void foo() {}\n" - "};\n" - "\n" - "int main()\n" - "{\n" - " A().foo();\n" - " return 0;\n" - "}\n" - ); - - TS_ASSERT( /*NOT!*/ !utility::containsElement( - client->methods, L"public void A::foo() <6:2 <6:7 6:9> 6:14>" - )); - TS_ASSERT(utility::containsElement( - client->templateSpecializations, L"void A::foo() -> void A::foo() <6:7 6:9>" - )); - } - - - - void test_foofooofooofow1() - { - { - std::shared_ptr client = parseCode( - "template \n" - "class A {};\n" - "template \n" - "class vector { };\n" - "template\n" - "class vector> { };\n" - ); - - TS_ASSERT(utility::containsElement( - client->classes, L"vector> <5:1 <6:7 6:12> 6:31>" - )); - } - { - std::shared_ptr client = parseCode( - "template \n" - "class vector { };\n" - "template\n" - "class vector { };\n" - ); - - TS_ASSERT(utility::containsElement( - client->classes, L"vector <3:1 <4:7 4:12> 4:33>" - )); - } - { - std::shared_ptr client = parseCode( - "template \n" - "class foo {\n" - " template \n" - " class vector { };\n" - " template\n" - " class vector { };\n" - "};\n" - ); - - TS_ASSERT(utility::containsElement( - client->classes, L"foo::vector <5:2 <6:8 6:13> 6:25>" - )); - } - { - //std::shared_ptr client = parseCode( - // "template \n" - // "class vector { };\n" - // "template\n" - // "struct Alloc { };\n" - // "template\n" - // "using Vec = vector>;\n" // record not Vector::T......... - // "Vec v;\n" - //); - - //TS_ASSERT(utility::containsElement( - // client->typeUses, L"B typename U> -> A <8:9 8:9>" - // )); - } - } - - void test_cxx_parser_finds_usage_of_field_in_function_call_arguments() - { - std::shared_ptr client = parseCode( - "class A\n" - "{\n" - "public:\n" - " void foo(int i)\n" - " {\n" - " foo(bar);\n" - " }\n" - " int bar;\n" - "};\n" - ); - - TS_ASSERT(utility::containsElement( - client->usages, L"void A::foo(int) -> int A::bar <6:7 6:9>" - )); - } - - void test_cxx_parser_usage_of_field_in_function_call_context() - { - std::shared_ptr client = parseCode( - "class A\n" - "{\n" - "public:\n" - " void foo(int i)\n" - " {\n" - " a->foo(6);\n" - " }\n" - " A* a;\n" - "};\n" - ); - - TS_ASSERT(utility::containsElement( - client->usages, L"void A::foo(int) -> A * A::a <6:3 6:3>" - )); - } - /////////////////////////////////////////////////////////////////////////////// // test finding symbol definitions and declarations @@ -929,16 +764,17 @@ public: )); } - //void __test_cxx_parser_finds_type_template_parameter_definition_of_template_type_alias() - //{ - // std::shared_ptr client = parseCode( - // "template\n" - // "using MyType = int;\n" - // ); + void test_cxx_parser_finds_type_template_parameter_definition_of_template_type_alias() + { + std::shared_ptr client = parseCode( + "template\n" + "using MyType = int;\n" + ); - // TS_ASSERT_EQUALS(client->templateParameterTypes.size(), 1); - // TS_ASSERT_EQUALS(client->templateParameterTypes[0], L"MyType::T <1:17 1:17>"); - //} + TS_ASSERT(utility::containsElement( + client->localSymbols, L"input.cc<1:16> <1:16 1:16>" + )); + } void test_cxx_parser_finds_type_template_parameter_definition_of_class_template() { @@ -1520,6 +1356,32 @@ public: )); } + void test_cxx_parser_skips_implicit_template_method_definition_of_implicit_template_class_instantiation() + { + std::shared_ptr client = parseCode( + "template \n" + "class A\n" + "{\n" + "public:\n" + " template \n" + " void foo() {}\n" + "};\n" + "\n" + "int main()\n" + "{\n" + " A().foo();\n" + " return 0;\n" + "}\n" + ); + + TS_ASSERT( /*NOT!*/ !utility::containsElement( + client->methods, L"public void A::foo() <6:2 <6:7 6:9> 6:14>" + )); + TS_ASSERT(utility::containsElement( + client->templateSpecializations, L"void A::foo() -> void A::foo() <6:7 6:9>" + )); + } + void test_cxx_parser_finds_lambda_definition_and_call_in_function() { std::shared_ptr client = parseCode( @@ -2684,6 +2546,44 @@ public: )); } + void test_cxx_parser_finds_usage_of_field_in_function_call_arguments() + { + std::shared_ptr client = parseCode( + "class A\n" + "{\n" + "public:\n" + " void foo(int i)\n" + " {\n" + " foo(bar);\n" + " }\n" + " int bar;\n" + "};\n" + ); + + TS_ASSERT(utility::containsElement( + client->usages, L"void A::foo(int) -> int A::bar <6:7 6:9>" + )); + } + + void test_cxx_parser_finds_usage_of_field_in_function_call_context() + { + std::shared_ptr client = parseCode( + "class A\n" + "{\n" + "public:\n" + " void foo(int i)\n" + " {\n" + " a->foo(6);\n" + " }\n" + " A* a;\n" + "};\n" + ); + + TS_ASSERT(utility::containsElement( + client->usages, L"void A::foo(int) -> A * A::a <6:3 6:3>" + )); + } + void test_cxx_parser_finds_usage_of_field_in_initialization_list() { std::shared_ptr client = parseCode( @@ -3164,6 +3064,26 @@ public: )); } + void test_cxx_parser_creates_single_node_for_all_possible_parameter_pack_expansions_of_template_function() + { + std::shared_ptr client = parseCode( + "template\n" + "T adder(T v) { return v; }\n" + "\n" + "template\n" + "T adder(T first, Args... args) { return first + adder(args...); }\n" + "\n" + "void foo() { long sum = adder(1, 2, 3, 8, 7); }\n" + ); + + TS_ASSERT(utility::containsElement( + client->functions, L"int adder>(int, ...) <5:1 <5:1 <5:3 5:7> 5:30> 5:65>" + )); + TS_ASSERT(utility::containsElement( + client->calls, L"int adder>(int, ...) -> int adder>(int, ...) <5:49 5:53>" + )); + } + void test_cxx_parser_finds_type_template_argument_of_explicit_template_instantiation() { std::shared_ptr client = parseCode( @@ -3898,6 +3818,25 @@ public: )); } + void test_record_base_class_of_implicit_template_class_specialization() + { + std::shared_ptr client = parseCode( + "template\n" + "class VectorBase {}; \n" + "\n" + "template\n" + "class Vector2 : public VectorBase { void foo(); }; \n" + "\n" + "typedef Vector2 Vec2f; \n" + "\n" + "Vec2f v; \n" + ); + + TS_ASSERT(utility::containsElement( + client->inheritances, L"Vector2 -> VectorBase <5:24 5:33>" + )); + } + void test_cxx_parser_finds_template_class_specialization_with_template_argument() { std::shared_ptr client = parseCode( @@ -3921,6 +3860,53 @@ public: TS_ASSERT(client->fields.size() == 1); } + void test_cxx_parser_finds_correct_order_of_template_arguments_for_explicit_class_template_specialization() + { + std::shared_ptr client = parseCode( + "template \n" + "class vector { };\n" + "template\n" + "class vector { };\n" + ); + + TS_ASSERT(utility::containsElement( + client->classes, L"vector <3:1 <4:7 4:12> 4:33>" + )); + } + + void test_cxx_parser_replaces_dependent_template_arguments_of_explicit_template_specialization_with_name_of_base_template() + { + std::shared_ptr client = parseCode( + "template \n" + "class A {};\n" + "template \n" + "class vector { };\n" + "template\n" + "class vector> { };\n" + ); + + TS_ASSERT(utility::containsElement( + client->classes, L"vector> <5:1 <6:7 6:12> 6:31>" + )); + } + + void test_cxx_parser_replaces_unknown_template_arguments_of_explicit_template_specialization_with_depth_and_position_index() + { + std::shared_ptr client = parseCode( + "template \n" + "class foo {\n" + " template \n" + " class vector { };\n" + " template\n" + " class vector { };\n" + "};\n" + ); + + TS_ASSERT(utility::containsElement( + client->classes, L"foo::vector <5:2 <6:8 6:13> 6:25>" + )); + } + void test_cxx_parser_finds_template_class_constructor_usage_of_field() { std::shared_ptr client = parseCode( @@ -4152,7 +4138,7 @@ public: "\n" "class A\n" "{\n" - " int foo = test(1);\n" // usage of "int" + " int foo = test(1);\n" // usage of "int" "};\n" ); @@ -4371,35 +4357,37 @@ public: } - //void __test_cxx_parser_finds_type_template_argument_of_static_cast_expression() - //{ - // std::shared_ptr client = parseCode( - // "int main()\n" - // "{\n" - // " return static_cast(4.0f);" - // "}\n" - // ); + void test_cxx_parser_finds_type_template_argument_of_static_cast_expression() + { + std::shared_ptr client = parseCode( + "int main()\n" + "{\n" + " return static_cast(4.0f);" + "}\n" + ); - // TS_ASSERT_EQUALS(client->templateArgumentTypes.size(), 1); - // TS_ASSERT_EQUALS(client->templateArgumentTypes[0], L"A<1> -> int <0:0 0:0>"); - //} + TS_ASSERT(utility::containsElement( + client->typeUses, L"int main() -> int <3:21 3:23>" + )); + } - //void _test_cxx_parser_finds_implicit_constructor_call_in_initialization() - //{ - // std::shared_ptr client = parseCode( - // "class A\n" - // "{\n" - // "};\n" - // "class B\n" - // "{\n" - // " B(){}\n" - // " A m_a;\n" - // "};\n" - // ); + void test_cxx_parser_finds_implicit_constructor_call_in_initialization() + { + std::shared_ptr client = parseCode( + "class A\n" + "{\n" + "};\n" + "class B\n" + "{\n" + " B(){}\n" + " A m_a;\n" + "};\n" + ); - // TS_ASSERT_EQUALS(client->calls.size(), 1); - // TS_ASSERT_EQUALS(client->calls[0], L"void B::B() -> A::A() <6:2 6:2>"); - //} + TS_ASSERT(utility::containsElement( + client->calls, L"void B::B() -> void A::A() <6:2 6:2>" + )); + } void test_cxx_parser_parses_multiple_files() {