Skip to content

Commit

Permalink
LineOverflow: Count tabs as tab_spaces when measuring line length for…
Browse files Browse the repository at this point in the history
… overflow
  • Loading branch information
kjvalencik committed Jan 19, 2018
1 parent e0e3e22 commit 1fb172f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions tests/system.rs
Expand Up @@ -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) {
Expand Down

0 comments on commit 1fb172f

Please sign in to comment.