i5-add-tests (part 2) #7

Merged
kemitix merged 10 commits from i5-add-tests into main 2023-07-28 18:35:41 +01:00
4 changed files with 91 additions and 0 deletions
Showing only changes of commit 1219eef089 - Show all commits

View file

@ -15,3 +15,86 @@ pub fn find(link: &Link, file_name: &str) -> Result<bool> {
}
Ok(false) // is not already downloaded
}
#[cfg(test)]
mod test {
use crate::{history::Link, test_utils::create_text_file};
use super::*;
#[test]
fn true_if_line_exists() -> Result<()> {
//given
let (dir, file_name) =
create_text_file("file", include_bytes!("../../test/data/with-llamma.txt"))?;
let link = Link {
href: "llamma".to_string(),
rel: "".to_string(),
hreflang: None,
mime_type: None,
title: None,
length: None,
};
//when
let result = find(&link, &file_name)?;
//then
drop(dir);
assert_eq!(result, true);
Ok(())
}
#[test]
fn false_if_line_absent() -> Result<()> {
//given
let (dir, file_name) =
create_text_file("file", include_bytes!("../../test/data/without-llamma.txt"))?;
let link = Link {
href: "llamma".to_string(),
rel: "".to_string(),
hreflang: None,
mime_type: None,
title: None,
length: None,
};
//when
let result = find(&link, &file_name)?;
//then
drop(dir);
assert_eq!(result, false);
Ok(())
}
#[test]
fn false_if_embedded_within_line() -> Result<()> {
//given
let (dir, file_name) = create_text_file(
"file",
include_bytes!("../../test/data/with-embedded-llamma.txt"),
)?;
let link = Link {
href: "llamma".to_string(),
rel: "".to_string(),
hreflang: None,
mime_type: None,
title: None,
length: None,
};
//when
let result = find(&link, &file_name)?;
//then
drop(dir);
assert_eq!(result, false);
Ok(())
}
}

View file

@ -0,0 +1,3 @@
this is a text file
embedded llamma
it has three lines

View file

@ -0,0 +1,3 @@
this is a text file
llamma
it has three lines

View file

@ -0,0 +1,2 @@
this is a text file
it has three lines