211 lines
4.3 KiB
Python
211 lines
4.3 KiB
Python
|
from io import StringIO
|
||
|
import pytest
|
||
|
|
||
|
from assembler.assembler import Assembler, ParsingError
|
||
|
|
||
|
def test_missing_comma(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, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_missing_newline(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, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
|
||
|
|
||
|
def test_additional_comma1(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, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_additional_comma2(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, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
|
||
|
|
||
|
def test_bad_mark1(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0xfe
|
||
|
this_is_a_bad_mark
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_mark2(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0xfe
|
||
|
This_is_a_bad_mark:
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_mark3(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0xfe
|
||
|
0this_is_a_bad_mark:
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_mark4(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, this_is_a_missing_mark
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_mark5(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, this_is_a_missing_mark:
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_directive1(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
.set data [0x00, 0x10]
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_directive2(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
.set[0x00, 0x10]
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_directive3(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
.set [0x00, 0x10,]
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|
||
|
def test_bad_directive4(basic_machine_definition):
|
||
|
memory_definition, command_defintion = basic_machine_definition
|
||
|
|
||
|
data = StringIO(
|
||
|
'''
|
||
|
ldi r0, 0
|
||
|
ldi r1, 0xfe
|
||
|
add r0, r1
|
||
|
.set [0x00, 0x10
|
||
|
'''
|
||
|
)
|
||
|
assembler = Assembler(data, memory_definition, command_defintion, {})
|
||
|
|
||
|
with pytest.raises(ParsingError):
|
||
|
assembler.parse()
|
||
|
|