Skip to content

Commit

Permalink
add tests for windows filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
toadslop committed Jun 29, 2024
1 parent fc14a6b commit 85c4996
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lychee-lib/src/types/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,4 +509,35 @@ mod tests {
String::from("http://example.com/")
);
}

// Test proves that a windows filepath is not mistaken for a Url
#[test]
fn test_windows_style_filepath_not_existing() {
let input = Input::new("C:\\example\\project\\here", None, false, None);
assert!(input.is_err());
let input = input.unwrap_err();

match input {
ErrorKind::InvalidFile(_) => (),
_ => panic!("Should have received InvalidFile error"),
}
}

// Test proves that one windows, a windows style filepath to an existing file is recognized as a filepath
#[cfg(windows)]
#[test]
fn test_windows_style_filepath_existing() {
use std::env::temp_dir;
use tempfile::NamedTempFile;

let dir = temp_dir();
let file = NamedTempFile::new_in(dir).unwrap();
let path = file.path();
let input = Input::new(path.to_str().unwrap(), None, false, None).unwrap();

match input.source {
InputSource::FsPath(_) => (),
_ => panic!("Input source should be FsPath but was not"),
}
}
}

0 comments on commit 85c4996

Please sign in to comment.