From a2a9f7b6de7165303efe3d53be0ac98be588a973 Mon Sep 17 00:00:00 2001 From: Till von Ahnen Date: Sat, 11 Dec 2021 14:11:32 +0100 Subject: [PATCH 1/7] Added foundation for DE_DE data --- fake/src/faker/mod.rs | 27 +++--- fake/src/locales/de_de.rs | 96 ++++++++++++++++++++++ fake/src/locales/mod.rs | 3 + fake/tests/de_manual_test.rs | 25 ++++++ fake/tests/determinism.rs | 154 ++++++++++++++++++----------------- 5 files changed, 216 insertions(+), 89 deletions(-) create mode 100644 fake/src/locales/de_de.rs create mode 100644 fake/tests/de_manual_test.rs diff --git a/fake/src/faker/mod.rs b/fake/src/faker/mod.rs index cf21a32..6f81816 100644 --- a/fake/src/faker/mod.rs +++ b/fake/src/faker/mod.rs @@ -39,6 +39,7 @@ macro_rules! def_fakers { def_fakers!(@m fr_fr=>FR_FR {$($name($($arg:$typ),*);)+}); def_fakers!(@m zh_tw=>ZH_TW {$($name($($arg:$typ),*);)+}); def_fakers!(@m zh_cn=>ZH_CN {$($name($($arg:$typ),*);)+}); + def_fakers!(@m de_de=>DE_DE {$($name($($arg:$typ),*);)+}); }; } @@ -127,19 +128,19 @@ pub mod http { pub mod internet { def_fakers! { - FreeEmailProvider(); - DomainSuffix(); - FreeEmail(); - SafeEmail(); - Username(); - Password(len_range: std::ops::Range); - IPv4(); - IPv6(); - IP(); - MACAddress(); - Color(); - UserAgent(); - } + FreeEmailProvider(); + DomainSuffix(); + FreeEmail(); + SafeEmail(); + Username(); + Password(len_range: std::ops::Range); + IPv4(); + IPv6(); + IP(); + MACAddress(); + Color(); + UserAgent(); + } } pub mod job { diff --git a/fake/src/locales/de_de.rs b/fake/src/locales/de_de.rs new file mode 100644 index 0000000..ed732aa --- /dev/null +++ b/fake/src/locales/de_de.rs @@ -0,0 +1,96 @@ +use crate::locales::Data; + +#[allow(non_camel_case_types)] +#[derive(Copy, Clone)] +pub struct DE_DE; + +impl Data for DE_DE { + const NAME_FIRST_NAME: &'static [&'static str] = &[ + "Erika", // German ID Card + "André", + "Johanna", + "Edeltraut", + "Lisbeth", + "Ağça", + "Hans", + "Günther", + "Annekathrin", + "Karl", + "Lilly", + "Hildegard", + "Maija", // EU Citizen Card + "Tomáš", + "Karel", + "Maria", + "Elena", + "Inês", + "Paddy", + "Åsa", + ]; + const NAME_LAST_NAME: &'static [&'static str] = &[ + "Mustermann", // German ID Card + "Musterfrau", + "Gabler", + "Müller-Schwarzenberg", + "Ćosić", + "Özm̂en", + "Drebenbusch-Dalgoßen", + "Lerch", + "Hillebrandt", + "Schuster", + "Meikäläinen", // EU Citizen Card + "Vomáčka", + "Rudaí", + "Lærke", + ]; + const NAME_TITLE: &'static [&'static str] = &["Frau", "Herr"]; + + const ADDRESS_STATE: &'static [&'static str] = &[ + "Baden-Württemberg", + "Bayern", + "Berlin", + "Brandenburg", + "Bremen", + "Hamburg", + "Hessen", + "Mecklenburg-Vorpommern", + "Niedersachsen", + "Nordrhein-Westfalen", + "Rheinland-Pfalz", + "Saarland", + "Sachsen", + "Sachsen-Anhalt", + "Schleswig-Holstein", + "Thüringen", + ]; + + const ADDRESS_STATE_ABBR: &'static [&'static str] = &[ + "BW", "BY", "BE", "BB", "HB", "HH", "HE", "MV", "NI", "NW", "RP", "SL", "SN", "ST", "SH", + "TH", + ]; + + const ADDRESS_COUNTRY: &'static [&'static str] = &["Deutschland", "Germany"]; + const ADDRESS_CITY_TPL: &'static str = "{CityName} {CitySuffix}"; + const ADDRESS_ZIP_FORMATS: &'static [&'static str] = &["#####"]; + const ADDRESS_STREET_SUFFIX: &'static [&'static str] = &[ + "allee", "gang", "gasse", "pfad", "platz", "steg", "straße", "ufer", "weg", + ]; + const ADDRESS_SECONDARY_ADDR_TYPE: &'static [&'static str] = + &["Hof", "Gebäude", "Etage", "Eingang", "Aufgang"]; + + const ADDRESS_STREET_TPL: &'static str = "{StreetName}{StreetSuffix}"; + + const COMPANY_SUFFIX: &'static [&'static str] = &[ + "OHG", + "KG", + "GbR", + "AG", + "GmbH", + "UG", + "eG", + "Stiftung", + "e.V.", + "und Partner", + "& Partner", + ]; +} diff --git a/fake/src/locales/mod.rs b/fake/src/locales/mod.rs index 05ef2b8..33ea5cf 100644 --- a/fake/src/locales/mod.rs +++ b/fake/src/locales/mod.rs @@ -210,3 +210,6 @@ pub use self::zh_cn::ZH_CN; mod ja_jp; pub use self::ja_jp::JA_JP; + +mod de_de; +pub use self::de_de::DE_DE; diff --git a/fake/tests/de_manual_test.rs b/fake/tests/de_manual_test.rs new file mode 100644 index 0000000..4476752 --- /dev/null +++ b/fake/tests/de_manual_test.rs @@ -0,0 +1,25 @@ +use fake::faker::address::raw::{CityName, StateName, StreetName, ZipCode}; +use fake::faker::company::raw::CompanyName; +use fake::locales::DE_DE; +use fake::Fake; +#[allow(unused)] +#[derive(Debug)] +pub struct Company { + name: String, + street: String, + zipcode: String, + city: String, + state: String, +} + +#[test] +fn de_manual_test() { + let c = Company { + name: CompanyName(DE_DE).fake(), + street: StreetName(DE_DE).fake(), + zipcode: ZipCode(DE_DE).fake(), + city: CityName(DE_DE).fake(), + state: StateName(DE_DE).fake(), + }; + println!("{:?}", c); +} diff --git a/fake/tests/determinism.rs b/fake/tests/determinism.rs index 34097eb..5f69ba4 100644 --- a/fake/tests/determinism.rs +++ b/fake/tests/determinism.rs @@ -26,12 +26,14 @@ macro_rules! check_determinism { ($op:expr; $name:ident, $ty:ty) => { check_determinism!(one $name, $ty, $op); }; - (l10d $op:expr; $ty:ty, $name_en:ident, $name_fr:ident, $name_cn:ident, $name_tw:ident, $name_ja:ident $(, $attrs:expr)*) => { + (l10d $op:expr; $ty:ty, $name_en:ident, $name_fr:ident, $name_cn:ident, $name_tw:ident, $name_ja:ident, $name_de:ident $(, $attrs:expr)*) => { check_determinism!(one $name_en, $ty, $op(EN $(, $attrs)*)); check_determinism!(one $name_fr, $ty, $op(FR_FR $(, $attrs)*)); check_determinism!(one $name_cn, $ty, $op(ZH_CN $(, $attrs)*)); check_determinism!(one $name_tw, $ty, $op(ZH_TW $(, $attrs)*)); check_determinism!(one $name_ja, $ty, $op(JA_JP $(, $attrs)*)); + check_determinism!(one $name_de, $ty, $op(DE_DE $(, $attrs)*)); + }; } @@ -46,24 +48,24 @@ check_determinism! { one fake_u64_range, u64, (1u64..54683546546434) } // Address use fake::faker::address::raw::*; -check_determinism! { l10d BuildingNumber; String, fake_buildingnumber_en, fake_buildingnumber_fr, fake_buildingnumber_cn, fake_buildingnumber_tw, fake_buildingnumber_jp } -check_determinism! { l10d CityName; String, fake_cityname_en, fake_cityname_fr, fake_cityname_cn, fake_cityname_tw, fake_cityname_jp } -check_determinism! { l10d CityPrefix; String, fake_cityprefix_en, fake_cityprefix_fr, fake_cityprefix_cn, fake_cityprefix_tw, fake_cityprefix_jp } -check_determinism! { l10d CitySuffix; String, fake_citysuffix_en, fake_citysuffix_fr, fake_citysuffix_cn, fake_citysuffix_tw, fake_citysuffix_jp } -check_determinism! { l10d CountryCode; String, fake_countrycode_en, fake_countrycode_fr, fake_countrycode_cn, fake_countrycode_tw, fake_countrycode_jp } -check_determinism! { l10d CountryName; String, fake_countryname_en, fake_countryname_fr, fake_countryname_cn, fake_countryname_tw, fake_countryname_jp } -check_determinism! { l10d Geohash; String, fake_geohash_en, fake_geohash_fr, fake_geohash_cn, fake_geohash_tw, fake_geohash_jp, 11 } -check_determinism! { l10d Latitude; String, fake_latitude_en, fake_latitude_fr, fake_latitude_cn, fake_latitude_tw, fake_latitude_jp } -check_determinism! { l10d Longitude; String, fake_longitude_en, fake_longitude_fr, fake_longitude_cn, fake_longitude_tw, fake_longitude_jp } -check_determinism! { l10d PostCode; String, fake_postcode_en, fake_postcode_fr, fake_postcode_cn, fake_postcode_tw, fake_postcode_jp } -check_determinism! { l10d SecondaryAddress; String, fake_secondary_address_en, fake_secondary_address_fr, fake_secondary_address_cn, fake_secondary_address_tw, fake_secondary_address_jp } -check_determinism! { l10d SecondaryAddressType; String, fake_secondary_address_type_en, fake_secondary_address_type_fr, fake_secondary_address_type_cn, fake_secondary_address_type_tw, fake_secondary_address_type_jp } -check_determinism! { l10d StateAbbr; String, fake_state_abbr_en, fake_state_abbr_fr, fake_state_abbr_cn, fake_state_abbr_tw, fake_state_abbr_jp } -check_determinism! { l10d StateName; String, fake_state_name_en, fake_state_name_fr, fake_state_name_cn, fake_state_name_tw, fake_state_name_jp } -check_determinism! { l10d StreetName; String, fake_street_name_en, fake_street_name_fr, fake_street_name_cn, fake_street_name_tw, fake_street_name_jp } -check_determinism! { l10d StreetSuffix; String, fake_street_suffix_en, fake_street_suffix_fr, fake_street_suffix_cn, fake_street_suffix_tw, fake_street_suffix_jp } -check_determinism! { l10d TimeZone; String, fake_time_zone_en, fake_time_zone_fr, fake_time_zone_cn, fake_time_zone_tw, fake_time_zone_jp } -check_determinism! { l10d ZipCode; String, fake_zip_code_en, fake_zip_code_fr, fake_zip_code_cn, fake_zip_code_tw, fake_zip_code_jp } +check_determinism! { l10d BuildingNumber; String, fake_buildingnumber_en, fake_buildingnumber_fr, fake_buildingnumber_cn, fake_buildingnumber_tw, fake_buildingnumber_jp , fake_buildingnumber_de} +check_determinism! { l10d CityName; String, fake_cityname_en, fake_cityname_fr, fake_cityname_cn, fake_cityname_tw, fake_cityname_jp, fake_cityname_de } +check_determinism! { l10d CityPrefix; String, fake_cityprefix_en, fake_cityprefix_fr, fake_cityprefix_cn, fake_cityprefix_tw, fake_cityprefix_jp, fake_cityprefix_de} +check_determinism! { l10d CitySuffix; String, fake_citysuffix_en, fake_citysuffix_fr, fake_citysuffix_cn, fake_citysuffix_tw, fake_citysuffix_jp, fake_citysuffix_de } +check_determinism! { l10d CountryCode; String, fake_countrycode_en, fake_countrycode_fr, fake_countrycode_cn, fake_countrycode_tw, fake_countrycode_jp, fake_countrycode_de } +check_determinism! { l10d CountryName; String, fake_countryname_en, fake_countryname_fr, fake_countryname_cn, fake_countryname_tw, fake_countryname_jp, fake_countryname_de } +check_determinism! { l10d Geohash; String, fake_geohash_en, fake_geohash_fr, fake_geohash_cn, fake_geohash_tw, fake_geohash_jp, fake_geohash_de, 11 } +check_determinism! { l10d Latitude; String, fake_latitude_en, fake_latitude_fr, fake_latitude_cn, fake_latitude_tw, fake_latitude_jp, fake_latitude_de } +check_determinism! { l10d Longitude; String, fake_longitude_en, fake_longitude_fr, fake_longitude_cn, fake_longitude_tw, fake_longitude_jp, fake_longitude_de } +check_determinism! { l10d PostCode; String, fake_postcode_en, fake_postcode_fr, fake_postcode_cn, fake_postcode_tw, fake_postcode_jp, fake_postcode_de } +check_determinism! { l10d SecondaryAddress; String, fake_secondary_address_en, fake_secondary_address_fr, fake_secondary_address_cn, fake_secondary_address_tw, fake_secondary_address_jp, fake_secondary_address_de } +check_determinism! { l10d SecondaryAddressType; String, fake_secondary_address_type_en, fake_secondary_address_type_fr, fake_secondary_address_type_cn, fake_secondary_address_type_tw, fake_secondary_address_type_jp, fake_secondary_address_type_de } +check_determinism! { l10d StateAbbr; String, fake_state_abbr_en, fake_state_abbr_fr, fake_state_abbr_cn, fake_state_abbr_tw, fake_state_abbr_jp, fake_state_abbr_de } +check_determinism! { l10d StateName; String, fake_state_name_en, fake_state_name_fr, fake_state_name_cn, fake_state_name_tw, fake_state_name_jp, fake_state_name_de } +check_determinism! { l10d StreetName; String, fake_street_name_en, fake_street_name_fr, fake_street_name_cn, fake_street_name_tw, fake_street_name_jp, fake_street_name_de } +check_determinism! { l10d StreetSuffix; String, fake_street_suffix_en, fake_street_suffix_fr, fake_street_suffix_cn, fake_street_suffix_tw, fake_street_suffix_jp, fake_street_suffix_de } +check_determinism! { l10d TimeZone; String, fake_time_zone_en, fake_time_zone_fr, fake_time_zone_cn, fake_time_zone_tw, fake_time_zone_jp, fake_time_zone_de } +check_determinism! { l10d ZipCode; String, fake_zip_code_en, fake_zip_code_fr, fake_zip_code_cn, fake_zip_code_tw, fake_zip_code_jp, fake_zip_code_de } // Administrative use fake::faker::administrative::raw::*; @@ -78,9 +80,9 @@ check_determinism! { one fake_license_plate_fr, String, LicencePlate(FR_FR) } // Barcode use fake::faker::barecode::raw::*; -check_determinism! { l10d Isbn; String, fake_isbn_en, fake_isbn_fr, fake_isbn_cn, fake_isbn_tw, fake_isbn_jp } -check_determinism! { l10d Isbn10; String, fake_isbn10_en, fake_isbn10_fr, fake_isbn10_cn, fake_isbn10_tw, fake_isbn10_jp } -check_determinism! { l10d Isbn13; String, fake_isbn13_en, fake_isbn13_fr, fake_isbn13_cn, fake_isbn13_tw, fake_isbn13_jp } +check_determinism! { l10d Isbn; String, fake_isbn_en, fake_isbn_fr, fake_isbn_cn, fake_isbn_tw, fake_isbn_jp, fake_isbn_de } +check_determinism! { l10d Isbn10; String, fake_isbn10_en, fake_isbn10_fr, fake_isbn10_cn, fake_isbn10_tw, fake_isbn10_jp, fake_isbn10_de } +check_determinism! { l10d Isbn13; String, fake_isbn13_en, fake_isbn13_fr, fake_isbn13_cn, fake_isbn13_tw, fake_isbn13_jp, fake_isbn13_de } // Chrono #[cfg(feature = "chrono")] @@ -111,18 +113,18 @@ mod chrono { // Company use fake::faker::company::raw::*; -check_determinism! { l10d Bs; String, fake_bs_en, fake_bs_fr, fake_bs_cn, fake_bs_tw, fake_bs_jp } -check_determinism! { l10d BsAdj; String, fake_bs_adj_en, fake_bs_adj_fr, fake_bs_adj_cn, fake_bs_adj_tw, fake_bs_adj_jp } -check_determinism! { l10d BsNoun; String, fake_bs_noun_en, fake_bs_noun_fr, fake_bs_noun_cn, fake_bs_noun_tw, fake_bs_noun_jp } -check_determinism! { l10d BsVerb; String, fake_bs_verb_en, fake_bs_verb_fr, fake_bs_verb_cn, fake_bs_verb_tw, fake_bs_verb_jp } -check_determinism! { l10d Buzzword; String, fake_buzzword_en, fake_buzzword_fr, fake_buzzword_cn, fake_buzzword_tw, fake_buzzword_jp } -check_determinism! { l10d BuzzwordMiddle; String, fake_buzzword_middle_en, fake_buzzword_middle_fr, fake_buzzword_middle_cn, fake_buzzword_middle_tw, fake_buzzword_middle_jp } -check_determinism! { l10d BuzzwordTail; String, fake_buzzword_tail_en, fake_buzzword_tail_fr, fake_buzzword_tail_cn, fake_buzzword_tail_tw, fake_buzzword_tail_jp } -check_determinism! { l10d CatchPhase; String, fake_catchphrase_en, fake_catchphrase_fr, fake_catchphrase_cn, fake_catchphrase_tw, fake_catchphrase_jp } -check_determinism! { l10d CompanyName; String, fake_company_name_en, fake_company_name_fr, fake_company_name_cn, fake_company_name_tw, fake_company_name_jp } -check_determinism! { l10d CompanySuffix; String, fake_company_suffix_en, fake_company_suffix_fr, fake_company_suffix_cn, fake_company_suffix_tw, fake_company_suffix_jp } -check_determinism! { l10d Industry; String, fake_industry_en, fake_industry_fr, fake_industry_cn, fake_industry_tw, fake_industry_jp } -check_determinism! { l10d Profession; String, fake_profession_en, fake_profession_fr, fake_profession_cn, fake_profession_tw, fake_profession_jp } +check_determinism! { l10d Bs; String, fake_bs_en, fake_bs_fr, fake_bs_cn, fake_bs_tw, fake_bs_jp, fake_bs_de } +check_determinism! { l10d BsAdj; String, fake_bs_adj_en, fake_bs_adj_fr, fake_bs_adj_cn, fake_bs_adj_tw, fake_bs_adj_jp, fake_bs_adj_de } +check_determinism! { l10d BsNoun; String, fake_bs_noun_en, fake_bs_noun_fr, fake_bs_noun_cn, fake_bs_noun_tw, fake_bs_noun_jp,fake_bs_noun_de } +check_determinism! { l10d BsVerb; String, fake_bs_verb_en, fake_bs_verb_fr, fake_bs_verb_cn, fake_bs_verb_tw, fake_bs_verb_jp, fake_bs_verb_de } +check_determinism! { l10d Buzzword; String, fake_buzzword_en, fake_buzzword_fr, fake_buzzword_cn, fake_buzzword_tw, fake_buzzword_jp, fake_buzzword_de } +check_determinism! { l10d BuzzwordMiddle; String, fake_buzzword_middle_en, fake_buzzword_middle_fr, fake_buzzword_middle_cn, fake_buzzword_middle_tw, fake_buzzword_middle_jp,fake_buzzword_middle_de } +check_determinism! { l10d BuzzwordTail; String, fake_buzzword_tail_en, fake_buzzword_tail_fr, fake_buzzword_tail_cn, fake_buzzword_tail_tw, fake_buzzword_tail_jp, fake_buzzword_tail_de} +check_determinism! { l10d CatchPhase; String, fake_catchphrase_en, fake_catchphrase_fr, fake_catchphrase_cn, fake_catchphrase_tw, fake_catchphrase_jp, fake_catchphrase_de } +check_determinism! { l10d CompanyName; String, fake_company_name_en, fake_company_name_fr, fake_company_name_cn, fake_company_name_tw, fake_company_name_jp, fake_company_name_de } +check_determinism! { l10d CompanySuffix; String, fake_company_suffix_en, fake_company_suffix_fr, fake_company_suffix_cn, fake_company_suffix_tw, fake_company_suffix_jp, fake_company_suffix_de } +check_determinism! { l10d Industry; String, fake_industry_en, fake_industry_fr, fake_industry_cn, fake_industry_tw, fake_industry_jp, fake_industry_de } +check_determinism! { l10d Profession; String, fake_profession_en, fake_profession_fr, fake_profession_cn, fake_profession_tw, fake_profession_jp, fake_profession_de } // Credit Card use fake::faker::creditcard::raw::*; @@ -133,24 +135,24 @@ check_determinism! { one fake_credit_card_number_en, String, CreditCardNumber(EN // Currency use fake::faker::currency::raw::*; -check_determinism! { l10d CurrencyCode; String, fake_currency_code_en, fake_currency_code_fr, fake_currency_code_cn, fake_currency_code_tw, fake_currency_code_jp } -check_determinism! { l10d CurrencyName; String, fake_currency_name_en, fake_currency_name_fr, fake_currency_name_cn, fake_currency_name_tw, fake_currency_name_jp } -check_determinism! { l10d CurrencySymbol; String, fake_currency_symbol_en, fake_currency_symbol_fr, fake_currency_symbol_cn, fake_currency_symbol_tw, fake_currency_symbol_jp } +check_determinism! { l10d CurrencyCode; String, fake_currency_code_en, fake_currency_code_fr, fake_currency_code_cn, fake_currency_code_tw, fake_currency_code_jp, fake_currency_code_de } +check_determinism! { l10d CurrencyName; String, fake_currency_name_en, fake_currency_name_fr, fake_currency_name_cn, fake_currency_name_tw, fake_currency_name_jp, fake_currency_name_de } +check_determinism! { l10d CurrencySymbol; String, fake_currency_symbol_en, fake_currency_symbol_fr, fake_currency_symbol_cn, fake_currency_symbol_tw, fake_currency_symbol_jp, fake_currency_symbol_de } // Filesystem use fake::faker::filesystem::raw::*; -check_determinism! { l10d DirPath; String, fake_dir_path_en, fake_dir_path_fr, fake_dir_path_cn, fake_dir_path_tw, fake_dir_path_jp } -check_determinism! { l10d FileExtension; String, fake_file_extension_en, fake_file_extension_fr, fake_file_extension_cn, fake_file_extension_tw, fake_file_extension_jp } -check_determinism! { l10d FileName; String, fake_file_name_en, fake_file_name_fr, fake_file_name_cn, fake_file_name_tw, fake_file_name_jp } -check_determinism! { l10d FilePath; String, fake_file_path_en, fake_file_path_fr, fake_file_path_cn, fake_file_path_tw, fake_file_path_jp } -check_determinism! { l10d MimeType; String, fake_mime_type_en, fake_mime_type_fr, fake_mime_type_cn, fake_mime_type_tw, fake_mime_type_jp } -check_determinism! { l10d Semver; String, fake_semver_en, fake_semver_fr, fake_semver_cn, fake_semver_tw, fake_semver_jp } +check_determinism! { l10d DirPath; String, fake_dir_path_en, fake_dir_path_fr, fake_dir_path_cn, fake_dir_path_tw, fake_dir_path_jp, fake_dir_path_de } +check_determinism! { l10d FileExtension; String, fake_file_extension_en, fake_file_extension_fr, fake_file_extension_cn, fake_file_extension_tw, fake_file_extension_jp, fake_file_extension_de } +check_determinism! { l10d FileName; String, fake_file_name_en, fake_file_name_fr, fake_file_name_cn, fake_file_name_tw, fake_file_name_jp,fake_file_name_de } +check_determinism! { l10d FilePath; String, fake_file_path_en, fake_file_path_fr, fake_file_path_cn, fake_file_path_tw, fake_file_path_jp,fake_file_path_de } +check_determinism! { l10d MimeType; String, fake_mime_type_en, fake_mime_type_fr, fake_mime_type_cn, fake_mime_type_tw, fake_mime_type_jp,fake_mime_type_de } +check_determinism! { l10d Semver; String, fake_semver_en, fake_semver_fr, fake_semver_cn, fake_semver_tw, fake_semver_jp, fake_semver_de } // Finance use fake::faker::finance::raw::*; -check_determinism! { l10d Bic; String, fake_bic_en, fake_bic_fr, fake_bic_cn, fake_bic_tw, fake_bic_jp } +check_determinism! { l10d Bic; String, fake_bic_en, fake_bic_fr, fake_bic_cn, fake_bic_tw, fake_bic_jp, fake_bic_de } // HTTP #[cfg(feature = "http")] @@ -165,18 +167,18 @@ mod http { // Internet use fake::faker::internet::raw::*; -check_determinism! { l10d Color; String, fake_color_en, fake_color_fr, fake_color_cn, fake_color_tw, fake_color_jp } -check_determinism! { l10d DomainSuffix; String, fake_domainsuffix_en, fake_domainsuffix_fr, fake_domainsuffix_cn, fake_domainsuffix_tw, fake_domainsuffix_jp } -check_determinism! { l10d FreeEmailProvider; String, fake_freeemailprovider_en, fake_freeemailprovider_fr, fake_freeemailprovider_cn, fake_freeemailprovider_tw, fake_freeemailprovider_jp } -check_determinism! { l10d FreeEmail; String, fake_freeemail_en, fake_freeemail_fr, fake_freeemail_cn, fake_freeemail_tw, fake_freeemail_jp } -check_determinism! { l10d IP; std::net::IpAddr, fake_ip_en, fake_ip_fr, fake_ip_cn, fake_ip_tw, fake_ip_jp } -check_determinism! { l10d IPv4; String, fake_ipv4_en, fake_ipv4_fr, fake_ipv4_cn, fake_ipv4_tw, fake_ipv4_jp } -check_determinism! { l10d IPv6; String, fake_ipv6_en, fake_ipv6_fr, fake_ipv6_cn, fake_ipv6_tw, fake_ipv6_jp } -check_determinism! { l10d MACAddress; String, fake_macaddress_en, fake_macaddress_fr, fake_macaddress_cn, fake_macaddress_tw, fake_macaddress_jp } -check_determinism! { l10d Password; String, fake_password_en, fake_password_fr, fake_password_cn, fake_password_tw, fake_password_jp, 6..12 } -check_determinism! { l10d SafeEmail; String, fake_safeemail_en, fake_safeemail_fr, fake_safeemail_cn, fake_safeemail_tw, fake_safeemail_jp } -check_determinism! { l10d UserAgent; String, fake_useragent_en, fake_useragent_fr, fake_useragent_cn, fake_useragent_tw, fake_useragent_jp } -check_determinism! { l10d Username; String, fake_username_en, fake_username_fr, fake_username_cn, fake_username_tw, fake_username_jp } +check_determinism! { l10d Color; String, fake_color_en, fake_color_fr, fake_color_cn, fake_color_tw, fake_color_jp,fake_color_de } +check_determinism! { l10d DomainSuffix; String, fake_domainsuffix_en, fake_domainsuffix_fr, fake_domainsuffix_cn, fake_domainsuffix_tw, fake_domainsuffix_jp, fake_domainsuffix_de } +check_determinism! { l10d FreeEmailProvider; String, fake_freeemailprovider_en, fake_freeemailprovider_fr, fake_freeemailprovider_cn, fake_freeemailprovider_tw, fake_freeemailprovider_jp, fake_freeemailprovider_de } +check_determinism! { l10d FreeEmail; String, fake_freeemail_en, fake_freeemail_fr, fake_freeemail_cn, fake_freeemail_tw, fake_freeemail_jp, fake_freeemail_de } +check_determinism! { l10d IP; std::net::IpAddr, fake_ip_en, fake_ip_fr, fake_ip_cn, fake_ip_tw, fake_ip_jp, fake_ip_de } +check_determinism! { l10d IPv4; String, fake_ipv4_en, fake_ipv4_fr, fake_ipv4_cn, fake_ipv4_tw, fake_ipv4_jp, fake_ipv4_de } +check_determinism! { l10d IPv6; String, fake_ipv6_en, fake_ipv6_fr, fake_ipv6_cn, fake_ipv6_tw, fake_ipv6_jp, fake_ipv6_de} +check_determinism! { l10d MACAddress; String, fake_macaddress_en, fake_macaddress_fr, fake_macaddress_cn, fake_macaddress_tw, fake_macaddress_jp, fake_macaddress_de} +check_determinism! { l10d Password; String, fake_password_en, fake_password_fr, fake_password_cn, fake_password_tw, fake_password_jp, fake_password_de, 6..12 } +check_determinism! { l10d SafeEmail; String, fake_safeemail_en, fake_safeemail_fr, fake_safeemail_cn, fake_safeemail_tw, fake_safeemail_jp, fake_safeemail_de } +check_determinism! { l10d UserAgent; String, fake_useragent_en, fake_useragent_fr, fake_useragent_cn, fake_useragent_tw, fake_useragent_jp, fake_useragent_de } +check_determinism! { l10d Username; String, fake_username_en, fake_username_fr, fake_username_cn, fake_username_tw, fake_username_jp, fake_username_de} // it's sufficient to check one language, because it doesn't change anything #[cfg(feature = "uuid")] mod uuid { @@ -194,43 +196,43 @@ mod job { use fake::{faker::job::raw::*, locales::*, Fake}; use rand::SeedableRng as _; - check_determinism! { l10d Field; String, fake_field_en, fake_field_fr, fake_field_cn, fake_field_tw, fake_field_jp } - check_determinism! { l10d Position; String, fake_position_en, fake_position_fr, fake_position_cn, fake_position_tw, fake_position_jp } - check_determinism! { l10d Seniority; String, fake_seniority_en, fake_seniority_fr, fake_seniority_cn, fake_seniority_tw, fake_seniority_jp } - check_determinism! { l10d Title; String, fake_title_en, fake_title_fr, fake_title_cn, fake_title_tw, fake_title_jp } + check_determinism! { l10d Field; String, fake_field_en, fake_field_fr, fake_field_cn, fake_field_tw, fake_field_jp,fake_field_de } + check_determinism! { l10d Position; String, fake_position_en, fake_position_fr, fake_position_cn, fake_position_tw, fake_position_jp, fake_position_de } + check_determinism! { l10d Seniority; String, fake_seniority_en, fake_seniority_fr, fake_seniority_cn, fake_seniority_tw, fake_seniority_jp, fake_seniority_de } + check_determinism! { l10d Title; String, fake_title_en, fake_title_fr, fake_title_cn, fake_title_tw, fake_title_jp, fake_title_de } } // Lorem use fake::faker::lorem::raw::*; -check_determinism! { l10d Paragraph; String, fake_paragraph_en, fake_paragraph_fr, fake_paragraph_cn, fake_paragraph_tw, fake_paragraph_jp, 1..3 } -check_determinism! { l10d Paragraphs; Vec, fake_paragraphs_en, fake_paragraphs_fr, fake_paragraphs_cn, fake_paragraphs_tw, fake_paragraphs_jp, 1..3 } -check_determinism! { l10d Sentence; String, fake_sentence_en, fake_sentence_fr, fake_sentence_cn, fake_sentence_tw, fake_sentence_jp, (1..3) } -check_determinism! { l10d Sentences; Vec, fake_sentences_en, fake_sentences_fr, fake_sentences_cn, fake_sentences_tw, fake_sentences_jp, (1..3) } -check_determinism! { l10d Word; String, fake_word_en, fake_word_fr, fake_word_cn, fake_word_tw, fake_word_jp } -check_determinism! { l10d Words; Vec, fake_words_en, fake_words_fr, fake_words_cn, fake_words_tw, fake_words_jp, (1..3) } +check_determinism! { l10d Paragraph; String, fake_paragraph_en, fake_paragraph_fr, fake_paragraph_cn, fake_paragraph_tw, fake_paragraph_jp, fake_paragraph_de, 1..3 } +check_determinism! { l10d Paragraphs; Vec, fake_paragraphs_en, fake_paragraphs_fr, fake_paragraphs_cn, fake_paragraphs_tw, fake_paragraphs_jp,fake_paragraphs_de, 1..3 } +check_determinism! { l10d Sentence; String, fake_sentence_en, fake_sentence_fr, fake_sentence_cn, fake_sentence_tw, fake_sentence_jp, fake_sentence_de, (1..3) } +check_determinism! { l10d Sentences; Vec, fake_sentences_en, fake_sentences_fr, fake_sentences_cn, fake_sentences_tw, fake_sentences_jp,fake_sentences_de,(1..3) } +check_determinism! { l10d Word; String, fake_word_en, fake_word_fr, fake_word_cn, fake_word_tw, fake_word_jp, fake_word_de } +check_determinism! { l10d Words; Vec, fake_words_en, fake_words_fr, fake_words_cn, fake_words_tw, fake_words_jp, fake_words_de, (1..3) } // Names mod name { use fake::{faker::name::raw::*, locales::*, Fake}; use rand::SeedableRng as _; - check_determinism! { l10d Name; String, fake_name_en, fake_name_fr, fake_name_cn, fake_name_tw, fake_name_jp } - check_determinism! { l10d FirstName; String, fake_first_name_en, fake_first_name_fr, fake_first_name_cn, fake_first_name_tw, fake_first_name_jp } - check_determinism! { l10d LastName; String, fake_last_name_en, fake_last_name_fr, fake_last_name_cn, fake_last_name_tw, fake_last_name_jp } - check_determinism! { l10d NameWithTitle; String, fake_name_with_title_en, fake_name_with_title_fr, fake_name_with_title_cn, fake_name_with_title_tw, fake_name_with_title_jp } - check_determinism! { l10d Title; String, fake_title_en, fake_title_fr, fake_title_cn, fake_title_tw, fake_title_jp } - check_determinism! { l10d Suffix; String, fake_suffix_en, fake_suffix_fr, fake_suffix_cn, fake_suffix_tw, fake_suffix_jp } + check_determinism! { l10d Name; String, fake_name_en, fake_name_fr, fake_name_cn, fake_name_tw, fake_name_jp, fake_name_de } + check_determinism! { l10d FirstName; String, fake_first_name_en, fake_first_name_fr, fake_first_name_cn, fake_first_name_tw, fake_first_name_jp, fake_first_name_de } + check_determinism! { l10d LastName; String, fake_last_name_en, fake_last_name_fr, fake_last_name_cn, fake_last_name_tw, fake_last_name_jp , fake_last_name_de} + check_determinism! { l10d NameWithTitle; String, fake_name_with_title_en, fake_name_with_title_fr, fake_name_with_title_cn, fake_name_with_title_tw, fake_name_with_title_jp, fake_name_with_title_de } + check_determinism! { l10d Title; String, fake_title_en, fake_title_fr, fake_title_cn, fake_title_tw, fake_title_jp, fake_title_de } + check_determinism! { l10d Suffix; String, fake_suffix_en, fake_suffix_fr, fake_suffix_cn, fake_suffix_tw, fake_suffix_jp, fake_suffix_jde} } // Numbers use fake::faker::number::raw::*; -check_determinism! { l10d Digit; String, fake_digit_en, fake_digit_fr, fake_digit_cn, fake_digit_tw, fake_digit_jp } -check_determinism! { l10d NumberWithFormat; String, fake_number_en, fake_number_fr, fake_number_cn, fake_number_tw, fake_number_jp, "{}" } +check_determinism! { l10d Digit; String, fake_digit_en, fake_digit_fr, fake_digit_cn, fake_digit_tw, fake_digit_jp,fake_digit_de } +check_determinism! { l10d NumberWithFormat; String, fake_number_en, fake_number_fr, fake_number_cn, fake_number_tw, fake_number_jp,fake_number_de, "{}" } // Phone Numbers use fake::faker::phone_number::raw::*; -check_determinism! { l10d CellNumber; String, fake_cell_number_en, fake_cell_number_fr, fake_cell_number_cn, fake_cell_number_tw, fake_cell_number_jp } -check_determinism! { l10d PhoneNumber; String, fake_phone_number_en, fake_phone_number_fr, fake_phone_number_cn, fake_phone_number_tw, fake_phone_number_jp } +check_determinism! { l10d CellNumber; String, fake_cell_number_en, fake_cell_number_fr, fake_cell_number_cn, fake_cell_number_tw, fake_cell_number_jp, fake_cell_number_de } +check_determinism! { l10d PhoneNumber; String, fake_phone_number_en, fake_phone_number_fr, fake_phone_number_cn, fake_phone_number_tw, fake_phone_number_jp, fake_phone_number_de } From b9b45bd3c62f7fa62e1729b0793e0fa5061b04a1 Mon Sep 17 00:00:00 2001 From: Till von Ahnen Date: Sat, 18 Dec 2021 16:45:59 +0100 Subject: [PATCH 2/7] Added common german first and lastnames Added german CityPrefix and Suffixes --- fake/src/locales/de_de.rs | 210 +++++++++++++++++++++++++++++++++++++- 1 file changed, 208 insertions(+), 2 deletions(-) diff --git a/fake/src/locales/de_de.rs b/fake/src/locales/de_de.rs index ed732aa..e6f9d30 100644 --- a/fake/src/locales/de_de.rs +++ b/fake/src/locales/de_de.rs @@ -1,5 +1,4 @@ use crate::locales::Data; - #[allow(non_camel_case_types)] #[derive(Copy, Clone)] pub struct DE_DE; @@ -26,6 +25,106 @@ impl Data for DE_DE { "Inês", "Paddy", "Åsa", + "Maria", + "Ursula", // 50 most common female first names + "Monika", + "Petra", + "Elisabeth", + "Sabine", + "Renate", + "Helga", + "Karin", + "Brigitte", + "Ingrid", + "Erika", + "Andrea", + "Gisela", + "Claudia", + "Susanne", + "Gabriele", + "Christa", + "Christine", + "Hildegard", + "Anna", + "Birgit", + "Barbara", + "Gertrud", + "Heike", + "Marianne", + "Elke", + "Martina", + "Angelika", + "Irmgard", + "Inge", + "Ute", + "Elfriede", + "Doris", + "Marion", + "Ruth", + "Ulrike", + "Hannelore", + "Jutta", + "Gerda", + "Kerstin", + "Ilse", + "Anneliese", + "Margarete", + "Ingeborg", + "Anja", + "Edith", + "Sandra", + "Waltraud", + "Beate", + "Peter", + "Wolfgang", // 50 most common male firstnames + "Michael", + "Werner", + "Klaus", + "Thomas", + "Manfred", + "Helmut", + "Jürgen", + "Heinz", + "Gerhard", + "Andreas", + "Hans", + "Josef", + "Günter", + "Dieter", + "Horst", + "Walter", + "Frank", + "Bernd", + "Karl", + "Herbert", + "Franz", + "Martin", + "Uwe", + "Georg", + "Heinrich", + "Stefan", + "Christian", + "Karl-Heinz", + "Rudolf", + "Kurt", + "Hermann", + "Johann", + "Wilhelm", + "Siegfried", + "Rolf", + "Joachim", + "Alfred", + "Rainer", + "Jörg", + "Ralf", + "Erich", + "Norbert", + "Bernhard", + "Willi", + "Alexander", + "Ulrich", + "Markus", + "Matthias", ]; const NAME_LAST_NAME: &'static [&'static str] = &[ "Mustermann", // German ID Card @@ -42,6 +141,106 @@ impl Data for DE_DE { "Vomáčka", "Rudaí", "Lærke", + "Müller", + "Schmidt", // 100 most common german lastnames + "Schneider", + "Fischer", + "Weber", + "Meyer", + "Wagner", + "Becker", + "Schulz", + "Hoffmann", + "Schäfer", + "Bauer", + "Koch", + "Richter", + "Klein", + "Wolf", + "Schröder", + "Neumann", + "Schwarz", + "Braun", + "Hofmann", + "Zimmermann", + "Schmitt", + "Hartmann", + "Krüger", + "Schmid", + "Werner", + "Lange", + "Schmitz", + "Meier", + "Krause", + "Maier", + "Lehmann", + "Huber", + "Mayer", + "Herrmann", + "Köhler", + "Walter", + "König", + "Schulze", + "Fuchs", + "Kaiser", + "Lang", + "Weiß", + "Peters", + "Scholz", + "Jung", + "Möller", + "Hahn", + "Keller", + "Vogel", + "Schubert", + "Roth", + "Frank", + "Friedrich", + "Beck", + "Günther", + "Berger", + "Winkler", + "Lorenz", + "Baumann", + "Schuster", + "Kraus", + "Böhm", + "Simon", + "Franke", + "Albrecht", + "Winter", + "Ludwig", + "Martin", + "Krämer", + "Schumacher", + "Vogt", + "Jäger", + "Stein", + "Otto", + "Groß", + "Sommer", + "Haas", + "Graf", + "Heinrich", + "Seidel", + "Schreiber", + "Ziegler", + "Brandt", + "Kuhn", + "Schulte", + "Dietrich", + "Kühn", + "Engel", + "Pohl", + "Horn", + "Sauer", + "Arnold", + "Thomas", + "Bergmann", + "Busch", + "Pfeiffer", + "Voigt", + "Götz", ]; const NAME_TITLE: &'static [&'static str] = &["Frau", "Herr"]; @@ -70,7 +269,14 @@ impl Data for DE_DE { ]; const ADDRESS_COUNTRY: &'static [&'static str] = &["Deutschland", "Germany"]; - const ADDRESS_CITY_TPL: &'static str = "{CityName} {CitySuffix}"; + const ADDRESS_CITY_SUFFIX: &'static [&'static str] = &[ + "berg", "burg", "feld", "furt", "heim", "ing", "kirchen", "stadt", + ]; + + const ADDRESS_CITY_PREFIX: &'static [&'static str] = + &["Alt", "Groß", "Hohen", "Klein", "Neu", "Ober", "Unter"]; + const ADDRESS_CITY_WITH_PREFIX_TPL: &'static str = "{CityPrefix}{CityName}{CitySuffix}"; + const ADDRESS_CITY_TPL: &'static str = "{CityName}{CitySuffix}"; const ADDRESS_ZIP_FORMATS: &'static [&'static str] = &["#####"]; const ADDRESS_STREET_SUFFIX: &'static [&'static str] = &[ "allee", "gang", "gasse", "pfad", "platz", "steg", "straße", "ufer", "weg", From 177373e06d2f3c6e05a9796442d17959f66c189b Mon Sep 17 00:00:00 2001 From: Till von Ahnen Date: Sat, 18 Dec 2021 16:47:28 +0100 Subject: [PATCH 3/7] Changed address format and println output --- fake/tests/de_manual_test.rs | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/fake/tests/de_manual_test.rs b/fake/tests/de_manual_test.rs index 4476752..581638d 100644 --- a/fake/tests/de_manual_test.rs +++ b/fake/tests/de_manual_test.rs @@ -1,12 +1,15 @@ +use fake::faker::address::de_de::SecondaryAddress; use fake::faker::address::raw::{CityName, StateName, StreetName, ZipCode}; use fake::faker::company::raw::CompanyName; use fake::locales::DE_DE; use fake::Fake; + #[allow(unused)] #[derive(Debug)] pub struct Company { name: String, - street: String, + address_line_1: String, + address_line_2: String, zipcode: String, city: String, state: String, @@ -14,12 +17,19 @@ pub struct Company { #[test] fn de_manual_test() { - let c = Company { - name: CompanyName(DE_DE).fake(), - street: StreetName(DE_DE).fake(), - zipcode: ZipCode(DE_DE).fake(), - city: CityName(DE_DE).fake(), - state: StateName(DE_DE).fake(), - }; - println!("{:?}", c); + for _ in 1..10 { + let c = Company { + name: CompanyName(DE_DE).fake(), + address_line_1: format!( + "{} {}", + StreetName(DE_DE).fake::(), + (1..100).fake::() + ), + address_line_2: SecondaryAddress().fake(), + zipcode: ZipCode(DE_DE).fake(), + city: CityName(DE_DE).fake(), + state: StateName(DE_DE).fake(), + }; + println!("{:#?}", c); + } } From 29414da7f0630ac5f75d7841776b8102ce531d00 Mon Sep 17 00:00:00 2001 From: xoryouyou Date: Tue, 24 Dec 2024 23:18:02 +0100 Subject: [PATCH 4/7] added missing de determinism tests for the Lorem section --- fake/tests/determinism.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/fake/tests/determinism.rs b/fake/tests/determinism.rs index d744c2d..a0f52ef 100644 --- a/fake/tests/determinism.rs +++ b/fake/tests/determinism.rs @@ -255,12 +255,12 @@ mod job { // Lorem use fake::faker::lorem::raw::*; -check_determinism! { l10d Paragraph; String, fake_paragraph_en, fake_paragraph_fr, fake_paragraph_cn, fake_paragraph_tw, fake_paragraph_jp, 1..3 } -check_determinism! { l10d Paragraphs; Vec, fake_paragraphs_en, fake_paragraphs_fr, fake_paragraphs_cn, fake_paragraphs_tw, fake_paragraphs_jp, 1..3 } -check_determinism! { l10d Sentence; String, fake_sentence_en, fake_sentence_fr, fake_sentence_cn, fake_sentence_tw, fake_sentence_jp, (1..3) } -check_determinism! { l10d Sentences; Vec, fake_sentences_en, fake_sentences_fr, fake_sentences_cn, fake_sentences_tw, fake_sentences_jp, (1..3) } -check_determinism! { l10d Word; String, fake_word_en, fake_word_fr, fake_word_cn, fake_word_tw, fake_word_jp } -check_determinism! { l10d Words; Vec, fake_words_en, fake_words_fr, fake_words_cn, fake_words_tw, fake_words_jp, (1..3) } +check_determinism! { l10d Paragraph; String, fake_paragraph_en, fake_paragraph_fr, fake_paragraph_cn, fake_paragraph_tw, fake_paragraph_jp, fake_paragraph_br, fake_paragraph_de, 1..3 } +check_determinism! { l10d Paragraphs; Vec, fake_paragraphs_en, fake_paragraphs_fr, fake_paragraphs_cn, fake_paragraphs_tw, fake_paragraphs_jp, fake_paragraphs_br, fake_paragraphs_de, 1..3 } +check_determinism! { l10d Sentence; String, fake_sentence_en, fake_sentence_fr, fake_sentence_cn, fake_sentence_tw, fake_sentence_jp, fake_sentence_br, fake_sentence_de, (1..3) } +check_determinism! { l10d Sentences; Vec, fake_sentences_en, fake_sentences_fr, fake_sentences_cn, fake_sentences_tw, fake_sentences_jp, fake_sentences_br, fake_sentences_de, (1..3) } +check_determinism! { l10d Word; String, fake_word_en, fake_word_fr, fake_word_cn, fake_word_tw, fake_word_jp, fake_word_br, fake_word_de } +check_determinism! { l10d Words; Vec, fake_words_en, fake_words_fr, fake_words_cn, fake_words_tw, fake_words_jp, fake_words_br, fake_words_de, (1..3) } // Names mod name { From 45b2572f77531055915c147e264881eeecfe5576 Mon Sep 17 00:00:00 2001 From: xoryouyou Date: Wed, 25 Dec 2024 22:45:46 +0100 Subject: [PATCH 5/7] Added ADDRESS_CITY_GEN_FN for de_de and removed the ADRESS_CITY_ constants which are unused now. --- fake/src/locales/de_de.rs | 107 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 4 deletions(-) diff --git a/fake/src/locales/de_de.rs b/fake/src/locales/de_de.rs index e6f9d30..41c5a89 100644 --- a/fake/src/locales/de_de.rs +++ b/fake/src/locales/de_de.rs @@ -1,4 +1,6 @@ -use crate::locales::Data; +use rand::Rng; + +use crate::{faker::{address::de_de::{CityPrefix, CitySuffix}, name::de_de::{LastName, Name}}, locales::Data, Fake}; #[allow(non_camel_case_types)] #[derive(Copy, Clone)] pub struct DE_DE; @@ -274,9 +276,7 @@ impl Data for DE_DE { ]; const ADDRESS_CITY_PREFIX: &'static [&'static str] = - &["Alt", "Groß", "Hohen", "Klein", "Neu", "Ober", "Unter"]; - const ADDRESS_CITY_WITH_PREFIX_TPL: &'static str = "{CityPrefix}{CityName}{CitySuffix}"; - const ADDRESS_CITY_TPL: &'static str = "{CityName}{CitySuffix}"; + &["Alt", "Bad", "Groß", "Hohen", "Klein", "Neu", "Alt", "Ober", "Unter"]; const ADDRESS_ZIP_FORMATS: &'static [&'static str] = &["#####"]; const ADDRESS_STREET_SUFFIX: &'static [&'static str] = &[ "allee", "gang", "gasse", "pfad", "platz", "steg", "straße", "ufer", "weg", @@ -299,4 +299,103 @@ impl Data for DE_DE { "und Partner", "& Partner", ]; + + const ADDRESS_CITY_GEN_FN: OptionString> = Some( || -> String { + + // this should come from the main.rs thread_rng + // and not be instantiated here on the fly + let mut rng = rand::thread_rng(); + + // german cities are often suffixed by a river name + const RIVERS: [&str; 10] = [ + "(Rhein)", + "(Elbe)", + "(Donau)", + "(Main)", + "(Weser)", + "(Oder)", + "(Neckar)", + "(Havel)", + "(Mosel)", + "(Ems)", + ]; + + // common formats for city names + const ADDRESS_CITY_WITHOUT_PREFIX: &str = "{CityName}{CitySuffix}"; + const ADDRESS_CITY_WITHOUT_SPACE: &str = "{CityPrefix}{CityName}{CitySuffix}"; + const ADDRESS_CITY_WITH_SPACE: &str = "{CityPrefix} {CityName}{CitySuffix}"; + const ADDRESS_CITY_WITH_DASH_TPL: &str = "{CityPrefix}-{CityName}{CitySuffix}"; + const ADDRESS_CITY_WITH_RIVER_TPL: &str = "{CityPrefix}-{CityName}{CitySuffix} {River}"; + + let result = match (0..5).fake_with_rng::(&mut rng) { + + 0 => ADDRESS_CITY_WITHOUT_SPACE + .replace( + "{CityPrefix}", + CityPrefix().fake_with_rng::<&str, _>(&mut rng), + ) + .replace( + "{CityName}", + (LastName().fake_with_rng::(&mut rng)).to_lowercase().as_ref() + ) + .replace( + "{CitySuffix}", + CitySuffix().fake_with_rng::<&str, _>(&mut rng), + ), + 1 => ADDRESS_CITY_WITH_SPACE + .replace( + "{CityPrefix}", + CityPrefix().fake_with_rng::<&str, _>(&mut rng), + ) + .replace( + "{CityName}", + LastName().fake_with_rng::(&mut rng).as_ref() + ) + .replace( + "{CitySuffix}", + CitySuffix().fake_with_rng::<&str, _>(&mut rng), + ), + 2 => ADDRESS_CITY_WITH_DASH_TPL + .replace( + "{CityPrefix}", + CityPrefix().fake_with_rng::<&str, _>(&mut rng), + ) + .replace( + "{CityName}", + Name().fake_with_rng::(&mut rng).as_ref(), + ) + .replace( + "{CitySuffix}", + CitySuffix().fake_with_rng::<&str, _>(&mut rng), + ), + 3 => ADDRESS_CITY_WITH_RIVER_TPL + .replace( + "{CityPrefix}", + CityPrefix().fake_with_rng::<&str, _>(&mut rng), + ) + .replace( + "{CityName}", + Name().fake_with_rng::(&mut rng).as_ref(), + ) + .replace( + "{CitySuffix}", + CitySuffix().fake_with_rng::<&str, _>(&mut rng), + ) + .replace( + "{River}", + RIVERS[rng.gen_range(0..RIVERS.len())], + ), + _ => ADDRESS_CITY_WITHOUT_PREFIX + .replace( + "{CityName}", + Name().fake_with_rng::(&mut rng).as_ref(), + ) + .replace( + "{CitySuffix}", + CitySuffix().fake_with_rng::<&str, _>(&mut rng), + ), + }; + + result + }); } From 54a5477d522dbe0eee530f974ad2a5668f0cc62f Mon Sep 17 00:00:00 2001 From: xoryouyou Date: Thu, 26 Dec 2024 10:21:13 +0100 Subject: [PATCH 6/7] Added de_de to the supported language table in the readme and deleted the manual tests which were only helper functions. --- README.md | 1 + fake/tests/de_manual_test.rs | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/README.md b/README.md index faf3445..baa5949 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ A Rust library and command line tool for generating fake data in different langu | Simplified Chinese | zh_cn | | Japanese | ja_jp | | Portugese (Brazilian) | pt_br | +| German | de_de | ## Installation diff --git a/fake/tests/de_manual_test.rs b/fake/tests/de_manual_test.rs index 581638d..a0e38e8 100644 --- a/fake/tests/de_manual_test.rs +++ b/fake/tests/de_manual_test.rs @@ -33,3 +33,10 @@ fn de_manual_test() { println!("{:#?}", c); } } +#[test] +fn de_manual_city_test() { + for _ in 1..10 { + let city: String = CityName(DE_DE).fake(); + println!("{:#?}", city); + } +} From 66eb15b4ce75dc5ceff327b5e81e3a3391c5f73b Mon Sep 17 00:00:00 2001 From: xoryouyou Date: Thu, 26 Dec 2024 10:24:34 +0100 Subject: [PATCH 7/7] completely remove the test file --- fake/tests/de_manual_test.rs | 42 ------------------------------------ 1 file changed, 42 deletions(-) delete mode 100644 fake/tests/de_manual_test.rs diff --git a/fake/tests/de_manual_test.rs b/fake/tests/de_manual_test.rs deleted file mode 100644 index a0e38e8..0000000 --- a/fake/tests/de_manual_test.rs +++ /dev/null @@ -1,42 +0,0 @@ -use fake::faker::address::de_de::SecondaryAddress; -use fake::faker::address::raw::{CityName, StateName, StreetName, ZipCode}; -use fake::faker::company::raw::CompanyName; -use fake::locales::DE_DE; -use fake::Fake; - -#[allow(unused)] -#[derive(Debug)] -pub struct Company { - name: String, - address_line_1: String, - address_line_2: String, - zipcode: String, - city: String, - state: String, -} - -#[test] -fn de_manual_test() { - for _ in 1..10 { - let c = Company { - name: CompanyName(DE_DE).fake(), - address_line_1: format!( - "{} {}", - StreetName(DE_DE).fake::(), - (1..100).fake::() - ), - address_line_2: SecondaryAddress().fake(), - zipcode: ZipCode(DE_DE).fake(), - city: CityName(DE_DE).fake(), - state: StateName(DE_DE).fake(), - }; - println!("{:#?}", c); - } -} -#[test] -fn de_manual_city_test() { - for _ in 1..10 { - let city: String = CityName(DE_DE).fake(); - println!("{:#?}", city); - } -}