Debian Codegraph @

tests/integration/validator.rs

raw symbols SCIP
1 use craterust-analyzer cargo schemars 1.2.2 crate/::preluderust-analyzer cargo schemars 1.2.2 prelude/::*;
2 use regexrust-analyzer cargo regex 1.13.1 crate/::Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#;
3 use validatorrust-analyzer cargo validator 0.20.0 crate/::Validaterust-analyzer cargo validator 0.20.0 traits/Validate#;
4
5 const ONErust-analyzer cargo schemars 1.2.2 validator/ONE.: f32 = 1.0;
6 const HUNDREDrust-analyzer cargo schemars 1.2.2 validator/HUNDRED.: f32 = 10.0;
7
8 // In real code, this would use something like a LazyLock
9 fn hello_regexrust-analyzer cargo schemars 1.2.2 validator/hello_regex().() -> Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex# {
10 Regexrust-analyzer cargo regex 1.13.1 regex/string/Regex#::newrust-analyzer cargo regex 1.13.1 regex/string/impl#[Regex]new().(r"^[Hh]ello").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
11 }
12
13 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Validaterust-analyzer cargo validator_derive 0.20.1 Validate:)]
14 pub struct ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct# {
15 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(range(min = 1.0, max = 100.0))]
16 min_maxrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max.: f32,
17 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(range(min = ONErust-analyzer cargo schemars 1.2.2 validator/ONE., max = HUNDREDrust-analyzer cargo schemars 1.2.2 validator/HUNDRED.))]
18 min_max2rust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max2.: f32,
19 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(regex(path = hello_regexrust-analyzer cargo schemars 1.2.2 validator/hello_regex().()))]
20 regex_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#regex_str.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
21 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(contains(pattern = "substring..."))]
22 contains_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#contains_str.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
23 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(email)]
24 email_addressrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#email_address.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
25 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(url)]
26 homepagerust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#homepage.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
27 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(length(min = 1, max = 100))]
28 non_empty_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#non_empty_str.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
29 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(length(equal = 2))]
30 pairrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#pair.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
31 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(required)]
32 required_optionrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_option.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>,
33 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(required, nested)]
34 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(flatten)]
35 required_flattenedrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_flattened.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ValidateAttrInnerrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner#>,
36 }
37
38 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:, Deserializerust-analyzer cargo serde_derive 1.0.229 Deserialize:, Serializerust-analyzer cargo serde_derive 1.0.229 Serialize:, Validaterust-analyzer cargo validator_derive 0.20.1 Validate:)]
39 pub struct ValidateAttrInnerrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner# {
40 #[validaterust-analyzer cargo schemars_derive 1.2.2 validate:(range(min = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().100, max = 100))]
41 xrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner#x.: i32,
42 }
43
44 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct# {
45 fn defaultrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct][Default]default().() -> Selfrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct][Default] {
46 Selfrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct][Default] {
47 min_maxrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max.: 1.0,
48 min_max2rust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max2.: 1.0,
49 regex_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#regex_str.: "Hello world".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
50 contains_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#contains_str.: "Contains substring...".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
51 email_addressrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#email_address.: "[email protected]".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
52 homepagerust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#homepage.: "http://test.test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
53 non_empty_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#non_empty_str.: "test".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
54 pairrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#pair.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "b".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()],
55 required_optionrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_option.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(true),
56 required_flattenedrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_flattened.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ValidateAttrInnerrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner# { xrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner#x.: 0 }),
57 }
58 }
59 }
60
61 impl ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct# {
62 pub fn invalid_valuesrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct]invalid_values().() -> impl IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = Selfrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct]> {
63 static MUTATORSrust-analyzer cargo schemars 1.2.2 validator/MUTATORS.: &[fn(&mut ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#)] = &[
64 |v| v.min_maxrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max. = 0.9,
65 |v| v.min_maxrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max. = 100.1,
66 |v| v.min_max2rust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max2. = 0.9,
67 |v| v.min_max2rust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#min_max2. = 100.1,
68 |v| v.regex_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#regex_str. = "fail".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
69 |v| v.contains_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#contains_str. = "fail".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
70 |v| v.email_addressrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#email_address. = "fail".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
71 |v| v.homepagerust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#homepage. = "fail".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(),
72 |v| v.non_empty_strrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#non_empty_str. = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(),
73 |v| v.pairrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#pair. = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(),
74 |v| v.pairrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#pair. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["a".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "b".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().(), "c".to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str][ToOwned]to_owned().()],
75 |v| v.required_optionrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_option. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
76 |v| v.required_flattenedrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_flattened. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
77 |v| v.required_flattenedrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_flattened. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ValidateAttrInnerrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner# { xrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner#x.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().101 }),
78 |v| v.required_flattenedrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#required_flattened. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ValidateAttrInnerrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner# { xrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrInner#x.: 101 }),
79 ];
80 MUTATORSrust-analyzer cargo schemars 1.2.2 validator/MUTATORS..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|f| {
81 let mut result = ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#::defaultrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct][Default]default().();
82 f(&mut result);
83 result
84 })
85 }
86 }
87
88 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
89 fn validate_attrsrust-analyzer cargo schemars 1.2.2 validator/validate_attrs().() {
90 testrust-analyzer cargo schemars 1.2.2 test!!(ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#)
91 .with_validatorrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]with_validator().(|v| v.validaterust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct][Validate]validate().().is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().())
92 .assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().()
93 .assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().()
94 .assert_rejects_invalidrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_rejects_invalid().(ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#::invalid_valuesrust-analyzer cargo schemars 1.2.2 validator/impl#[ValidateAttrStruct]invalid_values().())
95 .assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().(arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().());
96 }
97
98 #[allow(dead_code)]
99 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)]
100 #[schemars(rename = "ValidateAttrStruct")]
101 pub struct SchemarsAttrStructrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct# {
102 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(range(min = 1.0, max = 100.0))]
103 min_maxrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#min_max.: f32,
104 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(range(min = ONErust-analyzer cargo schemars 1.2.2 validator/ONE., max = HUNDREDrust-analyzer cargo schemars 1.2.2 validator/HUNDRED.))]
105 min_max2rust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#min_max2.: f32,
106 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(regex(pattern = hello_regexrust-analyzer cargo schemars 1.2.2 validator/hello_regex().()))]
107 regex_strrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#regex_str.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
108 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(contains(pattern = "substring..."))]
109 contains_strrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#contains_str.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
110 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(email)]
111 email_addressrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#email_address.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
112 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(url)]
113 homepagerust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#homepage.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
114 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(length(min = 1, max = 100))]
115 non_empty_strrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#non_empty_str.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
116 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(length(equal = 2))]
117 pairrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#pair.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
118 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(required)]
119 required_optionrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#required_option.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>,
120 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(required)]
121 #[serderust-analyzer cargo schemars_derive 1.2.2 serde:(flatten)]
122 required_flattenedrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#required_flattened.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<SchemarsAttrInnerrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrInner#>,
123 }
124
125 #[allow(dead_code)]
126 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(JsonSchemarust-analyzer cargo schemars_derive 1.2.2 JsonSchema:)]
127 pub struct SchemarsAttrInnerrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrInner# {
128 #[schemarsrust-analyzer cargo schemars_derive 1.2.2 schemars:(range(min = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().100, max = 100))]
129 xrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrInner#x.: i32,
130 }
131
132 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
133 fn schemars_attrsrust-analyzer cargo schemars 1.2.2 validator/schemars_attrs().() {
134 testrust-analyzer cargo schemars 1.2.2 test!!(SchemarsAttrStructrust-analyzer cargo schemars 1.2.2 validator/SchemarsAttrStruct#).assert_identicalrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_identical().::<ValidateAttrStructrust-analyzer cargo schemars 1.2.2 validator/ValidateAttrStruct#>();
135 }