From 1fb674182fe376d6561c6fe90003c87c2a166ab2 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Sun, 25 Oct 2020 03:44:28 +0900 Subject: [PATCH 1/4] Add class explicitly to the tests --- bindings/python/tests/test_parse.py | 39 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/bindings/python/tests/test_parse.py b/bindings/python/tests/test_parse.py index 7b1a791..3e837a7 100644 --- a/bindings/python/tests/test_parse.py +++ b/bindings/python/tests/test_parse.py @@ -342,21 +342,36 @@ def test_class_template(tmp_path): file_contents = """ template struct AStruct {}; + + template + class AClass {}; """ parsed_info = get_parsed_info(tmp_path=tmp_path, file_contents=file_contents) - class_template = parsed_info["members"][0] + struct_template = parsed_info["members"][0] + + assert struct_template["kind"] == "CLASS_TEMPLATE" + assert struct_template["name"] == "AStruct" + + template_type_parameter = struct_template["members"][0] + + assert template_type_parameter["kind"] == "TEMPLATE_TYPE_PARAMETER" + assert template_type_parameter["name"] == "T" + assert template_type_parameter["access_specifier"] == "PUBLIC" + + class_template = parsed_info["members"][1] assert class_template["kind"] == "CLASS_TEMPLATE" - assert class_template["name"] == "AStruct" + assert class_template["name"] == "AClass" template_type_parameter = class_template["members"][0] assert template_type_parameter["kind"] == "TEMPLATE_TYPE_PARAMETER" - assert template_type_parameter["name"] == "T" + assert template_type_parameter["name"] == "U" assert template_type_parameter["access_specifier"] == "PUBLIC" + def test_template_non_type_parameter(tmp_path): file_contents = """ template @@ -396,24 +411,34 @@ def test_function_template(tmp_path): assert template_type_parameter["access_specifier"] == "PUBLIC" -def test_template_type_parameter(tmp_path): +def test_template_type_single_parameter(tmp_path): file_contents = """ template struct AStruct {}; + template + class AClass {}; + template void aFunction() {} """ parsed_info = get_parsed_info(tmp_path=tmp_path, file_contents=file_contents) - class_template = parsed_info["members"][0] - template_type_parameter = class_template["members"][0] + struct_template = parsed_info["members"][0] + template_type_parameter = struct_template["members"][0] assert template_type_parameter["kind"] == "TEMPLATE_TYPE_PARAMETER" assert template_type_parameter["element_type"] == "Unexposed" assert template_type_parameter["name"] == "T" - function_template = parsed_info["members"][1] + class_template = parsed_info["members"][1] + template_type_parameter = class_template["members"][0] + + assert template_type_parameter["kind"] == "TEMPLATE_TYPE_PARAMETER" + assert template_type_parameter["element_type"] == "Unexposed" + assert template_type_parameter["name"] == "U" + + function_template = parsed_info["members"][2] template_type_parameter = function_template["members"][0] assert template_type_parameter["kind"] == "TEMPLATE_TYPE_PARAMETER" From 537870388ecee761beb37c9032bf9affd36527b6 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Sun, 25 Oct 2020 03:44:43 +0900 Subject: [PATCH 2/4] Add tests for instantiation parsing --- bindings/python/tests/test_parse.py | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/bindings/python/tests/test_parse.py b/bindings/python/tests/test_parse.py index 3e837a7..4f9cdf5 100644 --- a/bindings/python/tests/test_parse.py +++ b/bindings/python/tests/test_parse.py @@ -446,6 +446,37 @@ class AClass {}; assert template_type_parameter["name"] == "P" +def test_template_instantiate_single_parameter(tmp_path): + file_contents = """ + template + struct AStruct; + template + class AClass; + + template + void aFunction(bool); + """ + parsed_info = get_parsed_info(tmp_path=tmp_path, file_contents=file_contents) + print(parsed_info["members"]) + # As per generate.py:219, there should be some member with "kind" `TYPE_REF` + print( + "Member details:", + {sub_item["name"]: sub_item["members"] for sub_item in parsed_info["members"]}, + ) + # Doesn't detect 3 items in next line + assert len(parsed_info["members"]) == 3 + + struct_inst = parsed_info["members"][0] + class_inst = parsed_info["members"][1] + func_inst = parsed_info["members"][2] + + assert struct_inst["kind"] == "STRUCT_DECL" + assert struct_inst["kind_is_declaration"] == True + + assert class_inst["kind"] == "CLASS_DEC" + assert class_inst["kind_is_declaration"] == True + + def test_default_delete_constructor(tmp_path): file_contents = """ class aClass { From 8509f15505676f8f0ad32c9602121b475af793cd Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Sun, 25 Oct 2020 05:35:53 +0900 Subject: [PATCH 3/4] Satisfy black --- bindings/python/tests/test_parse.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/python/tests/test_parse.py b/bindings/python/tests/test_parse.py index 4f9cdf5..63acf2d 100644 --- a/bindings/python/tests/test_parse.py +++ b/bindings/python/tests/test_parse.py @@ -371,7 +371,6 @@ class AClass {}; assert template_type_parameter["access_specifier"] == "PUBLIC" - def test_template_non_type_parameter(tmp_path): file_contents = """ template From d9a1440041cf1e2a16015e451c2205d56df6e629 Mon Sep 17 00:00:00 2001 From: Kunal Tyagi Date: Sun, 25 Oct 2020 16:02:03 +0900 Subject: [PATCH 4/4] Update just in case the ill-formed nature of previous example was the cause --- bindings/python/tests/test_parse.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/bindings/python/tests/test_parse.py b/bindings/python/tests/test_parse.py index 63acf2d..cd5c592 100644 --- a/bindings/python/tests/test_parse.py +++ b/bindings/python/tests/test_parse.py @@ -447,34 +447,45 @@ class AClass {}; def test_template_instantiate_single_parameter(tmp_path): file_contents = """ + template + struct AStruct { T value; }; + template + class AClass { const T privateValue; } + template + T aFunction(T&& aValue) { return aValue; } + template struct AStruct; template class AClass; - template - void aFunction(bool); + bool aFunction(bool&&); """ parsed_info = get_parsed_info(tmp_path=tmp_path, file_contents=file_contents) print(parsed_info["members"]) # As per generate.py:219, there should be some member with "kind" `TYPE_REF` print( "Member details:", - {sub_item["name"]: sub_item["members"] for sub_item in parsed_info["members"]}, + [{sub_item["name"]: sub_item["kind"]} for sub_item in parsed_info["members"]], ) # Doesn't detect 3 items in next line - assert len(parsed_info["members"]) == 3 + assert len(parsed_info["members"]) == 6 struct_inst = parsed_info["members"][0] - class_inst = parsed_info["members"][1] - func_inst = parsed_info["members"][2] assert struct_inst["kind"] == "STRUCT_DECL" assert struct_inst["kind_is_declaration"] == True - assert class_inst["kind"] == "CLASS_DEC" + class_inst = parsed_info["members"][1] + + assert class_inst["kind"] == "CLASS_DECL" assert class_inst["kind_is_declaration"] == True + func_inst = parsed_info["members"][2] + + assert func_inst["kind"] == "FUNCTION_DECL" + assert func_inst["kind_is_declaration"] == True + def test_default_delete_constructor(tmp_path): file_contents = """