complish 0.0.1

Core library for project-aware task management with git integration
Documentation
use std::path::PathBuf;

use dir_spec::Dir;

use crate::env;

pub fn home_dir() -> PathBuf {
  if let Some(home) = env::home() {
    return home;
  }

  Dir::data_home().unwrap().join("complish")
}

pub fn vault_file() -> PathBuf {
  home_dir().join("vault")
}

#[cfg(test)]
mod tests {
  use super::*;

  mod home_dir {
    use pretty_assertions::assert_eq;
    use temp_env::{with_var, with_var_unset};

    use super::*;

    #[test]
    fn it_returns_complish_home_when_set() {
      let test_path = "/test/path";

      with_var("COMPLISH_HOME", Some(test_path), || {
        assert_eq!(home_dir(), PathBuf::from(test_path));
      });
    }

    #[test]
    fn it_returns_default_when_complish_home_is_unset() {
      let xdg_data_home = "/xdg/data/home";

      with_var_unset("COMPLISH_HOME", || {
        with_var("XDG_DATA_HOME", Some(xdg_data_home), || {
          assert_eq!(home_dir(), PathBuf::from(xdg_data_home).join("complish"));
        });
      });
    }
  }

  mod vault_file {
    use pretty_assertions::assert_eq;

    use super::*;

    #[test]
    fn it_returns_the_vault_file_path() {
      assert_eq!(vault_file(), home_dir().join("vault"));
    }
  }
}