add tests for history::find
This commit is contained in:
parent
20a4ef59d9
commit
1219eef089
4 changed files with 91 additions and 0 deletions
|
@ -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(())
|
||||
}
|
||||
}
|
||||
|
|
3
test/data/with-embedded-llamma.txt
Normal file
3
test/data/with-embedded-llamma.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
this is a text file
|
||||
embedded llamma
|
||||
it has three lines
|
3
test/data/with-llamma.txt
Normal file
3
test/data/with-llamma.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
this is a text file
|
||||
llamma
|
||||
it has three lines
|
2
test/data/without-llamma.txt
Normal file
2
test/data/without-llamma.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
this is a text file
|
||||
it has three lines
|
Loading…
Add table
Reference in a new issue