2025-06-23 20:27:16 +02:00
|
|
|
pub fn lowercase_ext(path: &std::path::Path) -> Option<&'static str> {
|
2025-06-24 20:27:06 +02:00
|
|
|
path.extension().and_then(|s| match s.to_str()? {
|
|
|
|
|
"rs" | "RS" => Some("rs"),
|
|
|
|
|
"c" => Some("c"),
|
|
|
|
|
"cpp" | "c++" => Some("cpp"),
|
|
|
|
|
"java" => Some("java"),
|
|
|
|
|
"go" => Some("go"),
|
|
|
|
|
"php" => Some("php"),
|
|
|
|
|
"py" | "PY" => Some("py"),
|
|
|
|
|
"ts" | "TSX" | "tsx" => Some("ts"),
|
|
|
|
|
"js" => Some("js"),
|
2026-02-24 23:44:07 -05:00
|
|
|
"rb" | "RB" => Some("rb"),
|
2025-06-24 20:27:06 +02:00
|
|
|
_ => None,
|
2025-06-23 20:27:16 +02:00
|
|
|
})
|
2025-06-24 20:27:06 +02:00
|
|
|
}
|
2025-06-24 23:18:01 +02:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn lowercase_ext_recognises_known_extensions() {
|
2025-06-24 23:38:32 +02:00
|
|
|
let cases = [
|
|
|
|
|
("file.rs", Some("rs")),
|
|
|
|
|
("FILE.RS", Some("rs")),
|
|
|
|
|
("main.cpp", Some("cpp")),
|
|
|
|
|
("script.PY", Some("py")),
|
|
|
|
|
("index.tsx", Some("ts")),
|
|
|
|
|
("style.css", None), // unsupported
|
|
|
|
|
];
|
2025-06-24 23:18:01 +02:00
|
|
|
|
2025-06-24 23:38:32 +02:00
|
|
|
for (file, expected) in cases {
|
|
|
|
|
assert_eq!(
|
|
|
|
|
lowercase_ext(std::path::Path::new(file)),
|
|
|
|
|
expected,
|
|
|
|
|
"case: {file}"
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-06-24 23:18:01 +02:00
|
|
|
}
|