From fc4a1aef0a37587c16636bf7806a6c1f47969100 Mon Sep 17 00:00:00 2001 From: Talin Date: Thu, 26 Oct 2023 20:29:25 -0700 Subject: [PATCH] Additional AssetPath unit tests. (#10279) # Objective Additional unit test for AssetPath. --- crates/bevy_asset/src/path.rs | 39 +++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/crates/bevy_asset/src/path.rs b/crates/bevy_asset/src/path.rs index 9374aefba6295..fccc0783f6249 100644 --- a/crates/bevy_asset/src/path.rs +++ b/crates/bevy_asset/src/path.rs @@ -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); + } }