def test_illegal_formatting_fails(text):
    # when:
    try:
        ParameterDocumentation.from_param_string(text)
    except MockGeneratorError:
        return
    assert False
def test_conflicting_length_specifiers(text):
    # when:
    try:
        ParameterDocumentation.from_param_string(text)
    except MockGeneratorError:
        return
    assert False
def test_no_attribution_is_allowed_to_appear_multiple_times(text):
    # when:
    try:
        ParameterDocumentation.from_param_string(text)
    except MockGeneratorError:
        return
    assert False
def test_duplicate_in_out_attributions_are_not_allowed():
    # given:
    text = '@param[in, out] test'

    # when:
    try:
        ParameterDocumentation.from_param_string(text)
    except MockGeneratorError:
        return
    assert False
def test_unknown_attribution():
    # given:
    text = '@param[so-what] d'

    # when:
    try:
        ParameterDocumentation.from_param_string(text)
    except MockGeneratorError:
        return
    assert False
def test_parse_fixed_length(text, fixed_length):
    # when:
    parameter_documentation = ParameterDocumentation.from_param_string(text)

    # then:
    assert parameter_documentation.identifier == 'test'
    assert parameter_documentation.kind == ParameterKind.kind_in()
    assert parameter_documentation.fixed_length == fixed_length
def test_parse_null_terminated():
    # given:
    text = '@param[in, null-terminated] value'

    # when:
    parameter_documentation = ParameterDocumentation.from_param_string(text)

    # then:
    assert parameter_documentation.identifier == 'value'
    assert parameter_documentation.kind == ParameterKind.kind_in()
    assert parameter_documentation.fixed_length is None
    assert parameter_documentation.null_terminated
def test_from_param_string(text, identifier, kind):
    # when:
    parameter_documentation = ParameterDocumentation.from_param_string(text)

    # then:
    assert parameter_documentation.identifier == identifier
    if kind is None:
        assert parameter_documentation.kind is None
    else:
        assert parameter_documentation.kind == kind
    assert parameter_documentation.fixed_length is None
    assert not parameter_documentation.null_terminated
    assert parameter_documentation.length_descriptor is None
def create_parameter_documentation(identifier: str,
                                   parameter_kind: Optional[str] = None,
                                   fixed_length: Optional[int] = None,
                                   null_terminated: bool = False,
                                   length_descriptor: Optional[str] = None):
    attributions = ActiveAttributions()
    if parameter_kind is not None:
        attributions.add_attribution(parameter_kind)
    if fixed_length is not None:
        attributions.add_attribution('fixed-length={}'.format(fixed_length))
    if null_terminated:
        attributions.add_attribution('null-terminated')
    if length_descriptor is not None:
        attributions.add_attribution(
            'length-descriptor={}'.format(length_descriptor))
    return ParameterDocumentation(identifier, attributions)
def test_length_descriptor_attribution_is_parsed(text, expected):
    # when:
    parameter_documentation = ParameterDocumentation.from_param_string(text)

    # then:
    assert parameter_documentation.length_descriptor == expected