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__closure_with_nested_type__custom_start_and_end( api_mock): nested_type = TypeRef("lang") nested_type.name = "Nested1" arg_type = TypeRef("lang") arg_type.name = "ArgType" arg_type.id = "lang-argtype" arg = Parameter() arg.type = arg_type return_type = TypeRef("lang") return_type.name = "MyType" return_type.prefix = "const " return_type.suffix = " &" return_type.id = "lang-tomtom_1_MyType" return_type.nested = [nested_type] ref = TypeRef("lang") ref.args = [arg] ref.returns = return_type class TestHelper(TemplateHelper): NESTED_START: str = "{" NESTED_END: str = ";" ARGS_START: str = "@" ARGS_END: str = "#" helper = TestHelper(api_mock) assert (helper.print_ref(ref, link=False) == "const MyType{Nested1; &@ArgType#")
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__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)