(sql: &str, e: parser::ParserError)
| 50 | use unicode_width::UnicodeWidthStr; |
| 51 | |
| 52 | fn render_error(sql: &str, e: parser::ParserError) -> String { |
| 53 | let mut s = format!("error: {}\n", e.message); |
| 54 | |
| 55 | // Do our best to emulate psql in rendering a caret pointing at the |
| 56 | // offending character in the query. This makes it possible to detect |
| 57 | // incorrect error positions by visually scanning the test files. |
| 58 | let end = sql.len(); |
| 59 | let line_start = sql[..e.pos].rfind('\n').map(|p| p + 1).unwrap_or(0); |
| 60 | let line_end = sql[e.pos..].find('\n').map(|p| e.pos + p).unwrap_or(end); |
| 61 | writeln!(s, "{}", &sql[line_start..line_end]); |
| 62 | for _ in 0..sql[line_start..e.pos].width() { |
| 63 | write!(s, " "); |
| 64 | } |
| 65 | writeln!(s, "^"); |
| 66 | |
| 67 | s |
| 68 | } |
| 69 | |
| 70 | fn parse_statement(tc: &TestCase) -> String { |
| 71 | let input = tc.input.strip_suffix('\n').unwrap_or(&tc.input); |
no test coverage detected