mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 15:27:33 +00:00
[api] Test which string fields get the null default
This commit is contained in:
@@ -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"),
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user