property_snapshot_test/
property_snapshot_test.rs

1//! Property Snapshot Test Function Example
2//!
3//! This example demonstrates using the `property_snapshot_test` helper function
4//! for concise property-based snapshot testing.
5//!
6//! Run with: cargo run --example property_snapshot_test --features protest/derive
7
8use protest::primitives::IntGenerator;
9use protest_insta::property_snapshot_test;
10use serde::Serialize;
11
12#[derive(Serialize, Debug)]
13struct MathOperation {
14    input: i32,
15    squared: i32,
16    cubed: i64,
17    doubled: i32,
18    is_positive: bool,
19}
20
21fn perform_operations(n: i32) -> MathOperation {
22    MathOperation {
23        input: n,
24        squared: n * n,
25        cubed: (n as i64) * (n as i64) * (n as i64),
26        doubled: n * 2,
27        is_positive: n > 0,
28    }
29}
30
31fn main() {
32    println!("=== Property Snapshot Test Function Example ===\n");
33    println!("Testing mathematical operations with property-based inputs...\n");
34
35    // Use the helper function for concise testing
36    property_snapshot_test(
37        "math_operations",
38        IntGenerator::new(-10, 10),
39        10,  // Generate 10 test cases
40        456, // Seed for reproducibility
41        |value, snapshots| {
42            let result = perform_operations(value);
43            println!("Operation on {}: {:?}", value, result);
44            snapshots.assert_json_snapshot(&result);
45        },
46    );
47
48    println!("\n✅ Created 10 snapshots in snapshots/ directory");
49    println!("   Review them with: cargo insta review");
50    println!("\nNote: This example uses the property_snapshot_test helper");
51    println!("      which combines generator setup with snapshot management.");
52}