#![warn(missing_docs)]
#![warn(rustdoc::missing_doc_code_examples)]
mod code;
mod detector;
mod ruleset;
pub mod project;
#[cfg(test)]
mod tests {
use super::project::Project;
use anyhow::*;
use std::{env, path::PathBuf};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum TestError {
#[error("Test Error")]
Test,
}
fn test_dir(dir: &str) -> String {
let mut path = env::current_dir().unwrap();
path.push("test_projects");
path.push(dir);
path.to_string_lossy().to_string()
}
#[test]
fn test_detect_rust_lang() -> Result<()> {
let dir = test_dir("rust");
let mut project = Project::new(&dir[..])?;
project.parse()?;
let result = vec![String::from("rust")];
assert_eq!(Some(result), project.project_langs);
Ok(())
}
#[test]
fn test_detect_rust_node() -> Result<()> {
let dir = test_dir("node");
let mut project = Project::new(&dir[..])?;
project.parse()?;
let result = vec![String::from("node")];
assert_eq!(Some(result), project.project_langs);
Ok(())
}
#[test]
fn test_get_gitignore() -> Result<()> {
let dir = test_dir("node");
let mut project = Project::new(&dir[..])?;
project.parse()?;
let gitignore = project.generic_gitignore.unwrap();
let gitignore = gitignore[0].as_str();
assert_eq!(Some(0), gitignore.find("\n### Node"));
Ok(())
}
#[test]
fn test_get_code_stats() -> Result<()> {
let dir = test_dir("node");
let mut project = Project::new(&dir[..])?;
project.parse()?;
project.get_code_stats()?;
assert_eq!(true, project.code_stats.unwrap().contains_key("JSON"));
Ok(())
}
#[test]
fn test_non_existing_dir() -> Result<()> {
let dir = "/imagigary/dir";
let err = match Project::new(&dir[..]) {
Err(e) => e,
_ => anyhow!(TestError::Test),
};
let err_msg = format!("{:?}", err);
let expected_err_msg = String::from("Directory /imagigary/dir Cannot be found!");
assert_eq!(err_msg, expected_err_msg);
Ok(())
}
}