From 07d4b7f68a579514037131d881240dd6d81702f3 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 21 Jan 2025 19:05:11 -0500 Subject: [PATCH] chore: add another url_or_path test from deno_core --- src/lib.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 85312f2..98749b8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -175,7 +175,7 @@ pub fn normalize_path>(path: P) -> PathBuf { inner(path.as_ref()) } -#[derive(Debug, Clone, Error, deno_error::JsError)] +#[derive(Debug, Clone, Error, deno_error::JsError, PartialEq, Eq)] #[class(uri)] #[error("Could not convert path to URL.\n Path: {0}")] pub struct PathToUrlError(pub PathBuf); @@ -342,7 +342,7 @@ pub fn specifier_has_uri_scheme(specifier: &str) -> bool { } } -#[derive(Debug, Clone, Error, JsError)] +#[derive(Debug, Clone, Error, JsError, PartialEq, Eq)] pub enum ResolveUrlOrPathError { #[error(transparent)] #[class(inherit)] @@ -721,4 +721,25 @@ mod tests { assert_eq!(url, expected_url); } } + + #[test] + fn test_resolve_url_or_path_deprecated_error() { + use url::ParseError::*; + use ResolveUrlOrPathError::*; + + let mut tests = vec![ + ("https://eggplant:b/c", UrlParse(InvalidPort)), + ("https://:8080/a/b/c", UrlParse(EmptyHost)), + ]; + if cfg!(target_os = "windows") { + let p = r"\\.\c:/stuff/deno/script.ts"; + tests.push((p, PathToUrl(PathToUrlError(PathBuf::from(p))))); + } + + for (specifier, expected_err) in tests { + let err = + resolve_url_or_path(specifier, &PathBuf::from("/")).unwrap_err(); + assert_eq!(err, expected_err); + } + } }