]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / src / tools / clippy / tests / ui / case_sensitive_file_extension_comparisons.rs
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     filename.ends_with(".rs")
15 }
16
17 fn main() {
18     // std::string::String and &str should trigger the lint failure with .ext12
19     let _ = String::new().ends_with(".ext12");
20     let _ = "str".ends_with(".ext12");
21
22     // The fixup should preserve the indentation level
23     {
24         let _ = "str".ends_with(".ext12");
25     }
26
27     // The test struct should not trigger the lint failure with .ext12
28     TestStruct {}.ends_with(".ext12");
29
30     // std::string::String and &str should trigger the lint failure with .EXT12
31     let _ = String::new().ends_with(".EXT12");
32     let _ = "str".ends_with(".EXT12");
33
34     // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
35     let _ = String::new().to_lowercase().ends_with(".EXT12");
36     let _ = String::new().to_uppercase().ends_with(".EXT12");
37
38     // The test struct should not trigger the lint failure with .EXT12
39     TestStruct {}.ends_with(".EXT12");
40
41     // Should not trigger the lint failure with .eXT12
42     let _ = String::new().ends_with(".eXT12");
43     let _ = "str".ends_with(".eXT12");
44     TestStruct {}.ends_with(".eXT12");
45
46     // Should not trigger the lint failure with .EXT123 (too long)
47     let _ = String::new().ends_with(".EXT123");
48     let _ = "str".ends_with(".EXT123");
49     TestStruct {}.ends_with(".EXT123");
50
51     // Shouldn't fail if it doesn't start with a dot
52     let _ = String::new().ends_with("a.ext");
53     let _ = "str".ends_with("a.extA");
54     TestStruct {}.ends_with("a.ext");
55 }