Add tests for minigrep
This commit is contained in:
parent
6af1aad588
commit
9d8641043e
2 changed files with 20 additions and 4 deletions
|
@ -21,6 +21,25 @@ impl Config {
|
|||
|
||||
pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
|
||||
let contents = fs::read_to_string(config.file_path)?;
|
||||
println!("With text:\n{contents}");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
|
||||
vec![]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn one_result() {
|
||||
let query = "duct";
|
||||
let contents = "\
|
||||
Rust:
|
||||
safe, fast, productive.
|
||||
Pick three.";
|
||||
|
||||
assert_eq!(vec!["safe, fast, productive."], search(query, contents));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,9 +11,6 @@ fn main() {
|
|||
process::exit(1);
|
||||
});
|
||||
|
||||
println!("Searching for {}", config.query);
|
||||
println!("In file {}", config.file_path);
|
||||
|
||||
if let Err(e) = minigrep::run(config) {
|
||||
println!("Application error: {e}");
|
||||
process::exit(1);
|
||||
|
|
Loading…
Reference in a new issue