def test_commandType(self): """ Simple test, no jumps""" testParser = Parser( '/Users/Sean/Desktop/nand2tetris/projects/06/add/Add.asm') goodRes = ['A', 'C', 'A', 'C', 'A', 'C'] first = True for res in goodRes: if not first: testParser.advance() print str(res) + " : " + str(testParser.getLine()) self.assertEqual(testParser.commandType(), res) first = False
def test_commandTypeLabel(self): """ More complicated test, includes Labels""" testParser = Parser( '/Users/Sean/Desktop/nand2tetris/projects/06/max/Max.asm') goodRes = [ 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'A', 'C', 'L', 'A', 'C', 'L', 'A', 'C', 'L', 'A', 'C' ] first = True for res in goodRes: if not first: testParser.advance() print str(res) + " : " + str(testParser.getLine()) self.assertEqual(testParser.commandType(), res) first = False
def test_command_type(self): file_path = './add/Add.asm' test_parser = Parser(file_path) test_parser.process_file() test_parser.advance() self.assertEqual(test_parser.commandType(), 'A_COMMAND') test_parser.advance() self.assertEqual(test_parser.commandType(), 'C_COMMAND') test_parser.advance() self.assertEqual(test_parser.commandType(), 'A_COMMAND') test_parser.advance() self.assertEqual(test_parser.commandType(), 'C_COMMAND') test_parser.advance() self.assertEqual(test_parser.commandType(), 'A_COMMAND') test_parser.advance() self.assertEqual(test_parser.commandType(), 'C_COMMAND')