Add basic unit test for language detection by extension

pull/78/head
Wilfred Hughes 2021-12-27 12:23:22 +07:00
parent f6f9f16e9f
commit 35c481289a
1 changed files with 13 additions and 0 deletions

@ -4,6 +4,7 @@ use std::{borrow::Borrow, ffi::OsStr, path::Path};
/// Languages supported by difftastic. Each language here has a
/// corresponding tree-sitter parser.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Language {
Bash,
C,
@ -79,3 +80,15 @@ fn from_extension(extension: &OsStr) -> Option<Language> {
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
#[test]
fn test_guess_by_extension() {
let path = Path::new("foo.el");
assert_eq!(guess(path), Some(EmacsLisp));
}
}