use std::io;
use std::path::Path;
use std::fs::File;
use std::io::Error;
use std::io::BufRead;
pub struct MutationsChecker<'a> {
filename: &'a str,
mutations: Vec<String>,
}
impl<'a> MutationsChecker<'a> {
pub fn new(filename: &'a str) -> Result<MutationsChecker<'a>, Error> {
let lines = load_file("./tests/target/mutagen/mutations.txt")?;
let mc = MutationsChecker {
filename,
mutations: lines,
};
Ok(mc)
}
pub fn has(&self, msg: &str, at: &str) -> bool {
let location = format!("{}:{}", self.filename, at);
self.mutations
.iter()
.find(|current| current.contains(msg) && current.contains(&location))
.is_some()
}
pub fn has_multiple(&self, msg: &[&str], at: &str) -> bool {
msg.iter().all(|current| self.has(current, at))
}
}
fn load_file<P: AsRef<Path>>(filename: P) -> Result<Vec<String>, Error> {
let file = File::open(filename)?;
let lines = io::BufReader::new(file).lines();
Ok(lines.map(|l| l.unwrap_or("".to_string())).collect())
}