Commit 1e6628f2 authored by Xavier Thompson's avatar Xavier Thompson

Make TreeFragment handle CArgDeclNodes as well

parent ad8f6640
......@@ -119,6 +119,33 @@ class TestTreeFragments(CythonTest):
self.assertTrue(isinstance(T3.stats[0].rhs.operand, NameNode), T3)
self.assertTrue(T3.stats[0].rhs.operand.name == "c", T3)
def test_args(self):
F = self.fragment(u"def test(self, ARGS): pass")
args = [
CArgDeclNode(
pos = None,
base_type = CSimpleBaseTypeNode(pos=None, signed=1),
declarator = CNameDeclaratorNode(pos=None, name="a")
),
CArgDeclNode(
pos = None,
base_type = CSimpleBaseTypeNode(pos=None, signed=1),
declarator = CNameDeclaratorNode(pos=None, name="b")
)
]
T = F.substitute({"ARGS" : args})
self.assertTrue(isinstance(T.stats[0], DefNode), T)
self.assertTrue(isinstance(T.stats[0].args[0], CArgDeclNode), T)
self.assertTrue(isinstance(T.stats[0].args[1], CArgDeclNode), T)
self.assertTrue(isinstance(T.stats[0].args[2], CArgDeclNode), T)
self.assertTrue(isinstance(T.stats[0].args[0].declarator, CNameDeclaratorNode), T)
self.assertTrue(isinstance(T.stats[0].args[1].declarator, CNameDeclaratorNode), T)
self.assertTrue(isinstance(T.stats[0].args[2].declarator, CNameDeclaratorNode), T)
self.assertTrue(T.stats[0].args[0].declarator.name == "self", T)
self.assertTrue(T.stats[0].args[1].declarator.name == "a", T)
self.assertTrue(T.stats[0].args[2].declarator.name == "b", T)
self.assertTrue(len(T.stats[0].args) == 3, T)
def test_attribute(self):
F = self.fragment(u"OBJ.ATTR")
base_type = CSimpleBaseTypeNode(pos=None, name="int", module_path = [],
......
......@@ -215,6 +215,13 @@ class TemplateTransform(VisitorTransform):
ret.attribute = EncodedString(sub)
return ret
def visit_CArgDeclNode(self, node):
if isinstance(node.declarator, CNameDeclaratorNode):
sub = self.substitutions.get(node.declarator.name)
if sub is not None:
return sub
return self.visit_Node(node)
def visit_ExprStatNode(self, node):
# If an expression-as-statement consists of only a replaceable
# NameNode, we replace the entire statement, not only the NameNode
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment