From 81df1e2eefed8831d4bae6ac0f0b2ac885c0f2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blar?= Date: Thu, 22 Aug 2024 20:38:59 +0200 Subject: [PATCH] feat: add locale to finance module (#869) --- CHANGELOG.md | 1 + include/faker-cxx/finance.h | 72 +- include/faker-cxx/helper.h | 2 +- src/modules/finance.cpp | 26 +- src/modules/finance_data.h | 1656 ++++++++++++++++---------------- src/modules/git.cpp | 8 +- src/modules/person_data.h | 2 - tests/modules/finance_test.cpp | 138 +-- tests/modules/person_test.cpp | 108 ++- 9 files changed, 972 insertions(+), 1041 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 878d35d6d..57aa7b049 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file * changed function name from `name` to `companyName` in company module * changed function `companyName` to take optional enum parameter in company module * changed function `branch` to take optional enum parameter in git module +* changed country, language, bic country, iban country params to locale ## v2.0.0 (27.06.2024) diff --git a/include/faker-cxx/finance.h b/include/faker-cxx/finance.h index 953c3b60c..965c2e7c5 100644 --- a/include/faker-cxx/finance.h +++ b/include/faker-cxx/finance.h @@ -1,11 +1,10 @@ #pragma once -#include #include #include #include "faker-cxx/export.h" -#include "types/country.h" +#include "faker-cxx/types/locale.h" #include "types/precision.h" namespace faker::finance @@ -92,78 +91,32 @@ FAKER_CXX_EXPORT std::string_view accountType(); FAKER_CXX_EXPORT std::string amount(double min = 0, double max = 1000, Precision precision = Precision::TwoDp, const std::string& symbol = ""); -enum class IbanCountry -{ - Austria, - Belgium, - Bulgaria, - Croatia, - Cyprus, - Czechia, - Denmark, - Estonia, - Finland, - France, - Germany, - Greece, - Hungary, - Ireland, - Italy, - Latvia, - Lithuania, - Luxembourg, - Malta, - Netherlands, - Poland, - Portugal, - Romania, - Slovakia, - Slovenia, - Spain, - Sweden -}; - /** - * Generates a random iban. + * Generates a random IBAN. + * + * @param locale The locale. Defaults to `Locale::de_DE`. * - * @param country The country from which you want to generate an IBAN, if none is provided a random country - will be used. * * @returns IBAN. * * @code - * faker::finance::iban(IbanCountry::Poland) // "PL61109010140000071219812874" + * faker::finance::iban(Locale::pl_PL) // "PL61109010140000071219812874" * @endcode */ -FAKER_CXX_EXPORT std::string iban(std::optional country = std::nullopt); - -enum class BicCountry -{ - France, - Germany, - India, - Italy, - Netherlands, - Poland, - Romania, - Spain, - UnitedKingdom, - UnitedStates, -}; +FAKER_CXX_EXPORT std::string iban(Locale locale = Locale::de_DE); /** - * Generates a random bic. + * Generates a random BIC. * - * @param country The country from which you want to generate a BIC, if none is provided a random country - will be used. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns BIC. * * @code - * faker::finance::bic(BicCountry::Poland) // "BREXPLPWMUL" + * faker::finance::bic(Locale::pl_PL) // "BREXPLPWMUL" * @endcode */ -FAKER_CXX_EXPORT std::string_view bic(std::optional country = std::nullopt); +FAKER_CXX_EXPORT std::string_view bic(Locale locale = Locale::en_US); /** * Generates a random account number. @@ -206,7 +159,6 @@ FAKER_CXX_EXPORT std::string routingNumber(); enum class CreditCardType { - DefaultCard, AmericanExpress, Discover, MasterCard, @@ -216,7 +168,7 @@ enum class CreditCardType /** * Generates a random credit card number. * - * @param creditCardType The type of the credit card. + * @param creditCardType The type of the credit card. Defaults to `CreditCardType::Visa`. * * @returns Credit card number. * @@ -224,7 +176,7 @@ enum class CreditCardType * faker::finance::creditCardNumber() // "4882664999007" * @endcode */ -FAKER_CXX_EXPORT std::string creditCardNumber(std::optional creditCardType = std::nullopt); +FAKER_CXX_EXPORT std::string creditCardNumber(CreditCardType creditCardType = CreditCardType::Visa); /** * Generates a random credit card CVV. diff --git a/include/faker-cxx/helper.h b/include/faker-cxx/helper.h index c53b30759..cb780e7bc 100644 --- a/include/faker-cxx/helper.h +++ b/include/faker-cxx/helper.h @@ -21,7 +21,7 @@ decltype(auto) randomElement(Range&& range) throw std::invalid_argument{"Range [start, end) is empty."}; } - auto size = std::ranges::distance(range); + const auto size = std::ranges::distance(range); const auto index = number::integer(size - 1); diff --git a/src/modules/finance.cpp b/src/modules/finance.cpp index f35d8efc7..b468683fe 100644 --- a/src/modules/finance.cpp +++ b/src/modules/finance.cpp @@ -1,6 +1,5 @@ #include "faker-cxx/finance.h" -#include #include #include #include @@ -12,6 +11,7 @@ #include "faker-cxx/number.h" #include "faker-cxx/string.h" #include "faker-cxx/types/hex.h" +#include "faker-cxx/types/locale.h" #include "faker-cxx/types/precision.h" #include "finance_data.h" @@ -54,11 +54,9 @@ std::string amount(double min, double max, Precision precision, const std::strin return result; } -std::string iban(std::optional country) +std::string iban(Locale locale) { - const auto ibanCountry = country ? *country : helper::randomElement(ibanCountries); - - const auto& ibanFormat = ibanFormats.at(ibanCountry); + const auto& ibanFormat = ibanFormats.contains(locale) ? ibanFormats.at(locale) : ibanFormats.at(Locale::de_DE); const auto& countryCode = ibanFormat[0]; @@ -89,11 +87,10 @@ std::string iban(std::optional country) return iban; } -std::string_view bic(std::optional country) +std::string_view bic(Locale locale) { - const auto bicCountry = country ? *country : helper::randomElement(bicCountries); - - return helper::randomElement(bicCountriesCodes.at(bicCountry)); + return helper::randomElement(bicCountriesCodes.contains(locale) ? bicCountriesCodes.at(locale) : + bicCountriesCodes.at(Locale::en_US)); } std::string accountNumber(unsigned int length) @@ -111,11 +108,9 @@ std::string routingNumber() return string::numeric(9, true); } -std::string creditCardNumber(std::optional creditCardType) +std::string creditCardNumber(CreditCardType creditCardType) { - const auto creditCardTargetType = creditCardType ? *creditCardType : helper::randomElement(creditCardTypes); - - switch (creditCardTargetType) + switch (creditCardType) { case CreditCardType::AmericanExpress: return helper::replaceCreditCardSymbols( @@ -126,12 +121,9 @@ std::string creditCardNumber(std::optional creditCardType) case CreditCardType::MasterCard: return helper::replaceCreditCardSymbols( static_cast(helper::randomElement(masterCardCreditCardFormats))); - case CreditCardType::Visa: + default: return helper::replaceCreditCardSymbols(static_cast(helper::randomElement(visaCreditCardFormats))); - default:; } - - return ""; } std::string creditCardCvv() diff --git a/src/modules/finance_data.h b/src/modules/finance_data.h index 88cca8511..45fe643c5 100644 --- a/src/modules/finance_data.h +++ b/src/modules/finance_data.h @@ -5,24 +5,10 @@ #include #include -#include "faker-cxx/finance.h" +#include "faker-cxx/types/locale.h" namespace faker::finance { -const auto bicCountries = std::to_array( - {BicCountry::Poland, BicCountry::UnitedStates, BicCountry::UnitedKingdom, BicCountry::Germany, BicCountry::Romania, - BicCountry::France, BicCountry::Italy, BicCountry::Spain, BicCountry::Netherlands, BicCountry::India}); - -const auto ibanCountries = std::to_array({ - IbanCountry::Austria, IbanCountry::Belgium, IbanCountry::Bulgaria, IbanCountry::Croatia, - IbanCountry::Cyprus, IbanCountry::Czechia, IbanCountry::Denmark, IbanCountry::Estonia, - IbanCountry::Finland, IbanCountry::France, IbanCountry::Germany, IbanCountry::Greece, - IbanCountry::Hungary, IbanCountry::Ireland, IbanCountry::Italy, IbanCountry::Latvia, - IbanCountry::Lithuania, IbanCountry::Luxembourg, IbanCountry::Malta, IbanCountry::Netherlands, - IbanCountry::Poland, IbanCountry::Portugal, IbanCountry::Romania, IbanCountry::Slovakia, - IbanCountry::Slovenia, IbanCountry::Spain, IbanCountry::Sweden, -}); - const auto accountTypes = std::to_array({ "Auto Loan", "Checking", @@ -34,26 +20,58 @@ const auto accountTypes = std::to_array({ "Savings", }); -const std::unordered_map> bicCountriesCodes = { - {BicCountry::Poland, +const std::unordered_map> bicCountriesCodes = { + {Locale::pl_PL, {"BPKOPLPW", "PKOPPLPW", "BREXPLPWMUL", "BNPAPLP", "POLUPLPR", "BIGBPLPW", "WBKPPLPP", "CITIPLPX", "INGBPLPW", "DEUTPLPK", "DEUTPLP"}}, - {BicCountry::UnitedStates, {"BOFAUS3N", "CITIUS33", "WELLSFARGO", "USBKUS44", "CHASUS33", "HSBCUS33", "PNCCUS33"}}, - {BicCountry::UnitedKingdom, {"BARCGB22", "HSBCKENW", "LOYDGB21", "NWBKGB2L", "RBOSGB2L", "HSBCGB2L", "DEUTGB2L"}}, - {BicCountry::Germany, + {Locale::en_US, {"BOFAUS3N", "CITIUS33", "WELLSFARGO", "USBKUS44", "CHASUS33", "HSBCUS33", "PNCCUS33"}}, + {Locale::en_GB, {"BARCGB22", "HSBCKENW", "LOYDGB21", "NWBKGB2L", "RBOSGB2L", "HSBCGB2L", "DEUTGB2L"}}, + {Locale::de_DE, {"DEUTDEFF", "DRESDEFF", "COBADEFF", "BYLADEM1", "GENODEFF", "HYVEDEMM", "MALADE51", "NOLADE21", "SOLADEST", "UNCRDEFF"}}, - {BicCountry::Romania, {"RNCBROBU", "BRDEROBU", "BTRLRO22", "PIRBROBU", "INGBROBU", "EXIMRO22", "CRDZROBU"}}, - {BicCountry::France, + {Locale::ro_RO, {"RNCBROBU", "BRDEROBU", "BTRLRO22", "PIRBROBU", "INGBROBU", "EXIMRO22", "CRDZROBU"}}, + {Locale::fr_FR, {"BNPAFRPP", "CEPAFRPP", "CRLYFRPP", "SOGEFRPP", "AGRIFRPP", "HSBDFRPP", "CCFRFRPP", "BNORDRPP", "CMCIFRPP"}}, - {BicCountry::Italy, {"UNCRITMM", "BCITITMM", "INTESA", "UBSPITPA", "BLOPIT22", "CITIITMX", "BNLIITRR"}}, - {BicCountry::Spain, - {"CAIXESBB", "BBVAESMM", "SABSESBB", "BSCHESMM", "POPUESMM", "INGDESMM", "CITIES2X", "BCOEESMM"}}, - {BicCountry::Netherlands, {"ABNANL2A", "INGBNL2A", "RABONL2U", "TRIONL2U", "KNABNL2H", "SBINNL2X", "DEUTNL2N"}}, + {Locale::it_IT, {"UNCRITMM", "BCITITMM", "INTESA", "UBSPITPA", "BLOPIT22", "CITIITMX", "BNLIITRR"}}, + {Locale::es_ES, {"CAIXESBB", "BBVAESMM", "SABSESBB", "BSCHESMM", "POPUESMM", "INGDESMM", "CITIES2X", "BCOEESMM"}}, + {Locale::nl_NL, {"ABNANL2A", "INGBNL2A", "RABONL2U", "TRIONL2U", "KNABNL2H", "SBINNL2X", "DEUTNL2N"}}, { - BicCountry::India, + Locale::hi_IN, {"HDFCINBB", "ICICINBB", "SBININBB", "PNBAINBB", "UBININBB", "AXISINBB", "KKBKINBB", "YESBINBB", "IDBIINBB"}, - }}; + }, +}; + +// Iban format structure from https://bank.codes/iban/structure/ +// Note: a - alphabets (letters only), c - characters (letters & numbers), n - numbers (numbers only) +const std::unordered_map> ibanFormats{ + {Locale::de_AT, {"AT", "2n", "5n", "11n"}}, + {Locale::de_BE, {"BE", "2n", "3n", "7n", "2n"}}, + {Locale::bg_BG, {"BG", "2n", "4a", "4n", "2n", "8c"}}, + {Locale::hr_HR, {"HR", "2n", "7n", "10n"}}, + {Locale::el_CY, {"CY", "2n", "3n", "5n", "16c"}}, + {Locale::cs_CZ, {"CZ", "2n", "4n", "6n", "10n"}}, + {Locale::da_DK, {"DK", "2n", "4n", "9n", "1n"}}, + {Locale::et_EE, {"EE", "2n", "2n", "2n", "11n", "1n"}}, + {Locale::fi_FI, {"FI", "2n", "6n", "7n", "1n"}}, + {Locale::fr_FR, {"FR", "2n", "5n", "5n", "11c", "2n"}}, + {Locale::de_DE, {"DE", "2n", "8n", "10n"}}, + {Locale::el_GR, {"GR", "2n", "3n", "4n", "16c"}}, + {Locale::hu_HU, {"HU", "2n", "3n", "4n", "1n", "15n", "1n"}}, + {Locale::en_IE, {"IE", "2n", "4a", "6n", "8n"}}, + {Locale::it_IT, {"IT", "2n", "1a", "5n", "5n", "12c"}}, + {Locale::lv_LV, {"LV", "2n", "4a", "13n"}}, + {Locale::lt_LT, {"LT", "2n", "5n", "11n"}}, + {Locale::de_LU, {"LU", "2n", "3n", "13c"}}, + {Locale::en_MT, {"MT", "2n", "4a", "5n", "18c"}}, + {Locale::nl_NL, {"NL", "2n", "4a", "10n"}}, + {Locale::pl_PL, {"PL", "2n", "3n", "4n", "1n", "16n"}}, + {Locale::pt_PT, {"PT", "2n", "4n", "4n", "11n", "2n"}}, + {Locale::ro_RO, {"RO", "2n", "4a", "16c"}}, + {Locale::sk_SK, {"SK", "2n", "4n", "6n", "10n"}}, + {Locale::sl_SI, {"SI", "2n", "2n", "3n", "8n", "2n"}}, + {Locale::es_ES, {"ES", "2n", "4n", "4n", "2n", "10n"}}, + {Locale::sv_SE, {"SE", "2n", "3n", "16n", "1n"}}, +}; const auto americanExpressCreditCardFormats = std::to_array({ "34##-######-####L", @@ -79,13 +97,6 @@ const auto visaCreditCardFormats = std::to_array({ "4###-####-####-###L", }); -const auto creditCardTypes = std::to_array({ - CreditCardType::Visa, - CreditCardType::AmericanExpress, - CreditCardType::MasterCard, - CreditCardType::Discover, -}); - const auto creditCardNames = std::to_array({ "American Express", "Discover", @@ -93,807 +104,776 @@ const auto creditCardNames = std::to_array({ "Visa", }); -const auto currencies = std::to_array({{ - "UAE Dirham", - "AED", - "", - }, - { - "Afghani", - "AFN", - "؋", - }, - { - "Lek", - "ALL", - "Lek", - }, - { - "Armenian Dram", - "AMD", - "", - }, - { - "Netherlands Antillian Guilder", - "ANG", - "ƒ", - }, - { - "Kwanza", - "AOA", - "", - }, - { - "Argentine Peso", - "ARS", - "$", - }, - { - "Australian Dollar", - "AUD", - "$", - }, - { - "Aruban Guilder", - "AWG", - "ƒ", - }, - { - "Azerbaijanian Manat", - "AZN", - "ман", - }, - { - "Convertible Marks", - "BAM", - "KM", - }, - { - "Barbados Dollar", - "BBD", - "$", - }, - { - "Taka", - "BDT", - "", - }, - { - "Bulgarian Lev", - "BGN", - "лв", - }, - { - "Bahraini Dinar", - "BHD", - "", - }, - { - "Burundi Franc", - "BIF", - "", - }, - { - "Bermudian Dollar (customarily known as Bermuda Dollar)", - "BMD", - "$", - }, - { - "Brunei Dollar", - "BND", - "$", - }, - { - "Boliviano boliviano", - "BOB", - "Bs", - }, - { - "Brazilian Real", - "BRL", - "R$", - }, - { - "Bahamian Dollar", - "BSD", - "$", - }, - { - "Pula", - "BWP", - "P", - }, - { - "Belarusian Ruble", - "BYN", - "Rbl", - }, - { - "Belize Dollar", - "BZD", - "BZ$", - }, - { - "Canadian Dollar", - "CAD", - "$", - }, - { - "Congolese Franc", - "CDF", - "", - }, - { - "Swiss Franc", - "CHF", - "CHF", - }, - { - "Chilean Peso", - "CLP", - "$", - }, - { - "Yuan Renminbi", - "CNY", - "¥", - }, - { - "Colombian Peso", - "COP", - "$", - }, - { - "Costa Rican Colon", - "CRC", - "₡", - }, - { - "Cuban Peso", - "CUP", - "₱", - }, - { - "Cape Verde Escudo", - "CVE", - "", - }, - { - "Czech Koruna", - "CZK", - "Kč", - }, - { - "Djibouti Franc", - "DJF", - "", - }, - { - "Danish Krone", - "DKK", - "kr", - }, - { - "Dominican Peso", - "DOP", - "RD$", - }, - { - "Algerian Dinar", - "DZD", - "", - }, - { - "Egyptian Pound", - "EGP", - "£", - }, - { - "Nakfa", - "ERN", - "", - }, - { - "Ethiopian Birr", - "ETB", - "", - }, - { - "Euro", - "EUR", - "€", - }, - { - "Fiji Dollar", - "FJD", - "$", - }, - { - "Falkland Islands Pound", - "FKP", - "£", - }, - { - "Pound Sterling", - "GBP", - "£", - }, - { - "Lari", - "GEL", - "", - }, - { - "Cedi", - "GHS", - "", - }, - { - "Gibraltar Pound", - "GIP", - "£", - }, - { - "Dalasi", - "GMD", - "", - }, - { - "Guinea Franc", - "GNF", - "", - }, - { - "Quetzal", - "GTQ", - "Q", - }, - { - "Guyana Dollar", - "GYD", - "$", - }, - { - "Hong Kong Dollar", - "HKD", - "$", - }, - { - "Lempira", - "HNL", - "L", - }, - { - "Gourde", - "HTG", - "", - }, - { - "Forint", - "HUF", - "Ft", - }, - { - "Rupiah", - "IDR", - "Rp", - }, - { - "New Israeli Sheqel", - "ILS", - "₪", - }, - { - "Bhutanese Ngultrum", - "BTN", - "Nu", - }, - { - "Indian Rupee", - "INR", - "₹", - }, - { - "Iraqi Dinar", - "IQD", - "", - }, - { - "Iranian Rial", - "IRR", - "﷼", - }, - { - "Iceland Krona", - "ISK", - "kr", - }, - { - "Jamaican Dollar", - "JMD", - "J$", - }, - { - "Jordanian Dinar", - "JOD", - "", - }, - { - "Yen", - "JPY", - "¥", - }, - { - "Kenyan Shilling", - "KES", - "", - }, - { - "Som", - "KGS", - "лв", - }, - { - "Riel", - "KHR", - "៛", - }, - { - "Comoro Franc", - "KMF", - "", - }, - { - "North Korean Won", - "KPW", - "₩", - }, - { - "Won", - "KRW", - "₩", - }, - { - "Kuwaiti Dinar", - "KWD", - "", - }, - { - "Cayman Islands Dollar", - "KYD", - "$", - }, - { - "Tenge", - "KZT", - "лв", - }, - { - "Kip", - "LAK", - "₭", - }, - { - "Lebanese Pound", - "LBP", - "£", - }, - { - "Sri Lanka Rupee", - "LKR", - "₨", - }, - { - "Liberian Dollar", - "LRD", - "$", - }, - { - "Libyan Dinar", - "LYD", - "", - }, - { - "Moroccan Dirham", - "MAD", - "", - }, - { - "Moldovan Leu", - "MDL", - "", - }, - { - "Malagasy Ariary", - "MGA", - "", - }, - { - "Denar", - "MKD", - "ден", - }, - { - "Kyat", - "MMK", - "", - }, - { - "Tugrik", - "MNT", - "₮", - }, - { - "Pataca", - "MOP", - "", - }, - { - "Ouguiya", - "MRU", - "", - }, - { - "Mauritius Rupee", - "MUR", - "₨", - }, - { - "Rufiyaa", - "MVR", - "", - }, - { - "Kwacha", - "MWK", - "", - }, - { - "Mexican Peso", - "MXN", - "$", - }, - { - "Malaysian Ringgit", - "MYR", - "RM", - }, - { - "Metical", - "MZN", - "MT", - }, - { - "Naira", - "NGN", - "₦", - }, - { - "Cordoba Oro", - "NIO", - "C$", - }, - { - "Norwegian Krone", - "NOK", - "kr", - }, - { - "Nepalese Rupee", - "NPR", - "₨", - }, - { - "New Zealand Dollar", - "NZD", - "$", - }, - { - "Rial Omani", - "OMR", - "﷼", - }, - { - "Balboa", - "PAB", - "B/.", - }, - { - "Nuevo Sol", - "PEN", - "S/.", - }, - { - "Kina", - "PGK", - "", - }, - { - "Philippine Peso", - "PHP", - "Php", - }, - { - "Pakistan Rupee", - "PKR", - "₨", - }, - { - "Zloty", - "PLN", - "zł", - }, - { - "Guarani", - "PYG", - "Gs", - }, - { - "Qatari Rial", - "QAR", - "﷼", - }, - { - "New Leu", - "RON", - "lei", - }, - { - "Serbian Dinar", - "RSD", - "Дин.", - }, - { - "Russian Ruble", - "RUB", - "руб", - }, - { - "Rwanda Franc", - "RWF", - "", - }, - { - "Saudi Riyal", - "SAR", - "﷼", - }, - { - "Solomon Islands Dollar", - "SBD", - "$", - }, - { - "Seychelles Rupee", - "SCR", - "₨", - }, - { - "Sudanese Pound", - "SDG", - "", - }, - { - "Swedish Krona", - "SEK", - "kr", - }, - { - "Singapore Dollar", - "SGD", - "$", - }, - { - "Saint Helena Pound", - "SHP", - "£", - }, - { - "Leone", - "SLE", - "", - }, - { - "Somali Shilling", - "SOS", - "S", - }, - { - "Surinam Dollar", - "SRD", - "$", - }, - { - "South Sudanese pound", - "SSP", - "", - }, - { - "Dobra", - "STN", - "Db", - }, - { - "Syrian Pound", - "SYP", - "£", - }, - { - "Lilangeni", - "SZL", - "", - }, - { - "Baht", - "THB", - "฿", - }, - { - "Somoni", - "TJS", - "", - }, - { - "Manat", - "TMT", - "", - }, - { - "Tunisian Dinar", - "TND", - "", - }, - { - "Pa' anga ", - "TOP", - "", - }, - { - "Turkish Lira", - "TRY", - "₺", - }, - { - "Trinidad and Tobago Dollar", - "TTD", - "TT$", - }, - { - "New Taiwan Dollar", - "TWD", - "NT$", - }, - { - "Tanzanian Shilling", - "TZS", - "", - }, - { - "Hryvnia", - "UAH", - "₴", - }, - { - "Uganda Shilling", - "UGX", - "", - }, - { - "US Dollar", - "USD", - "$", - }, - { - "Peso Uruguayo", - "UYU", - "$U", - }, - { - "Uzbekistan Sum", - "UZS", - "лв", - }, - { - "Venezuelan bolívar", - "VES", - "Bs", - }, - { - "Dong", - "VND", - "₫", - }, - { - "Vatu", - "VUV", - "", - }, - { - "Tala", - "WST", - "", - }, - { - "CFA Franc BEAC", - "XAF", - "", - }, - { - "East Caribbean Dollar", - "XCD", - "$", - }, - { - "CFA Franc BCEAO", - "XOF", - "", - }, - { - "CFP Franc", - "XPF", - "", - }, - { - "Yemeni Rial", - "YER", - "﷼", - }, - { - "Rand", - "ZAR", - "R", - }, - { - "Lesotho Loti", - "LSL", - "", - }, - { - "Namibia Dollar", - "NAD", - "N$", - }, - { - "Zambian Kwacha", - "ZMW", - "K", - }, - { - "Zimbabwe Dollar", - "ZWL", - "", - }}); - -// Iban format structure from https://bank.codes/iban/structure/ -// Note: a - alphabets (letters only), c - characters (letters & numbers), n - numbers (numbers only) -const std::unordered_map> ibanFormats{ - {IbanCountry::Austria, {"AT", "2n", "5n", "11n"}}, - {IbanCountry::Belgium, {"BE", "2n", "3n", "7n", "2n"}}, - {IbanCountry::Bulgaria, {"BG", "2n", "4a", "4n", "2n", "8c"}}, - {IbanCountry::Croatia, {"HR", "2n", "7n", "10n"}}, - {IbanCountry::Cyprus, {"CY", "2n", "3n", "5n", "16c"}}, - {IbanCountry::Czechia, {"CZ", "2n", "4n", "6n", "10n"}}, - {IbanCountry::Denmark, {"DK", "2n", "4n", "9n", "1n"}}, - {IbanCountry::Estonia, {"EE", "2n", "2n", "2n", "11n", "1n"}}, - {IbanCountry::Finland, {"FI", "2n", "6n", "7n", "1n"}}, - {IbanCountry::France, {"FR", "2n", "5n", "5n", "11c", "2n"}}, - {IbanCountry::Germany, {"DE", "2n", "8n", "10n"}}, - {IbanCountry::Greece, {"GR", "2n", "3n", "4n", "16c"}}, - {IbanCountry::Hungary, {"HU", "2n", "3n", "4n", "1n", "15n", "1n"}}, - {IbanCountry::Ireland, {"IE", "2n", "4a", "6n", "8n"}}, - {IbanCountry::Italy, {"IT", "2n", "1a", "5n", "5n", "12c"}}, - {IbanCountry::Latvia, {"LV", "2n", "4a", "13n"}}, - {IbanCountry::Lithuania, {"LT", "2n", "5n", "11n"}}, - {IbanCountry::Luxembourg, {"LU", "2n", "3n", "13c"}}, - {IbanCountry::Malta, {"MT", "2n", "4a", "5n", "18c"}}, - {IbanCountry::Netherlands, {"NL", "2n", "4a", "10n"}}, - {IbanCountry::Poland, {"PL", "2n", "3n", "4n", "1n", "16n"}}, - {IbanCountry::Portugal, {"PT", "2n", "4n", "4n", "11n", "2n"}}, - {IbanCountry::Romania, {"RO", "2n", "4a", "16c"}}, - {IbanCountry::Slovakia, {"SK", "2n", "4n", "6n", "10n"}}, - {IbanCountry::Slovenia, {"SI", "2n", "2n", "3n", "8n", "2n"}}, - {IbanCountry::Spain, {"ES", "2n", "4n", "4n", "2n", "10n"}}, - {IbanCountry::Sweden, {"SE", "2n", "3n", "16n", "1n"}}, -}; - +const auto currencies = std::to_array({ + { + "UAE Dirham", + "AED", + "", + }, + { + "Afghani", + "AFN", + "؋", + }, + { + "Lek", + "ALL", + "Lek", + }, + { + "Armenian Dram", + "AMD", + "", + }, + { + "Netherlands Antillian Guilder", + "ANG", + "ƒ", + }, + { + "Kwanza", + "AOA", + "", + }, + { + "Argentine Peso", + "ARS", + "$", + }, + { + "Australian Dollar", + "AUD", + "$", + }, + { + "Aruban Guilder", + "AWG", + "ƒ", + }, + { + "Azerbaijanian Manat", + "AZN", + "ман", + }, + { + "Convertible Marks", + "BAM", + "KM", + }, + { + "Barbados Dollar", + "BBD", + "$", + }, + { + "Taka", + "BDT", + "", + }, + { + "Bulgarian Lev", + "BGN", + "лв", + }, + { + "Bahraini Dinar", + "BHD", + "", + }, + { + "Burundi Franc", + "BIF", + "", + }, + { + "Bermudian Dollar (customarily known as Bermuda Dollar)", + "BMD", + "$", + }, + { + "Brunei Dollar", + "BND", + "$", + }, + { + "Boliviano boliviano", + "BOB", + "Bs", + }, + { + "Brazilian Real", + "BRL", + "R$", + }, + { + "Bahamian Dollar", + "BSD", + "$", + }, + { + "Pula", + "BWP", + "P", + }, + { + "Belarusian Ruble", + "BYN", + "Rbl", + }, + { + "Belize Dollar", + "BZD", + "BZ$", + }, + { + "Canadian Dollar", + "CAD", + "$", + }, + { + "Congolese Franc", + "CDF", + "", + }, + { + "Swiss Franc", + "CHF", + "CHF", + }, + { + "Chilean Peso", + "CLP", + "$", + }, + { + "Yuan Renminbi", + "CNY", + "¥", + }, + { + "Colombian Peso", + "COP", + "$", + }, + { + "Costa Rican Colon", + "CRC", + "₡", + }, + { + "Cuban Peso", + "CUP", + "₱", + }, + { + "Cape Verde Escudo", + "CVE", + "", + }, + { + "Czech Koruna", + "CZK", + "Kč", + }, + { + "Djibouti Franc", + "DJF", + "", + }, + { + "Danish Krone", + "DKK", + "kr", + }, + { + "Dominican Peso", + "DOP", + "RD$", + }, + { + "Algerian Dinar", + "DZD", + "", + }, + { + "Egyptian Pound", + "EGP", + "£", + }, + { + "Nakfa", + "ERN", + "", + }, + { + "Ethiopian Birr", + "ETB", + "", + }, + { + "Euro", + "EUR", + "€", + }, + { + "Fiji Dollar", + "FJD", + "$", + }, + { + "Falkland Islands Pound", + "FKP", + "£", + }, + { + "Pound Sterling", + "GBP", + "£", + }, + { + "Lari", + "GEL", + "", + }, + { + "Cedi", + "GHS", + "", + }, + { + "Gibraltar Pound", + "GIP", + "£", + }, + { + "Dalasi", + "GMD", + "", + }, + { + "Guinea Franc", + "GNF", + "", + }, + { + "Quetzal", + "GTQ", + "Q", + }, + { + "Guyana Dollar", + "GYD", + "$", + }, + { + "Hong Kong Dollar", + "HKD", + "$", + }, + { + "Lempira", + "HNL", + "L", + }, + { + "Gourde", + "HTG", + "", + }, + { + "Forint", + "HUF", + "Ft", + }, + { + "Rupiah", + "IDR", + "Rp", + }, + { + "New Israeli Sheqel", + "ILS", + "₪", + }, + { + "Bhutanese Ngultrum", + "BTN", + "Nu", + }, + { + "Indian Rupee", + "INR", + "₹", + }, + { + "Iraqi Dinar", + "IQD", + "", + }, + { + "Iranian Rial", + "IRR", + "﷼", + }, + { + "Iceland Krona", + "ISK", + "kr", + }, + { + "Jamaican Dollar", + "JMD", + "J$", + }, + { + "Jordanian Dinar", + "JOD", + "", + }, + { + "Yen", + "JPY", + "¥", + }, + { + "Kenyan Shilling", + "KES", + "", + }, + { + "Som", + "KGS", + "лв", + }, + { + "Riel", + "KHR", + "៛", + }, + { + "Comoro Franc", + "KMF", + "", + }, + { + "North Korean Won", + "KPW", + "₩", + }, + { + "Won", + "KRW", + "₩", + }, + { + "Kuwaiti Dinar", + "KWD", + "", + }, + { + "Cayman Islands Dollar", + "KYD", + "$", + }, + { + "Tenge", + "KZT", + "лв", + }, + { + "Kip", + "LAK", + "₭", + }, + { + "Lebanese Pound", + "LBP", + "£", + }, + { + "Sri Lanka Rupee", + "LKR", + "₨", + }, + { + "Liberian Dollar", + "LRD", + "$", + }, + { + "Libyan Dinar", + "LYD", + "", + }, + { + "Moroccan Dirham", + "MAD", + "", + }, + { + "Moldovan Leu", + "MDL", + "", + }, + { + "Malagasy Ariary", + "MGA", + "", + }, + { + "Denar", + "MKD", + "ден", + }, + { + "Kyat", + "MMK", + "", + }, + { + "Tugrik", + "MNT", + "₮", + }, + { + "Pataca", + "MOP", + "", + }, + { + "Ouguiya", + "MRU", + "", + }, + { + "Mauritius Rupee", + "MUR", + "₨", + }, + { + "Rufiyaa", + "MVR", + "", + }, + { + "Kwacha", + "MWK", + "", + }, + { + "Mexican Peso", + "MXN", + "$", + }, + { + "Malaysian Ringgit", + "MYR", + "RM", + }, + { + "Metical", + "MZN", + "MT", + }, + { + "Naira", + "NGN", + "₦", + }, + { + "Cordoba Oro", + "NIO", + "C$", + }, + { + "Norwegian Krone", + "NOK", + "kr", + }, + { + "Nepalese Rupee", + "NPR", + "₨", + }, + { + "New Zealand Dollar", + "NZD", + "$", + }, + { + "Rial Omani", + "OMR", + "﷼", + }, + { + "Balboa", + "PAB", + "B/.", + }, + { + "Nuevo Sol", + "PEN", + "S/.", + }, + { + "Kina", + "PGK", + "", + }, + { + "Philippine Peso", + "PHP", + "Php", + }, + { + "Pakistan Rupee", + "PKR", + "₨", + }, + { + "Zloty", + "PLN", + "zł", + }, + { + "Guarani", + "PYG", + "Gs", + }, + { + "Qatari Rial", + "QAR", + "﷼", + }, + { + "New Leu", + "RON", + "lei", + }, + { + "Serbian Dinar", + "RSD", + "Дин.", + }, + { + "Russian Ruble", + "RUB", + "руб", + }, + { + "Rwanda Franc", + "RWF", + "", + }, + { + "Saudi Riyal", + "SAR", + "﷼", + }, + { + "Solomon Islands Dollar", + "SBD", + "$", + }, + { + "Seychelles Rupee", + "SCR", + "₨", + }, + { + "Sudanese Pound", + "SDG", + "", + }, + { + "Swedish Krona", + "SEK", + "kr", + }, + { + "Singapore Dollar", + "SGD", + "$", + }, + { + "Saint Helena Pound", + "SHP", + "£", + }, + { + "Leone", + "SLE", + "", + }, + { + "Somali Shilling", + "SOS", + "S", + }, + { + "Surinam Dollar", + "SRD", + "$", + }, + { + "South Sudanese pound", + "SSP", + "", + }, + { + "Dobra", + "STN", + "Db", + }, + { + "Syrian Pound", + "SYP", + "£", + }, + { + "Lilangeni", + "SZL", + "", + }, + { + "Baht", + "THB", + "฿", + }, + { + "Somoni", + "TJS", + "", + }, + { + "Manat", + "TMT", + "", + }, + { + "Tunisian Dinar", + "TND", + "", + }, + { + "Pa' anga ", + "TOP", + "", + }, + { + "Turkish Lira", + "TRY", + "₺", + }, + { + "Trinidad and Tobago Dollar", + "TTD", + "TT$", + }, + { + "New Taiwan Dollar", + "TWD", + "NT$", + }, + { + "Tanzanian Shilling", + "TZS", + "", + }, + { + "Hryvnia", + "UAH", + "₴", + }, + { + "Uganda Shilling", + "UGX", + "", + }, + { + "US Dollar", + "USD", + "$", + }, + { + "Peso Uruguayo", + "UYU", + "$U", + }, + { + "Uzbekistan Sum", + "UZS", + "лв", + }, + { + "Venezuelan bolívar", + "VES", + "Bs", + }, + { + "Dong", + "VND", + "₫", + }, + { + "Vatu", + "VUV", + "", + }, + { + "Tala", + "WST", + "", + }, + { + "CFA Franc BEAC", + "XAF", + "", + }, + { + "East Caribbean Dollar", + "XCD", + "$", + }, + { + "CFA Franc BCEAO", + "XOF", + "", + }, + { + "CFP Franc", + "XPF", + "", + }, + { + "Yemeni Rial", + "YER", + "﷼", + }, + { + "Rand", + "ZAR", + "R", + }, + { + "Lesotho Loti", + "LSL", + "", + }, + { + "Namibia Dollar", + "NAD", + "N$", + }, + { + "Zambian Kwacha", + "ZMW", + "K", + }, + { + "Zimbabwe Dollar", + "ZWL", + "", + }, +}); } diff --git a/src/modules/git.cpp b/src/modules/git.cpp index 09d47a88c..1ce8ed1e4 100644 --- a/src/modules/git.cpp +++ b/src/modules/git.cpp @@ -74,13 +74,7 @@ std::string commitEntry(std::optional dateYears, std::optional({"Mr.", "Dr."}); const auto irishFemalePrefixes = std::to_array({"Mrs.", "Ms.", "Miss", "Dr."}); -// TODO: add handling lastName-lastName - const NameFormats irishNameFormats{{{"{firstName} {lastName}", 49}, {"{prefix} {firstName} {lastName}", 7}, {"{firstName} {lastName} {suffix}", 7}, diff --git a/tests/modules/finance_test.cpp b/tests/modules/finance_test.cpp index e0d88cb6d..f23828d8c 100644 --- a/tests/modules/finance_test.cpp +++ b/tests/modules/finance_test.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -10,6 +9,7 @@ #include "common/luhn_check.h" #include "common/string_helper.h" #include "faker-cxx/finance.h" +#include "faker-cxx/types/locale.h" #include "faker-cxx/types/precision.h" #include "finance_data.h" #include "gmock/gmock.h" @@ -22,81 +22,39 @@ using namespace faker::finance; namespace { const std::string creditCardCharacters = "0123456789-"; -const std::unordered_map expectedRegex{ - {IbanCountry::Austria, "^(AT)([0-9]{2})([0-9]{5})([0-9]{11})$"}, - {IbanCountry::Belgium, "^(BE)([0-9]{2})([0-9]{3})([0-9]{7})([0-9]{2})$"}, - {IbanCountry::Bulgaria, "^(BG)([0-9]{2})([A-Z]{4})([0-9]{4})([0-9]{2})([a-zA-Z0-9]{8})$"}, - {IbanCountry::Croatia, "^(HR)([0-9]{2})([0-9]{7})([0-9]{10})$"}, - {IbanCountry::Cyprus, "^(CY)([0-9]{2})([0-9]{3})([0-9]{5})([a-zA-Z0-9]{16})$"}, - {IbanCountry::Czechia, "^(CZ)([0-9]{2})([0-9]{4})([0-9]{6})([0-9]{10})$"}, - {IbanCountry::Denmark, "^(DK)([0-9]{2})([0-9]{4})([0-9]{9})([0-9]{1})$"}, - {IbanCountry::Estonia, "^(EE)([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{11})([0-9]{1})$"}, - {IbanCountry::Finland, "^(FI)([0-9]{2})([0-9]{6})([0-9]{7})([0-9]{1})$"}, - {IbanCountry::France, "^(FR)([0-9]{2})([0-9]{5})([0-9]{5})([a-zA-Z0-9]{11})([0-9]{2})$"}, - {IbanCountry::Germany, "^(DE)([0-9]{2})([0-9]{8})([0-9]{10})$"}, - {IbanCountry::Greece, "^(GR)([0-9]{2})([0-9]{3})([0-9]{4})([a-zA-Z0-9]{16})$"}, - {IbanCountry::Hungary, "^(HU)([0-9]{2})([0-9]{3})([0-9]{4})([0-9]{1})([0-9]{15})([0-9]{1})$"}, - {IbanCountry::Ireland, "^(IE)([0-9]{2})([A-Z]{4})([0-9]{6})([0-9]{8})$"}, - {IbanCountry::Italy, "^(IT)([0-9]{2})([A-Z]{1})([0-9]{5})([0-9]{5})([a-zA-Z0-9]{12})$"}, - {IbanCountry::Latvia, "^(LV)([0-9]{2})([A-Z]{4})([a-zA-Z0-9]{13})$"}, - {IbanCountry::Lithuania, "^(LT)([0-9]{2})([0-9]{5})([0-9]{11})$"}, - {IbanCountry::Luxembourg, "^(LU)([0-9]{2})([0-9]{3})([a-zA-Z0-9]{13})$"}, - {IbanCountry::Malta, "^(MT)([0-9]{2})([A-Z]{4})([0-9]{5})([a-zA-Z0-9]{18})$"}, - {IbanCountry::Netherlands, "^(NL)([0-9]{2})([A-Z]{4})([0-9]{10})$"}, - {IbanCountry::Poland, "^(PL)([0-9]{2})([0-9]{3})([0-9]{4})([0-9]{1})([0-9]{16})$"}, - {IbanCountry::Portugal, "^(PT)([0-9]{2})([0-9]{4})([0-9]{4})([0-9]{11})([0-9]{2})$"}, - {IbanCountry::Romania, "^(RO)([0-9]{2})([A-Z]{4})([a-zA-Z0-9]{16})$"}, - {IbanCountry::Slovakia, "^(SK)([0-9]{2})([0-9]{4})([0-9]{6})([0-9]{10})$"}, - {IbanCountry::Slovenia, "^(SI)([0-9]{2})([0-9]{2})([0-9]{3})([0-9]{8})([0-9]{2})$"}, - {IbanCountry::Spain, "^(ES)([0-9]{2})([0-9]{4})([0-9]{4})([0-9]{2})([0-9]{10})$"}, - {IbanCountry::Sweden, "^(SE)([0-9]{2})([0-9]{3})([0-9]{17})$"}, -}; - -const std::unordered_map generatedTestName{ - {IbanCountry::Austria, "shouldGenerateAustriaIban"}, - {IbanCountry::Belgium, "shouldGenerateBelgiumIban"}, - {IbanCountry::Bulgaria, "shouldGenerateBulgariaIban"}, - {IbanCountry::Croatia, "shouldGenerateCroatiaIban"}, - {IbanCountry::Cyprus, "shouldGenerateCyprusIban"}, - {IbanCountry::Czechia, "shouldGenerateCzechiaIban"}, - {IbanCountry::Denmark, "shouldGenerateDenmarkIban"}, - {IbanCountry::Estonia, "shouldGenerateEstoniaIban"}, - {IbanCountry::Finland, "shouldGenerateFinlandIban"}, - {IbanCountry::France, "shouldGenerateFranceIban"}, - {IbanCountry::Germany, "shouldGenerateGermanyIban"}, - {IbanCountry::Greece, "shouldGenerateGreeceIban"}, - {IbanCountry::Hungary, "shouldGenerateHungaryIban"}, - {IbanCountry::Ireland, "shouldGenerateIrelandIban"}, - {IbanCountry::Italy, "shouldGenerateItalyIban"}, - {IbanCountry::Latvia, "shouldGenerateLatviaIban"}, - {IbanCountry::Lithuania, "shouldGenerateLithuaniaIban"}, - {IbanCountry::Luxembourg, "shouldGenerateLuxembourgIban"}, - {IbanCountry::Malta, "shouldGenerateMaltaIban"}, - {IbanCountry::Netherlands, "shouldGenerateNetherlandsIban"}, - {IbanCountry::Poland, "shouldGeneratePolandIban"}, - {IbanCountry::Portugal, "shouldGeneratePortugalIban"}, - {IbanCountry::Romania, "shouldGenerateRomaniaIban"}, - {IbanCountry::Slovakia, "shouldGenerateSlovakiaIban"}, - {IbanCountry::Slovenia, "shouldGenerateSloveniaIban"}, - {IbanCountry::Spain, "shouldGenerateSpainIban"}, - {IbanCountry::Sweden, "shouldGenerateSwedenIban"}, -}; -const std::unordered_map generatedBicTestName{ - {BicCountry::Poland, "shouldGeneratePolandBic"}, - {BicCountry::UnitedStates, "shouldGenerateUnitedStatesBic"}, - {BicCountry::UnitedKingdom, "shouldGenerateUnitedKingdomBic"}, - {BicCountry::Germany, "shouldGenerateGermanyBic"}, - {BicCountry::Romania, "shouldGenerateRomaniaBic"}, - {BicCountry::France, "shouldGenerateFranceBic"}, - {BicCountry::Italy, "shouldGenerateItalyBic"}, - {BicCountry::Spain, "shouldGenerateSpainBic"}, - {BicCountry::Netherlands, "shouldGenerateNetherlandsBic"}, - {BicCountry::India, "shouldGenerateIndiaBic"}, +const std::unordered_map expectedRegexes{ + {Locale::de_AT, "^(AT)([0-9]{2})([0-9]{5})([0-9]{11})$"}, + {Locale::de_BE, "^(BE)([0-9]{2})([0-9]{3})([0-9]{7})([0-9]{2})$"}, + {Locale::bg_BG, "^(BG)([0-9]{2})([A-Z]{4})([0-9]{4})([0-9]{2})([a-zA-Z0-9]{8})$"}, + {Locale::hr_HR, "^(HR)([0-9]{2})([0-9]{7})([0-9]{10})$"}, + {Locale::el_CY, "^(CY)([0-9]{2})([0-9]{3})([0-9]{5})([a-zA-Z0-9]{16})$"}, + {Locale::cs_CZ, "^(CZ)([0-9]{2})([0-9]{4})([0-9]{6})([0-9]{10})$"}, + {Locale::da_DK, "^(DK)([0-9]{2})([0-9]{4})([0-9]{9})([0-9]{1})$"}, + {Locale::et_EE, "^(EE)([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{11})([0-9]{1})$"}, + {Locale::fi_FI, "^(FI)([0-9]{2})([0-9]{6})([0-9]{7})([0-9]{1})$"}, + {Locale::fr_FR, "^(FR)([0-9]{2})([0-9]{5})([0-9]{5})([a-zA-Z0-9]{11})([0-9]{2})$"}, + {Locale::de_DE, "^(DE)([0-9]{2})([0-9]{8})([0-9]{10})$"}, + {Locale::el_GR, "^(GR)([0-9]{2})([0-9]{3})([0-9]{4})([a-zA-Z0-9]{16})$"}, + {Locale::hu_HU, "^(HU)([0-9]{2})([0-9]{3})([0-9]{4})([0-9]{1})([0-9]{15})([0-9]{1})$"}, + {Locale::en_IE, "^(IE)([0-9]{2})([A-Z]{4})([0-9]{6})([0-9]{8})$"}, + {Locale::it_IT, "^(IT)([0-9]{2})([A-Z]{1})([0-9]{5})([0-9]{5})([a-zA-Z0-9]{12})$"}, + {Locale::lv_LV, "^(LV)([0-9]{2})([A-Z]{4})([a-zA-Z0-9]{13})$"}, + {Locale::lt_LT, "^(LT)([0-9]{2})([0-9]{5})([0-9]{11})$"}, + {Locale::de_LU, "^(LU)([0-9]{2})([0-9]{3})([a-zA-Z0-9]{13})$"}, + {Locale::en_MT, "^(MT)([0-9]{2})([A-Z]{4})([0-9]{5})([a-zA-Z0-9]{18})$"}, + {Locale::nl_NL, "^(NL)([0-9]{2})([A-Z]{4})([0-9]{10})$"}, + {Locale::pl_PL, "^(PL)([0-9]{2})([0-9]{3})([0-9]{4})([0-9]{1})([0-9]{16})$"}, + {Locale::pt_PT, "^(PT)([0-9]{2})([0-9]{4})([0-9]{4})([0-9]{11})([0-9]{2})$"}, + {Locale::ro_RO, "^(RO)([0-9]{2})([A-Z]{4})([a-zA-Z0-9]{16})$"}, + {Locale::sk_SK, "^(SK)([0-9]{2})([0-9]{4})([0-9]{6})([0-9]{10})$"}, + {Locale::sl_SI, "^(SI)([0-9]{2})([0-9]{2})([0-9]{3})([0-9]{8})([0-9]{2})$"}, + {Locale::es_ES, "^(ES)([0-9]{2})([0-9]{4})([0-9]{4})([0-9]{2})([0-9]{10})$"}, + {Locale::sv_SE, "^(SE)([0-9]{2})([0-9]{3})([0-9]{17})$"}, }; } -class FinanceTest : public TestWithParam +class FinanceTest : public TestWithParam { public: static bool checkIfAllCharactersAreNumeric(const std::string& data) @@ -195,15 +153,16 @@ MATCHER_P(MatchesRegexCpp, value, "") TEST_P(FinanceTest, CheckIbanGenerator) { - auto ibanCountry = GetParam(); + const auto locale = GetParam(); + + const auto expectedRegex = + expectedRegexes.contains(locale) ? expectedRegexes.at(locale) : expectedRegexes.at(Locale::de_DE); - ASSERT_THAT(iban(ibanCountry), MatchesRegexCpp(expectedRegex.at(ibanCountry))); + ASSERT_THAT(iban(locale), MatchesRegexCpp(expectedRegex)); } -INSTANTIATE_TEST_SUITE_P(TestIbanGenerator, FinanceTest, - ValuesIn(std::views::keys(expectedRegex).begin(), std::views::keys(expectedRegex).end()), - [](const TestParamInfo& paramInfo) - { return generatedTestName.at(paramInfo.param); }); +INSTANTIATE_TEST_SUITE_P(TestIbanGenerator, FinanceTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); TEST_F(FinanceTest, shouldGenerateAmountWithSymbol) { @@ -292,12 +251,6 @@ TEST_F(FinanceTest, shouldGenerateCreditCardNumber) ASSERT_TRUE(common::luhnCheck(generatedCreditCardNumber)); } -TEST_F(FinanceTest, shouldGenerateEmptyCreditCardNumber) -{ - const auto emptyString = ""; - ASSERT_TRUE(emptyString == creditCardNumber(CreditCardType::DefaultCard)); -} - TEST_F(FinanceTest, shouldGenerateAmericanExpressCreditCardNumber) { const auto generatedCreditCardNumber = creditCardNumber(CreditCardType::AmericanExpress); @@ -419,25 +372,22 @@ TEST_F(FinanceTest, shouldGenerateRandomCreditCardTypeName) ASSERT_TRUE(std::find(creditCardNames.begin(), creditCardNames.end(), creditCardTypeName) != creditCardNames.end()); } -class FinanceBicTest : public TestWithParam +class FinanceBicTest : public TestWithParam { }; TEST_P(FinanceBicTest, CheckBicGenerator) { - const auto country = GetParam(); + const auto locale = GetParam(); - const auto generatedBic = bic(country); + const auto generatedBic = bic(locale); - const auto& bankIdentifiersCodes = bicCountriesCodes.at(country); + const auto& bankIdentifiersCodes = + bicCountriesCodes.contains(locale) ? bicCountriesCodes.at(locale) : bicCountriesCodes.at(Locale::en_US); ASSERT_TRUE(std::ranges::any_of(bankIdentifiersCodes, [generatedBic](const std::string_view& bankIdentifierCode) { return generatedBic == bankIdentifierCode; })); } -INSTANTIATE_TEST_SUITE_P(TestBicGenerator, FinanceBicTest, - Values(BicCountry::Poland, BicCountry::UnitedStates, BicCountry::UnitedKingdom, - BicCountry::Germany, BicCountry::Romania, BicCountry::France, BicCountry::Italy, - BicCountry::Spain, BicCountry::Netherlands, BicCountry::India), - [](const TestParamInfo& paramInfo) - { return generatedBicTestName.at(paramInfo.param); }); +INSTANTIATE_TEST_SUITE_P(TestBicGenerator, FinanceBicTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); diff --git a/tests/modules/person_test.cpp b/tests/modules/person_test.cpp index 3dc7ff2ad..9a4734cb1 100644 --- a/tests/modules/person_test.cpp +++ b/tests/modules/person_test.cpp @@ -329,47 +329,111 @@ TEST_P(PersonTest, shouldGenerateFemaleFullName) { return generatedFullName.find(lastName) != std::string::npos; })); } -INSTANTIATE_TEST_SUITE_P(TestPersonNamesByLocale, PersonTest, ValuesIn(locales), - [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); - -// TODO: move to parameterized tests -TEST_F(PersonTest, shouldGeneratePrefix) +TEST_P(PersonTest, shouldGeneratePrefix) { - const auto generatedPrefix = prefix(); + const auto locale = GetParam(); + + const auto& peopleNames = getPeopleNamesByLocale(locale); - std::vector prefixes(englishMalePrefixes.begin(), englishMalePrefixes.end()); + const auto& femalesPrefixes = peopleNames.femalesNames.prefixes; - prefixes.insert(prefixes.end(), englishFemalePrefixes.begin(), englishFemalePrefixes.end()); + const auto& malesPrefixes = peopleNames.malesNames.prefixes; + + std::vector prefixes(femalesPrefixes.begin(), femalesPrefixes.end()); + + prefixes.insert(prefixes.end(), malesPrefixes.begin(), malesPrefixes.end()); + + const auto generatedPrefix = prefix(locale); ASSERT_TRUE(std::ranges::any_of(prefixes, [generatedPrefix](const std::string_view& prefix) - { return prefix == generatedPrefix; })); + { return generatedPrefix == prefix; }) || + generatedPrefix.empty()); +} + +TEST_P(PersonTest, shouldGenerateMalePrefix) +{ + const auto locale = GetParam(); + + const auto& peopleNames = getPeopleNamesByLocale(locale); + + const auto& malesPrefixes = peopleNames.malesNames.prefixes; + + const auto generatedPrefix = prefix(locale, Sex::Male); + + ASSERT_TRUE(std::ranges::any_of(malesPrefixes, [generatedPrefix](const std::string_view& prefix) + { return generatedPrefix == prefix; }) || + generatedPrefix.empty()); +} + +TEST_P(PersonTest, shouldGenerateFemalePrefix) +{ + const auto locale = GetParam(); + + const auto& peopleNames = getPeopleNamesByLocale(locale); + + const auto& femalesPrefixes = peopleNames.femalesNames.prefixes; + + const auto generatedPrefix = prefix(locale, Sex::Female); + + ASSERT_TRUE(std::ranges::any_of(femalesPrefixes, [generatedPrefix](const std::string_view& prefix) + { return generatedPrefix == prefix; }) || + generatedPrefix.empty()); } -// TODO: move to parameterized tests -TEST_F(PersonTest, shouldGenerateMalePrefix) +TEST_P(PersonTest, shouldGenerateSuffix) { - const auto generatedPrefix = prefix(Locale::en_US, Sex::Male); + const auto locale = GetParam(); + + const auto& peopleNames = getPeopleNamesByLocale(locale); - ASSERT_TRUE(std::ranges::any_of(englishMalePrefixes, [generatedPrefix](const std::string_view& prefix) - { return prefix == generatedPrefix; })); + const auto& femalesSuffixes = peopleNames.femalesNames.suffixes; + + const auto& malesSuffixes = peopleNames.malesNames.suffixes; + + std::vector suffixes(femalesSuffixes.begin(), femalesSuffixes.end()); + + suffixes.insert(suffixes.end(), malesSuffixes.begin(), malesSuffixes.end()); + + const auto generatedSuffix = suffix(locale); + + ASSERT_TRUE(std::ranges::any_of(suffixes, [generatedSuffix](const std::string_view& suffix) + { return generatedSuffix == suffix; }) || + generatedSuffix.empty()); } -TEST_F(PersonTest, shouldGenerateFemalePrefix) +TEST_P(PersonTest, shouldGenerateMaleSuffix) { - const auto generatedPrefix = prefix(Locale::en_US, Sex::Female); + const auto locale = GetParam(); - ASSERT_TRUE(std::ranges::any_of(englishFemalePrefixes, [generatedPrefix](const std::string_view& prefix) - { return prefix == generatedPrefix; })); + const auto& peopleNames = getPeopleNamesByLocale(locale); + + const auto& malesSuffixes = peopleNames.malesNames.suffixes; + + const auto generatedSuffix = suffix(locale, Sex::Male); + + ASSERT_TRUE(std::ranges::any_of(malesSuffixes, [generatedSuffix](const std::string_view& suffix) + { return generatedSuffix == suffix; }) || + generatedSuffix.empty()); } -TEST_F(PersonTest, shouldGenerateSuffix) +TEST_P(PersonTest, shouldGenerateFemaleSuffix) { - const auto generatedSuffix = suffix(); + const auto locale = GetParam(); + + const auto& peopleNames = getPeopleNamesByLocale(locale); + + const auto& femalesSuffixes = peopleNames.femalesNames.suffixes; + + const auto generatedSuffix = suffix(locale, Sex::Female); - ASSERT_TRUE(std::ranges::any_of(englishSuffixes, [generatedSuffix](const std::string_view& suffix) - { return suffix == generatedSuffix; })); + ASSERT_TRUE(std::ranges::any_of(femalesSuffixes, [generatedSuffix](const std::string_view& suffix) + { return generatedSuffix == suffix; }) || + generatedSuffix.empty()); } +INSTANTIATE_TEST_SUITE_P(TestPersonNamesByLocale, PersonTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); + TEST_F(PersonTest, shouldGenerateSex) { const auto generatedSex = sex();