summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorsharkdp <davidpeter@web.de>2020-03-15 14:14:01 +0100
committerDavid Peter <sharkdp@users.noreply.github.com>2020-03-15 22:33:26 +0100
commitb611d2aef4056c318e460bd12ad3de6b4014d6cb (patch)
tree8b25905cc860a67b55bfed058e2230218bc06738 /tests
parenta2075b0f24b458e029495bb7f3b45bb40badef79 (diff)
Add no-duplicate-extensions unit test
Diffstat (limited to 'tests')
-rw-r--r--tests/no_duplicate_extensions.rs35
-rw-r--r--tests/syntax_detection.rs11
2 files changed, 46 insertions, 0 deletions
diff --git a/tests/no_duplicate_extensions.rs b/tests/no_duplicate_extensions.rs
new file mode 100644
index 00000000..ef9e76a9
--- /dev/null
+++ b/tests/no_duplicate_extensions.rs
@@ -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
+ );
+ }
+ }
+}
diff --git a/tests/syntax_detection.rs b/tests/syntax_detection.rs
index 23a52de9..ac155959 100644
--- a/tests/syntax_detection.rs
+++ b/tests/syntax_detection.rs
@@ -58,6 +58,17 @@ fn syntax_detection_basic() {
}
#[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();