mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 15:32:06 +00:00
Auto merge of #33513 - sanxiyn:tab-in-error, r=nikomatsakis
Better handling of tab in error cc #33240.
This commit is contained in:
commit
edb6f83b89
@ -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);
|
||||
|
@ -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#"
|
||||
|
Loading…
Reference in New Issue
Block a user