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