Skip to main content

faker_rust/default/
ancient.rs

1//! Ancient generator - generates names of gods, heroes, and locations from antiquity
2
3use crate::base::sample;
4use crate::locale::fetch_locale;
5
6/// Generate a random ancient god
7pub fn god() -> String {
8    fetch_locale("ancient.god", "en")
9        .map(|v| sample(&v))
10        .unwrap_or_else(|| "Zeus".to_string())
11}
12
13/// Generate a random primordial deity
14pub fn primordial() -> String {
15    fetch_locale("ancient.primordial", "en")
16        .map(|v| sample(&v))
17        .unwrap_or_else(|| "Chaos".to_string())
18}
19
20/// Generate a random titan
21pub fn titan() -> String {
22    fetch_locale("ancient.titan", "en")
23        .map(|v| sample(&v))
24        .unwrap_or_else(|| "Atlas".to_string())
25}
26
27/// Generate a random ancient hero
28pub fn hero() -> String {
29    fetch_locale("ancient.hero", "en")
30        .map(|v| sample(&v))
31        .unwrap_or_else(|| "Hercules".to_string())
32}
33
34/// Generate a random ancient location
35pub fn location() -> String {
36    fetch_locale("ancient.location", "en")
37        .map(|v| sample(&v))
38        .unwrap_or_else(|| "Mount Olympus".to_string())
39}
40
41/// Generate a random ancient monster
42pub fn monster() -> String {
43    fetch_locale("ancient.monster", "en")
44        .map(|v| sample(&v))
45        .unwrap_or_else(|| "Medusa".to_string())
46}
47
48#[cfg(test)]
49mod tests {
50    use super::*;
51
52    #[test]
53    fn test_ancient_generation() {
54        assert!(!god().is_empty());
55        assert!(!primordial().is_empty());
56        assert!(!titan().is_empty());
57        assert!(!hero().is_empty());
58        assert!(!location().is_empty());
59        assert!(!monster().is_empty());
60    }
61}