コード例 #1
0
    def test_visit_index(self):
        fake_span = self.fake_span
        # Make a t[i] inde xnode.
        t = ast.NameRef(fake_span, 't', ast.NameDef(fake_span, 't'))
        i = ast.NameRef(fake_span, 'i', ast.NameDef(fake_span, 'i'))
        index = ast.Index(fake_span, t, i)

        c = _Collector()
        index.accept(c)
        self.assertEqual(c.collected, [t, i, index])
コード例 #2
0
    def test_visit_unop(self):
        fake_span = self.fake_span
        i_def = ast.NameDef(fake_span, 'i')
        i_ref = ast.NameRef(fake_span, 'i', i_def)
        negated = ast.Unop(Token(TokenKind.MINUS, fake_span), i_ref)

        c = _Collector()
        negated.accept(c)
        self.assertEqual(c.collected, [i_ref, negated])
コード例 #3
0
 def _builtin_name_ref(self, identifier: Text) -> ast.NameRef:
     return ast.NameRef(self.fake_span, identifier,
                        ast.BuiltinNameDef(identifier))
コード例 #4
0
 def _make_name_ref(self, name_def: ast.NameDef) -> ast.NameRef:
     return ast.NameRef(self.fake_span, name_def.identifier, name_def)