~irimi1/learning-rust

030b72bc9212edacdfad63e983ebdd897e13c489 — Manuel Groß 2 years ago c5ee219
minigrep: Add test for case insensitive search
1 files changed, 22 insertions(+), 2 deletions(-)

M projects/minigrep/src/lib.rs
M projects/minigrep/src/lib.rs => projects/minigrep/src/lib.rs +22 -2
@@ 23,6 23,10 @@ pub fn search<'a>(query: &str, contents: &'a str) -> Vec<&'a str> {
    results
}

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

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


@@ 45,16 49,32 @@ mod tests {
    use super::*;

    #[test]
    fn one_result() {
    fn case_sensitive() {
        let query = "duct";
        let contents = "\
Rust:
safe, fast, productive.
Pick three.";
Pick three.
Duct tape.";

        assert_eq!(
            vec!["safe, fast, productive."],
            search(query, contents)
        );
    }

    #[test]
    fn case_insensitive() {
        let query = "rUsT";
        let contents = "\
Rust:
safe, fast, productive.
Pick three.
Trust me.";
    
        assert_eq!(
            vec!["Rust:", "Trust me."],
            search_case_insensitive(query, contents)
        );
    }
}