From 7363842f971d3e2fab2a561e275b6aeea97ae29b Mon Sep 17 00:00:00 2001 From: Rob Berwick Date: Sun, 17 Nov 2024 16:51:07 +0000 Subject: [PATCH] test: Add tests for `string_to_info_block_data` --- tests/utilities/test_string_to_info_block.py | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/utilities/test_string_to_info_block.py diff --git a/tests/utilities/test_string_to_info_block.py b/tests/utilities/test_string_to_info_block.py new file mode 100644 index 0000000..64537fd --- /dev/null +++ b/tests/utilities/test_string_to_info_block.py @@ -0,0 +1,29 @@ +from src.blinkstick.utilities import string_to_info_block_data + + +def test_string_to_info_block_data_converts_string_to_byte_array(): + block_string = "hello" + expected_padding_length = 31 - len(block_string) + result = string_to_info_block_data("hello") + expected = b"\x01hello" + b"\x00" * expected_padding_length + assert result == expected + + +def test_string_to_info_block_data_handles_empty_string(): + result = string_to_info_block_data("") + expected = b"\x01" + b"\x00" * 31 + assert result == expected + + +def test_string_to_info_block_data_truncates_long_string(): + long_string = "a" * 40 + result = string_to_info_block_data(long_string) + expected = b"\x01" + b"a" * 31 + assert result == expected + + +def test_string_to_info_block_data_handles_exact_31_characters(): + exact_string = "a" * 31 + result = string_to_info_block_data(exact_string) + expected = b"\x01" + b"a" * 31 + assert result == expected