faker_rust/default/
crypto.rs1use crate::base::sample;
4use crate::locale::{fetch_locale_with_context, sample_with_resolve};
5
6pub fn coin() -> String {
8 fetch_locale_with_context("crypto_coin.coin", "en", Some("crypto_coin"))
9 .map(|v| sample_with_resolve(&v, Some("crypto_coin")))
10 .unwrap_or_else(|| sample(FALLBACK_COINS).to_string())
11}
12
13pub fn name() -> String {
15 coin()
16}
17
18pub fn symbol() -> String {
20 fetch_locale_with_context("crypto_coin.symbol", "en", Some("crypto_coin"))
21 .map(|v| sample_with_resolve(&v, Some("crypto_coin")))
22 .unwrap_or_else(|| sample(FALLBACK_SYMBOLS).to_string())
23}
24
25const FALLBACK_COINS: &[&str] = &["Bitcoin", "Ethereum", "Litecoin", "Ripple", "Dogecoin"];
27const FALLBACK_SYMBOLS: &[&str] = &["BTC", "ETH", "LTC", "XRP", "DOGE"];
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_coin() {
35 assert!(!coin().is_empty());
36 }
37
38 #[test]
39 fn test_symbol() {
40 assert!(!symbol().is_empty());
41 }
42}