mockd/hipster/mod.rs
1//!
2//! Provides 3 functions to return mock hipster data.
3//!
4//! # Examples
5//!
6//! ```rust
7//! use mockd::hipster;
8//!
9//! let data = hipster::word(); // word: fingerstache
10//! let data = hipster::sentence(12); // sentence: Itaque aliquid id ex repudiandae adipisci quibusdam excepturi deleniti qui alias animi.
11//! let data = hipster::paragraph(3, 4, 40, " ".to_string()); // paragraph: Voluptas minima delectus voluptatibus earum rerum accusamus consequatur sunt....
12//! ```
13//! # Feature
14//!
15//! Requires the "hipster" feature.
16//!
17
18use crate::misc;
19use crate::words;
20
21pub(crate) mod data;
22
23/// Generate a random hipster word from the word dictionary.
24///
25/// # Example
26///
27/// ```rust
28/// let word = mockd::hipster::word();
29///
30/// println!("Hipster word: {}", word);
31/// ```
32///
33/// # Feature
34///
35/// Requires the "hipster" feature.
36///
37pub fn word() -> String {
38 misc::random_data(data::WORD).to_string()
39}
40
41/// Generate a random sentence containing the given number of words.
42///
43/// # Example
44///
45/// ```rust
46/// let sentence = mockd::hipster::sentence(5);
47///
48/// println!("Hipster sentence: {}", sentence);
49/// ```
50///
51/// # Feature
52///
53/// Requires the "hipster" feature.
54///
55pub fn sentence(word_count: usize) -> String {
56 words::sentence(word_count)
57}
58
59/// Generate a random paragraph containing a number of sentences of words.
60///
61/// # Example
62///
63/// ```rust
64/// let paragraph = mockd::hipster::paragraph(1,5,5,". ".to_string());
65///
66/// println!("Hipster word: {}", paragraph);
67/// ```
68///
69/// # Feature
70///
71/// Requires the "hipster" feature.
72///
73pub fn paragraph(
74 count: usize,
75 sentence_count: usize,
76 word_count: usize,
77 separator: String,
78) -> String {
79 words::paragraph(count, sentence_count, word_count, separator)
80}
81
82#[cfg(test)]
83mod tests {
84 use crate::hipster;
85 use crate::testify::exec_mes;
86
87 #[test]
88 fn word() {
89 exec_mes("hipster::word", hipster::word);
90 }
91
92 #[test]
93 fn sentence() {
94 exec_mes("hipster::sentence", || hipster::sentence(12));
95 }
96
97 #[test]
98 fn paragraph() {
99 let data1 = hipster::paragraph(3, 4, 40, " ".to_string());
100 let data2 = hipster::paragraph(3, 4, 40, " ".to_string());
101 assert_ne!(data1, data2);
102 }
103}