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