Skip to content

Commit

Permalink
test: Add tests for string_to_info_block_data
Browse files Browse the repository at this point in the history
  • Loading branch information
robberwick committed Nov 17, 2024
1 parent 6a9a40b commit 7363842
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/utilities/test_string_to_info_block.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7363842

Please sign in to comment.