summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed')
-rw-r--r--src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed67
1 files changed, 67 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
new file mode 100644
index 000000000..5fbaa64db
--- /dev/null
+++ b/src/tools/clippy/tests/ui/case_sensitive_file_extension_comparisons.fixed
@@ -0,0 +1,67 @@
+// run-rustfix
+#![warn(clippy::case_sensitive_file_extension_comparisons)]
+
+use std::string::String;
+
+struct TestStruct;
+
+impl TestStruct {
+ fn ends_with(self, _arg: &str) {}
+}
+
+#[allow(dead_code)]
+fn is_rust_file(filename: &str) -> bool {
+ std::path::Path::new(filename)
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("rs"))
+}
+
+fn main() {
+ // std::string::String and &str should trigger the lint failure with .ext12
+ let _ = std::path::Path::new(&String::new())
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ let _ = std::path::Path::new("str")
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+
+ // The fixup should preserve the indentation level
+ {
+ let _ = std::path::Path::new("str")
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("ext12"));
+ }
+
+ // The test struct should not trigger the lint failure with .ext12
+ TestStruct {}.ends_with(".ext12");
+
+ // std::string::String and &str should trigger the lint failure with .EXT12
+ let _ = std::path::Path::new(&String::new())
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
+ let _ = std::path::Path::new("str")
+ .extension()
+ .map_or(false, |ext| ext.eq_ignore_ascii_case("EXT12"));
+
+ // Should not trigger the lint failure because of the calls to to_lowercase and to_uppercase
+ let _ = String::new().to_lowercase().ends_with(".EXT12");
+ let _ = String::new().to_uppercase().ends_with(".EXT12");
+
+ // The test struct should not trigger the lint failure with .EXT12
+ TestStruct {}.ends_with(".EXT12");
+
+ // Should not trigger the lint failure with .eXT12
+ let _ = String::new().ends_with(".eXT12");
+ let _ = "str".ends_with(".eXT12");
+ TestStruct {}.ends_with(".eXT12");
+
+ // Should not trigger the lint failure with .EXT123 (too long)
+ let _ = String::new().ends_with(".EXT123");
+ let _ = "str".ends_with(".EXT123");
+ TestStruct {}.ends_with(".EXT123");
+
+ // Shouldn't fail if it doesn't start with a dot
+ let _ = String::new().ends_with("a.ext");
+ let _ = "str".ends_with("a.extA");
+ TestStruct {}.ends_with("a.ext");
+}