OILS / opy / _regtest / src / asdl / format_test.py View on Github | oilshell.org

49 lines, 25 significant
1#!/usr/bin/python -S
2"""
3format_test.py: Tests for format.py
4"""
5
6import cStringIO
7import unittest
8
9from asdl import format as fmt
10
11from asdl import arith_ast # module under test
12
13
14class FormatTest(unittest.TestCase):
15
16 def testSimpleSum(self):
17 node = arith_ast.op_id_e.Plus
18 print(node)
19
20 f = cStringIO.StringIO()
21 ast_f = fmt.TextOutput(f)
22
23 tree = fmt.MakeTree(node)
24 fmt.PrintTree(tree, ast_f)
25
26 # Hm this prints 'Plus'. Doesn't print the class or the number.
27 # But those aren't intrinsic. These are mostly used for their IDENTITY.
28 # I think the ASDL_TYPE field contains the relevant info. Yes!
29 pretty_str = f.getvalue()
30 print(pretty_str)
31
32 def testRepeatedString(self):
33 node = arith_ast.assign('declare', ['-r', '-x'])
34
35 f = cStringIO.StringIO()
36 ast_f = fmt.TextOutput(f)
37
38 tree = fmt.MakeTree(node)
39 #print(tree)
40
41 fmt.PrintTree(tree, ast_f)
42 pretty_str = f.getvalue()
43 print(pretty_str)
44
45 self.assertEqual('(assign name:declare flags:[-r -x])', pretty_str)
46
47
48if __name__ == '__main__':
49 unittest.main()