def test_parse_cpp_type_from_text_with_nested_ref_type(): parser = DoxygenXmlParser() cpp = CppLanguage(parser) type_element = ET.Element("type") type_element.text = "const std::unique_ptr< const " sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail=" & > *") type_ref = cpp.parse_type(type_element) assert type_ref is not None assert not type_ref.id assert not type_ref.kind assert type_ref.language == "cpp" assert type_ref.name == "std::unique_ptr" assert type_ref.prefix == "const " assert type_ref.suffix == " *" assert len(type_ref.nested) == 1 nested_ref = type_ref.nested[0] assert nested_ref is not None assert nested_ref.id == "cpp-tomtom_coordinate" assert nested_ref.kind == "compound" assert nested_ref.language == "cpp" assert nested_ref.name == "Coordinate" assert nested_ref.prefix == "const " assert nested_ref.suffix == " &"
def test_parse_cpp_type_from_ref_with_nested_text_type(): type_element = ET.Element("type") type_element.text = "const " sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail="< const Unit > &") driver_mock = MagicMock() type_ref = CppTypeParser.parse_xml(type_element, driver=driver_mock) assert (sorted([ args[0].name for args, _ in driver_mock.unresolved_ref.call_args_list ]) == sorted(["Unit"])) assert type_ref is not None assert type_ref.id == "cpp-tomtom_coordinate" assert type_ref.kind == "compound" assert type_ref.language == "cpp" assert type_ref.name == "Coordinate" assert type_ref.prefix == "const " assert type_ref.suffix == " &" assert len(type_ref.nested) == 1 nested_ref = type_ref.nested[0] assert nested_ref is not None assert nested_ref.id is None assert nested_ref.kind is None assert nested_ref.language == "cpp" assert nested_ref.name == "Unit" assert nested_ref.prefix == "const " assert not nested_ref.suffix
def test_table(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para") table = sub_element(para, "table", rows="2", cols="2") for r in range(0, 2): next_row = sub_element(table, "row") for c in range(0, 2): next_entry = sub_element(next_row, "entry") cell = sub_element(next_entry, "para", text=f"col={c},row={r}", thead="no") cell.extend(nested_elements) result = DescriptionParser("lang").parse(description) assert result == re.sub( "\n{3,}", "\n\n", f"""[cols=2*] |=== |col=0,row=0{nested_result} |col=1,row=0{nested_result} |col=0,row=1{nested_result} |col=1,row=1{nested_result} |===""")
def test_parse_cpp_type_from_text_with_nested_ref_type(): type_element = ET.Element("type") type_element.text = "const std::unique_ptr< const " sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail=" & > *") driver_mock = MagicMock() type_ref = CppTypeParser.parse_xml(type_element, driver=driver_mock) driver_mock.unresolved_ref.assert_not_called() # has id, so not unresolved assert type_ref is not None assert not type_ref.id assert not type_ref.kind assert type_ref.language == "cpp" assert type_ref.name == "std::unique_ptr" assert type_ref.prefix == "const " assert type_ref.suffix == " *" assert len(type_ref.nested) == 1 nested_ref = type_ref.nested[0] assert nested_ref is not None assert nested_ref.id == "cpp-tomtom_coordinate" assert nested_ref.kind == "compound" assert nested_ref.language == "cpp" assert nested_ref.name == "Coordinate" assert nested_ref.prefix == "const " assert nested_ref.suffix == " &"
def test_nested_para(): description = ET.Element("description") sub_element(description, "para", text="Outer text.") sub_element(description, "para", text="Inner text.", tail="Tail outer text.") result = DescriptionParser("lang").parse(description) assert result == """Outer text.
def test_remove_trailing_whitespace(): description = ET.Element("description") sub_element(description, "para", text="Actual description text.") sub_element(description, "para", text="And some more text.", tail=" \n ") result = DescriptionParser("lang").parse(description) assert result == """Actual description text.
def test_computeroutput(): description = ET.Element("description") para = sub_element(description, "para", text="The computer says: ") sub_element(para, "computeroutput", text="I cannot do that, Dave", tail="!") result = DescriptionParser("lang").parse(description) assert result == "The computer says: `I cannot do that, Dave`!"
def test_bold(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para", text="The following is ") bold = sub_element(para, "bold", text="very, very, very", tail=" important!") bold.extend(nested_elements) result = DescriptionParser("lang").parse(description) assert result == f"The following is **very, very, very{nested_result}** important!"
def test_highlight(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para", text="I want to ") highlight = sub_element(para, "highlight", text="highlight these words", tail=" properly.") highlight.extend(nested_elements) result = DescriptionParser("lang").parse(description) assert result == f"I want to __highlight these words{nested_result}__ properly."
def test_ignore_parameterlist(): description = ET.Element("description") para = sub_element(description, "para") parameterlist = sub_element(para, "parameterlist", text="Ignored", tail="Also ignored") sub_element(parameterlist, "para", text="Ignored", tail="Ignored as well") result = DescriptionParser("lang").parse(description) assert result == ""
def test_simplesect_ignore_other_kinds(kind): description = ET.Element("description") para = sub_element(description, "para", "Some normal text first.") simplesect = sub_element(para, "simplesect", kind=kind, tail="More text after the note.") sub_element(simplesect, "para", text="Some kind of note.") result = DescriptionParser("lang").parse(description) assert result == "Some normal text first."
def test_ref(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para", text="See ") link = sub_element(para, "ref", text="Class", tail=" for more information.", refid="compound_class") link.extend(nested_elements) result = DescriptionParser("lang").parse(description) assert result == f"See xref:lang-compound_class[Class{nested_result}] for more information."
def test_unknown_tag(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para", text="The following is ") unknown = sub_element(para, "unknown", text="very, very, very", tail=" important!") unknown.extend(nested_elements) result = DescriptionParser("lang").parse(description) assert result == re.sub( "\n ", "\n", f"The following is very, very, very{nested_result} important!")
def test_table_with_header(): description = ET.Element("description") para = sub_element(description, "para") table = sub_element(para, "table", rows="2", cols="1") first_row = sub_element(table, "row") first_entry = sub_element(first_row, "entry", thead="yes") sub_element(first_entry, "para", text="header") second_row = sub_element(table, "row") second_entry = sub_element(second_row, "entry", thead="no") sub_element(second_entry, "para", text="content") result = DescriptionParser("lang").parse(description) assert result == """[%header,cols=1*]
def test_ulink(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para", text="Follow ") link = sub_element(para, "ulink", text="this link", tail=" for more information.", url="https://www.tomtom.com") link.extend(nested_elements) result = DescriptionParser("lang").parse(description) assert ( result == f"Follow https://www.tomtom.com[this link{nested_result}] for more information." )
def test_table_with_caption(): description = ET.Element("description") para = sub_element(description, "para") table = sub_element(para, "table", rows="1", cols="1") sub_element(table, "caption", text="Caption") row = sub_element(table, "row") entry = sub_element(row, "entry") sub_element(entry, "para", text="text") result = DescriptionParser("lang").parse(description) assert result == """.Caption
def test_programlisting(): description = ET.Element("description") para = sub_element(description, "para", text="Example of code:") listing = sub_element(para, "programlisting", tail="You know what it does.") sub_element(listing, "codeline", text="def main():") sub_element(listing, "codeline", text=" print('Hello world!')") sub_element(listing, "codeline") result = DescriptionParser("lang").parse(description) assert result == """Example of code:
def test_parse_cpp_type_from_ref_with_prefix_and_suffix( cpp_type_prefix, cpp_type_suffix): type_element = ET.Element("type") type_element.text = cpp_type_prefix sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail=cpp_type_suffix) driver_mock = MagicMock() type_ref = CppTypeParser.parse_xml(type_element, driver=driver_mock) driver_mock.unresolved_ref.assert_not_called() # has id, so not unresolved assert type_ref is not None assert type_ref.id == "cpp-tomtom_coordinate" assert type_ref.kind == "compound" assert type_ref.language == "cpp" assert type_ref.name == "Coordinate" assert_equal_or_none_if_empty(type_ref.prefix, cpp_type_prefix) assert_equal_or_none_if_empty(type_ref.suffix, cpp_type_suffix) assert not type_ref.nested
def test_parse_cpp_type_from_ref_with_prefix_and_suffix( cpp_type_prefix, cpp_type_suffix): parser = DoxygenXmlParser() cpp = CppLanguage(parser) type_element = ET.Element("type") type_element.text = cpp_type_prefix sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail=cpp_type_suffix) type_ref = cpp.parse_type(type_element) assert type_ref is not None assert type_ref.id == "cpp-tomtom_coordinate" assert type_ref.kind == "compound" assert type_ref.language == "cpp" assert type_ref.name == "Coordinate" assert_equal_or_none_if_empty(type_ref.prefix, cpp_type_prefix) assert_equal_or_none_if_empty(type_ref.suffix, cpp_type_suffix) assert len(type_ref.nested) == 0
def test_itemizedlist(nested_elements, nested_result): description = ET.Element("description") para = sub_element(description, "para", text="This is a list of items:") itemized_list = sub_element(para, "itemizedlist", tail="And some text after the list") list_item_1 = sub_element(itemized_list, "listitem") para_1 = sub_element(list_item_1, "para", text="List item 1") para_1.extend(nested_elements) list_item_2 = sub_element(itemized_list, "listitem") sub_element(list_item_2, "para", text="List item 2") result = DescriptionParser("lang").parse(description) assert result == re.sub( "\n{3,}", "\n\n", f"""This is a list of items: * List item 1{nested_result} * List item 2 And some text after the list""")
def test_parse_cpp_type_from_multiple_nested_text_and_ref(): type_element = ET.Element("type") type_element.text = "const " sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail=" < std::unique_ptr< ") sub_element(type_element, "ref", refid="tomtom_box", kindref="compound", text="Box", tail=" >, ") sub_element(type_element, "ref", refid="tomtom_point", kindref="compound", text="Point", tail=" < const std::string & > >") driver_mock = MagicMock() type_ref = CppTypeParser.parse_xml(type_element, driver=driver_mock) driver_mock.unresolved_ref.assert_not_called() # has id, so not unresolved assert type_ref is not None assert type_ref.id == "cpp-tomtom_coordinate" assert type_ref.kind == "compound" assert type_ref.language == "cpp" assert type_ref.name == "Coordinate" assert type_ref.prefix == "const " assert not type_ref.suffix assert len(type_ref.nested) == 2 nested_1 = type_ref.nested[0] assert nested_1 is not None assert not nested_1.id assert not nested_1.kind assert nested_1.language == "cpp" assert nested_1.name == "std::unique_ptr" assert not nested_1.prefix assert not nested_1.suffix assert len(nested_1.nested) == 1 nested_1_1 = nested_1.nested[0] assert nested_1_1 is not None assert nested_1_1.id == "cpp-tomtom_box" assert nested_1_1.kind == "compound" assert nested_1_1.language == "cpp" assert nested_1_1.name == "Box" assert not nested_1_1.prefix assert not nested_1_1.suffix nested_2 = type_ref.nested[1] assert nested_2 is not None assert nested_2.id == "cpp-tomtom_point" assert nested_2.kind == "compound" assert nested_2.language == "cpp" assert nested_2.name == "Point" assert not nested_2.prefix assert not nested_2.suffix assert len(nested_2.nested) == 1 nested_2_1 = nested_2.nested[0] assert nested_2_1 is not None assert not nested_2_1.id assert not nested_2_1.kind assert nested_2_1.language == "cpp" assert nested_2_1.name == "std::string" assert nested_2_1.prefix == "const " assert nested_2_1.suffix == " &"
def test_parse_cpp_type_from_multiple_nested_text_and_ref(): parser = DoxygenXmlParser() cpp = CppLanguage(parser) type_element = ET.Element("type") type_element.text = "const " sub_element(type_element, "ref", refid="tomtom_coordinate", kindref="compound", text="Coordinate", tail=" < std::unique_ptr< ") sub_element(type_element, "ref", refid="tomtom_box", kindref="compound", text="Box", tail=" >, ") sub_element(type_element, "ref", refid="tomtom_point", kindref="compound", text="Point", tail=" < const std::string & > >") type_ref = cpp.parse_type(type_element) assert type_ref is not None assert type_ref.id == "cpp-tomtom_coordinate" assert type_ref.kind == "compound" assert type_ref.language == "cpp" assert type_ref.name == "Coordinate" assert type_ref.prefix == "const " assert not type_ref.suffix assert len(type_ref.nested) == 2 nested_1 = type_ref.nested[0] assert nested_1 is not None assert not nested_1.id assert not nested_1.kind assert nested_1.language == "cpp" assert nested_1.name == "std::unique_ptr" assert not nested_1.prefix assert not nested_1.suffix assert len(nested_1.nested) == 1 nested_1_1 = nested_1.nested[0] assert nested_1_1 is not None assert nested_1_1.id == "cpp-tomtom_box" assert nested_1_1.kind == "compound" assert nested_1_1.language == "cpp" assert nested_1_1.name == "Box" assert not nested_1_1.prefix assert not nested_1_1.suffix nested_2 = type_ref.nested[1] assert nested_2 is not None assert nested_2.id == "cpp-tomtom_point" assert nested_2.kind == "compound" assert nested_2.language == "cpp" assert nested_2.name == "Point" assert not nested_2.prefix assert not nested_2.suffix assert len(nested_2.nested) == 1 nested_2_1 = nested_2.nested[0] assert nested_2_1 is not None assert not nested_2_1.id assert not nested_2_1.kind assert nested_2_1.language == "cpp" assert nested_2_1.name == "std::string" assert nested_2_1.prefix == "const " assert nested_2_1.suffix == " &"
def test_table_with_nested_itemizedlist(): description = ET.Element("description") para = sub_element(description, "para") table = sub_element(para, "table", rows="1", cols="1") row = sub_element(table, "row") entry = sub_element(row, "entry", thead="no") para = sub_element(entry, "para", text="This is a list of items:") itemized_list = sub_element(para, "itemizedlist") list_item_1 = sub_element(itemized_list, "listitem") sub_element(list_item_1, "para", text="List item 1") list_item_2 = sub_element(itemized_list, "listitem") sub_element(list_item_2, "para", text="List item 2") result = DescriptionParser("lang").parse(description) assert result == """[cols=1*]
def test_remove_single_leading_space(): description = ET.Element("description") sub_element(description, "para", text=" Actual description text.") sub_element(description, "para", text=" And some more text.") result = DescriptionParser("lang").parse(description) assert result == """Actual description text.
def test_multiple_para(): description = ET.Element("description") sub_element(description, "para", text="Actual description text.") sub_element(description, "para", text="And some more text.") result = DescriptionParser("lang").parse(description) assert result == """Actual description text.
def test_single_para(): description = ET.Element("description") sub_element(description, "para", text="Actual description text.") result = DescriptionParser("lang").parse(description) assert result == f"Actual description text."