ferrotype 0.1.3

An opinionated wrapper for insta.rs
Documentation
//! Basic usage of ferrotype for snapshot testing
//!
//! This example demonstrates the core functionality of ferrotype:
//! - Creating a snapshot
//! - Adding multiple sections
//! - Using different content types
//! - Asserting the snapshot

use ferrotype::Ferrotype;

fn main() {
  // Create a new snapshot
  let mut snapshot = Ferrotype::new();

  // Add a simple string section
  snapshot.add("Description", "Testing user registration flow".to_string());

  // Simulate some test data
  let user_input = UserInput {
    username: "alice_smith".to_string(),
    email: "alice@example.com".to_string(),
    age: 28,
  };

  // Add the input as a debug section
  snapshot.add_debug("User Input", &user_input);

  // Simulate processing the input
  let result = process_registration(&user_input);

  // Add the result
  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}"));
    },
  }

  // Add some metadata
  let metadata = vec![
    ("timestamp", "2024-01-15T10:30:00Z"),
    ("version", "1.0.0"),
    ("environment", "test"),
  ];
  snapshot.add_debug("Metadata", &metadata);

  // Print the snapshot to see what it looks like
  println!("=== Snapshot Preview ===");
  snapshot.print();
  println!("========================");

  // In a real test, you would use:
  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> {
  // Simulate validation
  if input.username.len() < 3 {
    return Err("Username too short".to_string());
  }

  if !input.email.contains('@') {
    return Err("Invalid email format".to_string());
  }

  // Simulate successful registration
  Ok(User {
    id: 12345,
    username: input.username.clone(),
    email: input.email.clone(),
    age: input.age,
    created_at: "2024-01-15T10:30:00Z".to_string(),
  })
}