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
use serde::Deserialize;
#[derive(PartialEq, Debug, Deserialize, Default)]
#[serde(rename_all = "kebab-case")]
pub struct TargetFormat {
#[serde(rename = "format?", default)]
pub should_format: bool,
pub format_options: Option<String>,
}
#[test]
fn deserialize() {
use pretty_assertions::assert_eq;
use serde_json::json;
assert_eq!(
TargetFormat { should_format: true, format_options: Some("-fs ext2".to_string()) },
serde_json::from_value::<TargetFormat>(json!({
"format?": true,
"format-options": "-fs ext2"
}))
.unwrap()
);
assert_eq!(
TargetFormat { should_format: false, format_options: None },
serde_json::from_value::<TargetFormat>(json!({
"format?": false,
}))
.unwrap()
);
}
#[test]
fn default() {
use pretty_assertions::assert_eq;
assert_eq!(
TargetFormat { should_format: false, format_options: None },
TargetFormat::default(),
);
}