BCI-dev/assembler/test/test_013_util.py
2018-10-27 16:51:52 +02:00

41 lines
1.3 KiB
Python

from assembler.util import can_be_mark, can_convert_to_int, autoint, int16_2_bytes
def test_can_be_mark():
assert can_be_mark("this_is_a_mark") == True
assert can_be_mark("this_is_a_mark0") == True
assert can_be_mark("tHIS0") == True
assert can_be_mark("This_is_not_a_mark") == False
assert can_be_mark("0this_is_no_mark") == False
assert can_be_mark("this#is_no_mark") == False
def test_can_convert_to_int():
assert can_convert_to_int("0xfe") == True
assert can_convert_to_int("0xFE") == True
assert can_convert_to_int("10") == True
assert can_convert_to_int("0b100") == True
assert can_convert_to_int("'a'") == True
assert can_convert_to_int("'\\n'") == True
assert can_convert_to_int("0xfg") == False
assert can_convert_to_int("0xFG") == False
assert can_convert_to_int("10a") == False
assert can_convert_to_int("0b20") == False
assert can_convert_to_int("'aa'") == False
assert can_convert_to_int("'\\z'") == False
def test_autoint():
assert autoint("0xfe") == 0xfe
assert autoint("0xFE") == 0xfe
assert autoint("10") == 10
assert autoint("0b1010101") == 0b1010101
assert autoint("'a'") == ord("a")
assert autoint("'\\n'") == ord("\n")
def test_int16_2_bytes():
assert int16_2_bytes(2) == b"\x02\00"
assert int16_2_bytes(0x0200) == b"\x00\x02"
assert int16_2_bytes(-1) == b"\xff\xff"