From cff9b961924a86915c8e74d664efff5eadf8837d Mon Sep 17 00:00:00 2001
From: Chris <Christopher.Happe@uni-duesseldorf.de>
Date: Sun, 15 Nov 2020 11:03:33 +0100
Subject: [PATCH] =?UTF-8?q?Tests=20f=C3=BCr=20Breakpoints=20und=20unbekann?=
 =?UTF-8?q?te=20Tokens?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Interpreter/test_loop_interpreter.py      | 25 +++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/info4/kapitel-8/Interpreter/test_loop_interpreter.py b/info4/kapitel-8/Interpreter/test_loop_interpreter.py
index f8552a8..1cb87c4 100644
--- a/info4/kapitel-8/Interpreter/test_loop_interpreter.py
+++ b/info4/kapitel-8/Interpreter/test_loop_interpreter.py
@@ -1,6 +1,17 @@
 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
-- 
GitLab