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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use crate::types::location::Location;
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
pub struct Venue {
pub location: Location,
pub title: String,
pub address: String,
pub foursquare_id: Option<String>,
pub foursquare_type: Option<String>,
}
#[cfg(test)]
mod tests {
#![allow(clippy::float_cmp)]
use super::*;
#[test]
fn deserialize_full() {
let data: Venue = serde_json::from_value(serde_json::json!({
"location": {
"latitude": 1.1,
"longitude": 2.0
},
"title": "venue title",
"address": "venue address",
"foursquare_id": "f-id",
"foursquare_type": "f-type"
}))
.unwrap();
assert_eq!(data.location.latitude, 1.1);
assert_eq!(data.location.longitude, 2.0);
assert_eq!(data.title, "venue title");
assert_eq!(data.address, "venue address");
assert_eq!(data.foursquare_id.unwrap(), "f-id");
assert_eq!(data.foursquare_type.unwrap(), "f-type");
}
#[test]
fn deserialize_partial() {
let data: Venue = serde_json::from_value(serde_json::json!({
"location": {
"latitude": 1.1,
"longitude": 2.0
},
"title": "venue title",
"address": "venue address"
}))
.unwrap();
assert_eq!(data.location.latitude, 1.1);
assert_eq!(data.location.longitude, 2.0);
assert_eq!(data.title, "venue title");
assert_eq!(data.address, "venue address");
assert!(data.foursquare_id.is_none());
assert!(data.foursquare_type.is_none());
}
}