faker_rust/default/
world_cup.rs1use crate::base::sample;
4use crate::locale::fetch_locale;
5
6pub fn year() -> String {
8 fetch_locale("world_cup.years", "en")
9 .map(|v| sample(&v))
10 .unwrap_or_else(|| sample(FALLBACK_YEARS).to_string())
11}
12
13pub fn host() -> String {
15 fetch_locale("world_cup.hosts", "en")
16 .map(|v| sample(&v))
17 .unwrap_or_else(|| sample(FALLBACK_HOSTS).to_string())
18}
19
20pub fn winner() -> String {
22 fetch_locale("world_cup.winners", "en")
23 .map(|v| sample(&v))
24 .unwrap_or_else(|| sample(FALLBACK_WINNERS).to_string())
25}
26
27pub fn stadium() -> String {
29 fetch_locale("world_cup.stadiums", "en")
30 .map(|v| sample(&v))
31 .unwrap_or_else(|| sample(FALLBACK_STADIUMS).to_string())
32}
33
34pub fn team() -> String {
36 let teams = [
37 "Brazil", "Germany", "Italy", "Argentina", "France", "Spain",
38 "England", "Netherlands", "Uruguay", "Portugal", "Belgium",
39 "Croatia", "Mexico", "USA", "Japan", "South Korea",
40 ];
41 sample(&teams).to_string()
42}
43
44const FALLBACK_YEARS: &[&str] = &[
46 "2022", "2018", "2014", "2010", "2006", "2002", "1998", "1994",
47 "1990", "1986", "1982", "1978", "1974", "1970", "1966", "1962",
48];
49
50const FALLBACK_HOSTS: &[&str] = &[
51 "Qatar", "Russia", "Brazil", "South Africa", "Germany", "Japan/Korea",
52 "France", "USA", "Italy", "Mexico", "Argentina", "Spain",
53];
54
55const FALLBACK_WINNERS: &[&str] = &[
56 "Argentina", "France", "Germany", "Brazil", "Spain", "Italy",
57 "England", "Uruguay", "France", "Argentina", "Germany",
58];
59
60const FALLBACK_STADIUMS: &[&str] = &[
61 "Lusail Stadium", "Al Bayt Stadium", "Khalifa International Stadium",
62 "Al Janoub Stadium", "Education City Stadium", "Stadium 974",
63 "Al Thumama Stadium", "Ahmad Bin Ali Stadium",
64];
65
66#[cfg(test)]
67mod tests {
68 use super::*;
69
70 #[test]
71 fn test_year() {
72 assert!(!year().is_empty());
73 }
74
75 #[test]
76 fn test_host() {
77 assert!(!host().is_empty());
78 }
79
80 #[test]
81 fn test_winner() {
82 assert!(!winner().is_empty());
83 }
84
85 #[test]
86 fn test_stadium() {
87 assert!(!stadium().is_empty());
88 }
89
90 #[test]
91 fn test_team() {
92 assert!(!team().is_empty());
93 }
94}