mirror of
https://github.com/sharkdp/bat
synced 2024-11-16 21:25:56 +00:00
Add no-duplicate-extensions unit test
This commit is contained in:
parent
a2075b0f24
commit
b611d2aef4
35
tests/no_duplicate_extensions.rs
Normal file
35
tests/no_duplicate_extensions.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use bat::assets::HighlightingAssets;
|
||||
|
||||
#[test]
|
||||
fn no_duplicate_extensions() {
|
||||
const KNOWN_EXCEPTIONS: &[&'static str] = &[
|
||||
// The '.h' extension currently appears in multiple syntaxes: C, C++, Objective C,
|
||||
// Objective C++
|
||||
"h",
|
||||
// In addition to the standard Haskell syntax in 'Packages', we also ship the 'Cabal'
|
||||
// syntax which comes with a "Haskell (improved)" syntax.
|
||||
"hs",
|
||||
// In addition to the standard JavaScript syntax in 'Packages', we also ship the
|
||||
// 'Javascript (Babel)' syntax.
|
||||
"js",
|
||||
// The "Ruby Haml" syntax also comes with a '.sass' extension. However, we make sure
|
||||
// that 'sass' is mapped to the 'Sass' syntax.
|
||||
"sass",
|
||||
];
|
||||
|
||||
let assets = HighlightingAssets::new();
|
||||
|
||||
let mut extensions = HashSet::new();
|
||||
|
||||
for syntax in assets.syntax_set.syntaxes() {
|
||||
for extension in &syntax.file_extensions {
|
||||
assert!(
|
||||
KNOWN_EXCEPTIONS.contains(&extension.as_str()) || extensions.insert(extension),
|
||||
"File extension / pattern \"{}\" appears twice in the syntax set",
|
||||
extension
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
@ -57,6 +57,17 @@ fn syntax_detection_basic() {
|
||||
assert_eq!(test.syntax_name("PKGBUILD"), "Bourne Again Shell (bash)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn syntax_detection_well_defined_mapping_for_duplicate_extensions() {
|
||||
let test = SyntaxDetectionTest::new();
|
||||
|
||||
assert_eq!(test.syntax_name("test.sass"), "Sass");
|
||||
// TODO: make these tests pass:
|
||||
// assert_eq!(test.syntax_name("test.h"), "C");
|
||||
// assert_eq!(test.syntax_name("test.hs"), "Haskell (Improved)");
|
||||
// assert_eq!(test.syntax_name("test.js"), "JavaScript (Babel)");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn syntax_detection_first_line() {
|
||||
let test = SyntaxDetectionTest::new();
|
||||
|
Loading…
Reference in New Issue
Block a user