with support.swap_attr(unicodedata, 'normalize', bad_normalize):
self.assertRaises(TypeError, ast.parse, '\u03D5')
+ def test_issue18374_binop_col_offset(self):
+ tree = ast.parse('4+5+6+7')
+ parent_binop = tree.body[0].value
+ child_binop = parent_binop.left
+ grandchild_binop = child_binop.left
+ self.assertEqual(parent_binop.col_offset, 0)
+ self.assertEqual(parent_binop.end_col_offset, 7)
+ self.assertEqual(child_binop.col_offset, 0)
+ self.assertEqual(child_binop.end_col_offset, 5)
+ self.assertEqual(grandchild_binop.col_offset, 0)
+ self.assertEqual(grandchild_binop.end_col_offset, 3)
+
+ tree = ast.parse('4+5-\\\n 6-7')
+ parent_binop = tree.body[0].value
+ child_binop = parent_binop.left
+ grandchild_binop = child_binop.left
+ self.assertEqual(parent_binop.col_offset, 0)
+ self.assertEqual(parent_binop.lineno, 1)
+ self.assertEqual(parent_binop.end_col_offset, 4)
+ self.assertEqual(parent_binop.end_lineno, 2)
+
+ self.assertEqual(child_binop.col_offset, 0)
+ self.assertEqual(parent_binop.lineno, 1)
+ self.assertEqual(child_binop.end_col_offset, 2)
+ self.assertEqual(parent_binop.end_lineno, 2)
+
+ self.assertEqual(grandchild_binop.col_offset, 0)
+ self.assertEqual(parent_binop.lineno, 1)
+ self.assertEqual(grandchild_binop.end_col_offset, 3)
+ self.assertEqual(parent_binop.end_lineno, 2)
class ASTHelpers_Test(unittest.TestCase):
maxDiff = None
return NULL;
tmp_result = BinOp(result, newoperator, tmp,
- LINENO(next_oper), next_oper->n_col_offset,
+ LINENO(n), n->n_col_offset,
CHILD(n, i * 2 + 2)->n_end_lineno,
CHILD(n, i * 2 + 2)->n_end_col_offset,
c->c_arena);