BCI-assembler/assembler/test/test_020_basic_parsing.py

69 lines
1.3 KiB
Python
Raw Normal View History

2018-10-09 09:44:00 +00:00
from io import StringIO
import pytest
from assembler.assembler import Assembler
def test_commands(basic_machine_definition):
memory_definition, command_defintion = basic_machine_definition
data = StringIO(
'''
ldi r0, 0xfe
ldi r1, 0xfe
add r0, r1
'''
)
assembler = Assembler(data, memory_definition, command_defintion, {})
assembler.parse()
2018-10-09 13:55:42 +00:00
assert assembler._code_objects == [32704 | 0, 0xfe
, 32704 | 1, 0xfe
, 40896 | 0, 1]
def test_mark(basic_machine_definition):
memory_definition, command_defintion = basic_machine_definition
data = StringIO(
'''
ldi r0, test_mark
ldi r1, 0xfe
test_mark:
add r0, r1
'''
)
assembler = Assembler(data, memory_definition, command_defintion, {})
assembler.parse()
assert assembler._code_objects == [32704 | 0, 4
, 32704 | 1, 0xfe
, 40896 | 0, 1]
def test_set_directive(basic_machine_definition):
memory_definition, command_defintion = basic_machine_definition
data = StringIO(
'''
ldi r0, test_mark
ldi r1, 0xfe
test_mark:
.set [0xfe, 0xef,
10, 20,
'a', 'b',
'\\n', 0b10]
'''
)
assembler = Assembler(data, memory_definition, command_defintion, {})
assembler.parse()
assert assembler._code_objects == [32704 | 0, 4
, 32704 | 1, 0xfe
, 0xfe, 0xef
, 10, 20
, ord("a"), ord("b")
, ord("\n"), 0b10]