forked from serde-rs/json
-
Notifications
You must be signed in to change notification settings - Fork 0
/
128bit.rs
38 lines (33 loc) · 1.01 KB
/
128bit.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use serde::Deserialize;
#[derive(Deserialize, Debug, PartialEq)]
struct Data {
value: u128,
}
#[derive(Deserialize, Debug, PartialEq)]
#[serde(untagged)]
enum UntaggedMessage {
TestMessage(Data),
}
#[derive(Deserialize, Debug, PartialEq)]
#[serde(tag = "type", content = "msg")]
enum TaggedMessage {
TestMessage(Data)
}
#[test]
fn deserialize_tagged_message_containing_128bit_value() {
let json = String::from(r#"{ "type": "TestMessage", "msg": { "value": 1000000000000000000000000 } }"#);
if let TaggedMessage::TestMessage(Data { value }) = serde_json::from_str(&json).unwrap() {
assert_eq!(1000000000000000000000000, value)
} else {
panic!("fail")
}
}
#[test]
fn deserialize_untagged_message_containing_128bit_value() {
let json = String::from(r#"{ "value": 1000000000000000000000000 }"#);
if let UntaggedMessage::TestMessage(Data { value }) = serde_json::from_str(&json).unwrap() {
assert_eq!(1000000000000000000000000, value)
} else {
panic!("fail")
}
}