]> git.lizzy.rs Git - rust.git/blob - tests/needless_continue_helpers.rs
needless_continue: Add tests for helper functions to the needless_continue lint.
[rust.git] / tests / needless_continue_helpers.rs
1 // Tests for the various helper functions used by the needless_continue
2 // lint that don't belong in utils.
3 extern crate clippy_lints;
4 use clippy_lints::needless_continue::{erode_from_back, erode_block, erode_from_front};
5
6 #[test]
7 #[cfg_attr(rustfmt, rustfmt_skip)]
8 fn test_erode_from_back() {
9     let input = "\
10 {
11     let x = 5;
12     let y = format!(\"{}\", 42);
13 }";
14
15     let expected = "\
16 {
17     let x = 5;
18     let y = format!(\"{}\", 42);";
19
20     let got = erode_from_back(input);
21     assert_eq!(expected, got);
22 }
23
24 #[test]
25 #[cfg_attr(rustfmt, rustfmt_skip)]
26 fn test_erode_from_back_no_brace() {
27     let input = "\
28 let x = 5;
29 let y = something();
30 ";
31     let expected = "";
32     let got = erode_from_back(input);
33     assert_eq!(expected, got);
34 }
35
36 #[test]
37 #[cfg_attr(rustfmt, rustfmt_skip)]
38 fn test_erode_from_front() {
39     let input = "
40         {
41             something();
42             inside_a_block();
43         }
44     ";
45     let expected =
46 "            something();
47             inside_a_block();
48         }
49     ";
50     let got = erode_from_front(input);
51     println!("input: {}\nexpected:\n{}\ngot:\n{}", input, expected, got);
52     assert_eq!(expected, got);
53 }
54
55 #[test]
56 #[cfg_attr(rustfmt, rustfmt_skip)]
57 fn test_erode_from_front_no_brace() {
58     let input = "
59             something();
60             inside_a_block();
61     ";
62     let expected =
63 "something();
64             inside_a_block();
65     ";
66     let got = erode_from_front(input);
67     println!("input: {}\nexpected:\n{}\ngot:\n{}", input, expected, got);
68     assert_eq!(expected, got);
69 }
70
71
72 #[test]
73 #[cfg_attr(rustfmt, rustfmt_skip)]
74 fn test_erode_block() {
75
76     let input = "
77         {
78             something();
79             inside_a_block();
80         }
81     ";
82     let expected =
83 "            something();
84             inside_a_block();";
85     let got = erode_block(input);
86     println!("input: {}\nexpected:\n{}\ngot:\n{}", input, expected, got);
87     assert_eq!(expected, got);
88 }
89