Skip to content

Commit fae89f5

Browse files
committed
fix(snap): For placeholder files, using type for ext
1 parent 7a986bd commit fae89f5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

crates/snapbox/src/data.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ macro_rules! file {
2222
}};
2323
[_ : $type:ident] => {{
2424
let stem = ::std::path::Path::new(::std::file!()).file_stem().unwrap();
25-
let rel_path = ::std::format!("snapshots/{}-{}.txt", stem.to_str().unwrap(), line!());
25+
let ext = $type.ext();
26+
let rel_path = ::std::format!("snapshots/{}-{}.{ext}", stem.to_str().unwrap(), line!());
2627
let mut path = $crate::current_dir!();
2728
path.push(rel_path);
2829
$crate::Data::read_from(&path, Some($crate::DataFormat:: $type))
@@ -356,6 +357,18 @@ pub enum DataFormat {
356357
Json,
357358
}
358359

360+
impl DataFormat {
361+
pub fn ext(self) -> &'static str {
362+
match self {
363+
Self::Error => "txt",
364+
Self::Binary => "bin",
365+
Self::Text => "txt",
366+
#[cfg(feature = "json")]
367+
Self::Json => "json",
368+
}
369+
}
370+
}
371+
359372
#[derive(Clone, Debug, PartialEq, Eq)]
360373
pub struct DataSource {
361374
inner: DataSourceInner,

0 commit comments

Comments
 (0)