From d1101ccdfecab380465af0f5731a4d3f06733e41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Wed, 10 Oct 2018 10:30:54 +0200 Subject: [PATCH] added tests for failures --- assembler/test/test_021_parsing_failures.py | 210 ++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 assembler/test/test_021_parsing_failures.py diff --git a/assembler/test/test_021_parsing_failures.py b/assembler/test/test_021_parsing_failures.py new file mode 100644 index 0000000..3a64168 --- /dev/null +++ b/assembler/test/test_021_parsing_failures.py @@ -0,0 +1,210 @@ +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() +