-
Notifications
You must be signed in to change notification settings - Fork 0
/
functionalityrequest.rs
62 lines (55 loc) · 1.82 KB
/
functionalityrequest.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
pub use ::semver::Version;
use ::serde::Deserialize;
use ::serde::Serialize;
use smallvec::SmallVec;
use crate::gen1::connect::layout::GenFeatures;
use crate::gen1::data::Party;
/// Specifies which inputs the generator expects from Apivolve.
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct FunctionalityRequest {
pub features: GenFeatures,
pub generate_parties: SmallVec<[Party; 3]>,
}
#[cfg(test)]
mod tests {
pub use ::semver::Version;
use ::smallvec::smallvec;
use crate::gen1::connect::layout::GenFeature;
use crate::gen1::connect::layout::GenFeatures;
use crate::Identifier;
use super::*;
#[test]
fn serialize() {
let features = smallvec![
GenFeature::Parser,
GenFeature::Parser,
GenFeature::Validator,
GenFeature::Documentation,
];
let json = serde_json::to_string(&FunctionalityRequest {
features: GenFeatures::new(features),
generate_parties: smallvec![Party::new(Identifier::new("server").unwrap())],
})
.unwrap();
assert_eq!(
json,
r#"{"apivolve_version":"1.2.4","features":{"features":["documentation","parser","validator"]},"encoding":"json"}"#
);
}
#[test]
fn deserialize() {
let config: FunctionalityRequest = serde_json::from_str(
r#"{"apivolve_version":"1.2.4","features":{"features":[
"parser","validator"]},"encoding":"json"}"#,
)
.unwrap();
assert_eq!(
config,
FunctionalityRequest {
features: GenFeatures::new(smallvec![GenFeature::Parser, GenFeature::Validator,]),
generate_parties: smallvec![Party::new(Identifier::new("server").unwrap())]
}
)
}
}