Esempio n. 1
0
    def test_sexp_tuple(self):
        parsed = sexp_parse('(f (g (h x)))')
        self.assertEqual(parsed, ('f', [('g', [('h', ['x'])])]))

        # First inner sexp
        head, args = parsed
        self.assertEqual(head, 'f')
        self.assertEqual(len(args),1)
        # Second inner sexp
        head, args = args[0]
        self.assertEqual(head, 'g')
        self.assertEqual(len(args),1)
Esempio n. 2
0
    def test_sexp_parser(self):
        self.assertIsNotNone(sexp_parse('(a b c)'))
        self.assertIsNotNone(sexp_parse('(a 2 (f a 3.5))'))
        self.assertIsNotNone(sexp_parse('(f (f (f x)))'))

        with self.assertRaises(Exception):
            sexp_parse('(a b c')

        with self.assertRaises(Exception):
            sexp_parse('a b c')
Esempio n. 3
0
    def test_sexp_tuples(self):
        tests = [
            ('(a)'         ,  ('a', [])                          ),
            ( '(a b c)'    ,  ('a', ['b', 'c'])                  ),
            ( '(f 1 2)'    ,  ('f', [1, 2])                      ),
            ( '(f 1.1 2.5)',  ('f', [1.1, 2.5])                  ),
            ( '(f 0 -1)'   ,  ('f', [0, -1])                     ),
            ( '(f (g (x)))',  ('f', [('g', [('x', [])])])        ),
        ]

        for sexp, output in tests:
            parsed = sexp_parse(sexp)
            mapped = make_sexp(parsed)
            self.assertEqual(parsed, output)
            self.assertEqual(len(mapped.args), len(output[1]))