mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-22 13:45:16 +00:00
Port SnapshotDir tests to use insta snapshots
This commit is contained in:
@@ -25,12 +25,12 @@
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
//! **The methods in this module can only handle relative paths, since absolute
|
||||
//! paths are never portable.**
|
||||
//! For absolute paths, which are only safe to serialize if they're artificial,
|
||||
//! use `serialize_absolute`.
|
||||
|
||||
use std::path::{Component, Path};
|
||||
|
||||
use serde::Serializer;
|
||||
use serde::{ser::SerializeSeq, Serialize, Serializer};
|
||||
|
||||
pub fn serialize_option<S, T>(maybe_path: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
@@ -72,3 +72,35 @@ where
|
||||
|
||||
serializer.serialize_str(&output)
|
||||
}
|
||||
|
||||
pub fn serialize_absolute<S, T>(path: T, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let as_str = path
|
||||
.as_ref()
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
.expect("Invalid Unicode in file path, cannot serialize");
|
||||
let replaced = as_str.replace("\\", "/");
|
||||
|
||||
serializer.serialize_str(&replaced)
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct WithAbsolute<'a>(#[serde(serialize_with = "serialize_absolute")] &'a Path);
|
||||
|
||||
pub fn serialize_vec_absolute<S, T>(paths: &Vec<T>, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
T: AsRef<Path>,
|
||||
{
|
||||
let mut seq = serializer.serialize_seq(Some(paths.len()))?;
|
||||
|
||||
for path in paths {
|
||||
seq.serialize_element(&WithAbsolute(path.as_ref()))?;
|
||||
}
|
||||
|
||||
seq.end()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user