]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / src / tools / clippy / tests / ui / case_sensitive_file_extension_comparisons.fixed
1 // run-rustfix
2 #![warn(clippy::case_sensitive_file_extension_comparisons)]
3
4 use std::string::String;
5
6 struct TestStruct;
7
8 impl TestStruct {
9     fn ends_with(self, _arg: &str) {}
10 }
11
12 #[allow(dead_code)]
13 fn is_rust_file(filename: &str) -> bool {
14     std::path::Path::new(filename)
15         .extension()
16         .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
17 }
18
19 fn main() {
20     // std::string::String and &str should trigger the lint failure with .ext12
21     let _ = std::path::Path::new(&String::new())
22         .extension()
23         .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
24     let _ = std::path::Path::new("str")
25         .extension()
26         .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
27
28     // The fixup should preserve the indentation level
29     {
30         let _ = std::path::Path::new("str")
31             .extension()
32             .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
33     }
34
35     // The test struct should not trigger the lint failure with .ext12
36     TestStruct {}.ends_with(".ext12");
37
38     // std::string::String and &str should trigger the lint failure with .EXT12
39     let _ = std::path::Path::new(&String::new())
40         .extension()
41         .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
42     let _ = std::path::Path::new("str")
43         .extension()
44         .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
45
46     // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
47     let _ = String::new().to_lowercase().ends_with(".EXT12");
48     let _ = String::new().to_uppercase().ends_with(".EXT12");
49
50     // The test struct should not trigger the lint failure with .EXT12
51     TestStruct {}.ends_with(".EXT12");
52
53     // Should not trigger the lint failure with .eXT12
54     let _ = String::new().ends_with(".eXT12");
55     let _ = "str".ends_with(".eXT12");
56     TestStruct {}.ends_with(".eXT12");
57
58     // Should not trigger the lint failure with .EXT123 (too long)
59     let _ = String::new().ends_with(".EXT123");
60     let _ = "str".ends_with(".EXT123");
61     TestStruct {}.ends_with(".EXT123");
62
63     // Shouldn't fail if it doesn't start with a dot
64     let _ = String::new().ends_with("a.ext");
65     let _ = "str".ends_with("a.extA");
66     TestStruct {}.ends_with("a.ext");
67 }