LineOverflow: Count tabs as tab_spaces when measuring line length for overflow

This commit is contained in:
K.J. Valencik 2018-01-19 12:18:25 -05:00
parent e0e3e22248
commit 1fb172f989
2 changed files with 11 additions and 1 deletions

View File

@ -463,7 +463,7 @@ fn format_lines(
is_string = false;
} else {
newline_count = 0;
line_len += 1;
line_len += if c == '\t' { config.tab_spaces() } else { 1 };
if c.is_whitespace() {
if last_wspace.is_none() {
last_wspace = Some(b);

View File

@ -261,6 +261,16 @@ fn format_lines_errors_are_reported() {
assert!(error_summary.has_formatting_errors());
}
#[test]
fn format_lines_errors_are_reported_with_tabs() {
let long_identifier = String::from_utf8(vec![b'a'; 97]).unwrap();
let input = Input::Text(format!("fn a() {{\n\t{}\n}}", long_identifier));
let config = Config::from_toml("hard_tabs = true").unwrap();
let (error_summary, _file_map, _report) =
format_input::<io::Stdout>(input, &config, None).unwrap();
assert!(error_summary.has_formatting_errors());
}
// For each file, run rustfmt and collect the output.
// Returns the number of files checked and the number of failures.
fn check_files(files: Vec<PathBuf>) -> (Vec<FormatReport>, u32, u32) {