1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-28 15:56:28 +00:00

feat: Add cabal and hpack detection for the haskell module (#915)

This commit is contained in:
Brett Mandler 2020-02-06 19:29:57 -05:00 committed by GitHub
parent 2509a79176
commit bc600e4321
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,10 +7,13 @@ use crate::utils;
///
/// Will display the Haskell version if any of the following criteria are met:
/// - Current directory contains a `stack.yaml` file
/// - Current directory contains a `.cabal` file
/// - Current directory contains a `package.yaml` file
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
let is_haskell_project = context
.try_begin_scan()?
.set_files(&["stack.yaml"])
.set_files(&["package.yaml", "stack.yaml", "package.yml", "stack.yml"])
.set_extensions(&["cabal"])
.is_match();
if !is_haskell_project {
@ -51,6 +54,25 @@ mod tests {
Ok(())
}
#[test]
fn folder_with_hpack_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("package.yaml"))?.sync_all()?;
let actual = render_module("haskell", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn folder_with_cabal_file() -> io::Result<()> {
let dir = tempfile::tempdir()?;
File::create(dir.path().join("test.cabal"))?.sync_all()?;
let actual = render_module("haskell", dir.path());
let expected = Some(format!("via {} ", Color::Red.bold().paint("λ v8.6.5")));
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn folder_with_stack_yaml() -> io::Result<()> {
let dir = tempfile::tempdir()?;