mod config;
mod endpoint;
mod error;
mod factory;
#[allow(dead_code)]
mod operator;
mod rat;
mod store;

use error::RatError;

fn main() -> Result<(), RatError> {
    let (store, tests) = config::Config::load()?;
    let global = vec![store];
    rat::Rat::new().test(global, tests)?;
    Ok(())
}

pub struct TestResult {
    name: String,
    result: bool,
    assertions: Vec<String>,
}

impl TestResult {
    pub fn print(&self) {
        println!("{} {}", Self::report_test(self.result), self.name);
        println!("\t{}", self.assertions.join("\n\t"));
    }

    pub fn report_test(result: bool) -> &'static str {
        if result {
            ""
        } else {
            ""
        }
    }
}

#[cfg(test)]
mod test {
    #[test]
    fn config_parsing_works() {
        let config = crate::config::Config::read();
        assert!(config.is_ok());
        println!("{:#?}", config);

        assert_eq!(
            evalexpr::eval("\"Isaac\" + \" \" + \"Adams\""),
            Ok(evalexpr::Value::from("Isaac Adams"))
        );
    }
}