Skip to content
Snippets Groups Projects
Commit cff9b961 authored by Chris's avatar Chris
Browse files

Tests für Breakpoints und unbekannte Tokens

parent 6bc3dc18
Branches
No related tags found
1 merge request!1Master
from interpreter import interpret
import unittest
from unittest import mock
def input_exit(prompt):
return "EXIT"
def input_continue(prompt):
return ""
def init_without_tokens(self, regex_to_token, program):
self.regex_to_token = {}
self.program = program
self.current_position = 0
class InterpreterTest(unittest.TestCase):
def test_assignment_default_zero(self):
......@@ -207,3 +218,17 @@ class InterpreterTest(unittest.TestCase):
self.assertEqual(interpret('''x2:=3;
x0:=x2+2'''), 5)
self.assertEqual(interpret('x1:=x1-2;\n x0:=x1+2'), 2)
@mock.patch('interpreter.input', side_effect=input_exit)
def test_break_exit(self, input):
self.assertEqual(interpret('x1:=2; BREAK x0:=2'), -1)
self.assertEqual(interpret('LOOP x1 DO BREAK x2:= 2 END'), -1)
@mock.patch('interpreter.input', side_effect=input_continue)
def test_break_continue(self, input):
self.assertEqual(interpret('x1:=2; LOOP x1 DO x0:=x0+2 BREAK END'), 4)
@mock.patch('lexer.Lexer.__init__', init_without_tokens)
def test_unknown_tokens(self):
with self.assertRaises(SyntaxError):
interpret('BLIBLABLUB')
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment