Move some tests to lib.rs

This commit is contained in:
Lucien Cartier-Tilet 2020-07-11 17:35:57 +02:00
parent de45ffc15c
commit 3c960eaa35
Signed by: phundrak
GPG Key ID: BD7789E705CB8DCA
2 changed files with 26 additions and 21 deletions

View File

@ -68,3 +68,29 @@ pub fn init() -> std::result::Result<(), log::SetLoggerError> {
} }
} }
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn write_settings() {
let s = settings::Settings::new();
let path = std::path::Path::new("test.yaml");
let settings = r#"---
version: "1"
categories: {}
rules: []"#;
utils::write_file(&path, &serde_yaml::to_string(&s).unwrap()).unwrap();
assert_eq!(settings, utils::read_file(&path).unwrap());
}
#[test]
fn read_settings() {
let s1 = settings::Settings::new();
let path = std::path::Path::new("test.yml");
s1.export(&path).unwrap();
let s2 = settings::Settings::import(&path).unwrap();
assert_eq!(s1, s2);
}
}

View File

@ -403,24 +403,3 @@ impl PartialEq for Settings {
} }
impl Eq for Settings {} impl Eq for Settings {}
#[test]
fn write_settings() {
let s = Settings::new();
let path = std::path::Path::new("test.yaml");
let settings = r#"---
version: "1"
categories: {}
rules: []"#;
utils::write_file(&path, &serde_yaml::to_string(&s).unwrap()).unwrap();
assert_eq!(settings, utils::read_file(&path).unwrap());
}
#[test]
fn read_settings() {
let s1 = Settings::new();
let path = std::path::Path::new("test.yml");
s1.export(&path).unwrap();
let s2 = Settings::import(&path).unwrap();
assert_eq!(s1, s2);
}