~irimi1/learning-rust

4a0af9c319ddbbad78dcb198a209e67912f07b0e — Manuel Groß 2 years ago 0575a56
minigrep: Add test for search function
1 files changed, 23 insertions(+), 0 deletions(-)

M projects/minigrep/src/lib.rs
M projects/minigrep/src/lib.rs => projects/minigrep/src/lib.rs +23 -0
@@ 7,6 7,10 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
    Ok(())
}

pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
    vec![]
}

pub struct Config {
    pub query: String,
    pub filename: String,


@@ 23,3 27,22 @@ impl Config {
        Ok(Config { query, filename })
    }
}

#[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)
        );
    }
}