bo4e_core/enums/
contract_form.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[non_exhaustive]
10pub enum ContractForm {
11 #[serde(rename = "ONLINE")]
13 Online,
14
15 #[serde(rename = "DIREKT")]
17 Direct,
18
19 #[serde(rename = "FAX")]
21 Fax,
22}
23
24impl ContractForm {
25 pub fn german_name(&self) -> &'static str {
27 match self {
28 Self::Online => "Online",
29 Self::Direct => "Direkt",
30 Self::Fax => "Auftragsfax",
31 }
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_serialize() {
41 assert_eq!(
42 serde_json::to_string(&ContractForm::Online).unwrap(),
43 r#""ONLINE""#
44 );
45 assert_eq!(
46 serde_json::to_string(&ContractForm::Direct).unwrap(),
47 r#""DIREKT""#
48 );
49 }
50
51 #[test]
52 fn test_deserialize() {
53 assert_eq!(
54 serde_json::from_str::<ContractForm>(r#""ONLINE""#).unwrap(),
55 ContractForm::Online
56 );
57 assert_eq!(
58 serde_json::from_str::<ContractForm>(r#""FAX""#).unwrap(),
59 ContractForm::Fax
60 );
61 }
62
63 #[test]
64 fn test_roundtrip() {
65 for form in [
66 ContractForm::Online,
67 ContractForm::Direct,
68 ContractForm::Fax,
69 ] {
70 let json = serde_json::to_string(&form).unwrap();
71 let parsed: ContractForm = serde_json::from_str(&json).unwrap();
72 assert_eq!(form, parsed);
73 }
74 }
75}