Skip to content

Commit a31e3ec

Browse files
authored
chore: add another url_or_path test from deno_core (#8)
1 parent e9057c0 commit a31e3ec

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/lib.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub fn normalize_path<P: AsRef<Path>>(path: P) -> PathBuf {
175175
inner(path.as_ref())
176176
}
177177

178-
#[derive(Debug, Clone, Error, deno_error::JsError)]
178+
#[derive(Debug, Clone, Error, deno_error::JsError, PartialEq, Eq)]
179179
#[class(uri)]
180180
#[error("Could not convert path to URL.\n Path: {0}")]
181181
pub struct PathToUrlError(pub PathBuf);
@@ -342,7 +342,7 @@ pub fn specifier_has_uri_scheme(specifier: &str) -> bool {
342342
}
343343
}
344344

345-
#[derive(Debug, Clone, Error, JsError)]
345+
#[derive(Debug, Clone, Error, JsError, PartialEq, Eq)]
346346
pub enum ResolveUrlOrPathError {
347347
#[error(transparent)]
348348
#[class(inherit)]
@@ -742,6 +742,27 @@ mod tests {
742742
}
743743
}
744744

745+
#[test]
746+
fn test_resolve_url_or_path_deprecated_error() {
747+
use url::ParseError::*;
748+
use ResolveUrlOrPathError::*;
749+
750+
let mut tests = vec![
751+
("https://eggplant:b/c", UrlParse(InvalidPort)),
752+
("https://:8080/a/b/c", UrlParse(EmptyHost)),
753+
];
754+
if cfg!(target_os = "windows") {
755+
let p = r"\\.\c:/stuff/deno/script.ts";
756+
tests.push((p, PathToUrl(PathToUrlError(PathBuf::from(p)))));
757+
}
758+
759+
for (specifier, expected_err) in tests {
760+
let err =
761+
resolve_url_or_path(specifier, &PathBuf::from("/")).unwrap_err();
762+
assert_eq!(err, expected_err);
763+
}
764+
}
765+
745766
#[test]
746767
fn test_is_relative_specifier() {
747768
assert!(is_relative_specifier("."));

0 commit comments

Comments
 (0)