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)
def test_expression_with_float(self): expr = ['(', 'set!', 'x', '23.', ')'] expExp = ['set!', 'x', 23.] actExp = parse(expr) self.assertEqual(actExp, expExp)
def test_empty_expresion(self): expExp = [] actExp = parse(['(', ')']) self.assertEqual(len(actExp), len(expExp))