| 1 |
use jsonschemarust-analyzer cargo jsonschema 0.51.0 crate/::Validatorrust-analyzer cargo jsonschema 0.51.0 validator/Validator#; |
| 2 |
use pretty_assertionsrust-analyzer cargo pretty_assertions 1.4.1 crate/::assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!; |
| 3 |
use schemarsrust-analyzer cargo schemars 1.2.2 crate/::{ |
| 4 |
generaterust-analyzer cargo schemars 1.2.2 generate/::{Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#, SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#}, |
| 5 |
JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#, Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, |
| 6 |
}; |
| 7 |
use serderust-analyzer cargo serde 1.0.229 crate/::{derust-analyzer cargo serde_core 1.0.229 de/::DeserializeOwnedrust-analyzer cargo serde_core 1.0.229 de/DeserializeOwned#, Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#}; |
| 8 |
use serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::{jsonrust-analyzer cargo serde_json 1.0.151 macros/json!, Valuerust-analyzer cargo serde_json 1.0.151 value/Value#}; |
| 9 |
use snapboxrust-analyzer cargo snapbox 0.6.24 crate/::{datarust-analyzer cargo snapbox 0.6.24 data/::DataFormatrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#, IntoJsonrust-analyzer cargo snapbox 0.6.24 data/IntoJson#}; |
| 10 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{ |
| 11 |
anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/::type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name()., borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, cellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/::OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#, f64rust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/, markerrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/::PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, |
| 12 |
syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#, |
| 13 |
}; |
| 14 |
|
| 15 |
pub struct TestHelperrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#<T> { |
| 16 |
settingsrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#settings.: SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#, |
| 17 |
namerust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#name.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 18 |
phantomrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#<T>, |
| 19 |
de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema.: Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, |
| 20 |
ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema.: Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, |
| 21 |
de_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema_validator.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#<Validatorrust-analyzer cargo jsonschema 0.51.0 validator/Validator#>, |
| 22 |
ser_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema_validator.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#<Validatorrust-analyzer cargo jsonschema 0.51.0 validator/Validator#>, |
| 23 |
validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.: fn(&T) -> bool, |
| 24 |
} |
| 25 |
|
| 26 |
impl<T> TestHelperrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#<T> { |
| 27 |
/// Should be used via the `test!(SomeType)` macro |
| 28 |
pub fn newrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]new().(name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, settings: SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#) -> Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] |
| 29 |
where |
| 30 |
T: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#, |
| 31 |
{ |
| 32 |
let de_schema = schema_forrust-analyzer cargo schemars 1.2.2 test_helper/schema_for().::<T>(&settings, Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#); |
| 33 |
let ser_schema = schema_forrust-analyzer cargo schemars 1.2.2 test_helper/schema_for().::<T>(&settings, Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize#); |
| 34 |
Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 35 |
settingsrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#settings., |
| 36 |
namerust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#name., |
| 37 |
phantomrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 38 |
de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema., |
| 39 |
ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema., |
| 40 |
de_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema_validator.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 41 |
ser_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema_validator.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 42 |
validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.: |_| true, |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
/// Should be used via the `test!(value: SomeType)` macro |
| 47 |
pub fn new_for_valuerust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]new_for_value().(name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, settings: SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#, value: T) -> Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] |
| 48 |
where |
| 49 |
T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 50 |
{ |
| 51 |
let de_schema = schema_for_valuerust-analyzer cargo schemars 1.2.2 test_helper/schema_for_value().(&settings, Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#, &value); |
| 52 |
let ser_schema = schema_for_valuerust-analyzer cargo schemars 1.2.2 test_helper/schema_for_value().(&settings, Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize#, &value); |
| 53 |
Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 54 |
settingsrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#settings., |
| 55 |
namerust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#name., |
| 56 |
phantomrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#phantom.: PhantomDatarust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/PhantomData#, |
| 57 |
de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema., |
| 58 |
ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema., |
| 59 |
de_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema_validator.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 60 |
ser_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema_validator.: OnceCellrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/OnceCell#::newrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]new().(), |
| 61 |
validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.: |_| true, |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
pub fn with_validatorrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]with_validator().(&mut self, validator: fn(&T) -> bool) -> &mut Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 66 |
self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator. = validator; |
| 67 |
self |
| 68 |
} |
| 69 |
|
| 70 |
/// Checks the generated schema against the saved schema in the snapshots directory, for manual verification of changes. |
| 71 |
/// |
| 72 |
/// Run tests with the SNAPSHOTS env var set to "overwrite" to overwrite any changed snapshots. |
| 73 |
pub fn assert_snapshotrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_snapshot().(&self) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| •74 |
let stripped_name = self.namerust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#name..strip_prefixrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]strip_prefix().("schemars/").unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(&self.namerust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#name.); |
| 75 |
let common_path = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("tests/integration/snapshots/schemars/{}.json", stripped_name); |
| 76 |
let de_path = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("tests/integration/snapshots/schemars/{}.de.json", stripped_name); |
| 77 |
let ser_path = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("tests/integration/snapshots/schemars/{}.ser.json", stripped_name); |
| 78 |
|
| 79 |
if self.de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema. rust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][`PartialEq<Self>`]eq().==rust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][`PartialEq<Self>`]eq(). rust-analyzer cargo schemars 1.2.2 schema/impl#[Schema][`PartialEq<Self>`]eq().self.ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema. { |
| 80 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::assert_data_eqrust-analyzer cargo snapbox 0.6.24 macros/assert_data_eq!!( |
| 81 |
(&self.de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema.).into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().(), |
| 82 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::Datarust-analyzer cargo snapbox 0.6.24 data/Data#::read_fromrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]read_from().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&common_path), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DataFormatrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#::Jsonrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#Json#)).rawrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]raw().() |
| 83 |
); |
| 84 |
_ = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(de_path); |
| 85 |
_ = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(ser_path); |
| 86 |
} else { |
| 87 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::assert_data_eqrust-analyzer cargo snapbox 0.6.24 macros/assert_data_eq!!( |
| 88 |
(&self.de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema.).into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().(), |
| 89 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::Datarust-analyzer cargo snapbox 0.6.24 data/Data#::read_fromrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]read_from().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&de_path), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DataFormatrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#::Jsonrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#Json#)).rawrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]raw().() |
| 90 |
); |
| 91 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::assert_data_eqrust-analyzer cargo snapbox 0.6.24 macros/assert_data_eq!!( |
| 92 |
(&self.ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema.).into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().(), |
| 93 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::Datarust-analyzer cargo snapbox 0.6.24 data/Data#::read_fromrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]read_from().(Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(&ser_path), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(DataFormatrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#::Jsonrust-analyzer cargo snapbox 0.6.24 data/format/DataFormat#Json#)).rawrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]raw().() |
| 94 |
); |
| 95 |
_ = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::remove_filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/remove_file().(common_path); |
| 96 |
} |
| 97 |
|
| 98 |
self |
| 99 |
} |
| 100 |
|
| 101 |
/// Checks that the schema generated for this type is identical to that of another type. |
| 102 |
pub fn assert_identicalrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_identical().<T2: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(&self) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] |
| 103 |
where |
| 104 |
T: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#, |
| 105 |
{ |
| 106 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::assert_data_eqrust-analyzer cargo snapbox 0.6.24 macros/assert_data_eq!!( |
| 107 |
(&self.de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema.).into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().(), |
| 108 |
schema_forrust-analyzer cargo schemars 1.2.2 test_helper/schema_for().::<T2>(&self.settingsrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#settings., Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#) |
| 109 |
.into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().() |
| 110 |
.rawrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]raw().() |
| 111 |
); |
| 112 |
snapboxrust-analyzer cargo snapbox 0.6.24 crate/::assert_data_eqrust-analyzer cargo snapbox 0.6.24 macros/assert_data_eq!!( |
| 113 |
(&self.ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema.).into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().(), |
| 114 |
schema_forrust-analyzer cargo schemars 1.2.2 test_helper/schema_for().::<T2>(&self.settingsrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#settings., Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize#) |
| 115 |
.into_jsonrust-analyzer cargo snapbox 0.6.24 data/impl#[S][IntoJson]into_json().() |
| 116 |
.rawrust-analyzer cargo snapbox 0.6.24 data/impl#[Data]raw().() |
| 117 |
); |
| 118 |
|
| 119 |
let t = type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<T>(); |
| 120 |
let t2 = type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<T2>(); |
| 121 |
assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!( |
| 122 |
T::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().(), |
| 123 |
T2::schema_namerust-analyzer cargo schemars 1.2.2 JsonSchema#schema_name().(), |
| 124 |
"`{t}` and `{t2}` have identical schemas, so should have the same schema_name" |
| 125 |
); |
| 126 |
|
| 127 |
assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!( |
| 128 |
T::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().(), |
| 129 |
T2::schema_idrust-analyzer cargo schemars 1.2.2 JsonSchema#schema_id().(), |
| 130 |
"`{t}` and `{t2}` have identical schemas, so should have the same schema_id" |
| 131 |
); |
| 132 |
|
| 133 |
assert_eqrust-analyzer cargo pretty_assertions 1.4.1 assert_eq!!( |
| 134 |
T::inline_schemarust-analyzer cargo schemars 1.2.2 JsonSchema#inline_schema().(), |
| 135 |
T2::inline_schemarust-analyzer cargo schemars 1.2.2 JsonSchema#inline_schema().(), |
| 136 |
"`{t}` and `{t2}` have identical schemas, so should have the same inline_schema" |
| 137 |
); |
| 138 |
|
| 139 |
self |
| 140 |
} |
| 141 |
|
| 142 |
pub fn customrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]custom().(&self, assertion: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#, Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#)) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 143 |
assertion(&self.de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema., Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Deserializerust-analyzer cargo schemars 1.2.2 generate/Contract#Deserialize#); |
| 144 |
assertion(&self.ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema., Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#::Serializerust-analyzer cargo schemars 1.2.2 generate/Contract#Serialize#); |
| 145 |
|
| 146 |
self |
| 147 |
} |
| 148 |
|
| 149 |
fn de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(&self, instance: &Valuerust-analyzer cargo serde_json 1.0.151 value/Value#) -> bool { |
| 150 |
self.de_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema_validator. |
| 151 |
.get_or_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]get_or_init().(|| build_validatorrust-analyzer cargo schemars 1.2.2 test_helper/build_validator().(&self.de_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#de_schema.)) |
| 152 |
.is_validrust-analyzer cargo jsonschema 0.51.0 validator/impl#[`Validator<F>`]is_valid().(instance) |
| 153 |
} |
| 154 |
|
| 155 |
fn ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(&self, instance: &Valuerust-analyzer cargo serde_json 1.0.151 value/Value#) -> bool { |
| 156 |
self.ser_schema_validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema_validator. |
| 157 |
.get_or_initrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cell/once/impl#[`OnceCell<T>`]get_or_init().(|| build_validatorrust-analyzer cargo schemars 1.2.2 test_helper/build_validator().(&self.ser_schemarust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#ser_schema.)) |
| 158 |
.is_validrust-analyzer cargo jsonschema 0.51.0 validator/impl#[`Validator<F>`]is_valid().(instance) |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
fn build_validatorrust-analyzer cargo schemars 1.2.2 test_helper/build_validator().(schema: &Schemarust-analyzer cargo schemars 1.2.2 schema/Schema#) -> Validatorrust-analyzer cargo jsonschema 0.51.0 validator/Validator# { |
| 163 |
jsonschemarust-analyzer cargo jsonschema 0.51.0 crate/::optionsrust-analyzer cargo jsonschema 0.51.0 options().() |
| 164 |
.should_validate_formatsrust-analyzer cargo jsonschema 0.51.0 options/impl#[`ValidationOptions<'i, R, F>`]should_validate_formats().(true) |
| 165 |
.buildrust-analyzer cargo jsonschema 0.51.0 options/impl#[`ValidationOptions<'_, Arc<dyn Retrieve + 'static>, F>`]build().(schema.as_valuerust-analyzer cargo schemars 1.2.2 schema/impl#[Schema]as_value().()) |
| 166 |
.expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("valid schema") |
| 167 |
} |
| 168 |
|
| 169 |
impl<T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#> TestHelperrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#<T> { |
| 170 |
/// Checks that the "serialize" schema allows the given sample values when serialized to JSON. |
| 171 |
/// If `T implements `DeserializeOwned`, prefer using `assert_allows_ser_roundtrip()` |
| 172 |
pub fn assert_allows_ser_onlyrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_only().(&self, samples: 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# = T>) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 173 |
for sample in samples { |
| 174 |
let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(&sample).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 175 |
|
| 176 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 177 |
(self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.)(&sample), |
| 178 |
"invalid test case - attempt to serialize value failing validation: {json}" |
| 179 |
); |
| 180 |
|
| 181 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 182 |
self.ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(&json), |
| 183 |
"serialize schema should allow serialized value: {json}" |
| 184 |
); |
| 185 |
} |
| 186 |
|
| 187 |
self |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
impl<T: Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize# + DeserializeOwnedrust-analyzer cargo serde_core 1.0.229 de/DeserializeOwned#> TestHelperrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#<T> { |
| 192 |
/// Checks that the "serialize" schema allows the given sample values when serialized to JSON |
| 193 |
/// and, if the value can then be deserialized, that the "deserialize" schema also allows it. |
| 194 |
pub fn assert_allows_ser_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip().(&self, samples: 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# = T>) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 195 |
for sample in samples { |
| 196 |
let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(&sample).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 197 |
|
| 198 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 199 |
(self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.)(&sample), |
| 200 |
"invalid test case - attempt to serialize value failing validation: {json}" |
| 201 |
); |
| 202 |
|
| 203 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 204 |
self.ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(&json), |
| 205 |
"serialize schema should allow serialized value: {json}" |
| 206 |
); |
| 207 |
|
| 208 |
if T::deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#deserialize().(&json).is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().() { |
| 209 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 210 |
(self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.)(&sample), |
| 211 |
"invalid test case - roundtripped value fails validation: {json}" |
| 212 |
); |
| 213 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 214 |
self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(&json), |
| 215 |
"deserialize schema should allow value accepted by deserialization: {json}" |
| 216 |
); |
| 217 |
} else { |
| 218 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 219 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(&json), |
| 220 |
"deserialize schema should reject undeserializable value: {json}" |
| 221 |
); |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
self |
| 226 |
} |
| 227 |
|
| 228 |
/// Checks that the "deserialize" schema allow the given sample values, and the "serialize" |
| 229 |
/// schema allows the value obtained from deserializing then re-serializing the sample values |
| 230 |
/// (only for values that can successfully be serialized). |
| 231 |
/// |
| 232 |
/// This is intended for types that have different serialize/deserialize schemas, or when you |
| 233 |
/// want to test specific values that are valid for deserialization but not for serialization. |
| 234 |
pub fn assert_allows_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_de_roundtrip().( |
| 235 |
&self, |
| 236 |
samples: 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# = impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>>, |
| 237 |
) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 238 |
for sample in samples { |
| 239 |
let sample = sample.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(); |
| 240 |
let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(deserialized) = T::deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#deserialize().(sample) else { |
| 241 |
panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!( |
| 242 |
"expected deserialize to succeed for {}: {sample}", |
| 243 |
type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<T>() |
| 244 |
) |
| 245 |
}; |
| 246 |
|
| 247 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 248 |
(self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.)(&deserialized), |
| 249 |
"invalid test case - deserialized value fails validation: {sample}" |
| 250 |
); |
| 251 |
|
| 252 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 253 |
self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(sample), |
| 254 |
"deserialize schema should allow value accepted by deserialization: {sample}" |
| 255 |
); |
| 256 |
|
| 257 |
if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(serialized) = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(&deserialized) { |
| 258 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 259 |
self.ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(&serialized), |
| 260 |
"serialize schema should allow serialized value: {serialized}" |
| 261 |
); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
self |
| 266 |
} |
| 267 |
|
| 268 |
/// Checks that the "deserialize" schema allows only the given sample values that successfully |
| 269 |
/// deserialize and pass validation. |
| 270 |
/// |
| 271 |
/// This is intended to be given a range of values (see `arbitrary_values`), allowing limited |
| 272 |
/// fuzzing. |
| 273 |
pub fn assert_matches_de_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_matches_de_roundtrip().( |
| 274 |
&self, |
| 275 |
samples: 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# = impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>>, |
| 276 |
) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 277 |
for value in samples { |
| 278 |
let value = value.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(); |
| 279 |
|
| 280 |
match T::deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#deserialize().(value) { |
| 281 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(deserialized) if (self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.)(&deserialized) => { |
| 282 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 283 |
self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(value), |
| 284 |
"deserialize schema should allow value accepted by deserialization: {value}" |
| 285 |
); |
| 286 |
|
| 287 |
if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(serialized) = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(&deserialized) { |
| 288 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 289 |
self.ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(&serialized), |
| 290 |
"serialize schema should allow serialized value: {serialized}" |
| 291 |
); |
| 292 |
} |
| 293 |
} |
| 294 |
_ => { |
| 295 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 296 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(value), |
| 297 |
"deserialize schema should reject invalid value: {value}" |
| 298 |
); |
| 299 |
|
| 300 |
// This assertion isn't necessarily valid in the general case but it would be |
| 301 |
// odd (though not necessarily wrong) for it to fail. If this does ever fail |
| 302 |
// a case that should be legitimate, then this assert can be removed/weakened. |
| 303 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 304 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(value), |
| 305 |
"serialize schema should reject invalid value: {value}" |
| 306 |
); |
| 307 |
} |
| 308 |
} |
| 309 |
} |
| 310 |
|
| 311 |
self |
| 312 |
} |
| 313 |
|
| 314 |
/// Checks that the "deserialize" schema does not allow any of the given sample values. |
| 315 |
/// |
| 316 |
/// While `assert_matches_de_roundtrip()` would also work in this case, `assert_rejects_de()` |
| 317 |
/// has the advantage that it also verifies that the test case itself is actually covering the |
| 318 |
/// failure case as intended. |
| 319 |
pub fn assert_rejects_derust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_rejects_de().(&self, 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# = impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>>) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 320 |
for value in values { |
| 321 |
let value = value.borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#borrow().(); |
| 322 |
|
| 323 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 324 |
T::deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#deserialize().(value).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().(), |
| 325 |
"invalid test case - expected deserialize to fail for {}: {value}", |
| 326 |
type_namerust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/type_name().::<T>() |
| 327 |
); |
| 328 |
|
| 329 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 330 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(value), |
| 331 |
"deserialize schema should reject invalid value: {value}" |
| 332 |
); |
| 333 |
} |
| 334 |
|
| 335 |
self |
| 336 |
} |
| 337 |
|
| 338 |
/// Checks that neither "serialize" nor "deserialize" schemas allow any of the given sample |
| 339 |
/// values when serialized to JSON due to the values failing validation. |
| 340 |
pub fn assert_rejects_invalidrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_rejects_invalid().(&self, samples: 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# = T>) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] { |
| 341 |
for sample in samples { |
| 342 |
let json = serde_jsonrust-analyzer cargo serde_json 1.0.151 crate/::to_valuerust-analyzer cargo serde_json 1.0.151 value/to_value().(&sample).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 343 |
|
| 344 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 345 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(self.validatorrust-analyzer cargo schemars 1.2.2 test_helper/TestHelper#validator.)(&sample), |
| 346 |
"invalid test case - serialized value passes validation: {json}" |
| 347 |
); |
| 348 |
|
| 349 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 350 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.de_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]de_schema_validate().(&json), |
| 351 |
"deserialize schema should reject invalid value: {json}" |
| 352 |
); |
| 353 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!( |
| 354 |
!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.ser_schema_validaterust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]ser_schema_validate().(&json), |
| 355 |
"serialize schema should reject invalid value: {json}" |
| 356 |
); |
| 357 |
} |
| 358 |
|
| 359 |
self |
| 360 |
} |
| 361 |
|
| 362 |
/// Checks that both the "serialize" and "deserialize" schema allow the type's default value |
| 363 |
/// when serialized to JSON. |
| 364 |
pub fn assert_allows_ser_roundtrip_defaultrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip_default().(&self) -> &Selfrust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`] |
| 365 |
where |
| 366 |
T: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 367 |
{ |
| 368 |
self.assert_allows_ser_roundtriprust-analyzer cargo schemars 1.2.2 test_helper/impl#[`TestHelper<T>`]assert_allows_ser_roundtrip().([T::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().()]) |
| 369 |
} |
| 370 |
} |
| 371 |
|
| 372 |
fn schema_forrust-analyzer cargo schemars 1.2.2 test_helper/schema_for().<T: JsonSchemarust-analyzer cargo schemars 1.2.2 JsonSchema#>(base_settings: &SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#, contract: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# { |
| 373 |
base_settings |
| 374 |
.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Clone]clone().() |
| 375 |
.withrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]with().(|s| s.contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract. = contract) |
| 376 |
.into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().() |
| 377 |
.into_root_schema_forrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]into_root_schema_for().::<T>() |
| 378 |
} |
| 379 |
|
| 380 |
fn schema_for_valuerust-analyzer cargo schemars 1.2.2 test_helper/schema_for_value().( |
| 381 |
base_settings: &SchemaSettingsrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#, |
| 382 |
contract: Contractrust-analyzer cargo schemars 1.2.2 generate/Contract#, |
| 383 |
value: impl Serializerust-analyzer cargo serde_core 1.0.229 ser/Serialize#, |
| 384 |
) -> Schemarust-analyzer cargo schemars 1.2.2 schema/Schema# { |
| 385 |
base_settings |
| 386 |
.clonerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings][Clone]clone().() |
| 387 |
.withrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]with().(|s| s.contractrust-analyzer cargo schemars 1.2.2 generate/SchemaSettings#contract. = contract) |
| 388 |
.into_generatorrust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaSettings]into_generator().() |
| 389 |
.into_root_schema_for_valuerust-analyzer cargo schemars 1.2.2 generate/impl#[SchemaGenerator]into_root_schema_for_value().(&value) |
| 390 |
.unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 391 |
} |
| 392 |
|
| 393 |
/// Returns an iterator over an selection of arbitrary JSON values. |
| 394 |
/// |
| 395 |
/// This is intended to be used as `test!(...).assert_matches_de_roundtrip(arbitrary_values())` |
| 396 |
pub fn arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().() -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'static Valuerust-analyzer cargo serde_json 1.0.151 value/Value#> { |
| 397 |
fn primitivesrust-analyzer cargo schemars 1.2.2 test_helper/primitives().() -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Valuerust-analyzer cargo serde_json 1.0.151 value/Value#> { |
| 398 |
[ |
| 399 |
Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Nullrust-analyzer cargo serde_json 1.0.151 value/Value#Null#, |
| 400 |
false.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 401 |
true.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 402 |
0.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 403 |
255.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 404 |
(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().1).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 405 |
u64::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]MAX..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 406 |
f64rust-analyzer cargo std https://github.com/rust-lang/rust/library/std f64/::constsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/consts/::PIrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/consts/PI..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 407 |
"".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 408 |
"0".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 409 |
"3E8".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 410 |
"\tPâté costs “£1”\0".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(), |
| 411 |
Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Arrayrust-analyzer cargo serde_json 1.0.151 value/Value#Array#(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][Default]default().()), |
| 412 |
Valuerust-analyzer cargo serde_json 1.0.151 value/Value#::Objectrust-analyzer cargo serde_json 1.0.151 value/Value#Object#(Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#::defaultrust-analyzer cargo serde_json 1.0.151 map/impl#[`Map<String, Value>`][Default]default().()), |
| 413 |
] |
| 414 |
.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`[T; N]`][IntoIterator]into_iter().() |
| 415 |
} |
| 416 |
|
| 417 |
// TODO once MSRV has reached 1.80, replace this with LazyLock |
| 418 |
static VALUESrust-analyzer cargo schemars 1.2.2 test_helper/VALUES.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Valuerust-analyzer cargo serde_json 1.0.151 value/Value#>> = OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]new().(); |
| 419 |
|
| 420 |
VALUESrust-analyzer cargo schemars 1.2.2 test_helper/VALUES. |
| 421 |
.get_or_initrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]get_or_init().(|| { |
| 422 |
Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`][`FromIterator<T>`]from_iter().( |
| 423 |
primitivesrust-analyzer cargo schemars 1.2.2 test_helper/primitives().() |
| 424 |
.chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(primitivesrust-analyzer cargo schemars 1.2.2 test_helper/primitives().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|p| jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!([p]))) |
| 425 |
.chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(primitivesrust-analyzer cargo schemars 1.2.2 test_helper/primitives().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|p| jsonrust-analyzer cargo serde_json 1.0.151 macros/json!!({"key": p}))), |
| 426 |
) |
| 427 |
}) |
| 428 |
.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 429 |
} |
| 430 |
|
| 431 |
/// Returns an iterator over an selection of arbitrary JSON values, except for value that match |
| 432 |
/// the given filter predicate. |
| 433 |
/// |
| 434 |
/// This is to handle known cases of schemas not matching the actual deserialize behaviour. |
| 435 |
pub fn arbitrary_values_exceptrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values_except().( |
| 436 |
filter: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&Valuerust-analyzer cargo serde_json 1.0.151 value/Value#) -> bool, |
| 437 |
_reason: &str, |
| 438 |
) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = &'static Valuerust-analyzer cargo serde_json 1.0.151 value/Value#> { |
| 439 |
arbitrary_valuesrust-analyzer cargo schemars 1.2.2 test_helper/arbitrary_values().().filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(move |v| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().filter(v)) |
| 440 |
} |