Skip to main content

faker_rust/default/
team.rs

1//! Team generator
2
3use crate::base::sample;
4use crate::locale::fetch_locale;
5
6/// Generate a random team name
7pub fn name() -> String {
8    fetch_locale("team.names", "en")
9        .map(|v| sample(&v))
10        .unwrap_or_else(|| sample(FALLBACK_NAMES).to_string())
11}
12
13/// Generate a random team mascot
14pub fn mascot() -> String {
15    fetch_locale("team.mascots", "en")
16        .map(|v| sample(&v))
17        .unwrap_or_else(|| sample(FALLBACK_MASCOTS).to_string())
18}
19
20/// Generate a random team sport
21pub fn sport() -> String {
22    fetch_locale("team.sports", "en")
23        .map(|v| sample(&v))
24        .unwrap_or_else(|| sample(FALLBACK_SPORTS).to_string())
25}
26
27/// Generate a random team state
28pub fn state() -> String {
29    fetch_locale("team.states", "en")
30        .map(|v| sample(&v))
31        .unwrap_or_else(|| sample(FALLBACK_STATES).to_string())
32}
33
34// Fallback data
35const FALLBACK_NAMES: &[&str] = &[
36    "Thunder", "Lightning", "Storm", "Wolves", "Bears", "Eagles", "Hawks",
37    "Lions", "Tigers", "Panthers", "Sharks", "Dragons", "Knights", "Warriors",
38    "Titans", "Giants", "Raiders", "Chargers", "Jets", "Rockets", "Stars",
39];
40
41const FALLBACK_MASCOTS: &[&str] = &[
42    "Wildcats", "Bulldogs", "Tigers", "Eagles", "Lions", "Bears", "Sharks",
43    "Dragons", "Knights", "Vikings", "Pirates", "Cowboys", "Spartans",
44    "Trojans", "Rangers", "Rebels", "Patriots", "Braves", "Chiefs",
45];
46
47const FALLBACK_SPORTS: &[&str] = &[
48    "Football", "Basketball", "Baseball", "Hockey", "Soccer", "Volleyball",
49    "Tennis", "Golf", "Swimming", "Track", "Wrestling", "Lacrosse", "Rugby",
50];
51
52const FALLBACK_STATES: &[&str] = &[
53    "New York", "California", "Texas", "Florida", "Illinois", "Pennsylvania",
54    "Ohio", "Georgia", "North Carolina", "Michigan", "New Jersey", "Virginia",
55];
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_name() {
63        assert!(!name().is_empty());
64    }
65
66    #[test]
67    fn test_mascot() {
68        assert!(!mascot().is_empty());
69    }
70
71    #[test]
72    fn test_sport() {
73        assert!(!sport().is_empty());
74    }
75
76    #[test]
77    fn test_state() {
78        assert!(!state().is_empty());
79    }
80}