]> git.lizzy.rs Git - rust.git/blob - tests/needless_continue_helpers.rs
Merge #3331
[rust.git] / tests / needless_continue_helpers.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10
11
12
13 // Tests for the various helper functions used by the needless_continue
14 // lint that don't belong in utils.
15
16 extern crate clippy_lints;
17 use clippy_lints::needless_continue::{erode_block, erode_from_back, erode_from_front};
18
19 #[test]
20 #[rustfmt::skip]
21 fn test_erode_from_back() {
22     let input = "\
23 {
24     let x = 5;
25     let y = format!(\"{}\", 42);
26 }";
27
28     let expected = "\
29 {
30     let x = 5;
31     let y = format!(\"{}\", 42);";
32
33     let got = erode_from_back(input);
34     assert_eq!(expected, got);
35 }
36
37 #[test]
38 #[rustfmt::skip]
39 fn test_erode_from_back_no_brace() {
40     let input = "\
41 let x = 5;
42 let y = something();
43 ";
44     let expected = "";
45     let got = erode_from_back(input);
46     assert_eq!(expected, got);
47 }
48
49 #[test]
50 #[rustfmt::skip]
51 fn test_erode_from_front() {
52     let input = "
53         {
54             something();
55             inside_a_block();
56         }
57     ";
58     let expected =
59 "            something();
60             inside_a_block();
61         }
62     ";
63     let got = erode_from_front(input);
64     println!("input: {}\nexpected:\n{}\ngot:\n{}", input, expected, got);
65     assert_eq!(expected, got);
66 }
67
68 #[test]
69 #[rustfmt::skip]
70 fn test_erode_from_front_no_brace() {
71     let input = "
72             something();
73             inside_a_block();
74     ";
75     let expected =
76 "something();
77             inside_a_block();
78     ";
79     let got = erode_from_front(input);
80     println!("input: {}\nexpected:\n{}\ngot:\n{}", input, expected, got);
81     assert_eq!(expected, got);
82 }
83
84 #[test]
85 #[rustfmt::skip]
86 fn test_erode_block() {
87
88     let input = "
89         {
90             something();
91             inside_a_block();
92         }
93     ";
94     let expected =
95 "            something();
96             inside_a_block();";
97     let got = erode_block(input);
98     println!("input: {}\nexpected:\n{}\ngot:\n{}", input, expected, got);
99     assert_eq!(expected, got);
100 }