bo4e_core/enums/
salutation.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[non_exhaustive]
10pub enum Salutation {
11 #[serde(rename = "HERR")]
13 Mr,
14
15 #[serde(rename = "FRAU")]
17 Ms,
18
19 #[serde(rename = "EHELEUTE")]
21 MarriedCouple,
22
23 #[serde(rename = "FIRMA")]
25 Company,
26
27 #[serde(rename = "FAMILIE")]
29 Family,
30
31 #[serde(rename = "ERBENGEMEINSCHAFT")]
33 HeirsCommunity,
34
35 #[serde(rename = "GRUNDSTUECKSGEMEINSCHAFT")]
37 PropertyCommunity,
38}
39
40impl Salutation {
41 pub fn german_name(&self) -> &'static str {
43 match self {
44 Self::Mr => "Herr",
45 Self::Ms => "Frau",
46 Self::MarriedCouple => "Eheleute",
47 Self::Company => "Firma",
48 Self::Family => "Familie",
49 Self::HeirsCommunity => "Erbengemeinschaft",
50 Self::PropertyCommunity => "Grundstuecksgemeinschaft",
51 }
52 }
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_serialize() {
61 assert_eq!(serde_json::to_string(&Salutation::Mr).unwrap(), r#""HERR""#);
62 assert_eq!(serde_json::to_string(&Salutation::Ms).unwrap(), r#""FRAU""#);
63 }
64
65 #[test]
66 fn test_deserialize() {
67 assert_eq!(
68 serde_json::from_str::<Salutation>(r#""HERR""#).unwrap(),
69 Salutation::Mr
70 );
71 assert_eq!(
72 serde_json::from_str::<Salutation>(r#""FIRMA""#).unwrap(),
73 Salutation::Company
74 );
75 }
76
77 #[test]
78 fn test_roundtrip() {
79 for salutation in [
80 Salutation::Mr,
81 Salutation::Ms,
82 Salutation::MarriedCouple,
83 Salutation::Company,
84 Salutation::Family,
85 Salutation::HeirsCommunity,
86 Salutation::PropertyCommunity,
87 ] {
88 let json = serde_json::to_string(&salutation).unwrap();
89 let parsed: Salutation = serde_json::from_str(&json).unwrap();
90 assert_eq!(salutation, parsed);
91 }
92 }
93}