Skip to content

Commit

Permalink
test for failure when deserialize bigint to int in enum
Browse files Browse the repository at this point in the history
  • Loading branch information
rnbguy committed Nov 20, 2023
1 parent 79bfbeb commit 9920493
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions itf/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,34 @@ fn test_bigint_to_int() {
assert!(itf::from_value::<num_bigint::BigInt>(itf).is_ok());
}

#[test]
fn test_enum_deserialization_failure() {
let itf = serde_json::json!({
"_foo": {"#bigint": "1"},
"typ": "Foo",
});

#[derive(Deserialize, Debug)]
#[serde(tag = "typ")]
enum FooBarInt {
// try to deserialize _foo as i64, instead of BigInt
Foo { _foo: i64 },
Bar { _bar: String },
}

assert!(itf::from_value::<FooBarInt>(itf.clone()).is_err());

#[derive(Deserialize, Debug)]
#[serde(tag = "typ")]
enum FooBarBigInt {
// can deserialize _foo to BigInt
Foo { _foo: num_bigint::BigInt },
Bar { _bar: String },
}

assert!(itf::from_value::<FooBarBigInt>(itf).is_ok());
}

#[test]
fn test_complete() {
use std::collections::{BTreeSet, HashMap, HashSet};
Expand Down

0 comments on commit 9920493

Please sign in to comment.