예제 #1
0
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 >* > &"
예제 #2
0
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&lt;const Type1, Type2 &&gt;)")
예제 #3
0
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&lt;const Type1, xref:lang-type2[Type2] &&gt; arg3)")
예제 #4
0
def test_argument_list__with_types(empty_context):
    type1 = TypeRef("lang")
    type1.name = "Type1"

    type2 = TypeRef("lang")
    type2.name = "Type2"
    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 (argument_list([param1, param2, param3],
                          empty_context) == "(arg1: Type1, arg2: xref:lang-type2[Type2], "
            "arg3: Type3[Type1, xref:lang-type2[Type2]])")
예제 #5
0
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 &>)")
예제 #6
0
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#")
예제 #7
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)
    ])
예제 #8
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<> &"
예제 #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)
예제 #10
0
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&lt;Nested1, Nested2&gt; &"
예제 #11
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> &"
예제 #12
0
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]&lt;xref:lang-nested1[Nested1], Nested2&gt; &")
    context_mock.link_to_element.assert_has_calls(
        [call(nested_type_with_id.id, nested_type_with_id.name),
         call(ref.id, ref.name)])
예제 #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)
    ])