use ferrotype::Ferrotype;
fn main() {
let mut snapshot = Ferrotype::new();
snapshot.add("Description", "Testing user registration flow".to_string());
let user_input = UserInput {
username: "alice_smith".to_string(),
email: "alice@example.com".to_string(),
age: 28,
};
snapshot.add_debug("User Input", &user_input);
let result = process_registration(&user_input);
match &result {
| Ok(user) => {
snapshot.add_debug("Success", user);
snapshot.add("User ID", user.id.to_string());
},
| Err(e) => {
snapshot.add("Error", format!("Registration failed: {e}"));
},
}
let metadata = vec![
("timestamp", "2024-01-15T10:30:00Z"),
("version", "1.0.0"),
("environment", "test"),
];
snapshot.add_debug("Metadata", &metadata);
println!("=== Snapshot Preview ===");
snapshot.print();
println!("========================");
ferrotype::assert!(snapshot);
}
#[derive(Debug)]
struct UserInput {
username: String,
email: String,
age: u32,
}
#[derive(Debug)]
#[allow(unused)]
struct User {
id: u64,
username: String,
email: String,
age: u32,
created_at: String,
}
fn process_registration(input: &UserInput) -> Result<User, String> {
if input.username.len() < 3 {
return Err("Username too short".to_string());
}
if !input.email.contains('@') {
return Err("Invalid email format".to_string());
}
Ok(User {
id: 12345,
username: input.username.clone(),
email: input.email.clone(),
age: input.age,
created_at: "2024-01-15T10:30:00Z".to_string(),
})
}