From 9761cf71d8384db2a75c7595b082dd7764575851 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Fri, 22 Apr 2016 18:53:39 +1200 Subject: [PATCH] Tests --- src/bin/cargo-fmt.rs | 8 ++++---- src/bin/rustfmt.rs | 9 +++------ src/chains.rs | 10 +++++----- src/items.rs | 2 +- src/missed_spans.rs | 8 ++++---- tests/system.rs | 12 ++++++------ tests/target/chains-indent-visual.rs | 10 +++++----- tests/target/hard-tabs.rs | 6 +++--- 8 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/bin/cargo-fmt.rs b/src/bin/cargo-fmt.rs index c033851f98a..575e25ed965 100644 --- a/src/bin/cargo-fmt.rs +++ b/src/bin/cargo-fmt.rs @@ -201,9 +201,9 @@ fn format_files(files: &Vec, println!(""); } let mut command = try!(Command::new("rustfmt") - .stdout(stdout) - .args(files) - .args(fmt_args) - .spawn()); + .stdout(stdout) + .args(files) + .args(fmt_args) + .spawn()); command.wait() } diff --git a/src/bin/rustfmt.rs b/src/bin/rustfmt.rs index 472098f59eb..2472001c38b 100644 --- a/src/bin/rustfmt.rs +++ b/src/bin/rustfmt.rs @@ -191,7 +191,7 @@ fn execute(opts: &Options) -> FmtResult { Operation::Stdin { input, config_path } => { // try to read config from local directory let (mut config, _) = match_cli_path_or_file(config_path, &env::current_dir().unwrap()) - .expect("Error resolving config"); + .expect("Error resolving config"); // write_mode is always Plain for Stdin. config.write_mode = WriteMode::Plain; @@ -205,8 +205,7 @@ fn execute(opts: &Options) -> FmtResult { // Load the config path file if provided if let Some(config_file) = config_path { let (cfg_tmp, path_tmp) = resolve_config(config_file.as_ref()) - .expect(&format!("Error resolving config for {:?}", - config_file)); + .expect(&format!("Error resolving config for {:?}", config_file)); config = cfg_tmp; path = path_tmp; }; @@ -219,9 +218,7 @@ fn execute(opts: &Options) -> FmtResult { // Check the file directory if the config-path could not be read or not provided if path.is_none() { let (config_tmp, path_tmp) = resolve_config(file.parent().unwrap()) - .expect(&format!("Error resolving config \ - for {}", - file.display())); + .expect(&format!("Error resolving config for {}", file.display())); if let Some(path) = path_tmp.as_ref() { println!("Using rustfmt config file {} for {}", path.display(), diff --git a/src/chains.rs b/src/chains.rs index 5d2ce8fedf7..ec9e6685878 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -144,9 +144,8 @@ pub fn rewrite_chain(expr: &ast::Expr, // Total of all items excluding the last. let almost_total = rewrites[..rewrites.len() - 1] - .iter() - .fold(0, |a, b| a + first_line_width(b)) + - parent_rewrite.len(); + .iter() + .fold(0, |a, b| a + first_line_width(b)) + parent_rewrite.len(); let total_width = almost_total + first_line_width(rewrites.last().unwrap()); let veto_single_line = if context.config.take_source_hints && subexpr_list.len() > 1 { @@ -271,8 +270,9 @@ fn chain_indent(context: &RewriteContext, offset: Indent) -> Indent { fn hacked_chain_indent(context: &RewriteContext, _offset: Indent) -> Indent { match context.config.chain_indent { BlockIndentStyle::Inherit => context.block_indent, - BlockIndentStyle::Visual | - BlockIndentStyle::Tabbed => context.block_indent.block_indent(context.config), + BlockIndentStyle::Visual | BlockIndentStyle::Tabbed => { + context.block_indent.block_indent(context.config) + } } } diff --git a/src/items.rs b/src/items.rs index 2566d9a436b..19dad7f866c 100644 --- a/src/items.rs +++ b/src/items.rs @@ -912,7 +912,7 @@ fn format_tuple_struct(context: &RewriteContext, // know that earlier, so the where clause will not be indented properly. result.push('\n'); result.push_str(&(context.block_indent + (context.config.tab_spaces - 1)) - .to_string(context.config)); + .to_string(context.config)); } result.push_str(&where_clause_str); diff --git a/src/missed_spans.rs b/src/missed_spans.rs index 092cc0093f1..3d1ef21478e 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -112,10 +112,10 @@ impl<'a> FmtVisitor<'a> { for (kind, offset, subslice) in CommentCodeSlices::new(snippet) { if let CodeCharKind::Comment = kind { let last_char = big_snippet[..(offset + big_diff)] - .chars() - .rev() - .skip_while(|rev_c| [' ', '\t'].contains(&rev_c)) - .next(); + .chars() + .rev() + .skip_while(|rev_c| [' ', '\t'].contains(&rev_c)) + .next(); let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c)); diff --git a/tests/system.rs b/tests/system.rs index 2a6b1a9e19c..9ec8404b1d8 100644 --- a/tests/system.rs +++ b/tests/system.rs @@ -102,8 +102,8 @@ fn assert_output(source: &str, expected_filename: &str) { fn idempotence_tests() { // Get all files in the tests/target directory. let files = fs::read_dir("tests/target") - .expect("Couldn't read target dir") - .map(get_path_string); + .expect("Couldn't read target dir") + .map(get_path_string); let (_reports, count, fails) = check_files(files); // Display results. @@ -116,9 +116,9 @@ fn idempotence_tests() { #[test] fn self_tests() { let files = fs::read_dir("src/bin") - .expect("Couldn't read src dir") - .chain(fs::read_dir("tests").expect("Couldn't read tests dir")) - .map(get_path_string); + .expect("Couldn't read src dir") + .chain(fs::read_dir("tests").expect("Couldn't read tests dir")) + .map(get_path_string); // Hack because there's no `IntoIterator` impl for `[T; N]`. let files = files.chain(Some("src/lib.rs".to_owned()).into_iter()); @@ -264,7 +264,7 @@ fn read_significant_comments(file_name: &str) -> HashMap { // Matches lines containing significant comments or whitespace. let line_regex = regex::Regex::new(r"(^\s*$)|(^\s*//\s*rustfmt-[^:]+:\s*\S+)") - .expect("Failed creating pattern 2"); + .expect("Failed creating pattern 2"); reader.lines() .map(|line| line.expect("Failed getting line")) diff --git a/tests/target/chains-indent-visual.rs b/tests/target/chains-indent-visual.rs index e91317bd5de..e3ab320c6e1 100644 --- a/tests/target/chains-indent-visual.rs +++ b/tests/target/chains-indent-visual.rs @@ -2,9 +2,9 @@ fn test() { let x = my_long_function() - .my_even_longer_function() - .my_nested_function() - .some_random_name() - .another_function() - .do_it(); + .my_even_longer_function() + .my_nested_function() + .some_random_name() + .another_function() + .do_it(); } diff --git a/tests/target/hard-tabs.rs b/tests/target/hard-tabs.rs index cd694099d95..de8adcceccd 100644 --- a/tests/target/hard-tabs.rs +++ b/tests/target/hard-tabs.rs @@ -51,9 +51,9 @@ fn main() { } let chain = funktion_kall() - .go_to_next_line_with_tab() - .go_to_next_line_with_tab() - .go_to_next_line_with_tab(); + .go_to_next_line_with_tab() + .go_to_next_line_with_tab() + .go_to_next_line_with_tab(); let z = [xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyy,