Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add another url_or_path test from deno_core #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading