コード例 #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_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))*"
コード例 #3
0
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()
コード例 #4
0
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 &"
コード例 #5
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;)")
コード例 #6
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 &>)")
コード例 #7
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#")
コード例 #8
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)")
コード例 #9
0
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 &"
コード例 #10
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()
コード例 #11
0
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)
コード例 #12
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 &"
コード例 #13
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 &"
コード例 #14
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)
コード例 #15
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<> &"
コード例 #16
0
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] &"
コード例 #17
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)
コード例 #18
0
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"
コード例 #19
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 &()"
コード例 #20
0
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++] &"
コード例 #21
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; &"
コード例 #22
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)
コード例 #23
0
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"
コード例 #24
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> &"
コード例 #25
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)])
コード例 #26
0
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")
コード例 #27
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)
    ])