use object_store::path::Path;
pub fn object_path_from_literal(path: &str) -> Path {
Path::parse(path).unwrap_or_else(|_| Path::from(path))
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
#[case::tilde("dir/a~b.vortex")]
#[case::double_tilde("dir/~~all~0.vortex")]
#[case::percent_literal("dir/a%20b.vortex")]
#[case::brackets("dir/a[1].vortex")]
#[case::hash("dir/a#b.vortex")]
#[case::braces("dir/a{x}.vortex")]
#[case::caret("dir/a^b.vortex")]
#[case::pipe("dir/a|b.vortex")]
#[case::star("dir/a*b.vortex")]
#[case::question("dir/a?b.vortex")]
#[case::backslash("dir/a\\b.vortex")]
#[case::angles("dir/a<b>.vortex")]
#[case::backtick("dir/a`b.vortex")]
#[case::quote("dir/a\"b.vortex")]
#[case::space("dir/a b.vortex")]
#[case::unicode("dir/é~ü.vortex")]
#[case::plain("dir/plain.vortex")]
fn test_literal_round_trip(#[case] key: &str) {
assert_eq!(object_path_from_literal(key).as_ref(), key);
}
#[rstest]
#[case::dot("a/./b", "a/%2E/b")]
#[case::dotdot("a/../b", "a/%2E%2E/b")]
#[case::empty_segment("a//b", "a/b")]
fn test_normalizing_fallback(#[case] key: &str, #[case] expected: &str) {
assert_eq!(object_path_from_literal(key).as_ref(), expected);
}
#[test]
fn test_leading_slash_stripped() {
assert_eq!(
object_path_from_literal("/a~b.vortex").as_ref(),
"a~b.vortex"
);
}
}