aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorldore <laurent.dore@gmail.com>2018-01-17 14:31:30 +0100
committerEli Bendersky <eliben@users.noreply.github.com>2018-01-17 05:31:30 -0800
commit216823845b2d123f7d443cf27ee057cd1943f0c1 (patch)
tree0b195f522ea964d900442c5b8013893468c49f97 /tests
parent97e74649a2aadbf317a74d421121af8060e841f3 (diff)
downloadpycparser-216823845b2d123f7d443cf27ee057cd1943f0c1.tar.gz
Implement __repr__ on Nodes (Issue #226) (#227)
* Implement __repr__ on Nodes.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_c_ast.py53
1 files changed, 51 insertions, 2 deletions
diff --git a/tests/test_c_ast.py b/tests/test_c_ast.py
index bfe301a..8e95d55 100644
--- a/tests/test_c_ast.py
+++ b/tests/test_c_ast.py
@@ -38,7 +38,6 @@ class Test_c_ast(unittest.TestCase):
self.assertEqual(weakref.getweakrefcount(coord), 1)
-
class TestNodeVisitor(unittest.TestCase):
class ConstantVisitor(c_ast.NodeVisitor):
def __init__(self):
@@ -94,7 +93,57 @@ class TestNodeVisitor(unittest.TestCase):
cv.visit(comp)
self.assertEqual(cv.values,
- ['5.6', 't', '5.6', 't', 't', '5.6', 't'])
+ ['5.6', 't', '5.6', 't', 't', '5.6', 't'])
+
+ def test_repr(self):
+ c1 = c_ast.Constant(type='float', value='5.6')
+ c2 = c_ast.Constant(type='char', value='t')
+
+ b1 = c_ast.BinaryOp(
+ op='+',
+ left=c1,
+ right=c2)
+
+ b2 = c_ast.BinaryOp(
+ op='-',
+ left=b1,
+ right=c2)
+
+ comp = c_ast.Compound(
+ block_items=[b1, b2, c1, c2])
+
+ expected = ("Compound(block_items=[BinaryOp(op='+',\n"
+ " left=Constant(type='float',\n"
+ " value='5.6'\n"
+ " ),\n"
+ " right=Constant(type='char',\n"
+ " value='t'\n"
+ " )\n"
+ " ),\n"
+ " BinaryOp(op='-',\n"
+ " left=BinaryOp(op='+',\n"
+ " left=Constant(type='float',\n"
+ " value='5.6'\n"
+ " ),\n"
+ " right=Constant(type='char',\n"
+ " value='t'\n"
+ " )\n"
+ " ),\n"
+ " right=Constant(type='char',\n"
+ " value='t'\n"
+ " )\n"
+ " ),\n"
+ " Constant(type='float',\n"
+ " value='5.6'\n"
+ " ),\n"
+ " Constant(type='char',\n"
+ " value='t'\n"
+ " )\n"
+ " ]\n"
+ " )")
+
+ self.assertEqual(repr(comp),
+ expected)
if __name__ == '__main__':