74 lines
2.2 KiB
Rust
74 lines
2.2 KiB
Rust
use super::*;
|
|
|
|
#[test]
|
|
fn selected_files_and_auxiliary_grammars_are_registered() {
|
|
for (filename, language) in [
|
|
("main.rs", "Rust"),
|
|
("Gemfile", "Ruby"),
|
|
("main.py", "Python"),
|
|
("package.json", "JSON"),
|
|
(".bashrc", "Bash"),
|
|
("GNUmakefile", "Makefile"),
|
|
("README.md", "Markdown"),
|
|
("main.jsx", "JavaScript"),
|
|
("main.ts", "TypeScript"),
|
|
("index.html", "HTML"),
|
|
("style.css", "CSS"),
|
|
("config.yml", "YAML"),
|
|
("Cargo.toml", "TOML"),
|
|
("Cargo.lock", "TOML"),
|
|
("main.c", "C"),
|
|
("main.cpp", "C++"),
|
|
("main.C", "C++"),
|
|
("main.go", "Go"),
|
|
("main.zig", "Zig"),
|
|
] {
|
|
assert_eq!(
|
|
detect(Some(Path::new(filename)), None).map(|spec| spec.name),
|
|
Some(language)
|
|
);
|
|
}
|
|
let ts = detect(Some(Path::new("main.ts")), None).unwrap();
|
|
let tsx = detect(Some(Path::new("main.tsx")), None).unwrap();
|
|
assert_eq!(ts.name, tsx.name);
|
|
assert!(!std::ptr::eq(ts, tsx));
|
|
assert_ne!(ts.language, tsx.language);
|
|
assert!(std::ptr::eq(tsx, by_name("TSX").unwrap()));
|
|
assert!(by_name("markdown_inline").is_some());
|
|
for filename in [
|
|
"notes.txt",
|
|
"main.hs",
|
|
"main.scala",
|
|
"main.lua",
|
|
"Dockerfile",
|
|
] {
|
|
assert!(detect(Some(Path::new(filename)), None).is_none());
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn shebangs_support_bom_env_options_and_filename_precedence() {
|
|
for (line, language) in [
|
|
("#!/usr/bin/python3", "Python"),
|
|
("\u{feff}#!/usr/bin/env -S python3.12 -u", "Python"),
|
|
("#!/usr/bin/env -u PYTHONHOME FOO=bar python3", "Python"),
|
|
("#!/usr/bin/ruby3.3", "Ruby"),
|
|
("#!/bin/bash", "Bash"),
|
|
("#! /usr/bin/env node", "JavaScript"),
|
|
] {
|
|
assert_eq!(
|
|
detect(None, Some(line)).map(|spec| spec.name),
|
|
Some(language)
|
|
);
|
|
}
|
|
assert_eq!(
|
|
detect(Some(Path::new("main.rs")), Some("#!/bin/bash"))
|
|
.unwrap()
|
|
.name,
|
|
"Rust"
|
|
);
|
|
assert!(detect(None, Some("#!/usr/bin/python-not-real")).is_none());
|
|
assert!(detect(None, Some("#!/usr/bin/perl")).is_none());
|
|
assert!(detect(None, Some("plain text")).is_none());
|
|
}
|