test_constructors_al_linkable.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import unittest
  2. import sys
  3. import os
  4. from utils import execute, kill, run_file, run_barebone
  5. def extend_commands(commands):
  6. # Initially we communicate with the compilation_manager to add the bytecodes
  7. pre = [
  8. '3',
  9. '"upload"',
  10. '"test.o"',
  11. '"MD5_HASH"',
  12. 'true', # use NEW interface for constructors
  13. '"funcdef"', '"main"', '0', # Main function
  14. ]
  15. # We only have to define "main" for now
  16. post = [
  17. 'true',
  18. '"main"',
  19. 'true',
  20. 'false',
  21. ]
  22. return pre + commands + post
  23. class TestConstructorsActionLanguageLinkable(unittest.TestCase):
  24. def test_constructors_simple(self):
  25. commands = [
  26. '"output"',
  27. '"const"', 'true',
  28. 'true',
  29. '"return"',
  30. 'true',
  31. '"const"', 'true',
  32. 'false',
  33. ]
  34. commands = extend_commands(commands)
  35. self.assertTrue(run_barebone(commands, ["True"], None, link=["test.o"]))
  36. def test_constructors_if_else_true(self):
  37. commands = [
  38. '"if"', # If
  39. '"const"', 'true', # Condition
  40. '"output"', # True-part
  41. '"const"', 'true',
  42. 'false', # Has next
  43. 'true', # Has else
  44. '"output"', # False-part
  45. '"const"', 'false',
  46. 'false', # Has next
  47. 'true', # Has next
  48. '"return"', # Return
  49. 'true', # Has value
  50. '"const"', "true",
  51. 'false',
  52. ]
  53. commands = extend_commands(commands)
  54. self.assertTrue(run_barebone(commands, ["True"], None, link=["test.o"]))
  55. def test_constructors_if_else_false(self):
  56. commands = [
  57. '"if"', # If
  58. '"const"', 'false', # Condition
  59. '"output"', # True-part
  60. '"const"', 'true',
  61. 'false', # Has next
  62. 'true', # Has else
  63. '"output"', # False-part
  64. '"const"', 'false',
  65. 'false', # Has next
  66. 'true', # Has next
  67. '"return"', # Return
  68. 'true', # Has value
  69. '"const"', "true",
  70. 'false',
  71. ]
  72. commands = extend_commands(commands)
  73. self.assertTrue(run_barebone(commands, ["False"], None, link=["test.o"]))
  74. def test_constructors_if_true(self):
  75. commands = [
  76. '"if"', # If
  77. '"const"', 'true', # Condition
  78. '"output"', # True-part
  79. '"const"', 'true',
  80. 'false', # Has next
  81. 'false', # Has else
  82. 'true', # Has next
  83. '"return"', # Return
  84. 'true', # Has value
  85. '"const"', "true",
  86. 'false',
  87. ]
  88. commands = extend_commands(commands)
  89. self.assertTrue(run_barebone(commands, ["True"], None, link=["test.o"]))
  90. def test_constructors_if_false(self):
  91. commands = [
  92. '"if"', # If
  93. '"const"', 'false', # Condition
  94. '"output"', # True-part
  95. '"const"', 'true',
  96. 'false', # Has next
  97. 'false', # Has else
  98. 'true', # Has next
  99. '"return"', # Return
  100. 'true', # Has value
  101. '"const"', "true",
  102. 'false',
  103. ]
  104. commands = extend_commands(commands)
  105. self.assertTrue(run_barebone(commands, [None], None, timeout=True, link=["test.o"]))
  106. def test_constructors_while_false(self):
  107. commands = [
  108. '"while"', # While
  109. '"const"', 'false', # Condition
  110. '"output"', # True-part
  111. '"const"', 'true',
  112. 'false', # Has next
  113. 'true', # Has next
  114. '"output"', # Output false
  115. '"const"', 'false',
  116. 'true', # Has next
  117. '"return"', # Return
  118. 'true', # Has value
  119. '"const"', "true",
  120. 'false',
  121. ]
  122. commands = extend_commands(commands)
  123. self.assertTrue(run_barebone(commands, ["False"], None, link=["test.o"]))
  124. def test_constructors_while_true(self):
  125. commands = [
  126. '"while"', # While
  127. '"const"', 'true', # Condition
  128. '"output"', # True-part
  129. '"const"', 'true',
  130. 'false', # Has next
  131. 'true', # Has next
  132. '"output"', # False-part
  133. '"const"', 'false',
  134. 'true', # Has next
  135. '"return"', # Return
  136. 'true', # Has value
  137. '"const"', "true",
  138. 'false',
  139. ]
  140. commands = extend_commands(commands)
  141. self.assertTrue(run_barebone(commands, ["True", "True", "True", "True"], None, link=["test.o"]))
  142. def test_constructors_declare_and_assign(self):
  143. commands = [
  144. '"declare"',
  145. 1,
  146. 'true',
  147. '"assign"',
  148. '"resolve"', 1,
  149. '"const"', '5',
  150. 'true',
  151. '"output"',
  152. '"access"', '"resolve"', 1,
  153. 'true',
  154. '"return"',
  155. 'true',
  156. '"const"', "true",
  157. 'false',
  158. ]
  159. commands = extend_commands(commands)
  160. self.assertTrue(run_barebone(commands, ["5"], None, link=["test.o"]))
  161. def test_constructors_output_input(self):
  162. commands = [
  163. '"output"',
  164. '"input"',
  165. 'true',
  166. '"return"',
  167. 'true',
  168. '"const"', "true",
  169. 'false',
  170. ]
  171. commands = extend_commands(commands)
  172. self.assertTrue(run_barebone(commands, ["123456"], None, link=["test.o"], inputs=["123456"]))
  173. """
  174. def test_constructors_funcdecl(self):
  175. commands = ['"declare"',
  176. 1,
  177. 'true',
  178. '"funcdef"', 1,
  179. '2',
  180. 2,
  181. 3,
  182. '"return"', 'true',
  183. '"call"',
  184. '"deref"', '"primitives/integer_addition"',
  185. '2',
  186. '"access"', '"resolve"', 2,
  187. '"access"', '"resolve"', 3,
  188. 'false',
  189. 'true',
  190. '"output"',
  191. '"call"',
  192. '"access"', '"resolve"', 1,
  193. '2',
  194. '"input"',
  195. '"input"',
  196. 'false',
  197. 'true',
  198. '"return"', 'true',
  199. '"const"', 'true',
  200. ]
  201. self.assertTrue(run_barebone(flatten(commands) + ['2', '5'], ["7"], 1))
  202. def test_constructors_continue(self):
  203. commands = ['"while"',
  204. '"const"', 'true',
  205. '"output"', '"const"', '1',
  206. 'true',
  207. '"if"',
  208. '"const"', 'true',
  209. '"continue"',
  210. 'false',
  211. 'true',
  212. '"output"', '"const"', '2',
  213. 'false',
  214. 'true',
  215. '"output"', '"const"', '3',
  216. 'true',
  217. '"return"', 'true',
  218. '"const"', 'true',
  219. ]
  220. self.assertTrue(run_barebone(flatten(commands), ['1', '1', '1', '1', '1'], 1))
  221. def test_constructors_break(self):
  222. commands = ['"while"',
  223. '"const"', 'true',
  224. '"output"', '"const"', '1',
  225. 'true',
  226. '"if"',
  227. '"const"', 'true',
  228. '"break"',
  229. 'false',
  230. 'true',
  231. '"output"', '"const"', '2',
  232. 'false',
  233. 'true',
  234. '"output"', '"const"', '3',
  235. 'true',
  236. '"return"', 'true',
  237. '"const"', 'true',
  238. ]
  239. self.assertTrue(run_barebone(flatten(commands), ['1', '3'], 1))
  240. """