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