| 1 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 2 | fn test_deserialize_seedrust-analyzer cargo ron 0.12.0 test_deserialize_seed().() { |
| 3 | // Test adapted from David Tolnay's serde-yaml: |
| 4 | // https://github.com/dtolnay/serde-yaml/blob/8a806e316302fd2e6541dccee6d166dd51b689d6/tests/test_de.rs#L357-L392 |
| 5 | |
| 6 | struct Seedrust-analyzer cargo ron 0.12.0 Seed#(i64); |
| 7 | |
| 8 | impl<'de> serderust-analyzer cargo serde 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::DeserializeSeedrust-analyzer cargo serde_core 1.0.228 de/DeserializeSeed#<'de> for Seedrust-analyzer cargo ron 0.12.0 Seed# { |
| 9 | type Valuerust-analyzer cargo ron 0.12.0 impl#[Seed][`DeserializeSeed<'de>`]Value# = i64; |
| 10 | |
| 11 | fn deserializerust-analyzer cargo ron 0.12.0 impl#[Seed][`DeserializeSeed<'de>`]deserialize().<D>(self, deserializer: D) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, D::Errorrust-analyzer cargo serde_core 1.0.228 de/Deserializer#Error#> |
| 12 | where |
| 13 | D: serderust-analyzer cargo serde 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::Deserializerrust-analyzer cargo serde_core 1.0.228 de/Deserializer#<'de>, |
| 14 | { |
| 15 | struct Visitorrust-analyzer cargo ron 0.12.0 Visitor#(i64); |
| 16 | |
| 17 | impl<'de> serderust-analyzer cargo serde 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::Visitorrust-analyzer cargo serde_core 1.0.228 de/Visitor#<'de> for Visitorrust-analyzer cargo ron 0.12.0 Visitor# { |
| 18 | type Valuerust-analyzer cargo ron 0.12.0 impl#[Visitor][`Visitor<'de>`]Value# = i64; |
| 19 | |
| 20 | fn expectingrust-analyzer cargo ron 0.12.0 impl#[Visitor][`Visitor<'de>`]expecting().(&self, formatter: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 21 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(formatter, "an integer") |
| 22 | } |
| 23 | |
| 24 | fn visit_i64rust-analyzer cargo ron 0.12.0 impl#[Visitor][`Visitor<'de>`]visit_i64().<E: serderust-analyzer cargo serde 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#>(self, v: i64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, E> { |
| 25 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().self.0rust-analyzer cargo ron 0.12.0 Visitor#0.) |
| 26 | } |
| 27 | |
| 28 | fn visit_u64rust-analyzer cargo ron 0.12.0 impl#[Visitor][`Visitor<'de>`]visit_u64().<E: serderust-analyzer cargo serde 1.0.228 crate/::derust-analyzer cargo serde_core 1.0.228 de/::Errorrust-analyzer cargo serde_core 1.0.228 de/Error#>(self, v: u64) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i64, E> { |
| 29 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(v as i64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().self.0rust-analyzer cargo ron 0.12.0 Visitor#0.) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | deserializer.deserialize_anyrust-analyzer cargo serde_core 1.0.228 de/Deserializer#deserialize_any().(Visitorrust-analyzer cargo ron 0.12.0 Visitor#(self.0rust-analyzer cargo ron 0.12.0 Seed#0.)) |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | let cases = [("3", 5, 15), ("6", 7, 42), ("-5", 9, -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().45)]; |
| 38 | |
| 39 | for &(ron, seed, expected) in &cases { |
| 40 | let deserialized = ronrust-analyzer cargo ron 0.12.0 crate/::Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().() |
| 41 | .from_str_seedrust-analyzer cargo ron 0.12.0 options/impl#[Options]from_str_seed().(ron, Seedrust-analyzer cargo ron 0.12.0 Seed#(seed)) |
| 42 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 43 | |
| 44 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(expected, deserialized); |
| 45 | } |
| 46 | |
| 47 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 48 | ronrust-analyzer cargo ron 0.12.0 crate/::Optionsrust-analyzer cargo ron 0.12.0 options/Options#::defaultrust-analyzer cargo ron 0.12.0 options/impl#[Options][Default]default().().from_str_seedrust-analyzer cargo ron 0.12.0 options/impl#[Options]from_str_seed().("'a'", Seedrust-analyzer cargo ron 0.12.0 Seed#(42)), |
| 49 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::SpannedErrorrust-analyzer cargo ron 0.12.0 error/SpannedError# { |
| 50 | coderust-analyzer cargo ron 0.12.0 error/SpannedError#code.: ronrust-analyzer cargo ron 0.12.0 crate/::Errorrust-analyzer cargo ron 0.12.0 error/Error#::InvalidValueForTyperust-analyzer cargo ron 0.12.0 error/Error#InvalidValueForType# { |
| 51 | expectedrust-analyzer cargo ron 0.12.0 error/Error#InvalidValueForType#expected.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("an integer"), |
| 52 | foundrust-analyzer cargo ron 0.12.0 error/Error#InvalidValueForType#found.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("the string \"a\""), |
| 53 | }, |
| 54 | spanrust-analyzer cargo ron 0.12.0 error/SpannedError#span.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Spanrust-analyzer cargo ron 0.12.0 error/Span# { |
| 55 | startrust-analyzer cargo ron 0.12.0 error/Span#start.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Positionrust-analyzer cargo ron 0.12.0 error/Position# { linerust-analyzer cargo ron 0.12.0 error/Position#line.: 1, colrust-analyzer cargo ron 0.12.0 error/Position#col.: 3 }, |
| 56 | endrust-analyzer cargo ron 0.12.0 error/Span#end.: ronrust-analyzer cargo ron 0.12.0 crate/::errorrust-analyzer cargo ron 0.12.0 error/::Positionrust-analyzer cargo ron 0.12.0 error/Position# { linerust-analyzer cargo ron 0.12.0 error/Position#line.: 1, colrust-analyzer cargo ron 0.12.0 error/Position#col.: 4 }, |
| 57 | } |
| 58 | }) |
| 59 | ); |
| 60 | } |