[api] Test which string fields get the null default

This commit is contained in:
J. Nick Koston
2026-09-07 23:11:47 +02:00
parent 7910c372cd
commit 144cd419ad
@@ -199,6 +199,24 @@ def _decode_case(field_type: int, number: int, *, repeated: bool = False) -> str
).decode_content
@pytest.mark.parametrize(
("needs_decode", "force", "member"),
[
(False, False, "StringRef value{nullptr, 0};"),
(True, False, "StringRef value{};"),
(False, True, "StringRef value{};"),
],
)
def test_string_fields_default_to_null_only_when_never_read(
needs_decode: bool, force: bool, member: str
) -> None:
"""Only a string that is neither decoded nor force encoded may start as a null StringRef."""
ti = create_field_type_info(
_field(STRING, force=force), needs_decode=needs_decode, needs_encode=True
)
assert ti.public_content == [member]
@pytest.mark.parametrize(
("field_type", "number", "wire_type", "accessor"),
[