def test_load_effective_address_program_counter_relative_extended_is_16_bit( self): statements = [ Statement(" ORG $0600"), Statement("B LDX [Z,PCR]"), ] statements.extend([Statement(" NOP ") for _ in range(255)]) statements.extend([ Statement("Z RTS "), Statement(" END B"), ]) program = Program() program.statements = statements program.translate_statements() self.assertEqual([ 0xAE, 0x9D, 0x00, 0xFF, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x39 ], program.get_binary_array())
def test_print_statements_empty_statements_correct(self, print_mock): program = Program() program.print_statements() self.assertEqual([call("-- Assembled Statements --")], print_mock.mock_calls)
def test_print_symbol_table_corect(self, print_mock): statement = Statement("POLCAT EQU $FFEE") program = Program() program.save_symbol(0, statement) program.print_symbol_table() self.assertEqual([call("-- Symbol Table --"), call("$FFEE POLCAT")], print_mock.mock_calls)
def test_print_empty_symbol_table_corect(self, print_mock): program = Program() program.print_symbol_table() self.assertEqual([call("-- Symbol Table --")], print_mock.mock_calls)
def test_save_symbol_saves_index_of_statement(self): statement = Statement("START JMP $FFEE") program = Program() program.save_symbol(0x35, statement) self.assertEqual("35", program.symbol_table["START"].hex())
def test_save_symbol_saves_value(self): statement = Statement("POLCAT EQU $FFEE") program = Program() program.save_symbol(0, statement) self.assertEqual("FFEE", program.symbol_table["POLCAT"].hex())
def test_org_sets_origin(self): statement = Statement(" ORG $1234") program = Program() program.statements = [statement] program.translate_statements() self.assertEqual("1234", program.origin.hex())
def test_nam_mnemonic_empty(self): program = Program() program.statements = [] program.translate_statements() self.assertEqual(None, program.name)
def test_nam_mnemonic_sets_name(self): statement = Statement(" NAM test") program = Program() program.statements = [statement] program.translate_statements() self.assertEqual("test", program.name)
def test_get_binary_array_postbyte_only(self): statement1 = Statement(" JMP $FFFF") statement1.code_pkg.post_byte = NumericValue("$FF") program = Program() program.statements = [statement1] self.assertEqual([0xFF], program.get_binary_array())
def test_get_binary_array_empty_on_comments_and_empty_lines(self): statement1 = Statement("") statement2 = Statement("; comment only") program = Program() program.statements = [statement1, statement2] self.assertEqual([], program.get_binary_array())
def test_get_binary_array_empty_if_no_statements(self): program = Program() self.assertEqual([], program.get_binary_array())
def test_explicit_direct_addressing_mode(self): statements = [Statement(" LDX <$88")] program = Program() program.statements = statements program.translate_statements() self.assertEqual([0x9E, 0x88], program.get_binary_array())
def test_extended_indexed_with_empty_lhs(self): statements = [Statement(" STX [,X]")] program = Program() program.statements = statements program.translate_statements() self.assertEqual([0xAF, 0x94], program.get_binary_array())
def test_save_symbol_does_nothing_if_no_label(self): statement = Statement(" JMP $FFFF") program = Program() program.symbol_table = {"BLAH": 1234} program.save_symbol(0, statement) self.assertEqual({"BLAH": 1234}, program.symbol_table)