|
| 1 | +use facet::Facet; |
| 2 | +use safe_debug::SafeDebug; |
| 3 | + |
| 4 | +// --- Type definitions for snapshot tests --- |
| 5 | + |
| 6 | +#[derive(Facet, SafeDebug)] |
| 7 | +struct PatientRecord { |
| 8 | + id: String, |
| 9 | + name: String, |
| 10 | + #[facet(sensitive)] |
| 11 | + ssn: String, |
| 12 | + #[facet(sensitive)] |
| 13 | + medical_history: String, |
| 14 | +} |
| 15 | + |
| 16 | +#[derive(Facet, SafeDebug)] |
| 17 | +struct TupleRecord(String, #[facet(sensitive)] String, i32); |
| 18 | + |
| 19 | +#[derive(Facet, SafeDebug)] |
| 20 | +#[repr(C)] |
| 21 | +enum ApiResponse { |
| 22 | + Success { |
| 23 | + code: u16, |
| 24 | + data: String, |
| 25 | + }, |
| 26 | + Error { |
| 27 | + code: u16, |
| 28 | + #[facet(sensitive)] |
| 29 | + details: String, |
| 30 | + }, |
| 31 | + Pending, |
| 32 | + Token(#[facet(sensitive)] String), |
| 33 | +} |
| 34 | + |
| 35 | +#[derive(Facet, SafeDebug)] |
| 36 | +struct Inner { |
| 37 | + public_data: String, |
| 38 | + #[facet(sensitive)] |
| 39 | + secret_data: String, |
| 40 | +} |
| 41 | + |
| 42 | +#[derive(Facet, SafeDebug)] |
| 43 | +struct Outer { |
| 44 | + id: u32, |
| 45 | + inner: Inner, |
| 46 | +} |
| 47 | + |
| 48 | +// --- Snapshot tests --- |
| 49 | + |
| 50 | +#[test] |
| 51 | +fn snapshot_named_struct() { |
| 52 | + let record = PatientRecord { |
| 53 | + id: "P-12345".to_string(), |
| 54 | + name: "Jane Doe".to_string(), |
| 55 | + ssn: "123-45-6789".to_string(), |
| 56 | + medical_history: "Chronic condition notes".to_string(), |
| 57 | + }; |
| 58 | + insta::assert_snapshot!(format!("{:?}", record)); |
| 59 | +} |
| 60 | + |
| 61 | +#[test] |
| 62 | +fn snapshot_named_struct_pretty() { |
| 63 | + let record = PatientRecord { |
| 64 | + id: "P-12345".to_string(), |
| 65 | + name: "Jane Doe".to_string(), |
| 66 | + ssn: "123-45-6789".to_string(), |
| 67 | + medical_history: "Chronic condition notes".to_string(), |
| 68 | + }; |
| 69 | + insta::assert_snapshot!(format!("{:#?}", record)); |
| 70 | +} |
| 71 | + |
| 72 | +#[test] |
| 73 | +fn snapshot_tuple_struct() { |
| 74 | + let record = TupleRecord("visible".to_string(), "secret-token".to_string(), 42); |
| 75 | + insta::assert_snapshot!(format!("{:?}", record)); |
| 76 | +} |
| 77 | + |
| 78 | +#[test] |
| 79 | +fn snapshot_enum_struct_variant() { |
| 80 | + let success = ApiResponse::Success { |
| 81 | + code: 200, |
| 82 | + data: "OK".to_string(), |
| 83 | + }; |
| 84 | + insta::assert_snapshot!("enum_success", format!("{:?}", success)); |
| 85 | + |
| 86 | + let error = ApiResponse::Error { |
| 87 | + code: 500, |
| 88 | + details: "password leaked in stack trace".to_string(), |
| 89 | + }; |
| 90 | + insta::assert_snapshot!("enum_error_redacted", format!("{:?}", error)); |
| 91 | +} |
| 92 | + |
| 93 | +#[test] |
| 94 | +fn snapshot_enum_unit_and_tuple_variants() { |
| 95 | + let pending = ApiResponse::Pending; |
| 96 | + insta::assert_snapshot!("enum_pending", format!("{:?}", pending)); |
| 97 | + |
| 98 | + let token = ApiResponse::Token("secret-bearer-token".to_string()); |
| 99 | + insta::assert_snapshot!("enum_token_redacted", format!("{:?}", token)); |
| 100 | +} |
| 101 | + |
| 102 | +#[test] |
| 103 | +fn snapshot_nested_struct() { |
| 104 | + let data = Outer { |
| 105 | + id: 999, |
| 106 | + inner: Inner { |
| 107 | + public_data: "visible-info".to_string(), |
| 108 | + secret_data: "classified-payload".to_string(), |
| 109 | + }, |
| 110 | + }; |
| 111 | + insta::assert_snapshot!(format!("{:?}", data)); |
| 112 | +} |
| 113 | + |
| 114 | +#[test] |
| 115 | +fn snapshot_nested_struct_pretty() { |
| 116 | + let data = Outer { |
| 117 | + id: 999, |
| 118 | + inner: Inner { |
| 119 | + public_data: "visible-info".to_string(), |
| 120 | + secret_data: "classified-payload".to_string(), |
| 121 | + }, |
| 122 | + }; |
| 123 | + insta::assert_snapshot!(format!("{:#?}", data)); |
| 124 | +} |
0 commit comments