def test_objc_method_signature__multiple_params_linked_return(helper):
    method = Compound("objc")
    method.name = "setValue:withUnit:andALongerParam:"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="Value")
    method.returns.type.id = "objc-value"

    param1 = Parameter()
    param1.name = "arg1"
    param1.type = TypeRef("objc", "Type1")

    param2 = Parameter()
    param2.name = "arg2"
    param2.type = TypeRef("objc", "Type2")
    param2.type.id = "objc-type2"

    param3 = Parameter()
    param3.name = "arg3"
    param3.type = TypeRef("objc", "Type3")

    method.params = [param1, param2, param3]

    assert (helper.method_signature(method) == """\
- (xref:objc-value[++Value++])setValue:(Type1)arg1
         withUnit:(xref:objc-type2[++Type2++])arg2
  andALongerParam:(Type3)arg3""")
def test_method_signature__single_param(helper):
    method = Compound("python")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("python", "int")

    method.params = [Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("python", "int")

    assert helper.method_signature(
        method) == "def ShortMethod(value: int) -> int"
def test_params__no_type():
    param1 = Parameter()
    param1.type = None
    param1.name = "arg1"

    param2 = Parameter()
    param2.type = None
    param2.name = "arg2"

    member = Compound("lang")
    member.params = [param1, param2]

    assert list(params(member)) == [param1, param2]
Esempio n. 4
0
def test_method_signature__single_param(empty_generating_api):
    method = Compound("lang")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("lang", "void")

    method.params = [Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("lang", "int")

    helper = TemplateHelper(empty_generating_api)
    assert helper.method_signature(method) == "void ShortMethod(int value)"
def test_method_signature__one_param(helper):
    method = Compound("swift")
    method.name = "setValue"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("swift", name="Value")

    param1 = Parameter()
    param1.name = "arg1"
    param1.type = TypeRef("objc", "Type1")
    method.params = [param1]

    assert helper.method_signature(
        method) == "func setValue(arg1: Type1) -> Value"
def test_objc_method_signature__one_param(helper):
    method = Compound("objc")
    method.name = "setValue:"
    method.returns = ReturnValue()
    method.returns.type = TypeRef("objc", name="Value")
    method.returns.type.id = "objc-value"

    param1 = Parameter()
    param1.name = "arg1"
    param1.type = TypeRef("objc", "Type1")
    method.params = [param1]

    assert helper.method_signature(
        method) == "- (xref:objc-value[++Value++])setValue:(Type1)arg1"
def test_method_signature__ignore_param_type_xref_length(helper):
    method = Compound("python")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("python", "None")

    method.params = [Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("python", "int")
    method.params[0].type.id = "ab" * 80

    assert (helper.method_signature(method) ==
            f"def ShortMethod(value: xref:{'ab' * 80}[++int++]) -> None")
def test_method_signature__single_param__too_wide(helper):
    method = Compound("python")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("python", "str")

    method.params = [Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("python", "int")

    assert (helper.method_signature(method, max_width=20) == """\
def ShortMethod(
    value: int) -> str""")
Esempio n. 9
0
def test_method_signature__ignore_param_type_xref_length(empty_generating_api):
    method = Compound("lang")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("lang", "void")

    method.params = [Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("lang", "int")
    method.params[0].type.id = "ab" * 80

    helper = TemplateHelper(empty_generating_api)
    assert (helper.method_signature(method) ==
            f"void ShortMethod(xref:{'ab' * 80}[++int++] "
            "value)")
def test_params__self():
    type1 = TypeRef("lang")
    type1.name = "self"

    type2 = TypeRef("lang")
    type2.name = "float"

    param1 = Parameter()
    param1.type = type1

    param2 = Parameter()
    param2.type = type2
    param2.name = "arg2"

    member = Compound("lang")
    member.params = [param1, param2]

    assert list(params(member)) == [param2]
def test_method_signature__multiple_params(helper):
    method = Compound("python")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("python", "None")

    method.params = [Parameter(), Parameter(), Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("python", "int")
    method.params[1].name = "other_value"
    method.params[1].type = TypeRef("python", "float")
    method.params[2].name = "text"
    method.params[2].type = TypeRef("python", "str")

    assert (helper.method_signature(method) == """\
def ShortMethod(value: int,
                other_value: float,
                text: str) -> None""")
def test_method_signature__multiple_params__last_param_too_wide(helper):
    method = Compound("python")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("python", "Type")

    method.params = [Parameter(), Parameter(), Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("python", "int")
    method.params[1].name = "other_value"
    method.params[1].type = TypeRef("python", "float")
    method.params[2].name = "text" * 10
    method.params[2].type = TypeRef("python", "str")

    assert (helper.method_signature(method, max_width=40) == f"""\
def ShortMethod(
    value: int,
    other_value: float,
    {"text" * 10}: str) -> Type""")
Esempio n. 13
0
def test_method_signature__multiple_params(empty_generating_api):
    method = Compound("lang")
    method.name = "ShortMethod"

    method.returns = ReturnValue()
    method.returns.type = TypeRef("lang", "void")

    method.params = [Parameter(), Parameter(), Parameter()]
    method.params[0].name = "value"
    method.params[0].type = TypeRef("lang", "int")
    method.params[1].name = "other_value"
    method.params[1].type = TypeRef("lang", "double")
    method.params[2].name = "text"
    method.params[2].type = TypeRef("lang", "std::string")

    helper = TemplateHelper(empty_generating_api)
    assert (helper.method_signature(method) == """\
void ShortMethod(int value,
                 double other_value,
                 std::string text)""")