1#![forbid(unsafe_code)]
2#![doc = include_str!("../README.md")]
3
4macro_rules! snapshot_string_type {
5 ($type_name:ident) => {
6 #[derive(Clone, Debug, Eq, Hash, PartialEq)]
7 pub struct $type_name(pub String);
8
9 impl $type_name {
10 pub fn new(value: impl Into<String>) -> Self {
11 Self(value.into())
12 }
13
14 pub fn as_str(&self) -> &str {
15 &self.0
16 }
17
18 pub fn into_string(self) -> String {
19 self.0
20 }
21 }
22 };
23}
24
25snapshot_string_type!(TestSnapshotId);
26snapshot_string_type!(TestSnapshotName);
27snapshot_string_type!(TestSnapshotVersion);
28
29#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
31pub enum TestSnapshotStatus {
32 #[default]
33 Missing,
34 Created,
35 Matched,
36 Changed,
37 Accepted,
38 Rejected,
39}
40
41#[cfg(test)]
42mod tests {
43 use super::{TestSnapshotId, TestSnapshotName, TestSnapshotStatus, TestSnapshotVersion};
44
45 #[test]
46 fn stores_snapshot_identity_wrappers() {
47 let id = TestSnapshotId::new("home-v1");
48 let name = TestSnapshotName::new("home");
49 let version = TestSnapshotVersion::new("v1");
50
51 assert_eq!(id.as_str(), "home-v1");
52 assert_eq!(name.as_str(), "home");
53 assert_eq!(version.as_str(), "v1");
54 assert_eq!(version.into_string(), "v1".to_string());
55 }
56
57 #[test]
58 fn missing_is_default_status() {
59 assert_eq!(TestSnapshotStatus::default(), TestSnapshotStatus::Missing);
60 }
61}