Auto merge of #33513 - sanxiyn:tab-in-error, r=nikomatsakis

Better handling of tab in error

cc #33240.
This commit is contained in:
bors 2016-05-13 06:26:15 -07:00
commit edb6f83b89
2 changed files with 32 additions and 2 deletions

View File

@ -312,9 +312,15 @@ impl StyledBuffer {
self.text[line][col] = chr;
self.styles[line][col] = style;
} else {
while self.text[line].len() < col {
self.text[line].push(' ');
let mut i = self.text[line].len();
while i < col {
let s = match self.text[0].get(i) {
Some(&'\t') => '\t',
_ => ' '
};
self.text[line].push(s);
self.styles[line].push(Style::NoStyle);
i += 1;
}
self.text[line].push(chr);
self.styles[line].push(style);

View File

@ -79,6 +79,30 @@ fn make_string(lines: &[RenderedLine]) -> String {
.collect()
}
#[test]
fn tab() {
let file_text = "
fn foo() {
\tbar;
}
";
let cm = Rc::new(CodeMap::new());
let foo = cm.new_filemap_and_lines("foo.rs", file_text);
let span_bar = cm.span_substr(&foo, file_text, "bar", 0);
let mut snippet = SnippetData::new(cm, Some(span_bar));
snippet.push(span_bar, true, None);
let lines = snippet.render_lines();
let text = make_string(&lines);
assert_eq!(&text[..], &"
--> foo.rs:3:2
3 |> \tbar;
|> \t^^^
"[1..]);
}
#[test]
fn one_line() {
let file_text = r#"