Пример #1
0
 def test_basics(self):
     code = """
     (set! x 3)
     (+ x 2)
     (if y p q)
     (define a (if (= 2 3) (* 3 3) (* 4 4)))
     """
     tokens = tokenize(code)
     actT = []
     while tokens:
         actT.append(parse(tokens))
     expT = [['set!', 'x', 3],
             ['+', 'x', 2],
             ['if', 'y', 'p', 'q'],
             ['define', 'a', 
                 ['if',
                     ['=', 2, 3],
                     ['*', 3, 3],
                     ['*', 4, 4]]]]
     self.assertEqual(expT, actT)
Пример #2
0
 def test_expression_with_float(self):
     expr = ['(', 'set!', 'x', '23.', ')']
     expExp = ['set!', 'x', 23.]
     actExp = parse(expr)
     self.assertEqual(actExp, expExp)
Пример #3
0
 def test_empty_expresion(self):
     expExp = []
     actExp = parse(['(', ')'])
     self.assertEqual(len(actExp), len(expExp))