faker_rust/fantasy/
mod.rs1use crate::base::sample;
4use crate::locale::fetch_locale;
5
6pub fn tolkien_race() -> String {
8 fetch_locale("fantasy.tolkien_races", "en")
9 .map(|v| sample(&v))
10 .unwrap_or_else(|| sample(FALLBACK_TOLKIEN_RACES).to_string())
11}
12
13pub fn creature() -> String {
15 fetch_locale("fantasy.creatures", "en")
16 .map(|v| sample(&v))
17 .unwrap_or_else(|| sample(FALLBACK_CREATURES).to_string())
18}
19
20pub fn location() -> String {
22 fetch_locale("fantasy.locations", "en")
23 .map(|v| sample(&v))
24 .unwrap_or_else(|| sample(FALLBACK_LOCATIONS).to_string())
25}
26
27pub fn weapon() -> String {
29 fetch_locale("fantasy.weapons", "en")
30 .map(|v| sample(&v))
31 .unwrap_or_else(|| sample(FALLBACK_WEAPONS).to_string())
32}
33
34pub fn spell() -> String {
36 fetch_locale("fantasy.spells", "en")
37 .map(|v| sample(&v))
38 .unwrap_or_else(|| sample(FALLBACK_SPELLS).to_string())
39}
40
41const FALLBACK_TOLKIEN_RACES: &[&str] = &[
43 "Elf", "Dwarf", "Human", "Hobbit", "Orc", "Ent", "Wizard", "Dragon",
44 "Troll", "Goblin", "Uruk-hai", "Balrog", "Nazgûl",
45];
46
47const FALLBACK_CREATURES: &[&str] = &[
48 "Dragon", "Phoenix", "Unicorn", "Griffin", "Kraken", "Basilisk",
49 "Chimera", "Hydra", "Minotaur", "Pegasus", "Centaur", "Werewolf",
50 "Vampire", "Fairy", "Giant", "Troll", "Ogre", "Goblin",
51];
52
53const FALLBACK_LOCATIONS: &[&str] = &[
54 "Mordor", "Rivendell", "The Shire", "Gondor", "Rohan", "Isengard",
55 "Helm's Deep", "Minas Tirith", "Lothlórien", "Mirkwood", "The Misty Mountains",
56 "Castle Dracula", "The Forbidden Forest", "Hogwarts", "Narnia",
57];
58
59const FALLBACK_WEAPONS: &[&str] = &[
60 "Excalibur", "Glamdring", "Orcrist", "Sting", "Narsil", "Andúril",
61 "The Master Sword", "The Elder Wand", "Stormbringer", "Mjolnir",
62 "Longbow", "Battle Axe", "War Hammer", "Dagger", "Spear", "Staff",
63];
64
65const FALLBACK_SPELLS: &[&str] = &[
66 "Fireball", "Lightning Bolt", "Healing Touch", "Invisibility", "Teleport",
67 "Frost Nova", "Chain Lightning", "Arcane Blast", "Shadow Bolt", "Holy Light",
68 "Polymorph", "Time Stop", "Resurrection", "Summon Demon", "Shield of Light",
69];
70
71#[cfg(test)]
72mod tests {
73 use super::*;
74
75 #[test]
76 fn test_tolkien_race() {
77 assert!(!tolkien_race().is_empty());
78 }
79
80 #[test]
81 fn test_creature() {
82 assert!(!creature().is_empty());
83 }
84
85 #[test]
86 fn test_location() {
87 assert!(!location().is_empty());
88 }
89
90 #[test]
91 fn test_weapon() {
92 assert!(!weapon().is_empty());
93 }
94
95 #[test]
96 fn test_spell() {
97 assert!(!spell().is_empty());
98 }
99}