From a0997481133e02ec0034991e913d69b8b21bba64 Mon Sep 17 00:00:00 2001 From: Yati Sagade Date: Sun, 9 Apr 2017 14:09:54 +0200 Subject: [PATCH] utils: Add tests for the `align_blocks` helper in utils. --- tests/test_align_snippets.rs | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/test_align_snippets.rs diff --git a/tests/test_align_snippets.rs b/tests/test_align_snippets.rs new file mode 100644 index 000000000000..f6a80036b351 --- /dev/null +++ b/tests/test_align_snippets.rs @@ -0,0 +1,74 @@ +extern crate clippy_lints; + +use clippy_lints::utils::align_snippets; + +#[test] +fn test_align_snippets_single_line() { + assert_eq!("", align_snippets(&[""])); + assert_eq!("...", align_snippets(&["..."])); +} + +#[test] +#[cfg_attr(rustfmt, rustfmt_skip)] +fn test_align_snippets_multiline() { + let expected = "\ +if condition() { + do_something(); + do_another_thing(); + yet_another_thing(); + { + and_then_an_indented_block(); + } + and_then_something_the_user_indented();"; // expected + + let input = &[ +"\ +if condition() { + do_something();", +" do_another_thing();", +" yet_another_thing(); + { + and_then_an_indented_block(); + } + and_then_something_the_user_indented();", + ]; // input + + let got = align_snippets(input); + assert_eq!(expected, got); + +} + +#[test] +#[cfg_attr(rustfmt, rustfmt_skip)] +fn test_align_snippets_multiline_with_empty_lines() { + let expected = "\ +if condition() { + do_something(); + do_another_thing(); + yet_another_thing(); + { + + and_then_an_indented_block(); + } + + and_then_something_the_user_indented();"; // expected + + let input = &[ +"\ +if condition() { + do_something();", +" do_another_thing();", +" yet_another_thing(); + { + + and_then_an_indented_block(); + } + + and_then_something_the_user_indented();", + ]; // input + + let got = align_snippets(input); + println!("Input: {}\nExpected: {}\nGot: {}", input.join("\n"), &expected, &got); + assert_eq!(expected, got); +} +