1 | #!/usr/bin/env python2
|
2 | """format_test.py: Tests for format.py."""
|
3 |
|
4 | import cStringIO
|
5 | import unittest
|
6 |
|
7 | from asdl import format as fmt
|
8 |
|
9 | from _devbuild.gen import typed_demo_asdl as demo_asdl # module under test
|
10 |
|
11 |
|
12 | class FormatTest(unittest.TestCase):
|
13 |
|
14 | def testSimpleSum(self):
|
15 | node = demo_asdl.op_id_e.Plus
|
16 | # This calls __repr__, but does NOT call asdl/format.py
|
17 | print(node)
|
18 |
|
19 | array = demo_asdl.op_array([node, node])
|
20 | print(array)
|
21 |
|
22 | def testRepeatedString(self):
|
23 | node = demo_asdl.assign('declare', ['-r', '-x'])
|
24 |
|
25 | f = cStringIO.StringIO()
|
26 | tree = node.PrettyTree(False)
|
27 |
|
28 | fmt.HNodePrettyPrint(tree, f)
|
29 | pretty_str = f.getvalue()
|
30 | print(pretty_str)
|
31 |
|
32 | self.assertEqual('(assign name:declare flags:[-r -x])\n', pretty_str)
|
33 |
|
34 | t2 = node.PrettyTree(True)
|
35 | fmt.HNodePrettyPrint(t2, f)
|
36 |
|
37 |
|
38 | if __name__ == '__main__':
|
39 | unittest.main()
|