Debian Codegraph @

tests/integration/transparent.rs

raw symbols SCIP
1 use crate::prelude::*;
2
3 #[derive(JsonSchema, Deserialize, Serialize, Default)]
4 #[serde(transparent)]
5 pub struct TransparentStruct {
6 inner: String,
7 }
8
9 #[test]
10 fn transparent_struct() {
11 test!(TransparentStruct)
12 .assert_identical::<String>()
13 .assert_allows_ser_roundtrip_default()
14 .assert_matches_de_roundtrip(arbitrary_values());
15 }
16
17 #[derive(JsonSchema, Deserialize, Serialize, Default)]
18 #[serde(transparent)]
19 /// A doc comment
20 pub struct TransparentStructWithDoc {
21 /// Another doc comment (ignored)
22 inner: String,
23 }
24
25 #[test]
26 fn transparent_struct_with_doc() {
27 test!(TransparentStructWithDoc)
28 .assert_snapshot()
29 .assert_allows_ser_roundtrip_default()
30 .assert_matches_de_roundtrip(arbitrary_values());
31 }
32
33 #[derive(JsonSchema, Deserialize, Serialize, Default)]
34 #[serde(transparent)]
35 pub struct TransparentNewType(String);
36
37 #[test]
38 fn transparent_newtype() {
39 test!(TransparentNewType)
40 .assert_identical::<String>()
41 .assert_allows_ser_roundtrip_default()
42 .assert_matches_de_roundtrip(arbitrary_values());
43 }
44
45 #[derive(JsonSchema, Deserialize, Serialize)]
46 #[serde(transparent)]
47 pub struct TransparentNewTypeWithValidation(#[schemars(length(min = 1))] String);
48
49 #[test]
50 fn transparent_newtype_with_validation() {
51 test!(TransparentNewTypeWithValidation)
52 .with_validator(|v| !v.0.is_empty())
53 .assert_snapshot()
54 .assert_allows_ser_roundtrip([TransparentNewTypeWithValidation("[email protected]".into())])
55 .assert_matches_de_roundtrip(arbitrary_values());
56 }