Skip to content

Commit

Permalink
chore: add another url_or_path test from deno_core
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jan 22, 2025
1 parent 603f84f commit 07d4b7f
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn normalize_path<P: AsRef<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);
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 07d4b7f

Please sign in to comment.