mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-03 20:23:59 +00:00
utils: Add tests for the align_blocks
helper in utils.
This commit is contained in:
parent
8ea6d6a8d2
commit
a099748113
74
tests/test_align_snippets.rs
Normal file
74
tests/test_align_snippets.rs
Normal file
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user