Skip to main content

faker_rust/default/
adjective.rs

1//! Adjective generator
2
3use crate::base::sample;
4use crate::locale::fetch_locale;
5
6/// Generate a random adjective
7pub fn adjective() -> String {
8    fetch_locale("adjective.adjectives", "en")
9        .map(|v| sample(&v))
10        .unwrap_or_else(|| sample(FALLBACK_ADJECTIVES).to_string())
11}
12
13/// Generate a positive adjective
14pub fn positive() -> String {
15    fetch_locale("adjective.positives", "en")
16        .map(|v| sample(&v))
17        .unwrap_or_else(|| sample(FALLBACK_POSITIVE).to_string())
18}
19
20/// Generate a negative adjective
21pub fn negative() -> String {
22    fetch_locale("adjective.negatives", "en")
23        .map(|v| sample(&v))
24        .unwrap_or_else(|| sample(FALLBACK_NEGATIVE).to_string())
25}
26
27// Fallback data
28const FALLBACK_ADJECTIVES: &[&str] = &[
29    "adorable", "adventurous", "aggressive", "agreeable", "alert", "alive",
30    "amused", "angry", "annoyed", "annoying", "anxious", "arrogant", "ashamed",
31    "attractive", "average", "awful", "bad", "beautiful", "better", "bewildered",
32    "black", "bloody", "blue", "blushing", "bored", "brainy", "brave", "breakable",
33    "bright", "busy", "calm", "careful", "cautious", "charming", "cheerful",
34    "clean", "clear", "clever", "cloudy", "clumsy", "colorful", "combative",
35    "comfortable", "concerned", "condemned", "confused", "cooperative", "courageous",
36    "crazy", "creepy", "crowded", "cruel", "curious", "cute", "dangerous",
37    "dark", "dead", "defeated", "defiant", "delightful", "depressed", "determined",
38];
39
40const FALLBACK_POSITIVE: &[&str] = &[
41    "amazing", "awesome", "brilliant", "excellent", "fantastic", "good",
42    "great", "incredible", "outstanding", "perfect", "remarkable", "superb",
43    "terrific", "wonderful", "magnificent", "extraordinary", "fabulous",
44];
45
46const FALLBACK_NEGATIVE: &[&str] = &[
47    "awful", "bad", "terrible", "horrible", "disgusting", "unpleasant",
48    "disappointing", "mediocre", "poor", "weak", "useless", "pathetic",
49    "dreadful", "atrocious", "appalling",
50];
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_adjective() {
58        assert!(!adjective().is_empty());
59    }
60
61    #[test]
62    fn test_positive() {
63        assert!(!positive().is_empty());
64    }
65
66    #[test]
67    fn test_negative() {
68        assert!(!negative().is_empty());
69    }
70}