Пример #1
0
 def test_begin(self):
     c = Compiler()
     c.compile([
         sym_begin, [sym_define, Symbol('answer'), 42],
         ['abs', Symbol('answer')]
     ])
     self.assertEqual(eval(c.dump()), 42)
Пример #2
0
 def test_func(self):
     src = """
     (abs -42)
     """
     r = Reader(src).read()
     c = Compiler()
     c.compile(r)
     self.assertEqual(eval(c.dump()), 42)
Пример #3
0
 def test_func(self):
     src = """
     (abs -42)
     """
     r = Reader(src).read()
     c = Compiler()
     c.compile(r)
     self.assertEqual(eval(c.dump()), 42)
Пример #4
0
 def setUp(self):
     c = Compiler()
     c.compile(['ord', 'a'])
     self.co = c.dump()
Пример #5
0
 def test_if(self):
     c = Compiler()
     c.compile([sym_if, True, "True!"])
     self.assertEqual(eval(c.dump()), "True!")
     c = Compiler()
     c.compile([sym_if, True, "True!", "False!"])
     self.assertEqual(eval(c.dump()), "True!")
     c = Compiler()
     c.compile([sym_if, False, "True!", "False!"])
     self.assertEqual(eval(c.dump()), "False!")
Пример #6
0
 def test_define(self):
     c = Compiler()
     c.compile([sym_define, Symbol('answer'), -42])
     c.compile(['abs', Symbol('answer')])
     self.assertEqual(eval(c.dump()), 42)
Пример #7
0
 def test_nest_func_call(self):
     c = Compiler()
     c.compile(['abs', ['max', -100, -42]])
     self.assertEqual(eval(c.dump()), 42)
Пример #8
0
 def test_func_call(self):
     c = Compiler()
     c.compile(['ord', 'a'])
     self.assertEqual(eval(c.dump()), 97)
Пример #9
0
 def setUp(self):
     c = Compiler()
     c.compile(['ord', 'a'])
     self.co = c.dump()
Пример #10
0
 def test_begin(self):
     c = Compiler()
     c.compile([sym_begin, [sym_define, Symbol('answer'), 42],
         ['abs', Symbol('answer')]])
     self.assertEqual(eval(c.dump()), 42)
Пример #11
0
 def test_if(self):
     c = Compiler()
     c.compile([sym_if, True, "True!"])
     self.assertEqual(eval(c.dump()), "True!")
     c = Compiler()
     c.compile([sym_if, True, "True!", "False!"])
     self.assertEqual(eval(c.dump()), "True!")
     c = Compiler()
     c.compile([sym_if, False, "True!", "False!"])
     self.assertEqual(eval(c.dump()), "False!")
Пример #12
0
 def test_define(self):
     c = Compiler()
     c.compile([sym_define, Symbol('answer'), -42])
     c.compile(['abs', Symbol('answer')])
     self.assertEqual(eval(c.dump()), 42)
Пример #13
0
 def test_nest_func_call(self):
     c = Compiler()
     c.compile(['abs', ['max', -100, -42]])
     self.assertEqual(eval(c.dump()), 42)
Пример #14
0
 def test_func_call(self):
     c = Compiler()
     c.compile(['ord', 'a'])
     self.assertEqual(eval(c.dump()), 97)