def test_parse_error_get_span(self): s = scanner.Scanner(self.fake_filename, '+') p = parser.Parser(s, 'test_module') try: p.parse_expression(None) except parser.CppParseError as e: pos = Pos(self.fake_filename, 0, 0) want = Span(pos, pos.bump_col()) self.assertEqual(parser.get_parse_error_span(str(e)), want) else: raise AssertionError
def test_pprint_parse_error(self): output = io.StringIO() filename = '/fake/test_file.x' text = 'oh\nwhoops\nI did an\nerror somewhere\nthat is bad' with fakefs_test_util.scoped_fakefs(filename, text): pos = Pos(filename, lineno=2, colno=0) span = Span(pos, pos.bump_col()) error = parser.ParseError(span, 'This is bad') parser_helpers.pprint_positional_error(error, output=cast( io.IOBase, output), color=False, error_context_line_count=3) expected = textwrap.dedent("""\ /fake/test_file.x:2-4 0002: whoops * 0003: I did an ^^ This is bad @ /fake/test_file.x:3:1-3:2 0004: error somewhere """) self.assertMultiLineEqual(expected, output.getvalue())