|
@@ -4,143 +4,107 @@ import os
|
|
|
|
|
|
from utils import execute, kill, run_file, run_barebone
|
|
|
|
|
|
-def flatten(lst):
|
|
|
- new_lst = []
|
|
|
- for f in lst:
|
|
|
- if isinstance(f, (list, tuple)):
|
|
|
- new_lst.extend(flatten(f))
|
|
|
- else:
|
|
|
- new_lst.append(f)
|
|
|
- return new_lst
|
|
|
-
|
|
|
class TestConstructorsActionLanguage(unittest.TestCase):
|
|
|
def test_constructors_simple(self):
|
|
|
- commands = [('"output"', # Output
|
|
|
- ('"const"', 'true'),
|
|
|
+ commands = ['"output"', # Output
|
|
|
+ '"const"', 'true',
|
|
|
'true', # (has next)
|
|
|
- ('"return"', # Return
|
|
|
+ '"return"', # Return
|
|
|
'true', # (has value)
|
|
|
- ('"const"', 'true'),
|
|
|
- ),
|
|
|
- )
|
|
|
+ '"const"', 'true',
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["True"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["True"], 1))
|
|
|
|
|
|
def test_constructors_if_else_true(self):
|
|
|
- commands = [('"if"', # If
|
|
|
- ('"const"', 'true'), # Condition
|
|
|
- ('"output"', # True-part
|
|
|
- ('"const"', 'true'),
|
|
|
+ commands = ['"if"', # If
|
|
|
+ '"const"', 'true', # Condition
|
|
|
+ '"output"', # True-part
|
|
|
+ '"const"', 'true',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'true', # Has else
|
|
|
- ('"output"', # False-part
|
|
|
- ('"const"', 'false'),
|
|
|
+ '"output"', # False-part
|
|
|
+ '"const"', 'false',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'true', # Has next
|
|
|
- ('"return"', # Return
|
|
|
+ '"return"', # Return
|
|
|
'true', # Has value
|
|
|
- ('"const"', "true"),
|
|
|
- ),
|
|
|
-
|
|
|
- )
|
|
|
+ '"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["True"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["True"], 1))
|
|
|
|
|
|
def test_constructors_if_else_false(self):
|
|
|
- commands = [('"if"', # If
|
|
|
- ('"const"', 'false'), # Condition
|
|
|
- ('"output"', # True-part
|
|
|
- ('"const"', 'true'),
|
|
|
+ commands = ['"if"', # If
|
|
|
+ '"const"', 'false', # Condition
|
|
|
+ '"output"', # True-part
|
|
|
+ '"const"', 'true',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'true', # Has else
|
|
|
- ('"output"', # False-part
|
|
|
- ('"const"', 'false'),
|
|
|
+ '"output"', # False-part
|
|
|
+ '"const"', 'false',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'true', # Has next
|
|
|
- ('"return"', # Return
|
|
|
+ '"return"', # Return
|
|
|
'true', # Has value
|
|
|
- ('"const"', "true"),
|
|
|
- ),
|
|
|
-
|
|
|
- )
|
|
|
+ '"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["False"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["False"], 1))
|
|
|
|
|
|
def test_constructors_if_true(self):
|
|
|
- commands = [('"if"', # If
|
|
|
- ('"const"', 'true'), # Condition
|
|
|
- ('"output"', # True-part
|
|
|
- ('"const"', 'true'),
|
|
|
+ commands = ['"if"', # If
|
|
|
+ '"const"', 'true', # Condition
|
|
|
+ '"output"', # True-part
|
|
|
+ '"const"', 'true',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'false', # Has else
|
|
|
'true', # Has next
|
|
|
- ('"return"', # Return
|
|
|
+ '"return"', # Return
|
|
|
'true', # Has value
|
|
|
- ('"const"', "true"),
|
|
|
- ),
|
|
|
-
|
|
|
- )
|
|
|
+ '"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["True"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["True"], 1))
|
|
|
|
|
|
def test_constructors_if_false(self):
|
|
|
- commands = [('"if"', # If
|
|
|
- ('"const"', 'false'), # Condition
|
|
|
- ('"output"', # True-part
|
|
|
- ('"const"', 'true'),
|
|
|
+ commands = ['"if"', # If
|
|
|
+ '"const"', 'false', # Condition
|
|
|
+ '"output"', # True-part
|
|
|
+ '"const"', 'true',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'false', # Has else
|
|
|
'true', # Has next
|
|
|
- ('"return"', # Return
|
|
|
+ '"return"', # Return
|
|
|
'true', # Has value
|
|
|
- ('"const"', "true"),
|
|
|
- ),
|
|
|
-
|
|
|
- )
|
|
|
+ '"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), [None], 1, timeout=True))
|
|
|
+ self.assertTrue(run_barebone(commands, [None], 1, timeout=True))
|
|
|
|
|
|
def test_constructors_addition(self):
|
|
|
- commands = [('"output"',
|
|
|
- ('"call"',
|
|
|
- ('"deref"', '"primitives/integer_addition"'),
|
|
|
+ commands = ['"output"',
|
|
|
+ '"call"',
|
|
|
+ '"deref"', '"primitives/integer_addition"',
|
|
|
'2',
|
|
|
- ('"const"', '1'),
|
|
|
- ('"const"', '5'),
|
|
|
+ '"const"', '1',
|
|
|
+ '"const"', '5',
|
|
|
'false',
|
|
|
- ),
|
|
|
'true',
|
|
|
- ('"return"', 'true', '"const"', 'true'),
|
|
|
- )
|
|
|
+ '"return"', 'true', '"const"', 'true',
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["6"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["6"], 1))
|
|
|
|
|
|
def test_constructors_while_false(self):
|
|
|
- commands = [('"while"', # While
|
|
|
- ('"const"', 'false'), # Condition
|
|
|
- ('"output"', # True-part
|
|
|
- ('"const"', 'true'),
|
|
|
+ commands = ['"while"', # While
|
|
|
+ '"const"', 'false', # Condition
|
|
|
+ '"output"', # True-part
|
|
|
+ '"const"', 'true',
|
|
|
'false', # Has next
|
|
|
- ),
|
|
|
'true', # Has next
|
|
|
- ('"output"', # Output false
|
|
|
- ('"const"', 'false'),
|
|
|
+ '"output"', # Output false
|
|
|
+ '"const"', 'false',
|
|
|
'true', # Has next
|
|
|
- ('"return"', # Return
|
|
|
+ '"return"', # Return
|
|
|
'true', # Has value
|
|
|
- ('"const"', "true"),
|
|
|
- ),
|
|
|
- ),
|
|
|
-
|
|
|
- )
|
|
|
+ '"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["False"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["False"], 1))
|
|
|
|
|
|
def test_constructors_while_true(self):
|
|
|
commands = ['"while"', # While
|
|
@@ -156,7 +120,7 @@ class TestConstructorsActionLanguage(unittest.TestCase):
|
|
|
'true', # Has value
|
|
|
'"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["True", "True", "True", "True"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["True", "True", "True", "True"], 1))
|
|
|
|
|
|
def test_constructors_declare_and_assign(self):
|
|
|
commands = ['"declare"',
|
|
@@ -173,7 +137,7 @@ class TestConstructorsActionLanguage(unittest.TestCase):
|
|
|
'true',
|
|
|
'"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ["5"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ["5"], 1))
|
|
|
|
|
|
def test_constructors_output_input(self):
|
|
|
commands = ['"output"',
|
|
@@ -183,7 +147,7 @@ class TestConstructorsActionLanguage(unittest.TestCase):
|
|
|
'true',
|
|
|
'"const"', "true",
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands) + ['123456'], ["123456"], 1))
|
|
|
+ self.assertTrue(run_barebone(commands + ['123456'], ["123456"], 1))
|
|
|
|
|
|
def test_constructors_continue(self):
|
|
|
commands = ['"while"',
|
|
@@ -203,7 +167,7 @@ class TestConstructorsActionLanguage(unittest.TestCase):
|
|
|
'"return"', 'true',
|
|
|
'"const"', 'true',
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ['1', '1', '1', '1', '1'], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ['1', '1', '1', '1', '1'], 1))
|
|
|
|
|
|
def test_constructors_break(self):
|
|
|
commands = ['"while"',
|
|
@@ -223,4 +187,4 @@ class TestConstructorsActionLanguage(unittest.TestCase):
|
|
|
'"return"', 'true',
|
|
|
'"const"', 'true',
|
|
|
]
|
|
|
- self.assertTrue(run_barebone(flatten(commands), ['1', '3'], 1))
|
|
|
+ self.assertTrue(run_barebone(commands, ['1', '3'], 1))
|