Exemplo n.º 1
0
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)
    ])
Exemplo n.º 2
0
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)
    ])
Exemplo n.º 3
0
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))*"
Exemplo n.º 4
0
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 &"
Exemplo n.º 5
0
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 &"
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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<> &"
Exemplo n.º 8
0
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)
Exemplo n.º 9
0
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)
Exemplo n.º 10
0
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 &()"
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
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> &"
Exemplo n.º 13
0
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)
    ])
Exemplo n.º 14
0
def test_print_ref__no_link__empty(api_mock):
    ref = TypeRef("lang")
    helper = TemplateHelper(api_mock)
    assert helper.print_ref(ref, link=False) == ""
Exemplo n.º 15
0
def test_print_ref__no_link__none(api_mock):
    helper = TemplateHelper(api_mock)
    assert helper.print_ref(None, link=False) == ""
Exemplo n.º 16
0
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()
Exemplo n.º 17
0
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()
Exemplo n.º 18
0
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"
Exemplo n.º 19
0
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()