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 67d302e
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions itf/tests/regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,35 @@ 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"},
"_bar": "",
"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 67d302e

Please sign in to comment.