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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use std::fmt;
include!(concat!(env!("OUT_DIR"), "/lang.rs"));
impl Lang {
pub fn from_code<S: Into<String>>(code: S) -> Option<Lang> {
lang_from_code(code)
}
pub fn code(&self) -> &str {
lang_to_code(*self)
}
pub fn name(self) -> &'static str {
lang_to_name(self)
}
pub fn eng_name(self) -> &'static str {
lang_to_eng_name(self)
}
}
impl fmt::Display for Lang {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.name())
}
}
pub type LangProfile = &'static [&'static str];
pub type LangProfileList = &'static [(Lang, LangProfile)];
#[cfg(test)]
mod tests {
use super::Lang;
#[test]
fn test_from_code() {
assert_eq!(Lang::from_code("rus".to_string()), Some(Lang::Rus));
assert_eq!(Lang::from_code("ukr"), Some(Lang::Ukr));
assert_eq!(Lang::from_code("ENG"), Some(Lang::Eng));
assert_eq!(Lang::from_code("oops"), None);
}
#[test]
fn test_code() {
assert_eq!(Lang::Spa.code(), "spa");
}
#[test]
fn test_name() {
assert_eq!(Lang::Rus.name(), "Русский");
assert_eq!(Lang::Spa.name(), "Español");
assert_eq!(Lang::Epo.name(), "Esperanto");
}
#[test]
fn test_eng_name() {
assert_eq!(Lang::Spa.eng_name(), "Spanish");
assert_eq!(Lang::Epo.eng_name(), "Esperanto");
assert_eq!(Lang::Rus.eng_name(), "Russian");
}
}