Skip to content

Commit

Permalink
fix(snap): For placeholder files, using type for ext
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 14, 2024
1 parent 7a986bd commit fae89f5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion crates/snapbox/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ macro_rules! file {
}};
[_ : $type:ident] => {{
let stem = ::std::path::Path::new(::std::file!()).file_stem().unwrap();
let rel_path = ::std::format!("snapshots/{}-{}.txt", stem.to_str().unwrap(), line!());
let ext = $type.ext();
let rel_path = ::std::format!("snapshots/{}-{}.{ext}", stem.to_str().unwrap(), line!());
let mut path = $crate::current_dir!();
path.push(rel_path);
$crate::Data::read_from(&path, Some($crate::DataFormat:: $type))
Expand Down Expand Up @@ -356,6 +357,18 @@ pub enum DataFormat {
Json,
}

impl DataFormat {
pub fn ext(self) -> &'static str {
match self {
Self::Error => "txt",
Self::Binary => "bin",
Self::Text => "txt",
#[cfg(feature = "json")]
Self::Json => "json",
}
}
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DataSource {
inner: DataSourceInner,
Expand Down

0 comments on commit fae89f5

Please sign in to comment.