fake/faker/
mod.rs

1use crate::Fake;
2use rand::Rng;
3use std::char;
4
5#[inline]
6fn numerify_sym<R: Rng + ?Sized>(string: &str, rng: &mut R) -> String {
7    string
8        .chars()
9        .map(|x| match x {
10            '^' => char::from_digit((1..10).fake_with_rng::<u32, _>(rng), 10).unwrap(),
11            '#' => char::from_digit((0..10).fake_with_rng::<u32, _>(rng), 10).unwrap(),
12            other => other,
13        })
14        .collect()
15}
16
17macro_rules! def_fakers {
18    (@m $locale_m:ident=>$locale_s:ident { $($name:ident$(< $($lts:lifetime),* >)?($($arg:ident : $typ:ty),*);)+}) => {
19        pub mod $locale_m {
20            use super::raw;
21            use crate::locales::$locale_s;
22        $(
23            #[inline]
24            #[allow(non_snake_case)]
25            pub fn $name$(< $($lts),* >)?($($arg:$typ),*) -> raw::$name<$($($lts),*,)?$locale_s> {
26                raw::$name($locale_s, $($arg),*)
27            }
28        )+
29        }
30    };
31    ($($name:ident$(< $($lts:lifetime),* >)?($($arg:ident : $typ:ty),*);)+) => {
32        pub mod raw {
33        $(
34            pub struct $name<$( $($lts),* , )?L>(pub L, $(pub $typ),*);
35        )+
36        }
37
38        def_fakers!(@m en=>EN {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
39        def_fakers!(@m fr_fr=>FR_FR {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
40        def_fakers!(@m zh_tw=>ZH_TW {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
41        def_fakers!(@m zh_cn=>ZH_CN {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
42        def_fakers!(@m ar_sa=>AR_SA {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
43        def_fakers!(@m ja_jp=>JA_JP {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
44        def_fakers!(@m pt_br=>PT_BR {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
45        def_fakers!(@m pt_pt=>PT_PT {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
46        def_fakers!(@m de_de=>DE_DE {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
47        def_fakers!(@m it_it=>IT_IT {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
48        def_fakers!(@m cy_gb=>CY_GB {$($name$(< $($lts),* >)?($($arg:$typ),*);)+});
49
50    };
51}
52
53pub mod impls;
54
55pub mod address {
56    def_fakers! {
57        CityPrefix();
58        CitySuffix();
59        CityName();
60        CountryName();
61        CountryCode();
62        StreetSuffix();
63        StreetName();
64        TimeZone();
65        StateName();
66        StateAbbr();
67        SecondaryAddressType();
68        SecondaryAddress();
69        ZipCode();
70        PostCode();
71        BuildingNumber();
72        Latitude();
73        Longitude();
74        Geohash(precision: u8);
75    }
76}
77
78pub mod barcode {
79    def_fakers! {
80        Isbn();
81        Isbn10();
82        Isbn13();
83    }
84}
85
86pub mod boolean {
87    def_fakers! {
88        Boolean(ratio: u8);
89    }
90}
91
92#[cfg(feature = "random_color")]
93pub mod color {
94    def_fakers! {
95        HexColor();
96        RgbColor();
97        RgbaColor();
98        HslColor();
99        HslaColor();
100        Color();
101    }
102}
103
104#[cfg(feature = "chrono")]
105pub mod chrono {
106    def_fakers! {
107        Time();
108        Date();
109        DateTime();
110        Duration();
111        DateTimeBefore(dt: chrono::DateTime<chrono::Utc>);
112        DateTimeAfter(dt: chrono::DateTime<chrono::Utc>);
113        DateTimeBetween(start: chrono::DateTime<chrono::Utc>, end: chrono::DateTime<chrono::Utc>);
114    }
115}
116
117#[cfg(feature = "time")]
118pub mod time {
119    def_fakers! {
120        Time();
121        Date();
122        DateTime();
123        Duration();
124        DateTimeBefore(dt: time::OffsetDateTime);
125        DateTimeAfter(dt: time::OffsetDateTime);
126        DateTimeBetween(start: time::OffsetDateTime, end: time::OffsetDateTime);
127    }
128}
129
130pub mod creditcard {
131    def_fakers! {
132        CreditCardNumber();
133    }
134}
135
136pub mod company {
137    def_fakers! {
138        CompanySuffix();
139        CompanyName();
140        Buzzword();
141        BuzzwordMiddle();
142        BuzzwordTail();
143        CatchPhrase();
144        BsVerb();
145        BsAdj();
146        BsNoun();
147        Bs();
148        Profession();
149        Industry();
150    }
151}
152
153#[cfg(feature = "http")]
154pub mod http {
155    def_fakers! {
156        RfcStatusCode();
157        ValidStatusCode();
158    }
159}
160
161pub mod internet {
162    def_fakers! {
163        FreeEmailProvider();
164        DomainSuffix();
165        FreeEmail();
166        SafeEmail();
167        Username();
168        Password(len_range: std::ops::Range<usize>);
169        IPv4();
170        IPv6();
171        IP();
172        MACAddress();
173        UserAgent();
174    }
175}
176
177pub mod job {
178    def_fakers! {
179        Seniority();
180        Field();
181        Position();
182        Title();
183    }
184}
185
186pub mod lorem {
187    def_fakers! {
188        Word();
189        Words(count: std::ops::Range<usize>);
190        Sentence(count: std::ops::Range<usize>);
191        Sentences(count: std::ops::Range<usize>);
192        Paragraph(count: std::ops::Range<usize>);
193        Paragraphs(count: std::ops::Range<usize>);
194    }
195}
196
197pub mod markdown {
198    def_fakers! {
199        ItalicWord();
200        BoldWord();
201        Link();
202        BulletPoints(count: std::ops::Range<usize>);
203        ListItems(count: std::ops::Range<usize>);
204        BlockQuoteSingleLine(count: std::ops::Range<usize>);
205        BlockQuoteMultiLine(count: std::ops::Range<usize>);
206        Code(count: std::ops::Range<usize>);
207    }
208}
209
210pub mod name {
211    def_fakers! {
212        FirstName();
213        LastName();
214        Title();
215        Suffix();
216        Name();
217        NameWithTitle();
218    }
219}
220
221pub mod number {
222    def_fakers! {
223        Digit();
224        NumberWithFormat<'a>(fmt: &'a str);
225    }
226}
227
228pub mod phone_number {
229    def_fakers! {
230        PhoneNumber();
231        CellNumber();
232    }
233}
234
235pub mod filesystem {
236    def_fakers! {
237        FilePath();
238        FileName();
239        FileExtension();
240        DirPath();
241        MimeType();
242        Semver();
243        SemverStable();
244        SemverUnstable();
245    }
246}
247
248pub mod currency {
249    def_fakers! {
250        CurrencyCode();
251        CurrencyName();
252        CurrencySymbol();
253    }
254}
255
256pub mod finance {
257    def_fakers! {
258        Bic();
259        Isin();
260    }
261}
262
263pub mod administrative {
264    def_fakers! {
265        HealthInsuranceCode();
266    }
267}
268
269pub mod automotive {
270    def_fakers! {
271        LicencePlate();
272    }
273}