diff --git a/lychee-bin/src/commands/check.rs b/lychee-bin/src/commands/check.rs index d661657e2c..0a266c6ffc 100644 --- a/lychee-bin/src/commands/check.rs +++ b/lychee-bin/src/commands/check.rs @@ -398,7 +398,7 @@ mod tests { use crate::{formatters::get_response_formatter, options}; use http::StatusCode; use log::info; - use lychee_lib::{CacheStatus, ClientBuilder, ErrorKind, InputSource, Uri}; + use lychee_lib::{CacheStatus, ClientBuilder, ErrorKind, ResolvedInputSource, Uri}; use super::*; @@ -408,7 +408,7 @@ mod tests { let response = Response::new( Uri::try_from("http://127.0.0.1").unwrap(), Status::Cached(CacheStatus::Ok(200)), - InputSource::Stdin, + ResolvedInputSource::Stdin, ); let formatter = get_response_formatter(&options::OutputMode::Plain); show_progress( @@ -430,7 +430,7 @@ mod tests { let response = Response::new( Uri::try_from("http://127.0.0.1").unwrap(), Status::Cached(CacheStatus::Ok(200)), - InputSource::Stdin, + ResolvedInputSource::Stdin, ); let formatter = get_response_formatter(&options::OutputMode::Plain); show_progress( diff --git a/lychee-bin/src/formatters/stats/markdown.rs b/lychee-bin/src/formatters/stats/markdown.rs index d9e4b47b4d..908c9682da 100644 --- a/lychee-bin/src/formatters/stats/markdown.rs +++ b/lychee-bin/src/formatters/stats/markdown.rs @@ -159,7 +159,9 @@ impl StatsFormatter for Markdown { #[cfg(test)] mod tests { use http::StatusCode; - use lychee_lib::{CacheStatus, InputSource, Response, ResponseBody, Status, Uri}; + use lychee_lib::{ + CacheStatus, InputSource, ResolvedInputSource, Response, ResponseBody, Status, Uri, + }; use reqwest::Url; use crate::formatters::suggestion::Suggestion; @@ -219,7 +221,7 @@ mod tests { let response = Response::new( Uri::try_from("http://127.0.0.1").unwrap(), Status::Cached(CacheStatus::Error(Some(404))), - InputSource::Stdin, + ResolvedInputSource::Stdin, ); stats.add(response); stats diff --git a/lychee-bin/src/formatters/stats/mod.rs b/lychee-bin/src/formatters/stats/mod.rs index a9cd0c002c..0af5600153 100644 --- a/lychee-bin/src/formatters/stats/mod.rs +++ b/lychee-bin/src/formatters/stats/mod.rs @@ -55,14 +55,14 @@ where mod tests { use super::*; - use lychee_lib::{ErrorKind, Response, Status, Uri}; + use lychee_lib::{ErrorKind, ResolvedInputSource, Response, Status, Uri}; use url::Url; fn make_test_url(url: &str) -> Url { Url::parse(url).expect("Expected valid Website URI") } - fn make_test_response(url_str: &str, source: InputSource) -> Response { + fn make_test_response(url_str: &str, source: ResolvedInputSource) -> Response { let uri = Uri::from(make_test_url(url_str)); Response::new(uri, Status::Error(ErrorKind::TestError), source) @@ -74,12 +74,18 @@ mod tests { // Sorted list of test sources let test_sources = vec![ - InputSource::RemoteUrl(Box::new(make_test_url("https://example.com/404"))), - InputSource::RemoteUrl(Box::new(make_test_url("https://example.com/home"))), - InputSource::RemoteUrl(Box::new(make_test_url("https://example.com/page/1"))), - InputSource::RemoteUrl(Box::new(make_test_url("https://example.com/page/10"))), + ResolvedInputSource::RemoteUrl(Box::new(make_test_url("https://example.com/404"))), + ResolvedInputSource::RemoteUrl(Box::new(make_test_url("https://example.com/home"))), + ResolvedInputSource::RemoteUrl(Box::new(make_test_url("https://example.com/page/1"))), + ResolvedInputSource::RemoteUrl(Box::new(make_test_url("https://example.com/page/10"))), ]; + let unresolved_test_sources: Vec = test_sources + .iter() + .map(Clone::clone) + .map(Into::::into) + .collect(); + // Sorted list of test responses let test_response_urls = vec![ "https://example.com/", @@ -104,7 +110,7 @@ mod tests { .collect(); // Check that the input sources are sorted - assert_eq!(test_sources, sorted_sources); + assert_eq!(unresolved_test_sources, sorted_sources); // Check that the responses are sorted for (_, response_bodies) in sorted_errors { diff --git a/lychee-bin/src/stats.rs b/lychee-bin/src/stats.rs index 87cd1448b1..29ba730a30 100644 --- a/lychee-bin/src/stats.rs +++ b/lychee-bin/src/stats.rs @@ -90,7 +90,7 @@ impl ResponseStats { /// Add a response status to the appropriate map (success, fail, excluded) fn add_response_status(&mut self, response: Response) { let status = response.status(); - let source = response.source().clone(); + let source: InputSource = response.source().clone().into(); let status_map_entry = match status { _ if status.is_error() => self.error_map.entry(source).or_default(), Status::Ok(_) if self.detailed_stats => self.success_map.entry(source).or_default(), @@ -126,7 +126,9 @@ mod tests { use std::collections::{HashMap, HashSet}; use http::StatusCode; - use lychee_lib::{ErrorKind, InputSource, Response, ResponseBody, Status, Uri}; + use lychee_lib::{ + ErrorKind, InputSource, ResolvedInputSource, Response, ResponseBody, Status, Uri, + }; use reqwest::Url; use super::ResponseStats; @@ -140,7 +142,7 @@ mod tests { // and it's a lot faster to just generate a fake response fn mock_response(status: Status) -> Response { let uri = website("https://some-url.com/ok"); - Response::new(uri, status, InputSource::Stdin) + Response::new(uri, status, ResolvedInputSource::Stdin) } fn dummy_ok() -> Response { @@ -176,7 +178,10 @@ mod tests { let response = dummy_error(); let expected_error_map: HashMap> = - HashMap::from_iter([(response.source().clone(), HashSet::from_iter([response.1]))]); + HashMap::from_iter([( + response.source().clone().into(), + HashSet::from_iter([response.1]), + )]); assert_eq!(stats.error_map, expected_error_map); assert!(stats.success_map.is_empty()); @@ -196,7 +201,7 @@ mod tests { let mut expected_error_map: HashMap> = HashMap::new(); let response = dummy_error(); let entry = expected_error_map - .entry(response.source().clone()) + .entry(response.source().clone().into()) .or_default(); entry.insert(response.1); assert_eq!(stats.error_map, expected_error_map); @@ -204,7 +209,7 @@ mod tests { let mut expected_success_map: HashMap> = HashMap::new(); let response = dummy_ok(); let entry = expected_success_map - .entry(response.source().clone()) + .entry(response.source().clone().into()) .or_default(); entry.insert(response.1); assert_eq!(stats.success_map, expected_success_map); @@ -212,7 +217,7 @@ mod tests { let mut expected_excluded_map: HashMap> = HashMap::new(); let response = dummy_excluded(); let entry = expected_excluded_map - .entry(response.source().clone()) + .entry(response.source().clone().into()) .or_default(); entry.insert(response.1); assert_eq!(stats.excluded_map, expected_excluded_map); diff --git a/lychee-lib/src/extract/mod.rs b/lychee-lib/src/extract/mod.rs index f3a3f783fa..08dd9a220f 100644 --- a/lychee-lib/src/extract/mod.rs +++ b/lychee-lib/src/extract/mod.rs @@ -71,7 +71,7 @@ mod tests { use crate::{ Uri, test_utils::{load_fixture, mail, website}, - types::{FileType, InputContent, InputSource}, + types::{FileType, InputContent, ResolvedInputSource}, utils::url::find_links, }; @@ -204,7 +204,7 @@ mod tests { #[test] fn test_extract_relative_url() { - let source = InputSource::RemoteUrl(Box::new( + let source = ResolvedInputSource::RemoteUrl(Box::new( Url::parse("https://example.com/some-post").unwrap(), )); diff --git a/lychee-lib/src/lib.rs b/lychee-lib/src/lib.rs index e896734ba3..c38969e926 100644 --- a/lychee-lib/src/lib.rs +++ b/lychee-lib/src/lib.rs @@ -100,7 +100,7 @@ pub use crate::{ types::{ AcceptRange, AcceptRangeError, Base, BasicAuthCredentials, BasicAuthSelector, CacheStatus, CookieJar, ErrorKind, FileExtensions, FileType, Input, InputContent, InputResolver, - InputSource, Request, Response, ResponseBody, Result, Status, StatusCodeExcluder, - StatusCodeSelector, uri::valid::Uri, + InputSource, Request, ResolvedInputSource, Response, ResponseBody, Result, Status, + StatusCodeExcluder, StatusCodeSelector, uri::valid::Uri, }, }; diff --git a/lychee-lib/src/types/base.rs b/lychee-lib/src/types/base.rs index 4c68900c18..c2ec3b56d3 100644 --- a/lychee-lib/src/types/base.rs +++ b/lychee-lib/src/types/base.rs @@ -2,7 +2,7 @@ use reqwest::Url; use serde::{Deserialize, Serialize}; use std::{convert::TryFrom, path::PathBuf}; -use crate::{ErrorKind, InputSource}; +use crate::{ErrorKind, ResolvedInputSource}; /// When encountering links without a full domain in a document, /// the base determines where this resource can be found. @@ -30,9 +30,9 @@ impl Base { } } - pub(crate) fn from_source(source: &InputSource) -> Option { + pub(crate) fn from_source(source: &ResolvedInputSource) -> Option { match &source { - InputSource::RemoteUrl(url) => { + ResolvedInputSource::RemoteUrl(url) => { // Create a new URL with just the scheme, host, and port let mut base_url = url.clone(); base_url.set_path(""); @@ -124,7 +124,7 @@ mod test_base { ), ] { let url = Url::parse(url).unwrap(); - let source = InputSource::RemoteUrl(Box::new(url.clone())); + let source = ResolvedInputSource::RemoteUrl(Box::new(url.clone())); let base = Base::from_source(&source); let expected = Base::Remote(Url::parse(expected).unwrap()); assert_eq!(base, Some(expected)); diff --git a/lychee-lib/src/types/input/content.rs b/lychee-lib/src/types/input/content.rs index 18174c79e9..9a7dc1c3db 100644 --- a/lychee-lib/src/types/input/content.rs +++ b/lychee-lib/src/types/input/content.rs @@ -3,7 +3,7 @@ //! The `InputContent` type represents the actual content extracted from various //! input sources, along with metadata about the source and file type. -use super::source::InputSource; +use super::source::ResolvedInputSource; use crate::ErrorKind; use crate::types::FileType; use std::borrow::Cow; @@ -14,7 +14,7 @@ use std::path::PathBuf; #[derive(Debug)] pub struct InputContent { /// Input source - pub source: InputSource, + pub source: ResolvedInputSource, /// File type of given input pub file_type: FileType, /// Raw UTF-8 string content @@ -26,7 +26,7 @@ impl InputContent { /// Create an instance of `InputContent` from an input string pub fn from_string(s: &str, file_type: FileType) -> Self { Self { - source: InputSource::String(Cow::Owned(s.to_owned())), + source: ResolvedInputSource::String(Cow::Owned(s.to_owned())), file_type, content: s.to_owned(), } @@ -37,7 +37,7 @@ impl InputContent { pub fn from_str>>(s: S, file_type: FileType) -> Self { let cow = s.into(); Self { - source: InputSource::String(cow.clone()), + source: ResolvedInputSource::String(cow.clone()), file_type, content: cow.into_owned(), } @@ -61,7 +61,7 @@ impl TryFrom<&PathBuf> for InputContent { }; Ok(Self { - source: InputSource::String(Cow::Owned(input.clone())), + source: ResolvedInputSource::String(Cow::Owned(input.clone())), file_type: FileType::from(path), content: input, }) diff --git a/lychee-lib/src/types/input/input.rs b/lychee-lib/src/types/input/input.rs index 456d5166a6..1df0297f1d 100644 --- a/lychee-lib/src/types/input/input.rs +++ b/lychee-lib/src/types/input/input.rs @@ -353,7 +353,7 @@ impl Input { let input_content = InputContent { file_type: FileType::from(&path), - source: InputSource::FsPath(path), + source: ResolvedInputSource::FsPath(path), content, }; @@ -371,7 +371,7 @@ impl Input { stdin.read_to_string(&mut content).await?; let input_content = InputContent { - source: InputSource::Stdin, + source: ResolvedInputSource::Stdin, file_type: file_type_hint.unwrap_or_default(), content, }; diff --git a/lychee-lib/src/types/input/mod.rs b/lychee-lib/src/types/input/mod.rs index 2fccf00e60..3208500573 100644 --- a/lychee-lib/src/types/input/mod.rs +++ b/lychee-lib/src/types/input/mod.rs @@ -33,3 +33,4 @@ pub use content::InputContent; pub use input::Input; pub use resolver::InputResolver; pub use source::InputSource; +pub use source::ResolvedInputSource; diff --git a/lychee-lib/src/types/input/resolver.rs b/lychee-lib/src/types/input/resolver.rs index 1c63c533a6..2abc52b94b 100644 --- a/lychee-lib/src/types/input/resolver.rs +++ b/lychee-lib/src/types/input/resolver.rs @@ -152,7 +152,7 @@ impl InputResolver { yield ResolvedInputSource::Stdin; }, InputSource::String(s) => { - yield ResolvedInputSource::String(s.clone().into_owned()); + yield ResolvedInputSource::String(s.clone()); } } } diff --git a/lychee-lib/src/types/input/source.rs b/lychee-lib/src/types/input/source.rs index 930d52ffca..6a62086f06 100644 --- a/lychee-lib/src/types/input/source.rs +++ b/lychee-lib/src/types/input/source.rs @@ -58,7 +58,7 @@ pub enum ResolvedInputSource { /// Standard Input. Stdin, /// Raw string input. - String(String), + String(Cow<'static, str>), } impl From for InputSource { @@ -67,7 +67,7 @@ impl From for InputSource { ResolvedInputSource::RemoteUrl(url) => InputSource::RemoteUrl(url), ResolvedInputSource::FsPath(path) => InputSource::FsPath(path), ResolvedInputSource::Stdin => InputSource::Stdin, - ResolvedInputSource::String(s) => InputSource::String(Cow::Owned(s)), + ResolvedInputSource::String(s) => InputSource::String(s), } } } diff --git a/lychee-lib/src/types/mod.rs b/lychee-lib/src/types/mod.rs index 79bfdd5fa8..4d41c5e830 100644 --- a/lychee-lib/src/types/mod.rs +++ b/lychee-lib/src/types/mod.rs @@ -23,7 +23,7 @@ pub use cache::CacheStatus; pub use cookies::CookieJar; pub use error::ErrorKind; pub use file::{FileExtensions, FileType}; -pub use input::{Input, InputContent, InputResolver, InputSource}; +pub use input::{Input, InputContent, InputResolver, InputSource, ResolvedInputSource}; pub use request::Request; pub use response::{Response, ResponseBody}; pub use status::Status; diff --git a/lychee-lib/src/types/request.rs b/lychee-lib/src/types/request.rs index 743bb8dfca..da6844398a 100644 --- a/lychee-lib/src/types/request.rs +++ b/lychee-lib/src/types/request.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, convert::TryFrom, fmt::Display}; use crate::{BasicAuthCredentials, ErrorKind, Uri}; -use super::InputSource; +use super::ResolvedInputSource; /// A request type that can be handle by lychee #[derive(Debug, PartialEq, Eq, Hash, Clone)] @@ -12,7 +12,7 @@ pub struct Request { pub uri: Uri, /// The resource which contained the given URI - pub source: InputSource, + pub source: ResolvedInputSource, /// Specifies how the URI was rendered inside a document /// (for example `img`, `a`, `pre`, or `code`). @@ -32,7 +32,7 @@ impl Request { #[must_use] pub const fn new( uri: Uri, - source: InputSource, + source: ResolvedInputSource, element: Option, attribute: Option, credentials: Option, @@ -59,7 +59,7 @@ impl TryFrom for Request { fn try_from(uri: Uri) -> Result { Ok(Request::new( uri.clone(), - InputSource::RemoteUrl(Box::new(uri.url)), + ResolvedInputSource::RemoteUrl(Box::new(uri.url)), None, None, None, @@ -74,7 +74,7 @@ impl TryFrom for Request { let uri = Uri::try_from(s.as_str())?; Ok(Request::new( uri, - InputSource::String(Cow::Owned(s)), + ResolvedInputSource::String(Cow::Owned(s)), None, None, None, @@ -89,7 +89,7 @@ impl TryFrom<&str> for Request { let uri = Uri::try_from(s)?; Ok(Request::new( uri, - InputSource::String(Cow::Owned(s.to_owned())), + ResolvedInputSource::String(Cow::Owned(s.to_owned())), None, None, None, diff --git a/lychee-lib/src/types/resolver.rs b/lychee-lib/src/types/resolver.rs index 550583fcfb..c6baadce38 100644 --- a/lychee-lib/src/types/resolver.rs +++ b/lychee-lib/src/types/resolver.rs @@ -1,4 +1,4 @@ -use super::{FileType, InputContent, InputSource}; +use super::{FileType, InputContent, ResolvedInputSource}; use crate::utils::request; use crate::{BasicAuthExtractor, ErrorKind, Result, Uri}; use http::HeaderMap; @@ -33,7 +33,7 @@ impl UrlContentResolver { let content = get_request_body_text(&self.client, request).await?; let input_content = InputContent { - source: InputSource::RemoteUrl(Box::new(url.clone())), + source: ResolvedInputSource::RemoteUrl(Box::new(url.clone())), file_type, content, }; diff --git a/lychee-lib/src/types/response.rs b/lychee-lib/src/types/response.rs index 7609e84b97..7a54d6f291 100644 --- a/lychee-lib/src/types/response.rs +++ b/lychee-lib/src/types/response.rs @@ -3,7 +3,7 @@ use std::fmt::Display; use http::StatusCode; use serde::Serialize; -use crate::{InputSource, Status, Uri}; +use crate::{ResolvedInputSource, Status, Uri}; /// Response type returned by lychee after checking a URI // @@ -14,13 +14,13 @@ use crate::{InputSource, Status, Uri}; // `pub(crate)` is insufficient, because the `stats` module is in the `bin` // crate crate. #[derive(Debug)] -pub struct Response(InputSource, pub ResponseBody); +pub struct Response(ResolvedInputSource, pub ResponseBody); impl Response { #[inline] #[must_use] /// Create new response - pub const fn new(uri: Uri, status: Status, source: InputSource) -> Self { + pub const fn new(uri: Uri, status: Status, source: ResolvedInputSource) -> Self { Response(source, ResponseBody { uri, status }) } @@ -35,7 +35,7 @@ impl Response { #[must_use] /// Retrieve the underlying source of the response /// (e.g. the input file or the URL) - pub const fn source(&self) -> &InputSource { + pub const fn source(&self) -> &ResolvedInputSource { &self.0 } diff --git a/lychee-lib/src/utils/request.rs b/lychee-lib/src/utils/request.rs index dc9a13d6a6..abf5b8c4de 100644 --- a/lychee-lib/src/utils/request.rs +++ b/lychee-lib/src/utils/request.rs @@ -9,7 +9,7 @@ use std::{ use crate::{ Base, BasicAuthCredentials, ErrorKind, Request, Result, Uri, basic_auth::BasicAuthExtractor, - types::{InputSource, uri::raw::RawUri}, + types::{ResolvedInputSource, uri::raw::RawUri}, utils::{path, url}, }; @@ -24,7 +24,7 @@ pub(crate) fn extract_credentials( /// Create a request from a raw URI. fn create_request( raw_uri: &RawUri, - source: &InputSource, + source: &ResolvedInputSource, root_dir: Option<&PathBuf>, base: Option<&Base>, extractor: Option<&BasicAuthExtractor>, @@ -51,7 +51,7 @@ fn create_request( /// - If the source is not a file path (i.e. the URI type is not supported). fn try_parse_into_uri( raw_uri: &RawUri, - source: &InputSource, + source: &ResolvedInputSource, root_dir: Option<&PathBuf>, base: Option<&Base>, ) -> Result { @@ -64,7 +64,7 @@ fn try_parse_into_uri( None => return Err(ErrorKind::InvalidBaseJoin(text.clone())), }, None => match source { - InputSource::FsPath(root) => { + ResolvedInputSource::FsPath(root) => { create_uri_from_file_path(root, &text, root_dir.is_none())? } _ => return Err(ErrorKind::UnsupportedUriType(text)), @@ -117,12 +117,12 @@ fn create_uri_from_file_path( /// This is only needed for string inputs. /// For other inputs, the source is simply a "label" (an enum variant). // TODO: This would not be necessary if we used `Cow` for the source. -fn truncate_source(source: &InputSource) -> InputSource { +fn truncate_source(source: &ResolvedInputSource) -> ResolvedInputSource { const MAX_TRUNCATED_STR_LEN: usize = 100; match source { - InputSource::String(s) => { - InputSource::String(s.chars().take(MAX_TRUNCATED_STR_LEN).collect()) + ResolvedInputSource::String(s) => { + ResolvedInputSource::String(s.chars().take(MAX_TRUNCATED_STR_LEN).collect()) } other => other.clone(), } @@ -135,7 +135,7 @@ fn truncate_source(source: &InputSource) -> InputSource { /// it will not be added to the `HashSet`. pub(crate) fn create( uris: Vec, - source: &InputSource, + source: &ResolvedInputSource, root_dir: Option<&PathBuf>, base: Option<&Base>, extractor: Option<&BasicAuthExtractor>, @@ -226,7 +226,7 @@ mod tests { #[test] fn test_relative_url_resolution() { let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let uris = vec![RawUri::from("relative.html")]; let requests = create(uris, &source, None, Some(&base), None); @@ -242,7 +242,7 @@ mod tests { #[test] fn test_absolute_url_resolution() { let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let uris = vec![RawUri::from("https://another.com/page")]; let requests = create(uris, &source, None, Some(&base), None); @@ -258,7 +258,7 @@ mod tests { #[test] fn test_root_relative_url_resolution() { let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let uris = vec![RawUri::from("/root-relative")]; let requests = create(uris, &source, None, Some(&base), None); @@ -274,7 +274,7 @@ mod tests { #[test] fn test_parent_directory_url_resolution() { let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let uris = vec![RawUri::from("../parent")]; let requests = create(uris, &source, None, Some(&base), None); @@ -290,7 +290,7 @@ mod tests { #[test] fn test_fragment_url_resolution() { let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let uris = vec![RawUri::from("#fragment")]; let requests = create(uris, &source, None, Some(&base), None); @@ -306,7 +306,7 @@ mod tests { #[test] fn test_relative_url_resolution_from_root_dir() { let root_dir = PathBuf::from("/tmp/lychee"); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("relative.html")]; let requests = create(uris, &source, Some(&root_dir), None, None); @@ -322,7 +322,7 @@ mod tests { #[test] fn test_absolute_url_resolution_from_root_dir() { let root_dir = PathBuf::from("/tmp/lychee"); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("https://another.com/page")]; let requests = create(uris, &source, Some(&root_dir), None, None); @@ -338,7 +338,7 @@ mod tests { #[test] fn test_root_relative_url_resolution_from_root_dir() { let root_dir = PathBuf::from("/tmp/lychee"); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("/root-relative")]; let requests = create(uris, &source, Some(&root_dir), None, None); @@ -354,7 +354,7 @@ mod tests { #[test] fn test_parent_directory_url_resolution_from_root_dir() { let root_dir = PathBuf::from("/tmp/lychee"); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("../parent")]; let requests = create(uris, &source, Some(&root_dir), None, None); @@ -370,7 +370,7 @@ mod tests { #[test] fn test_fragment_url_resolution_from_root_dir() { let root_dir = PathBuf::from("/tmp/lychee"); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("#fragment")]; let requests = create(uris, &source, Some(&root_dir), None, None); @@ -387,7 +387,7 @@ mod tests { fn test_relative_url_resolution_from_root_dir_and_base_url() { let root_dir = PathBuf::from("/tmp/lychee"); let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("relative.html")]; let requests = create(uris, &source, Some(&root_dir), Some(&base), None); @@ -404,7 +404,7 @@ mod tests { fn test_absolute_url_resolution_from_root_dir_and_base_url() { let root_dir = PathBuf::from("/tmp/lychee"); let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("https://another.com/page")]; let requests = create(uris, &source, Some(&root_dir), Some(&base), None); @@ -421,7 +421,7 @@ mod tests { fn test_root_relative_url_resolution_from_root_dir_and_base_url() { let root_dir = PathBuf::from("/tmp/lychee"); let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("/root-relative")]; let requests = create(uris, &source, Some(&root_dir), Some(&base), None); @@ -438,7 +438,7 @@ mod tests { fn test_parent_directory_url_resolution_from_root_dir_and_base_url() { let root_dir = PathBuf::from("/tmp/lychee"); let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("../parent")]; let requests = create(uris, &source, Some(&root_dir), Some(&base), None); @@ -455,7 +455,7 @@ mod tests { fn test_fragment_url_resolution_from_root_dir_and_base_url() { let root_dir = PathBuf::from("/tmp/lychee"); let base = Base::try_from("https://example.com/path/page.html").unwrap(); - let source = InputSource::FsPath(PathBuf::from("/some/page.html")); + let source = ResolvedInputSource::FsPath(PathBuf::from("/some/page.html")); let uris = vec![RawUri::from("#fragment")]; let requests = create(uris, &source, Some(&root_dir), Some(&base), None); @@ -470,7 +470,7 @@ mod tests { #[test] fn test_no_base_url_resolution() { - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let uris = vec![RawUri::from("https://example.com/page")]; let requests = create(uris, &source, None, None, None); @@ -486,7 +486,7 @@ mod tests { #[test] fn test_create_request_from_relative_file_path() { let base = Base::Local(PathBuf::from("/tmp/lychee")); - let input_source = InputSource::FsPath(PathBuf::from("page.html")); + let input_source = ResolvedInputSource::FsPath(PathBuf::from("page.html")); let actual = create_request( &RawUri::from("file.html"), @@ -514,7 +514,7 @@ mod tests { #[test] fn test_create_request_from_absolute_file_path() { let base = Base::Local(PathBuf::from("/tmp/lychee")); - let input_source = InputSource::FsPath(PathBuf::from("/tmp/lychee/page.html")); + let input_source = ResolvedInputSource::FsPath(PathBuf::from("/tmp/lychee/page.html")); // Use an absolute path that's outside the base directory let actual = create_request( @@ -543,7 +543,7 @@ mod tests { #[test] fn test_parse_relative_path_into_uri() { let base = Base::Local(PathBuf::from("/tmp/lychee")); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let raw_uri = RawUri::from("relative.html"); let uri = try_parse_into_uri(&raw_uri, &source, None, Some(&base)).unwrap(); @@ -554,7 +554,7 @@ mod tests { #[test] fn test_parse_absolute_path_into_uri() { let base = Base::Local(PathBuf::from("/tmp/lychee")); - let source = InputSource::String(Cow::Borrowed("")); + let source = ResolvedInputSource::String(Cow::Borrowed("")); let raw_uri = RawUri::from("absolute.html"); let uri = try_parse_into_uri(&raw_uri, &source, None, Some(&base)).unwrap();