Skip to main content

faker_rust/default/
types.rs

1//! Types generator - programming types
2
3use crate::base::sample;
4
5/// Generate a random Ruby type
6pub fn ruby() -> String {
7    let types = [
8        "String", "Integer", "Float", "Boolean", "Array", "Hash",
9        "Symbol", "NilClass", "Range", "Regexp", "Time", "Date",
10    ];
11    sample(&types).to_string()
12}
13
14/// Generate a random JavaScript type
15pub fn javascript() -> String {
16    let types = [
17        "string", "number", "boolean", "object", "array", "function",
18        "undefined", "null", "symbol", "bigint", "Date", "RegExp",
19    ];
20    sample(&types).to_string()
21}
22
23/// Generate a random SQL type
24pub fn sql() -> String {
25    let types = [
26        "VARCHAR", "INTEGER", "FLOAT", "DOUBLE", "BOOLEAN", "DATE",
27        "TIMESTAMP", "TEXT", "BLOB", "DECIMAL", "CHAR", "BIGINT",
28    ];
29    sample(&types).to_string()
30}
31
32/// Generate a random Rust type
33pub fn rust() -> String {
34    let types = [
35        "String", "i32", "i64", "f32", "f64", "bool", "Vec<T>",
36        "Option<T>", "Result<T, E>", "HashMap<K, V>", "Arc<T>", "Rc<T>",
37    ];
38    sample(&types).to_string()
39}
40
41#[cfg(test)]
42mod tests {
43    use super::*;
44
45    #[test]
46    fn test_ruby() {
47        assert!(!ruby().is_empty());
48    }
49
50    #[test]
51    fn test_javascript() {
52        assert!(!javascript().is_empty());
53    }
54
55    #[test]
56    fn test_sql() {
57        assert!(!sql().is_empty());
58    }
59
60    #[test]
61    fn test_rust() {
62        assert!(!rust().is_empty());
63    }
64}