def test_type_ref_to_str(): assert str(TypeRef("cpp")) == "" assert str(TypeRef("cpp", "Type")) == "Type" type_ref = TypeRef("cpp", "Type") type_ref.id = "12345" assert str(type_ref) == "Type" type_ref.kind = "class" assert str(type_ref) == "Type" type_ref.prefix = "const " assert str(type_ref) == "const Type" type_ref.suffix = " &" assert str(type_ref) == "const Type &" nested_type_1 = TypeRef("cpp", "Nested1") type_ref.nested = [nested_type_1] assert str(type_ref) == "const Type< Nested1 > &" nested_type_2 = TypeRef("cpp", "Nested2") nested_type_2.prefix = "const " nested_type_2.suffix = "*" type_ref.nested.append(nested_type_2) assert str(type_ref) == "const Type< Nested1, const Nested2* > &" nested_type_2.nested = [nested_type_1] assert str( type_ref) == "const Type< Nested1, const Nested2< Nested1 >* > &"
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_link_from_ref__name_prefix_suffix_no_id(context_mock): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" assert link_from_ref(ref, context_mock) == "const MyType &" context_mock.assert_not_called()
def test_print_ref__name_prefix_suffix_no_id(): ref = TypeRef("lang") ref.name = "MyType" ref.id = "lang-mytype" ref.prefix = "const " ref.suffix = " &" assert print_ref(ref) == "const MyType &"
def test_type_list(): type1 = TypeRef("lang") type1.prefix = "const " type1.name = "Type1" type2 = TypeRef("lang") type2.name = "Type2" type2.suffix = " &" type2.id = "lang-type2" type3 = TypeRef("lang") type3.name = "Type3" type3.nested = [type1, type2] param1 = Parameter() param1.type = type1 param1.name = "arg1" param2 = Parameter() param2.type = type2 param2.name = "arg2" param3 = Parameter() param3.type = type3 param3.name = "arg3" assert (type_list([param1, param2, param3]) == "(const Type1, Type2 &, Type3<const Type1, Type2 &>)")
def test_type_list(empty_generating_api): type1 = TypeRef("lang") type1.prefix = "const " type1.name = "Type1" type2 = TypeRef("lang") type2.name = "Type2" type2.suffix = " &" type2.id = "lang-type2" type3 = TypeRef("lang") type3.name = "Type3" type3.nested = [type1, type2] param1 = Parameter() param1.type = type1 param1.name = "arg1" param2 = Parameter() param2.type = type2 param2.name = "arg2" param3 = Parameter() param3.type = type3 param3.name = "arg3" helper = TemplateHelper(empty_generating_api) assert (helper.type_list( [param1, param2, param3]) == "(const Type1, Type2 &, Type3<const Type1, Type2 &>)")
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_argument_list(empty_context): type1 = TypeRef("lang") type1.prefix = "const " type1.name = "Type1" type2 = TypeRef("lang") type2.name = "Type2" type2.suffix = " &" type2.id = "lang-type2" type3 = TypeRef("lang") type3.name = "Type3" type3.nested = [type1, type2] param1 = Parameter() param1.type = type1 param2 = Parameter() param2.type = type2 param2.name = "arg2" param3 = Parameter() param3.type = type3 param3.name = "arg3" assert (argument_list([param1, param2, param3], empty_context) == "(const Type1, xref:lang-type2[Type2] & arg2, " "Type3<const Type1, xref:lang-type2[Type2] &> arg3)")
def test_print_ref__strip_surrounding_whitespace(): ref = TypeRef("lang") ref.name = "MyType" ref.id = "lang-mytype" ref.prefix = "\tconst " ref.suffix = " & " assert print_ref(ref) == "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_link_from_ref__strip_surrounding_whitespace(context_mock): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = " const " ref.suffix = " & " ref.id = "lang-tomtom_1_MyType" assert link_from_ref(ref, context_mock) == "const xref:lang-tomtom_1_MyType[MyType] &" context_mock.link_to_element.assert_called_once_with(ref.id, ref.name)
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__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__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_type_and_name__no_name(empty_context): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" param = Parameter() param.type = ref param.name = "" assert type_and_name(param, empty_context) == "const xref:lang-tomtom_1_MyType[MyType] &"
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_parameter__no_link(empty_generating_api): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" param = Parameter() param.type = ref param.name = "arg" helper = TemplateHelper(empty_generating_api) assert helper.parameter(param, link=False) == "const MyType & arg"
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_parameter__no_name(empty_generating_api): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" param = Parameter() param.type = ref param.name = "" helper = TemplateHelper(empty_generating_api) assert helper.parameter( param) == "const xref:lang-tomtom_1_MyType[++MyType++] &"
def test_print_ref__nested_types(): 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] assert print_ref(ref) == "const MyType<Nested1, Nested2> &"
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_parameter__default_value(empty_generating_api): ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" param = Parameter() param.type = ref param.name = "arg" param.default_value = "12" helper = TemplateHelper(empty_generating_api) assert helper.parameter( param, default_value=True ) == "const xref:lang-tomtom_1_MyType[++MyType++] & arg = 12"
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_link_from_ref__nested_types(context_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] assert (link_from_ref(ref, context_mock) == "const xref:lang-tomtom_1_MyType[MyType]<xref:lang-nested1[Nested1], Nested2> &") context_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_parameter__param_name_first(empty_generating_api): class _TemplateHelper(TemplateHelper): PARAM_NAME_FIRST = True ref = TypeRef("lang") ref.name = "MyType" ref.prefix = "const " ref.suffix = " &" ref.id = "lang-tomtom_1_MyType" param = Parameter() param.type = ref param.name = "arg" param.prefix = "vararg " param.default_value = "12" helper = _TemplateHelper(empty_generating_api) assert (helper.parameter(param, default_value=True) == "vararg arg const xref:lang-tomtom_1_MyType[++MyType++] " "& = 12")
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) ])