| 1 | #![cfg(feature = "serde")] |
| 2 | |
| 3 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::TryFromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryFrom#; |
| 4 | use js_intrust-analyzer cargo js_int 0.2.2 crate/::{intrust-analyzer cargo js_int 0.2.2 int/, Intrust-analyzer cargo js_int 0.2.2 int/Int#}; |
| 5 | use serderust-analyzer cargo serde 1.0.229 crate/::{derust-analyzer cargo serde_core 1.0.229 de/::IntoDeserializerrust-analyzer cargo serde_core 1.0.229 de/IntoDeserializer#, Deserializerust-analyzer cargo serde_core 1.0.229 de/Deserialize#}; |
| 6 | use serde_testrust-analyzer cargo serde_test 1.0.177 crate/::{assert_ser_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_ser_tokens()., Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#}; |
| 7 | |
| 8 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 9 | fn serializerust-analyzer cargo js_int 0.2.2 serialize().() { |
| 10 | assert_serializerust-analyzer cargo js_int 0.2.2 assert_serialize().(100); |
| 11 | assert_serializerust-analyzer cargo js_int 0.2.2 assert_serialize().(0); |
| 12 | assert_serializerust-analyzer cargo js_int 0.2.2 assert_serialize().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().100); |
| 13 | } |
| 14 | |
| 15 | fn assert_serializerust-analyzer cargo js_int 0.2.2 assert_serialize().(number: i32) { |
| 16 | assert_ser_tokensrust-analyzer cargo serde_test 1.0.177 assert/assert_ser_tokens().( |
| 17 | &Intrust-analyzer cargo js_int 0.2.2 int/Int#::fromrust-analyzer cargo js_int 0.2.2 int/impl#[Int][`From<i32>`]from().(number), |
| 18 | &[Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::NewtypeStructrust-analyzer cargo serde_test 1.0.177 token/Token#NewtypeStruct# { namerust-analyzer cargo serde_test 1.0.177 token/Token#NewtypeStruct#name.: "Int" }, Tokenrust-analyzer cargo serde_test 1.0.177 token/Token#::I64rust-analyzer cargo serde_test 1.0.177 token/Token#I64#(number as _)], |
| 19 | ) |
| 20 | } |
| 21 | |
| 22 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 23 | fn deserializerust-analyzer cargo js_int 0.2.2 deserialize().() { |
| 24 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(100).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(100)); |
| 25 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(0)); |
| 26 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().100).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().100)); |
| 27 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().9007199254740991i64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Intrust-analyzer cargo js_int 0.2.2 int/Int#::MINrust-analyzer cargo js_int 0.2.2 int/impl#[Int]MIN.); |
| 28 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740991i64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Intrust-analyzer cargo js_int 0.2.2 int/Int#::MAXrust-analyzer cargo js_int 0.2.2 int/impl#[Int]MAX.); |
| 29 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740992i64).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 30 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().9007199254740992i64).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 31 | } |
| 32 | |
| 33 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 34 | #[cfg_attr(feature = "float_deserialize", ignore)] |
| 35 | fn dont_deserialize_integral_floatrust-analyzer cargo js_int 0.2.2 dont_deserialize_integral_float().() { |
| 36 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().10.0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 37 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 38 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(1.0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 39 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740991.0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 40 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740992.0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 41 | } |
| 42 | |
| 43 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 44 | #[cfg_attr(feature = "lax_deserialize", ignore)] |
| 45 | fn dont_deserialize_fractional_floatrust-analyzer cargo js_int 0.2.2 dont_deserialize_fractional_float().() { |
| 46 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(0.5).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 47 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(42.1337).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 48 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().42.1337).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 49 | } |
| 50 | |
| 51 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 52 | #[cfg_attr(not(feature = "float_deserialize"), ignore)] |
| 53 | fn deserialize_integral_floatrust-analyzer cargo js_int 0.2.2 deserialize_integral_float().() { |
| 54 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().10.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().10)); |
| 55 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().0.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(0)); |
| 56 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(1.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(1)); |
| 57 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740991.0).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), Intrust-analyzer cargo js_int 0.2.2 int/Int#::MAXrust-analyzer cargo js_int 0.2.2 int/impl#[Int]MAX.); |
| 58 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740992.0).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 59 | // NOTE: This still ends up as integral because the .49 exceeds the representable range of f64 |
| 60 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 61 | deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(9007199254740991.49).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 62 | Intrust-analyzer cargo js_int 0.2.2 int/Int#::try_fromrust-analyzer cargo js_int 0.2.2 int/impl#[Int][`TryFrom<i64>`]try_from().(9007199254740991i64).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().() |
| 63 | ); |
| 64 | |
| 65 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(f64::NANrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NAN.).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 66 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(f64::INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]INFINITY.).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 67 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(f64::NEG_INFINITYrust-analyzer cargo core https://github.com/rust-lang/rust/library/core f64/impl#[f64]NEG_INFINITY.).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 68 | } |
| 69 | |
| 70 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 71 | #[cfg_attr(not(feature = "lax_deserialize"), ignore)] |
| 72 | fn deserialize_fractional_floatrust-analyzer cargo js_int 0.2.2 deserialize_fractional_float().() { |
| 73 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(0.5).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(0)); |
| 74 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(42.1337).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(42)); |
| 75 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][Neg]neg().42.1337).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), intrust-analyzer cargo js_int 0.2.2 macros/int!!(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().42)); |
| 76 | } |
| 77 | |
| 78 | fn deserialize_fromrust-analyzer cargo js_int 0.2.2 deserialize_from().<'de, Value: IntoDeserializerrust-analyzer cargo serde_core 1.0.229 de/IntoDeserializer#<'de>>( |
| 79 | value: Value, |
| 80 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Intrust-analyzer cargo js_int 0.2.2 int/Int#, serderust-analyzer cargo serde 1.0.229 crate/::derust-analyzer cargo serde_core 1.0.229 de/::valuerust-analyzer cargo serde_core 1.0.229 de/value/::Errorrust-analyzer cargo serde_core 1.0.229 de/value/Error#> { |
| 81 | Intrust-analyzer cargo js_int 0.2.2 int/Int#::deserializerust-analyzer cargo js_int 0.2.2 int/impl#[Int][`Deserialize<'de>`]deserialize().(value.into_deserializerrust-analyzer cargo serde_core 1.0.229 de/IntoDeserializer#into_deserializer().()) |
| 82 | } |