Skip to content

Commit

Permalink
Add a basic test for convert_to_pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
insolor committed Jun 2, 2024
1 parent 391184b commit cd124ae
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/test_patterns.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import pytest
from hypothesis import given
from hypothesis import strategies as st

from search_offsets.patterns import hex_to_bytes
from search_offsets.patterns import convert_to_pattern, hex_to_bytes


@given(st.integers(0, 255))
def test_hex_to_bytes(byte: int):
assert hex_to_bytes(f"{byte:02X}") == byte.to_bytes(1, "little")


@pytest.mark.parametrize(
("pattern", "expected"),
[
(["??"], [None]),
(["FF"], [255]),
(["FF", "??"], [255, None]),
],
)
def test_convert_to_pattern(pattern: str, expected: list[int | None]):
assert convert_to_pattern(pattern) == expected

0 comments on commit cd124ae

Please sign in to comment.