Skip to main content

faker_rust/default/
hacker.rs

1//! Hacker/coder generator - generates hacker-related data
2
3use crate::base::sample;
4use crate::locale::fetch_locale;
5
6/// Generate a random hacker abbreviation
7pub fn abbreviation() -> String {
8    fetch_locale("hacker.abbreviations", "en")
9        .map(|v| sample(&v))
10        .unwrap_or_else(|| sample(FALLBACK_ABBREVIATIONS).to_string())
11}
12
13/// Generate a random hacker adjective
14pub fn adjective() -> String {
15    fetch_locale("hacker.adjectives", "en")
16        .map(|v| sample(&v))
17        .unwrap_or_else(|| sample(FALLBACK_ADJECTIVES).to_string())
18}
19
20/// Generate a random hacker noun
21pub fn noun() -> String {
22    fetch_locale("hacker.nouns", "en")
23        .map(|v| sample(&v))
24        .unwrap_or_else(|| sample(FALLBACK_NOUNS).to_string())
25}
26
27/// Generate a random hacker verb
28pub fn verb() -> String {
29    fetch_locale("hacker.verbs", "en")
30        .map(|v| sample(&v))
31        .unwrap_or_else(|| sample(FALLBACK_VERBS).to_string())
32}
33
34/// Generate a random hacker phrase
35pub fn ingverb() -> String {
36    fetch_locale("hacker.ingverbs", "en")
37        .map(|v| sample(&v))
38        .unwrap_or_else(|| sample(FALLBACK_INGVERBS).to_string())
39}
40
41/// Generate a random hacker phrase
42pub fn phrase() -> String {
43    let parts = [adjective(),
44        abbreviation(),
45        noun(),
46        verb(),
47        ingverb()];
48    parts.join(" ")
49}
50
51// Fallback data
52const FALLBACK_ABBREVIATIONS: &[&str] = &[
53    "TCP", "HTTP", "SSD", "RAM", "GB", "CSS", "SSL", "AGP", "SQL", "XML",
54    "EXE", "COM", "HDD", "THX", "SMTP", "SMS", "USB", "PNG", "SAS", "IB",
55    "PCI", "DNS", "FTP", "GSM", "CSS", "HDMI", "HTTP", "TLS", "CSS", "JSON",
56];
57
58const FALLBACK_ADJECTIVES: &[&str] = &[
59    "auxiliary", "primary", "back-end", "digital", "open-source", "virtual",
60    "cross-platform", "redundant", "online", "haptic", "multi-byte", "bluetooth",
61    "wireless", "1080p", "neural", "optical", "solid state", "mobile",
62];
63
64const FALLBACK_NOUNS: &[&str] = &[
65    "driver", "protocol", "bandwidth", "panel", "microchip", "program",
66    "port", "card", "array", "interface", "system", "sensor", "firewall",
67    "hard drive", "pixel", "alarm", "feed", "monitor", "application",
68    "transmitter", "bus", "circuit", "capacitor", "matrix",
69];
70
71const FALLBACK_VERBS: &[&str] = &[
72    "back up", "bypass", "hack", "override", "compress", "copy", "navigate",
73    "index", "connect", "generate", "quantify", "calculate", "synthesize",
74    "input", "transmit", "program", "reboot", "parse",
75];
76
77const FALLBACK_INGVERBS: &[&str] = &[
78    "backing up", "bypassing", "hacking", "overriding", "compressing",
79    "copying", "navigating", "indexing", "connecting", "generating",
80    "quantifying", "calculating", "synthesizing", "inputting", "transmitting",
81    "programming", "rebooting", "parsing",
82];
83
84#[cfg(test)]
85mod tests {
86    use super::*;
87
88    #[test]
89    fn test_abbreviation() {
90        assert!(!abbreviation().is_empty());
91    }
92
93    #[test]
94    fn test_adjective() {
95        assert!(!adjective().is_empty());
96    }
97
98    #[test]
99    fn test_noun() {
100        assert!(!noun().is_empty());
101    }
102
103    #[test]
104    fn test_verb() {
105        assert!(!verb().is_empty());
106    }
107
108    #[test]
109    fn test_phrase() {
110        assert!(!phrase().is_empty());
111    }
112}