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); +} +