Additional AssetPath unit tests. (#10279)

# Objective

Additional unit test for AssetPath.
This commit is contained in:
Talin 2023-10-26 20:29:25 -07:00 committed by GitHub
parent 65b3ff1c63
commit cfcc113fb7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -717,6 +717,36 @@ mod tests {
assert_eq!(result, Err(crate::ParseAssetPathError::InvalidSourceSyntax));
}
#[test]
fn test_parent() {
// Parent consumes path segments, returns None when insufficient
let result = AssetPath::from("a/b.test");
assert_eq!(result.parent(), Some(AssetPath::from("a")));
assert_eq!(result.parent().unwrap().parent(), Some(AssetPath::from("")));
assert_eq!(result.parent().unwrap().parent().unwrap().parent(), None);
// Parent cannot consume asset source
let result = AssetPath::from("http://a");
assert_eq!(result.parent(), Some(AssetPath::from("http://")));
assert_eq!(result.parent().unwrap().parent(), None);
// Parent consumes labels
let result = AssetPath::from("http://a#Foo");
assert_eq!(result.parent(), Some(AssetPath::from("http://")));
}
#[test]
fn test_with_source() {
let result = AssetPath::from("http://a#Foo");
assert_eq!(result.with_source("ftp"), AssetPath::from("ftp://a#Foo"));
}
#[test]
fn test_without_label() {
let result = AssetPath::from("http://a#Foo");
assert_eq!(result.without_label(), AssetPath::from("http://a"));
}
#[test]
fn test_resolve_full() {
// A "full" path should ignore the base path.
@ -966,4 +996,13 @@ mod tests {
AssetPath::from("../joe/next")
);
}
#[test]
fn test_get_extension() {
let result = AssetPath::from("http://a.tar.gz#Foo");
assert_eq!(result.get_full_extension(), Some("tar.gz".to_string()));
let result = AssetPath::from("http://a#Foo");
assert_eq!(result.get_full_extension(), None);
}
}