def test_print_ref__link__closure(api_mock): arg1_type = TypeRef("lang") arg1_type.name = "ArgType1" arg1_type.id = "lang-argtype1" arg1 = Parameter() arg1.type = arg1_type arg2_type = TypeRef("lang") arg2_type.name = "ArgType2" arg2 = Parameter() arg2.name = "value" arg2.type = arg2_type return_type = TypeRef("lang") return_type.name = "MyType" return_type.id = "lang-tomtom_1_MyType" ref = TypeRef("lang") ref.args = [arg1, arg2] ref.returns = return_type helper = TemplateHelper(api_mock) assert ( helper.print_ref(ref) == "xref:lang-tomtom_1_MyType[++MyType++](xref:lang-argtype1[++ArgType1++], ArgType2 " "value)") api_mock.link_to_element.assert_has_calls([ call(arg1_type.id, arg1_type.name), call(return_type.id, return_type.name) ])
def test_print_ref__link__complex_closure(api_mock): ref = TypeRef("lang") ref.name = "std::function" ref.nested = [TypeRef("lang")] ref.nested[0].returns = TypeRef("lang") ref.nested[0].returns.name = "void" ref.nested[0].args = [Parameter()] ref.nested[0].args[0].type = TypeRef("lang") ref.nested[0].args[0].type.name = "std::shared_ptr" ref.nested[0].args[0].type.prefix = "const " ref.nested[0].args[0].type.suffix = "&" ref.nested[0].args[0].type.nested = [TypeRef("lang")] ref.nested[0].args[0].type.nested[0].name = "detail::SuccessDescriptor" ref.nested[0].args[0].type.nested[0].id = "lang-successdescriptor" helper = TemplateHelper(api_mock) assert ( helper.print_ref(ref) == "std::function<void(const std::shared_ptr<xref:lang-successdescriptor" "[++detail::SuccessDescriptor++]>&)>") api_mock.link_to_element.assert_has_calls([ call(ref.nested[0].args[0].type.nested[0].id, ref.nested[0].args[0].type.nested[0].name) ])
def test_print_ref__no_link__closure_prefix_suffix(api_mock): arg1_type = TypeRef("lang") arg1_type.name = "ArgType1" arg1_type.id = "lang-argtype1" arg1 = Parameter() arg1.type = arg1_type arg2_type = TypeRef("lang") arg2_type.name = "ArgType2" arg2 = Parameter() arg2.name = "value" arg2.type = arg2_type return_type = TypeRef("lang") return_type.name = "MyType" return_type.id = "lang-tomtom_1_MyType" return_type.prefix = "const " return_type.suffix = "&" ref = TypeRef("lang") ref.returns = return_type ref.args = [arg1, arg2] ref.prefix = "final " ref.suffix = "*" helper = TemplateHelper(api_mock) assert helper.print_ref( ref, link=False) == "final (const MyType&(ArgType1, ArgType2 value))*"
def test_print_ref__no_link__strip_surrounding_whitespace(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.id = "lang-mytype" ref.prefix = "\tconst " ref.suffix = " & " helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == "const MyType &"
def test_print_ref__no_link__name_prefix_suffix_no_id(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.id = "lang-mytype" ref.prefix = "const " ref.suffix = " &" helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == "const MyType &"
def test_print_ref__link__name_prefix_suffix_no_id(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" helper = TemplateHelper(api_mock) assert helper.print_ref(ref) == "const MyType &" api_mock.link_to_element.assert_not_called()
def test_print_ref__no_link__empty_nested_types(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" ref.nested = [] helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == "const MyType<> &"
def test_print_ref__link__strip_surrounding_whitespace(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = " const " ref.suffix = " & " ref.id = "lang-tomtom_1_MyType" helper = TemplateHelper(api_mock) assert helper.print_ref( ref) == "const xref:lang-tomtom_1_MyType[++MyType++] &" api_mock.link_to_element.assert_called_once_with(ref.id, ref.name)
def test_print_ref__link__empty_nested_types(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" ref.nested = [] helper = TemplateHelper(api_mock) assert helper.print_ref( ref) == "const xref:lang-tomtom_1_MyType[++MyType++]<> &" api_mock.link_to_element.assert_called_once_with(ref.id, ref.name)
def test_print_ref__no_link__empty_closure(api_mock): return_type = TypeRef("lang") return_type.name = "MyType" return_type.prefix = "const " return_type.suffix = " &" return_type.id = "lang-tomtom_1_MyType" ref = TypeRef("lang") ref.args = [] ref.returns = return_type helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == "const MyType &()"
def test_print_ref__link__empty_closure(api_mock): return_type = TypeRef("lang") return_type.name = "MyType" return_type.prefix = "const " return_type.suffix = " &" return_type.id = "lang-tomtom_1_MyType" ref = TypeRef("lang") ref.args = [] ref.returns = return_type helper = TemplateHelper(api_mock) assert helper.print_ref( ref) == "const xref:lang-tomtom_1_MyType[++MyType++] &()" api_mock.link_to_element.assert_called_once_with(return_type.id, return_type.name)
def test_print_ref__no_link__nested_types(api_mock): nested_type_with_id = TypeRef("lang") nested_type_with_id.name = "Nested1" nested_type_with_id.id = "lang-nested1" nested_type_without_id = TypeRef("lang") nested_type_without_id.name = "Nested2" ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" ref.nested = [nested_type_with_id, nested_type_without_id] helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == "const MyType<Nested1, Nested2> &"
def test_print_ref__link__nested_types(api_mock): nested_type_with_id = TypeRef("lang") nested_type_with_id.name = "Nested1" nested_type_with_id.id = "lang-nested1" nested_type_without_id = TypeRef("lang") nested_type_without_id.name = "Nested2" ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" ref.nested = [nested_type_with_id, nested_type_without_id] helper = TemplateHelper(api_mock) assert ( helper.print_ref(ref) == "const xref:lang-tomtom_1_MyType[++MyType++]<xref:lang-nested1[++Nested1++], " "Nested2> &") api_mock.link_to_element.assert_has_calls([ call(nested_type_with_id.id, nested_type_with_id.name), call(ref.id, ref.name) ])
def test_print_ref__no_link__empty(api_mock): ref = TypeRef("lang") helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == ""
def test_print_ref__no_link__none(api_mock): helper = TemplateHelper(api_mock) assert helper.print_ref(None, link=False) == ""
def test_print_ref__link__name_only(api_mock): ref = TypeRef("lang") ref.name = "MyType" helper = TemplateHelper(api_mock) assert helper.print_ref(ref) == "MyType" api_mock.link_to_element.assert_not_called()
def test_print_ref__link__none(api_mock): helper = TemplateHelper(api_mock) assert helper.print_ref(None) == "" api_mock.link_to_element.assert_not_called()
def test_print_ref__no_link__name_only(api_mock): ref = TypeRef("lang") ref.name = "MyType" ref.id = "lang-mytype" helper = TemplateHelper(api_mock) assert helper.print_ref(ref, link=False) == "MyType"
def test_print_ref__link__empty(api_mock): ref = TypeRef("lang") helper = TemplateHelper(api_mock) assert helper.print_ref(ref) == "" api_mock.link_to_element.assert_not_called()