Skip to main content

faker_rust/default/
quote.rs

1//! Quote generator - generates famous quotes from various sources
2
3use crate::base::sample;
4use crate::locale::fetch_locale;
5
6/// Generate a famous quote
7pub fn famous() -> String {
8    fetch_locale("quote.famous", "en")
9        .map(|v| sample(&v))
10        .unwrap_or_else(|| "I think, therefore I am.".to_string())
11}
12
13/// Generate a quote from Matz (Yukihiro Matsumoto)
14pub fn matz() -> String {
15    fetch_locale("quote.matz", "en")
16        .map(|v| sample(&v))
17        .unwrap_or_else(|| "Ruby is designed to make programmers happy.".to_string())
18}
19
20/// Generate a quote from Robin Williams
21pub fn robin() -> String {
22    fetch_locale("quote.robin", "en")
23        .map(|v| sample(&v))
24        .unwrap_or_else(|| {
25            "No matter what people tell you, words and ideas can change the world.".to_string()
26        })
27}
28
29/// Generate a quote by Jack Handey
30pub fn jack_handey() -> String {
31    fetch_locale("quote.jack_handey", "en")
32        .map(|v| sample(&v))
33        .unwrap_or_else(|| "I hope if dogs ever take over the world, and they chose a king, they don't just go by size, because I bet there are some Lincoln Terrier-sized dogs with a lot of good ideas.".to_string())
34}
35
36/// Generate a quote from the Yiddish proverb
37pub fn yiddish() -> String {
38    fetch_locale("quote.yiddish", "en")
39        .map(|v| sample(&v))
40        .unwrap_or_else(|| "A bad peace is better than a good war.".to_string())
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn test_quote_generation() {
49        assert!(!famous().is_empty());
50        assert!(!matz().is_empty());
51        assert!(!robin().is_empty());
52        assert!(!jack_handey().is_empty());
53        assert!(!yiddish().is_empty());
54    }
55}