From 1fb172f98952e8f8a26115de219f46f5f889dbbd Mon Sep 17 00:00:00 2001 From: "K.J. Valencik" Date: Fri, 19 Jan 2018 12:18:25 -0500 Subject: [PATCH] LineOverflow: Count tabs as tab_spaces when measuring line length for overflow --- src/lib.rs | 2 +- tests/system.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e24a6c1949c..817188925cd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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); diff --git a/tests/system.rs b/tests/system.rs index 8125e7fd2b6..24a6b15e421 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -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::(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) -> (Vec, u32, u32) {