From 42b0664d40b310b63a8aa24926aa966fc9794af6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blar?= Date: Sat, 6 Apr 2024 12:19:10 +0100 Subject: [PATCH] move types to modules (#526) --- include/faker-cxx/Finance.h | 8 +- include/faker-cxx/Person.h | 86 ++++- include/faker-cxx/Phone.h | 238 ++++++++++++- .../faker-cxx/{types => }/RandomGenerator.h | 0 include/faker-cxx/String.h | 2 +- include/faker-cxx/Structure.h | 311 ++++++++++++++++- include/faker-cxx/System.h | 13 +- include/faker-cxx/types/Country.h | 95 ------ include/faker-cxx/types/Currency.h | 18 - include/faker-cxx/types/FileType.h | 26 -- include/faker-cxx/types/Language.h | 71 ---- include/faker-cxx/types/PassportType.h | 24 -- .../types/PhoneNumberCountryFormat.h | 238 ------------- include/faker-cxx/types/Precision.h | 2 - include/faker-cxx/types/Sex.h | 72 ---- include/faker-cxx/types/SsnCountry.h | 45 --- include/faker-cxx/types/StructureToken.h | 312 ------------------ .../mappers/precisionMapper/PrecisionMapper.h | 2 + src/modules/finance/FinanceTest.cpp | 8 +- src/modules/finance/data/Currencies.h | 2 +- src/modules/person/Person.cpp | 90 ++++- src/modules/person/PersonTest.cpp | 123 ++++++- src/modules/person/data/SsnFormats.h | 3 +- src/modules/string/StringTest.cpp | 2 +- src/modules/system/System.cpp | 12 +- src/modules/system/SystemTest.cpp | 25 +- src/modules/system/data/MimeTypes.h | 1 + 27 files changed, 880 insertions(+), 949 deletions(-) rename include/faker-cxx/{types => }/RandomGenerator.h (100%) delete mode 100644 include/faker-cxx/types/Currency.h delete mode 100644 include/faker-cxx/types/FileType.h delete mode 100644 include/faker-cxx/types/Language.h delete mode 100644 include/faker-cxx/types/PassportType.h delete mode 100644 include/faker-cxx/types/PhoneNumberCountryFormat.h delete mode 100644 include/faker-cxx/types/Sex.h delete mode 100644 include/faker-cxx/types/SsnCountry.h delete mode 100644 include/faker-cxx/types/StructureToken.h diff --git a/include/faker-cxx/Finance.h b/include/faker-cxx/Finance.h index 75afabb33..667f18ae7 100644 --- a/include/faker-cxx/Finance.h +++ b/include/faker-cxx/Finance.h @@ -4,11 +4,17 @@ #include #include "types/Country.h" -#include "types/Currency.h" #include "types/Precision.h" namespace faker { +struct Currency +{ + std::string name; + std::string code; + std::string symbol; +}; + class Finance { public: diff --git a/include/faker-cxx/Person.h b/include/faker-cxx/Person.h index cc0872720..ff610d919 100644 --- a/include/faker-cxx/Person.h +++ b/include/faker-cxx/Person.h @@ -3,13 +3,15 @@ #include #include -#include "faker-cxx/types/Country.h" -#include "faker-cxx/types/PassportType.h" -#include "faker-cxx/types/Sex.h" -#include "faker-cxx/types/SsnCountry.h" +#include "types/Country.h" namespace faker { +enum class PassportCountry; +enum class Sex; +enum class SsnCountry; +enum class Language; + class Person { public: @@ -27,7 +29,7 @@ class Person * Person::firstName(Country::England, Sex::Male) // "Arthur" * @endcode */ - static std::string firstName(Country country = Country::England, std::optional sex = std::nullopt); + static std::string firstName(std::optional country = std::nullopt, std::optional sex = std::nullopt); /** * @brief Returns a random last name. @@ -41,7 +43,7 @@ class Person * Person::lastName() // "Peterson" * @endcode */ - static std::string lastName(Country country = Country::England, std::optional sex = std::nullopt); + static std::string lastName(std::optional country = std::nullopt, std::optional sex = std::nullopt); /** * @brief Returns a random middle name. @@ -70,7 +72,7 @@ class Person * Person::fullName(Country::England, Sex::Male) // "Samuel Walker" * @endcode */ - static std::string fullName(Country country = Country::England, std::optional sex = std::nullopt); + static std::string fullName(std::optional country = std::nullopt, std::optional sex = std::nullopt); /** * @brief Returns a random name prefix. @@ -118,7 +120,7 @@ class Person * Person::sex() // "Male" * @endcode */ - static std::string sex(Language language = Language::English); + static std::string sex(std::optional language = std::nullopt); /** * @brief Returns a random gender. @@ -220,7 +222,7 @@ class Person * Person::ssn(SsnCountry::Polish) // "95111901567" * @endcode */ - static std::string ssn(std::optional country); + static std::string ssn(std::optional country = std::nullopt); /** * @brief Returns a random Western Zodiac @@ -253,6 +255,70 @@ class Person * Person::passport(PassportCountry::Romania) // "12345678" * @endcode */ - static std::string passport(PassportCountry country = PassportCountry::Usa); + static std::string passport(std::optional country = std::nullopt); +}; + +enum class PassportCountry +{ + Usa, + Poland, + France, + Romania, +}; + +enum class Sex +{ + Male, + Female, +}; + +enum class SsnCountry +{ + Poland, + UnitedStates, + UnitedKingdom, + Germany, + France, + Italy, + Spain, + India, +}; + +enum class Language +{ + English, + Polish, + French, + German, + Italian, + Russian, + Romanian, + Hindi, + Finnish, + Nepali, + Spanish, + Turkish, + Czech, + Slovak, + Ukrainian, + Danish, + Swedish, + Portuguese, + Norwegian, + Japanese, + Hungarian, + Croatian, + Greek, + Slovene, + Dutch, + Mandarin, + Korean, + Serbian, + Macedonian, + Albanian, + Latvian, + Irish, + Belarusian, + Estonian }; } diff --git a/include/faker-cxx/Phone.h b/include/faker-cxx/Phone.h index a1e447e85..24873f824 100644 --- a/include/faker-cxx/Phone.h +++ b/include/faker-cxx/Phone.h @@ -4,10 +4,10 @@ #include #include -#include "types/PhoneNumberCountryFormat.h" - namespace faker { +enum class PhoneNumberCountryFormat; + class Phone { public: @@ -98,4 +98,238 @@ class Phone static std::map createPhoneNumberFormatMap(); static std::map phoneNumberFormatMap; }; + +enum class PhoneNumberCountryFormat +{ + Default, + Afghanistan, + AlandIslands, + Albania, + Algeria, + AmericanSamoa, + Andorra, + Angola, + Anguilla, + AntiguaAndBarbuda, + Argentina, + Armenia, + Aruba, + Australia, + Austria, + Azerbaijan, + Bahamas, + Bahrain, + Bangladesh, + Barbados, + Belarus, + Belgium, + Belize, + Benin, + Bermuda, + Bhutan, + Bolivia, + BosniaAndHerzegovina, + Botswana, + Brazil, + BruneiDarussalam, + Bulgaria, + BurkinaFaso, + Burundi, + Cambodia, + Cameroon, + Canada, + CapeVerde, + CaymanIslands, + CentralAfricanRepublic, + Chad, + Chile, + China, + Colombia, + Comoros, + Congo, + CookIslands, + CostaRica, + Croatia, + Cuba, + Curacao, + Cyprus, + Czechia, + DemocraticRepublicOfTheCongo, + Denmark, + Djibouti, + Dominica, + DominicanRepublic, + Ecuador, + Egypt, + ElSalvador, + EquatorialGuinea, + Eritrea, + Estonia, + Eswatini, + Ethiopia, + FaroeIslands, + Fiji, + Finland, + France, + FrenchGuiana, + FrenchPolynesia, + Gabon, + Gambia, + Georgia, + Germany, + Ghana, + Gibraltar, + Greece, + Greenland, + Grenada, + Guadeloupe, + Guam, + Guatemala, + Guernsey, + Guinea, + GuineaBissau, + Guyana, + Haiti, + HolySeeVaticanCityState, + Honduras, + HongKong, + Hungary, + Iceland, + India, + Indonesia, + Iran, + Iraq, + Ireland, + IsleOfMan, + Israel, + Italy, + Jamaica, + Japan, + Jersey, + Jordan, + RepublicOfKorea, + Kuwait, + KyrgyzRepublic, + Latvia, + Lebanon, + Lesotho, + Liberia, + LibyanArabJamahiriya, + Liechtenstein, + Lithuania, + Luxembourg, + Macao, + Madagascar, + Malawi, + Malaysia, + Maldives, + Mali, + Malta, + MarshallIslands, + Martinique, + Mauritania, + Mauritius, + Mayotte, + Mexico, + Micronesia, + Moldova, + Monaco, + Mongolia, + Montenegro, + Montserrat, + Morocco, + Mozambique, + Myanmar, + Namibia, + Nauru, + Nepal, + Netherlands, + NewCaledonia, + NewZealand, + Nicaragua, + Niger, + Nigeria, + Niue, + NorthMacedonia, + NorthernMarianaIslands, + Norway, + Oman, + Pakistan, + Palau, + Palestine, + Panama, + PapuaNewGuinea, + Paraguay, + Peru, + Philippines, + Poland, + Portugal, + PuertoRico, + Qatar, + Reunion, + Romania, + RussianFederation, + Rwanda, + SaintBarthelemy, + SaintHelena, + SaintKittsAndNevis, + SaintLucia, + SaintMartin, + SaintPierreAndMiquelon, + SaintVincentAndTheGrenadines, + Samoa, + SanMarino, + SaoTomeAndPrincipe, + SaudiArabia, + Senegal, + Serbia, + Seychelles, + SierraLeone, + Singapore, + SintMaarten, + Slovakia, + Slovenia, + SolomonIslands, + Somalia, + SouthAfrica, + SouthSudan, + Spain, + SriLanka, + Sudan, + Suriname, + SvalbardAndJanMayenIslands, + Sweden, + Switzerland, + SyrianArabRepublic, + Taiwan, + Tajikistan, + Tanzania, + Thailand, + TimorLeste, + Togo, + Tonga, + TrinidadAndTobago, + Tunisia, + Turkey, + Turkmenistan, + TurksAndCaicosIslands, + Tuvalu, + Uganda, + Ukraine, + UnitedArabEmirates, + UK, + Usa, + Uruguay, + Uzbekistan, + Vanuatu, + Venezuela, + Vietnam, + VirginIslandsBritish, + VirginIslandsUS, + WallisAndFutuna, + WesternSahara, + Yemen, + Zambia, + Zimbabwe +}; } diff --git a/include/faker-cxx/types/RandomGenerator.h b/include/faker-cxx/RandomGenerator.h similarity index 100% rename from include/faker-cxx/types/RandomGenerator.h rename to include/faker-cxx/RandomGenerator.h diff --git a/include/faker-cxx/String.h b/include/faker-cxx/String.h index 05b4e8a91..9e13cfab4 100644 --- a/include/faker-cxx/String.h +++ b/include/faker-cxx/String.h @@ -8,8 +8,8 @@ #include #include +#include "RandomGenerator.h" #include "types/Hex.h" -#include "types/RandomGenerator.h" namespace faker { diff --git a/include/faker-cxx/Structure.h b/include/faker-cxx/Structure.h index d347d39d0..e8fb74045 100644 --- a/include/faker-cxx/Structure.h +++ b/include/faker-cxx/Structure.h @@ -3,10 +3,10 @@ #include #include -#include "types/StructureToken.h" - namespace faker { +enum class StructureToken; + class Structure { public: @@ -45,4 +45,311 @@ class Structure static std::string csv(const std::map& items, unsigned int rows); }; +enum class StructureToken +{ + // Airline module + AirlineAircraftType, + AirlineAirplaneName, + AirlineAirplaneCode, + AirlineAirlineName, + AirlineAirlineCode, + AirlineAirportName, + AirlineAirportCode, + AirlineSeat, + AirlineRecordLocator, + AirlineFlightNumber, + + // Animal module + AnimalBear, + AnimalBird, + AnimalCat, + AnimalCetacean, + AnimalCow, + AnimalCrocodilia, + AnimalDog, + AnimalFish, + AnimalHorse, + AnimalInsect, + AnimalLion, + AnimalRabbit, + AnimalRodent, + AnimalSnake, + AnimalType, + + // Book module + BookTitle, + BookGenre, + BookAuthor, + BookPublisher, + BookIsbn, + + // Color module + ColorName, + ColorRGB, + ColorHEX, + ColorHSL, + ColorLCH, + ColorCMYK, + + // Commerce module + CommerceDepartment, + CommercePrice, + CommerceSku, + CommerceProductAdjective, + CommerceProductMaterial, + CommerceProductName, + CommerceProductFullName, + CommerceEAN13, + CommerceEAN8, + CommerceISBN13, + CommerceISBN10, + + // Company module + CompanyName, + CompanyType, + CompanyIndustry, + CompanyBuzzPhrase, + CompanyBuzzAdjective, + CompanyBuzzNoun, + CompanyBuzzVerb, + CompanyCatchPhrase, + CompanyCtachPhraseAdjective, + CompanyCatchPhraseDescriptor, + CompanyCatchPhraseNoun, + + // Computer module + ComputerType, + ComputerManufacture, + ComputerModel, + ComputerCPUManufacture, + ComputerCPUType, + ComputerCPUModel, + ComputerGPUManufacture, + ComputerGPUType, + ComputerGPUModel, + + // Crypto module + CryptoSHA256, + CryptoMD5, + + // Database module + DatabaseColumnName, + DatabaseColumnType, + DatabaseCollation, + DatabaseEngine, + DatabaseMongoDBObjectId, + + // Datatype module + DatatypeBoolean, + + // Date module ISO and Timestamp + DatePastDateISO, + DatePastDateTimestamp, + DatefutureDateISO, + DatefutureDateTimestamp, + DateRecentDateISO, + DateRecentDateTimestamp, + DateSoonDateISO, + DateSoonDateTimestamp, + DateBirthdateByAgeISO, + DateBirthdateByAgeTimestamp, + DateBirthdateByYearISO, + DateBirthdateByYearTimestamp, + DateWeekdayName, + DateWeekdayAbbreviatedName, + DateMontName, + DateMonthAbbreviatedName, + + // Finance module + FinanceCurrencyName, + FinanceCurrencyCode, + FinanceCurrencySymbol, + FinanceAccountType, + FinanceAmount, + FinanceIban, + FinanceBic, + FinanceAccountNumber, + FinancePin, + FinanceRoutingNumber, + FinanceCreditCardNumber, + FinanceCreditCardCvv, + FinanceBitcoinAddress, + FinanceLitecoinAddress, + FinanceEthereumAddress, + + // Food module + FoodAlcoholicBeverage, + FoodGrain, + FoodMilkProduct, + FoodFruit, + FoodMeat, + FoodSeafood, + FoodVegetable, + FoodOil, + FoodNut, + FoodSeed, + FoodSugarProduct, + FoodNonAlcoholicBeverage, + FoodDishName, + FoodFoodCategory, + + // Git module + GitBranch, + GitCommitDate, + GitCommitEntry, + GitCommitMessage, + GitCommitSha, + + // Hacker module + HackerAbbreviation, + HackerAdjective, + HackerNoun, + HackerVerb, + HackerIngverb, + HackerPhrase, + + // Image module + ImageImageURL, + ImageGitHubAvatarURL, + ImageDimensions, + + // Internet module + InternetUsername, + InternetEmail, + InternetExampleEmail, + InternetPassword, + InternetEmoji, + InternetProtocol, + InternetHttpMethod, + InternetHttpRequestHeader, + InternetHttpResponseHeader, + InternetHttpMediaType, + InternetIpv4, + InternetIpv6, + InternetMac, + InternetURL, + InternetDomainName, + InternetDomainWord, + InternetDomainSuffix, + + // Location module + LocationCountry, + LocationCountryCode, + LocationState, + LocationCity, + LocationZipCode, + LocationStreetAddress, + LocationStreet, + LocationBuildingNumber, + LocationSecondaryAddress, + LocationLatitude, + LocationLongitude, + LocationDirection, + LocationTimeZone, + + // Lorem module + LoremWord, + LoremWords, + LoremSentence, + LoremSentences, + LoremSlung, + LoremParagraph, + LoremParagraphs, + + // Medicine module + MedicineCondition, + MedicineMedicalTest, + MedicineSpecialty, + + // Movie module + MovieGenre, + MovieMovieTitle, + MovieTvShow, + MovieDirector, + MovieActor, + MovieActress, + + // Music module + MusicArtist, + MusicGenre, + MusicSongName, + + // Person module + PersonFirstName, + PersonLastName, + PersonMiddleName, + PersonFullName, + PersonPrefix, + PersonSuffix, + PersonSex, + PersonGender, + PersonJobTitle, + PersonJobDescriptor, + PersonJobArea, + PersonJobType, + PersonHoby, + PersonLanguage, + PersonNationality, + PersonWesternZodiac, + PersonChineseZodiac, + + // Phone module + PhoneNumber, + PhonePlatform, + PhoneModelName, + PhoneManufacturer, + PhoneIMEI, + + // Sport module + SportSport, + SportSoccerTeam, + SportMaleAthelete, + SportFemaleAthlete, + SportSportEvent, + + // System module + SystemFileName, + SystemFileExtension, + SystemCommonFileName, + SystemCommonFileExtension, + SystemMimeType, + SystemCommonFileType, + SystemFileType, + SystemDirectoryPath, + SystemFilePath, + SystemSemver, + SystemNetworkInterface, + SystemCron, + + // VideoGame module + VideoGameGameTitle, + VideoGameGenre, + VideoGamePlatform, + VideoGameStudioName, + + // Weather module + WeatherTemperatureMetric, + WeatherTemperatureImperial, + WeatherPressureMetric, + WeatherPressureImperial, + WeatherVisibilityMetric, + WeatherVisibilityImperial, + WeatherWindSpeedMetric, + WeatherWindSpeedImperial, + WeatherUvIndex, + WeatherHumidity, + WeatherWeatherDescription, + WeatherCloudCover, + + // Word module + WordSample, + WordWords, + WordAdjective, + WordAdverb, + WordConjunction, + WordInterjection, + WordNoun, + WordPreposition, + WordVerb, +}; } diff --git a/include/faker-cxx/System.h b/include/faker-cxx/System.h index 13d2b5047..f7c167795 100644 --- a/include/faker-cxx/System.h +++ b/include/faker-cxx/System.h @@ -1,8 +1,7 @@ #pragma once #include - -#include "types/FileType.h" +#include namespace faker { @@ -16,13 +15,21 @@ struct FileOptions } extensionRange; }; +enum class FileType +{ + Video, + Audio, + Image, + Text, + Application +}; + struct CronOptions { bool includeYear = false; bool includeNonStandard = false; }; -// TODO: change to enums struct NetworkInterfaceOptions { std::optional interfaceType; diff --git a/include/faker-cxx/types/Country.h b/include/faker-cxx/types/Country.h index 560612f14..0904afe1d 100644 --- a/include/faker-cxx/types/Country.h +++ b/include/faker-cxx/types/Country.h @@ -1,10 +1,5 @@ #pragma once -#include -#include -#include -#include - namespace faker { enum class Country @@ -71,94 +66,4 @@ enum class Country Kazakhstan, Maldives, }; - -const std::vector countries{ - Country::Usa, Country::England, Country::Poland, Country::Italy, Country::France, - Country::Germany, Country::Russia, Country::Romania, Country::India, Country::Finland, - Country::Nepal, Country::Spain, Country::Turkey, Country::Czech, Country::Slovakia, - Country::Ukraine, Country::Denmark, Country::Sweden, Country::Brazil, Country::Norway, - Country::Japan, Country::Portugal, Country::Hungary, Country::Croatia, Country::Greece, - Country::Slovenia, Country::Austria, Country::Switzerland, Country::Belgium, Country::Netherlands, - Country::China, Country::Korea, Country::Canada, Country::Mexico, Country::Argentina, - Country::Australia, Country::Serbia, Country::Macedonia, Country::Albania, Country::Latvia, - Country::Ireland, Country::Belarus, Country::Estonia, Country::Iran, Country::Bulgaria, - Country::Moldova, Country::Lithuania, Country::Iceland, Country::Palestine, Country::Israel, - Country::Vietnam, Country::Monaco, Country::Bosnia, Country::Lebanon, Country::Syria, - Country::Malta, Country::SouthAfrica, Country::Azerbaijan, Country::Ghana, Country::Kazakhstan, - Country::Maldives, -}; - -inline std::string toString(Country country) -{ - std::map countryToStringMapping{ - {Country::Usa, "Usa"}, - {Country::England, "England"}, - {Country::Poland, "Poland"}, - {Country::Italy, "Italy"}, - {Country::France, "France"}, - {Country::Germany, "Germany"}, - {Country::Russia, "Russia"}, - {Country::Romania, "Romania"}, - {Country::India, "India"}, - {Country::Finland, "Finland"}, - {Country::Nepal, "Nepal"}, - {Country::Spain, "Spain"}, - {Country::Turkey, "Turkey"}, - {Country::Czech, "Czech"}, - {Country::Slovakia, "Slovakia"}, - {Country::Ukraine, "Ukraine"}, - {Country::Denmark, "Denmark"}, - {Country::Sweden, "Sweden"}, - {Country::Brazil, "Brazil"}, - {Country::Norway, "Norway"}, - {Country::Japan, "Japan"}, - {Country::Portugal, "Portugal"}, - {Country::Hungary, "Hungary"}, - {Country::Croatia, "Croatia"}, - {Country::Greece, "Greece"}, - {Country::Slovenia, "Slovenia"}, - {Country::Austria, "Austria"}, - {Country::Switzerland, "Switzerland"}, - {Country::Belgium, "Belgium"}, - {Country::Netherlands, "Netherlands"}, - {Country::China, "China"}, - {Country::Korea, "Korea"}, - {Country::Canada, "Canada"}, - {Country::Mexico, "Mexico"}, - {Country::Argentina, "Argentina"}, - {Country::Australia, "Australia"}, - {Country::Serbia, "Serbia"}, - {Country::Macedonia, "Macedonia"}, - {Country::Albania, "Albania"}, - {Country::Latvia, "Latvia"}, - {Country::Ireland, "Ireland"}, - {Country::Belarus, "Belarus"}, - {Country::Estonia, "Estonia"}, - {Country::Iran, "Iran"}, - {Country::Bulgaria, "Bulgaria"}, - {Country::Moldova, "Moldova"}, - {Country::Lithuania, "Lithuania"}, - {Country::Iceland, "Iceland"}, - {Country::Palestine, "Palestine"}, - {Country::Israel, "Israel"}, - {Country::Vietnam, "Vietnam"}, - {Country::Monaco, "Monaco"}, - {Country::Bosnia, "Bosnia"}, - {Country::Lebanon, "Lebanon"}, - {Country::Syria, "Syria"}, - {Country::Malta, "Malta"}, - {Country::SouthAfrica, "South Africa"}, - {Country::Azerbaijan, "Azerbaijan"}, - {Country::Ghana, "Ghana"}, - {Country::Kazakhstan, "Kazakhstan"}, - {Country::Maldives, "Maldives"}, - }; - - return countryToStringMapping.at(country); -} - -inline std::ostream& operator<<(std::ostream& os, Country country) -{ - return os << toString(country); -} } diff --git a/include/faker-cxx/types/Currency.h b/include/faker-cxx/types/Currency.h deleted file mode 100644 index c4ff3ef1d..000000000 --- a/include/faker-cxx/types/Currency.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include - -namespace faker -{ -struct Currency -{ - std::string name; - std::string code; - std::string symbol; -}; - -inline bool operator==(const Currency& lhs, const Currency& rhs) -{ - return lhs.name == rhs.name && lhs.code == rhs.code && lhs.symbol == rhs.symbol; -} -} diff --git a/include/faker-cxx/types/FileType.h b/include/faker-cxx/types/FileType.h deleted file mode 100644 index d47db004c..000000000 --- a/include/faker-cxx/types/FileType.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -enum class FileType -{ - Video, - Audio, - Image, - Text, - Application -}; - -inline std::string toString(FileType type) -{ - std::map enumToStringMapping{{FileType::Video, "video"}, - {FileType::Audio, "audio"}, - {FileType::Image, "image"}, - {FileType::Text, "text"}, - {FileType::Application, "application"}}; - return enumToStringMapping.at(type); -} -} diff --git a/include/faker-cxx/types/Language.h b/include/faker-cxx/types/Language.h deleted file mode 100644 index 5d120becf..000000000 --- a/include/faker-cxx/types/Language.h +++ /dev/null @@ -1,71 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ - -enum class Language -{ - English, - Polish, - French, - German, - Italian, - Russian, - Romanian, - Hindi, - Finnish, - Nepali, - Spanish, - Turkish, - Czech, - Slovak, - Ukrainian, - Danish, - Swedish, - Portuguese, - Norwegian, - Japanese, - Hungarian, - Croatian, - Greek, - Slovene, - Dutch, - Mandarin, - Korean, - Serbian, - Macedonian, - Albanian, - Latvian, - Irish, - Belarusian, - Estonian -}; - -inline std::string toString(Language language) -{ - static const std::map languageToStringMapping{ - {Language::English, "English"}, {Language::Polish, "Polish"}, {Language::Italian, "Italian"}, - {Language::French, "French"}, {Language::German, "German"}, {Language::Russian, "Russian"}, - {Language::Romanian, "Romanian"}, {Language::Hindi, "Hindi"}, {Language::Finnish, "Finnish"}, - {Language::Nepali, "Nepali"}, {Language::Spanish, "Spanish"}, {Language::Turkish, "Turkish"}, - {Language::Czech, "Czech"}, {Language::Slovak, "Slovak"}, {Language::Ukrainian, "Ukrainian"}, - {Language::Danish, "Danish"}, {Language::Swedish, "Swedish"}, {Language::Portuguese, "Portuguese"}, - {Language::Norwegian, "Norwegian"}, {Language::Japanese, "Japanese"}, {Language::Hungarian, "Hungarian"}, - {Language::Croatian, "Croatian"}, {Language::Greek, "Greek"}, {Language::Slovene, "Slovene"}, - {Language::Dutch, "Dutch"}, {Language::Mandarin, "Mandarin"}, {Language::Korean, "Korean"}, - {Language::Serbian, "Serbian"}, {Language::Macedonian, "Macedonian"}, {Language::Albanian, "Albanian"}, - {Language::Latvian, "Latvian"}, {Language::Irish, "Irish"}, {Language::Belarusian, "Belarusian"}, - {Language::Estonian, "Estonian"}}; - - return languageToStringMapping.at(language); -} - -inline std::ostream& operator<<(std::ostream& os, Language language) -{ - return os << toString(language); -} - -} diff --git a/include/faker-cxx/types/PassportType.h b/include/faker-cxx/types/PassportType.h deleted file mode 100644 index 08b239992..000000000 --- a/include/faker-cxx/types/PassportType.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ - -enum class PassportCountry -{ - Usa, - Poland, - France, - Romania, -}; - -const std::map passportFormats{ - {PassportCountry::Usa, "AA0000000"}, - {PassportCountry::Poland, "AA0000000"}, - {PassportCountry::France, "00AA00000"}, - {PassportCountry::Romania, "00000000"}, -}; - -} diff --git a/include/faker-cxx/types/PhoneNumberCountryFormat.h b/include/faker-cxx/types/PhoneNumberCountryFormat.h deleted file mode 100644 index f9d28409f..000000000 --- a/include/faker-cxx/types/PhoneNumberCountryFormat.h +++ /dev/null @@ -1,238 +0,0 @@ -#pragma once - -namespace faker -{ -enum class PhoneNumberCountryFormat -{ - Default, - Afghanistan, - AlandIslands, - Albania, - Algeria, - AmericanSamoa, - Andorra, - Angola, - Anguilla, - AntiguaAndBarbuda, - Argentina, - Armenia, - Aruba, - Australia, - Austria, - Azerbaijan, - Bahamas, - Bahrain, - Bangladesh, - Barbados, - Belarus, - Belgium, - Belize, - Benin, - Bermuda, - Bhutan, - Bolivia, - BosniaAndHerzegovina, - Botswana, - Brazil, - BruneiDarussalam, - Bulgaria, - BurkinaFaso, - Burundi, - Cambodia, - Cameroon, - Canada, - CapeVerde, - CaymanIslands, - CentralAfricanRepublic, - Chad, - Chile, - China, - Colombia, - Comoros, - Congo, - CookIslands, - CostaRica, - Croatia, - Cuba, - Curacao, - Cyprus, - Czechia, - DemocraticRepublicOfTheCongo, - Denmark, - Djibouti, - Dominica, - DominicanRepublic, - Ecuador, - Egypt, - ElSalvador, - EquatorialGuinea, - Eritrea, - Estonia, - Eswatini, - Ethiopia, - FaroeIslands, - Fiji, - Finland, - France, - FrenchGuiana, - FrenchPolynesia, - Gabon, - Gambia, - Georgia, - Germany, - Ghana, - Gibraltar, - Greece, - Greenland, - Grenada, - Guadeloupe, - Guam, - Guatemala, - Guernsey, - Guinea, - GuineaBissau, - Guyana, - Haiti, - HolySeeVaticanCityState, - Honduras, - HongKong, - Hungary, - Iceland, - India, - Indonesia, - Iran, - Iraq, - Ireland, - IsleOfMan, - Israel, - Italy, - Jamaica, - Japan, - Jersey, - Jordan, - RepublicOfKorea, - Kuwait, - KyrgyzRepublic, - Latvia, - Lebanon, - Lesotho, - Liberia, - LibyanArabJamahiriya, - Liechtenstein, - Lithuania, - Luxembourg, - Macao, - Madagascar, - Malawi, - Malaysia, - Maldives, - Mali, - Malta, - MarshallIslands, - Martinique, - Mauritania, - Mauritius, - Mayotte, - Mexico, - Micronesia, - Moldova, - Monaco, - Mongolia, - Montenegro, - Montserrat, - Morocco, - Mozambique, - Myanmar, - Namibia, - Nauru, - Nepal, - Netherlands, - NewCaledonia, - NewZealand, - Nicaragua, - Niger, - Nigeria, - Niue, - NorthMacedonia, - NorthernMarianaIslands, - Norway, - Oman, - Pakistan, - Palau, - Palestine, - Panama, - PapuaNewGuinea, - Paraguay, - Peru, - Philippines, - Poland, - Portugal, - PuertoRico, - Qatar, - Reunion, - Romania, - RussianFederation, - Rwanda, - SaintBarthelemy, - SaintHelena, - SaintKittsAndNevis, - SaintLucia, - SaintMartin, - SaintPierreAndMiquelon, - SaintVincentAndTheGrenadines, - Samoa, - SanMarino, - SaoTomeAndPrincipe, - SaudiArabia, - Senegal, - Serbia, - Seychelles, - SierraLeone, - Singapore, - SintMaarten, - Slovakia, - Slovenia, - SolomonIslands, - Somalia, - SouthAfrica, - SouthSudan, - Spain, - SriLanka, - Sudan, - Suriname, - SvalbardAndJanMayenIslands, - Sweden, - Switzerland, - SyrianArabRepublic, - Taiwan, - Tajikistan, - Tanzania, - Thailand, - TimorLeste, - Togo, - Tonga, - TrinidadAndTobago, - Tunisia, - Turkey, - Turkmenistan, - TurksAndCaicosIslands, - Tuvalu, - Uganda, - Ukraine, - UnitedArabEmirates, - UK, - Usa, - Uruguay, - Uzbekistan, - Vanuatu, - Venezuela, - Vietnam, - VirginIslandsBritish, - VirginIslandsUS, - WallisAndFutuna, - WesternSahara, - Yemen, - Zambia, - Zimbabwe -}; -} diff --git a/include/faker-cxx/types/Precision.h b/include/faker-cxx/types/Precision.h index 06204b883..8803782b3 100644 --- a/include/faker-cxx/types/Precision.h +++ b/include/faker-cxx/types/Precision.h @@ -1,7 +1,5 @@ #pragma once -#include - namespace faker { enum class Precision diff --git a/include/faker-cxx/types/Sex.h b/include/faker-cxx/types/Sex.h deleted file mode 100644 index 2b7e57b45..000000000 --- a/include/faker-cxx/types/Sex.h +++ /dev/null @@ -1,72 +0,0 @@ -#pragma once - -#include - -#include "Language.h" - -namespace faker -{ -enum class Sex -{ - Male, - Female, -}; - -const std::map> sexTranslations = { - {Language::English, {{Sex::Male, "Male"}, {Sex::Female, "Female"}}}, - {Language::Polish, {{Sex::Male, "Mężczyzna"}, {Sex::Female, "Kobieta"}}}, - {Language::Italian, {{Sex::Male, "Maschio"}, {Sex::Female, "Femmina"}}}, - {Language::French, {{Sex::Male, "Homme"}, {Sex::Female, "Femme"}}}, - {Language::German, {{Sex::Male, "Mann"}, {Sex::Female, "Frau"}}}, - {Language::Russian, {{Sex::Male, "Мужчина"}, {Sex::Female, "Женщина"}}}, - {Language::Romanian, {{Sex::Male, "Bărbat"}, {Sex::Female, "Femeie"}}}, - {Language::Hindi, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}}, - {Language::Finnish, {{Sex::Male, "Mies"}, {Sex::Female, "Nainen"}}}, - {Language::Nepali, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}}, - {Language::Spanish, {{Sex::Male, "Hombre"}, {Sex::Female, "Mujer"}}}, - {Language::Turkish, {{Sex::Male, "Erkek"}, {Sex::Female, "Kadın"}}}, - {Language::Czech, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}}, - {Language::Slovak, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}}, - {Language::Ukrainian, {{Sex::Male, "Чоловік"}, {Sex::Female, "Жінка"}}}, - {Language::Danish, {{Sex::Male, "Mand"}, {Sex::Female, "Kvinde"}}}, - {Language::Swedish, {{Sex::Male, "Man"}, {Sex::Female, "Kvinna"}}}, - {Language::Portuguese, {{Sex::Male, "Homem"}, {Sex::Female, "Mulher"}}}, - {Language::Norwegian, {{Sex::Male, "Mann"}, {Sex::Female, "Kvinne"}}}, - {Language::Japanese, {{Sex::Male, "男性"}, {Sex::Female, "女性"}}}, - {Language::Hungarian, {{Sex::Male, "Férfi"}, {Sex::Female, "Nő"}}}, - {Language::Croatian, {{Sex::Male, "Muškarac"}, {Sex::Female, "Žena"}}}, - {Language::Greek, {{Sex::Male, "Άνδρας"}, {Sex::Female, "Γυναίκα"}}}, - {Language::Slovene, {{Sex::Male, "Moški"}, {Sex::Female, "Ženska"}}}, - {Language::Dutch, {{Sex::Male, "Man"}, {Sex::Female, "Vrouw"}}}, - {Language::Mandarin, {{Sex::Male, "男"}, {Sex::Female, "女"}}}, - {Language::Korean, {{Sex::Male, "남자"}, {Sex::Female, "여자"}}}, - {Language::Serbian, {{Sex::Male, "Мушкарац"}, {Sex::Female, "Жена"}}}, - {Language::Macedonian, {{Sex::Male, "Маж"}, {Sex::Female, "Жена"}}}, - {Language::Albanian, {{Sex::Male, "Mashkull"}, {Sex::Female, "Femër"}}}, - {Language::Latvian, {{Sex::Male, "Vīrietis"}, {Sex::Female, "Sieviete"}}}, - {Language::Belarusian, {{Sex::Male, "Мужчына"}, {Sex::Female, "Жанчына"}}}, - {Language::Estonian, {{Sex::Male, "Mees"}, {Sex::Female, "Naine"}}}, - {Language::Irish, {{Sex::Male, "fireannach"}, {Sex::Female, "baineann"}}}}; - -inline std::string translateSex(Sex sex, Language language = Language::English) -{ - const auto sexTranslation = sexTranslations.find(language); - - if (sexTranslation == sexTranslations.end()) - { - throw std::runtime_error{"Sex not found."}; - } - - return sexTranslation->second.at(sex); -} - -inline std::string toString(Sex sex, Language language = Language::English) -{ - return translateSex(sex, language); -} - -inline std::ostream& operator<<(std::ostream& os, Sex sex) -{ - return os << toString(sex); -} -} diff --git a/include/faker-cxx/types/SsnCountry.h b/include/faker-cxx/types/SsnCountry.h deleted file mode 100644 index 4d34529a0..000000000 --- a/include/faker-cxx/types/SsnCountry.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once - -#include - -namespace faker -{ -enum class SsnCountry -{ - Poland, - UnitedStates, - UnitedKingdom, - Germany, - France, - Italy, - Spain, - India, -}; - -const std::vector supportedSsnCountries{ - SsnCountry::Poland, SsnCountry::UnitedStates, SsnCountry::UnitedKingdom, SsnCountry::Germany, - SsnCountry::France, SsnCountry::Italy, SsnCountry::Spain, SsnCountry::India, -}; - -inline std::string toString(SsnCountry country) -{ - std::map countryToStringMapping{ - {SsnCountry::UnitedStates, "UnitedStates"}, - {SsnCountry::UnitedKingdom, "UnitedKingdom"}, - {SsnCountry::Poland, "Poland"}, - {SsnCountry::Italy, "Italy"}, - {SsnCountry::France, "France"}, - {SsnCountry::Germany, "Germany"}, - {SsnCountry::India, "India"}, - {SsnCountry::Spain, "Spain"}, - }; - - return countryToStringMapping.at(country); -} - -inline std::ostream& operator<<(std::ostream& os, SsnCountry country) -{ - return os << toString(country); -} - -} diff --git a/include/faker-cxx/types/StructureToken.h b/include/faker-cxx/types/StructureToken.h deleted file mode 100644 index 27b30e600..000000000 --- a/include/faker-cxx/types/StructureToken.h +++ /dev/null @@ -1,312 +0,0 @@ -#pragma once - -namespace faker -{ -enum class StructureToken -{ - // Airline module - AirlineAircraftType, - AirlineAirplaneName, - AirlineAirplaneCode, - AirlineAirlineName, - AirlineAirlineCode, - AirlineAirportName, - AirlineAirportCode, - AirlineSeat, - AirlineRecordLocator, - AirlineFlightNumber, - - // Animal module - AnimalBear, - AnimalBird, - AnimalCat, - AnimalCetacean, - AnimalCow, - AnimalCrocodilia, - AnimalDog, - AnimalFish, - AnimalHorse, - AnimalInsect, - AnimalLion, - AnimalRabbit, - AnimalRodent, - AnimalSnake, - AnimalType, - - // Book module - BookTitle, - BookGenre, - BookAuthor, - BookPublisher, - BookIsbn, - - // Color module - ColorName, - ColorRGB, - ColorHEX, - ColorHSL, - ColorLCH, - ColorCMYK, - - // Commerce module - CommerceDepartment, - CommercePrice, - CommerceSku, - CommerceProductAdjective, - CommerceProductMaterial, - CommerceProductName, - CommerceProductFullName, - CommerceEAN13, - CommerceEAN8, - CommerceISBN13, - CommerceISBN10, - - // Company module - CompanyName, - CompanyType, - CompanyIndustry, - CompanyBuzzPhrase, - CompanyBuzzAdjective, - CompanyBuzzNoun, - CompanyBuzzVerb, - CompanyCatchPhrase, - CompanyCtachPhraseAdjective, - CompanyCatchPhraseDescriptor, - CompanyCatchPhraseNoun, - - // Computer module - ComputerType, - ComputerManufacture, - ComputerModel, - ComputerCPUManufacture, - ComputerCPUType, - ComputerCPUModel, - ComputerGPUManufacture, - ComputerGPUType, - ComputerGPUModel, - - // Crypto module - CryptoSHA256, - CryptoMD5, - - // Database module - DatabaseColumnName, - DatabaseColumnType, - DatabaseCollation, - DatabaseEngine, - DatabaseMongoDBObjectId, - - // Datatype module - DatatypeBoolean, - - // Date module ISO and Timestamp - DatePastDateISO, - DatePastDateTimestamp, - DatefutureDateISO, - DatefutureDateTimestamp, - DateRecentDateISO, - DateRecentDateTimestamp, - DateSoonDateISO, - DateSoonDateTimestamp, - DateBirthdateByAgeISO, - DateBirthdateByAgeTimestamp, - DateBirthdateByYearISO, - DateBirthdateByYearTimestamp, - DateWeekdayName, - DateWeekdayAbbreviatedName, - DateMontName, - DateMonthAbbreviatedName, - - // Finance module - FinanceCurrencyName, - FinanceCurrencyCode, - FinanceCurrencySymbol, - FinanceAccountType, - FinanceAmount, - FinanceIban, - FinanceBic, - FinanceAccountNumber, - FinancePin, - FinanceRoutingNumber, - FinanceCreditCardNumber, - FinanceCreditCardCvv, - FinanceBitcoinAddress, - FinanceLitecoinAddress, - FinanceEthereumAddress, - - // Food module - FoodAlcoholicBeverage, - FoodGrain, - FoodMilkProduct, - FoodFruit, - FoodMeat, - FoodSeafood, - FoodVegetable, - FoodOil, - FoodNut, - FoodSeed, - FoodSugarProduct, - FoodNonAlcoholicBeverage, - FoodDishName, - FoodFoodCategory, - - // Git module - GitBranch, - GitCommitDate, - GitCommitEntry, - GitCommitMessage, - GitCommitSha, - - // Hacker module - HackerAbbreviation, - HackerAdjective, - HackerNoun, - HackerVerb, - HackerIngverb, - HackerPhrase, - - // Image module - ImageImageURL, - ImageGitHubAvatarURL, - ImageDimensions, - - // Internet module - InternetUsername, - InternetEmail, - InternetExampleEmail, - InternetPassword, - InternetEmoji, - InternetProtocol, - InternetHttpMethod, - InternetHttpRequestHeader, - InternetHttpResponseHeader, - InternetHttpMediaType, - InternetIpv4, - InternetIpv6, - InternetMac, - InternetURL, - InternetDomainName, - InternetDomainWord, - InternetDomainSuffix, - - // Location module - LocationCountry, - LocationCountryCode, - LocationState, - LocationCity, - LocationZipCode, - LocationStreetAddress, - LocationStreet, - LocationBuildingNumber, - LocationSecondaryAddress, - LocationLatitude, - LocationLongitude, - LocationDirection, - LocationTimeZone, - - // Lorem module - LoremWord, - LoremWords, - LoremSentence, - LoremSentences, - LoremSlung, - LoremParagraph, - LoremParagraphs, - - // Medicine module - MedicineCondition, - MedicineMedicalTest, - MedicineSpecialty, - - // Movie module - MovieGenre, - MovieMovieTitle, - MovieTvShow, - MovieDirector, - MovieActor, - MovieActress, - - // Music module - MusicArtist, - MusicGenre, - MusicSongName, - - // Person module - PersonFirstName, - PersonLastName, - PersonMiddleName, - PersonFullName, - PersonPrefix, - PersonSuffix, - PersonSex, - PersonGender, - PersonJobTitle, - PersonJobDescriptor, - PersonJobArea, - PersonJobType, - PersonHoby, - PersonLanguage, - PersonNationality, - PersonWesternZodiac, - PersonChineseZodiac, - - // Phone module - PhoneNumber, - PhonePlatform, - PhoneModelName, - PhoneManufacturer, - PhoneIMEI, - - // Sport module - SportSport, - SportSoccerTeam, - SportMaleAthelete, - SportFemaleAthlete, - SportSportEvent, - - // System module - SystemFileName, - SystemFileExtension, - SystemCommonFileName, - SystemCommonFileExtension, - SystemMimeType, - SystemCommonFileType, - SystemFileType, - SystemDirectoryPath, - SystemFilePath, - SystemSemver, - SystemNetworkInterface, - SystemCron, - - // VideoGame module - VideoGameGameTitle, - VideoGameGenre, - VideoGamePlatform, - VideoGameStudioName, - - // Weather module - WeatherTemperatureMetric, - WeatherTemperatureImperial, - WeatherPressureMetric, - WeatherPressureImperial, - WeatherVisibilityMetric, - WeatherVisibilityImperial, - WeatherWindSpeedMetric, - WeatherWindSpeedImperial, - WeatherUvIndex, - WeatherHumidity, - WeatherWeatherDescription, - WeatherCloudCover, - - // Word module - WordSample, - WordWords, - WordAdjective, - WordAdverb, - WordConjunction, - WordInterjection, - WordNoun, - WordPreposition, - WordVerb, -}; -} diff --git a/src/common/mappers/precisionMapper/PrecisionMapper.h b/src/common/mappers/precisionMapper/PrecisionMapper.h index 1c022b7f8..33581fffc 100644 --- a/src/common/mappers/precisionMapper/PrecisionMapper.h +++ b/src/common/mappers/precisionMapper/PrecisionMapper.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "faker-cxx/types/Precision.h" namespace faker diff --git a/src/modules/finance/FinanceTest.cpp b/src/modules/finance/FinanceTest.cpp index f15679b1c..aca52283f 100644 --- a/src/modules/finance/FinanceTest.cpp +++ b/src/modules/finance/FinanceTest.cpp @@ -120,6 +120,12 @@ class FinanceTest : public TestWithParam { return creditCardCharacter == dataCharacter; }); }); } + + static bool checkIfCurrenciesAreEqual(const Currency& currency1, const Currency& currency2) + { + return currency1.name == currency2.name && currency1.code == currency2.code && + currency1.symbol == currency2.symbol; + } }; TEST_F(FinanceTest, shouldGenerateCurrency) @@ -127,7 +133,7 @@ TEST_F(FinanceTest, shouldGenerateCurrency) const auto generatedCurrency = Finance::currency(); ASSERT_TRUE(std::ranges::any_of(currencies, [generatedCurrency](const Currency& currency) - { return currency == generatedCurrency; })); + { return checkIfCurrenciesAreEqual(currency, generatedCurrency); })); } TEST_F(FinanceTest, shouldGenerateCurrencyName) diff --git a/src/modules/finance/data/Currencies.h b/src/modules/finance/data/Currencies.h index 5065553ef..691854af2 100644 --- a/src/modules/finance/data/Currencies.h +++ b/src/modules/finance/data/Currencies.h @@ -3,7 +3,7 @@ #include #include -#include "faker-cxx/types/Currency.h" +#include "faker-cxx/Finance.h" namespace faker { diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 4c2b3586c..db6cb245c 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -77,13 +77,72 @@ #include "faker-cxx/Helper.h" #include "faker-cxx/Internet.h" #include "faker-cxx/String.h" -#include "faker-cxx/types/PassportType.h" #include "faker-cxx/Word.h" namespace faker { namespace { +const std::vector supportedSsnCountries{ + SsnCountry::Poland, SsnCountry::UnitedStates, SsnCountry::UnitedKingdom, SsnCountry::Germany, + SsnCountry::France, SsnCountry::Italy, SsnCountry::Spain, SsnCountry::India, +}; + +const std::map> sexTranslations = { + {Language::English, {{Sex::Male, "Male"}, {Sex::Female, "Female"}}}, + {Language::Polish, {{Sex::Male, "Mężczyzna"}, {Sex::Female, "Kobieta"}}}, + {Language::Italian, {{Sex::Male, "Maschio"}, {Sex::Female, "Femmina"}}}, + {Language::French, {{Sex::Male, "Homme"}, {Sex::Female, "Femme"}}}, + {Language::German, {{Sex::Male, "Mann"}, {Sex::Female, "Frau"}}}, + {Language::Russian, {{Sex::Male, "Мужчина"}, {Sex::Female, "Женщина"}}}, + {Language::Romanian, {{Sex::Male, "Bărbat"}, {Sex::Female, "Femeie"}}}, + {Language::Hindi, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}}, + {Language::Finnish, {{Sex::Male, "Mies"}, {Sex::Female, "Nainen"}}}, + {Language::Nepali, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}}, + {Language::Spanish, {{Sex::Male, "Hombre"}, {Sex::Female, "Mujer"}}}, + {Language::Turkish, {{Sex::Male, "Erkek"}, {Sex::Female, "Kadın"}}}, + {Language::Czech, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}}, + {Language::Slovak, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}}, + {Language::Ukrainian, {{Sex::Male, "Чоловік"}, {Sex::Female, "Жінка"}}}, + {Language::Danish, {{Sex::Male, "Mand"}, {Sex::Female, "Kvinde"}}}, + {Language::Swedish, {{Sex::Male, "Man"}, {Sex::Female, "Kvinna"}}}, + {Language::Portuguese, {{Sex::Male, "Homem"}, {Sex::Female, "Mulher"}}}, + {Language::Norwegian, {{Sex::Male, "Mann"}, {Sex::Female, "Kvinne"}}}, + {Language::Japanese, {{Sex::Male, "男性"}, {Sex::Female, "女性"}}}, + {Language::Hungarian, {{Sex::Male, "Férfi"}, {Sex::Female, "Nő"}}}, + {Language::Croatian, {{Sex::Male, "Muškarac"}, {Sex::Female, "Žena"}}}, + {Language::Greek, {{Sex::Male, "Άνδρας"}, {Sex::Female, "Γυναίκα"}}}, + {Language::Slovene, {{Sex::Male, "Moški"}, {Sex::Female, "Ženska"}}}, + {Language::Dutch, {{Sex::Male, "Man"}, {Sex::Female, "Vrouw"}}}, + {Language::Mandarin, {{Sex::Male, "男"}, {Sex::Female, "女"}}}, + {Language::Korean, {{Sex::Male, "남자"}, {Sex::Female, "여자"}}}, + {Language::Serbian, {{Sex::Male, "Мушкарац"}, {Sex::Female, "Жена"}}}, + {Language::Macedonian, {{Sex::Male, "Маж"}, {Sex::Female, "Жена"}}}, + {Language::Albanian, {{Sex::Male, "Mashkull"}, {Sex::Female, "Femër"}}}, + {Language::Latvian, {{Sex::Male, "Vīrietis"}, {Sex::Female, "Sieviete"}}}, + {Language::Belarusian, {{Sex::Male, "Мужчына"}, {Sex::Female, "Жанчына"}}}, + {Language::Estonian, {{Sex::Male, "Mees"}, {Sex::Female, "Naine"}}}, + {Language::Irish, {{Sex::Male, "fireannach"}, {Sex::Female, "baineann"}}}}; + +std::string translateSex(Sex sex, Language language = Language::English) +{ + const auto sexTranslation = sexTranslations.find(language); + + if (sexTranslation == sexTranslations.end()) + { + throw std::runtime_error{"Sex not found."}; + } + + return sexTranslation->second.at(sex); +} + +const std::map passportFormats{ + {PassportCountry::Usa, "AA0000000"}, + {PassportCountry::Poland, "AA0000000"}, + {PassportCountry::France, "00AA00000"}, + {PassportCountry::Romania, "00000000"}, +}; + const std::map countryToPeopleNamesMapping{ {Country::England, englishPeopleNames}, {Country::France, frenchPeopleNames}, @@ -153,8 +212,10 @@ std::string prefixForCountry(Country country, std::optional sex); std::string suffixForCountry(Country country, std::optional sex); } -std::string Person::firstName(Country country, std::optional sex) +std::string Person::firstName(std::optional countryOpt, std::optional sex) { + const auto country = countryOpt ? *countryOpt : Country::England; + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector firstNames; @@ -183,8 +244,10 @@ std::string Person::firstName(Country country, std::optional sex) return Helper::arrayElement(firstNames); } -std::string Person::lastName(Country country, std::optional sex) +std::string Person::lastName(std::optional countryOpt, std::optional sex) { + const auto country = countryOpt ? *countryOpt : Country::England; + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector lastNames; @@ -252,14 +315,16 @@ std::string Person::middleName(std::optional sex) if (allMiddleNames.empty()) { throw std::runtime_error{ - FormatHelper::format("No middle name fround, sex: {}.", sex ? toString(*sex) : "none")}; + FormatHelper::format("No middle name fround, sex: {}.", sex ? translateSex(*sex) : "none")}; } return Helper::arrayElement(allMiddleNames); } -std::string Person::fullName(Country country, std::optional sex) +std::string Person::fullName(std::optional countryOpt, std::optional sex) { + const auto country = countryOpt ? *countryOpt : Country::England; + const auto& peopleNames = countryToPeopleNamesMapping.at(country); std::vector> weightedElements; @@ -319,7 +384,8 @@ std::string Person::prefix(std::optional sex) if (allPrefixes.empty()) { - throw std::runtime_error{FormatHelper::format("No prefixes fround, sex: {}.", sex ? toString(*sex) : "none")}; + throw std::runtime_error{ + FormatHelper::format("No prefixes fround, sex: {}.", sex ? translateSex(*sex) : "none")}; } return Helper::arrayElement(allPrefixes); @@ -362,7 +428,7 @@ std::string Person::suffix() return Helper::arrayElement(allSuffixes); } -std::string Person::sex(Language language) +std::string Person::sex(std::optional languageOpt) { const std::vector sexes{"Male", "Female"}; @@ -370,6 +436,8 @@ std::string Person::sex(Language language) const auto sexEnum = chosenSex == "Male" ? Sex::Male : Sex::Female; + const auto language = languageOpt ? *languageOpt : Language::English; + return translateSex(sexEnum, language); } @@ -456,9 +524,12 @@ std::string Person::chineseZodiac() return Helper::arrayElement(chineseZodiacs); } -std::string Person::passport(PassportCountry country) +std::string Person::passport(std::optional countryOpt) { - std::string passportFormat = passportFormats.at(country); + const auto country = countryOpt ? *countryOpt : PassportCountry::Usa; + + const auto& passportFormat = passportFormats.at(country); + std::string passportNumber; for (const char& c : passportFormat) @@ -568,5 +639,6 @@ std::string suffixForCountry(Country country, std::optional sex) return Helper::arrayElement(suffixes); } + } } diff --git a/src/modules/person/PersonTest.cpp b/src/modules/person/PersonTest.cpp index 7c742d218..9263848a5 100644 --- a/src/modules/person/PersonTest.cpp +++ b/src/modules/person/PersonTest.cpp @@ -76,15 +76,71 @@ #include "data/vietnam/VietnamesePeopleNames.h" #include "data/ZodiacSigns.h" #include "faker-cxx/Internet.h" -#include "faker-cxx/types/PassportType.h" using namespace ::testing; using namespace faker; namespace { +const std::vector supportedSsnCountries{ + SsnCountry::Poland, SsnCountry::UnitedStates, SsnCountry::UnitedKingdom, SsnCountry::Germany, + SsnCountry::France, SsnCountry::Italy, SsnCountry::Spain, SsnCountry::India, +}; + const std::vector sexes{"Male", "Female"}; +const std::map> sexTranslations = { + {Language::English, {{Sex::Male, "Male"}, {Sex::Female, "Female"}}}, + {Language::Polish, {{Sex::Male, "Mężczyzna"}, {Sex::Female, "Kobieta"}}}, + {Language::Italian, {{Sex::Male, "Maschio"}, {Sex::Female, "Femmina"}}}, + {Language::French, {{Sex::Male, "Homme"}, {Sex::Female, "Femme"}}}, + {Language::German, {{Sex::Male, "Mann"}, {Sex::Female, "Frau"}}}, + {Language::Russian, {{Sex::Male, "Мужчина"}, {Sex::Female, "Женщина"}}}, + {Language::Romanian, {{Sex::Male, "Bărbat"}, {Sex::Female, "Femeie"}}}, + {Language::Hindi, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}}, + {Language::Finnish, {{Sex::Male, "Mies"}, {Sex::Female, "Nainen"}}}, + {Language::Nepali, {{Sex::Male, "पुरुष"}, {Sex::Female, "महिला"}}}, + {Language::Spanish, {{Sex::Male, "Hombre"}, {Sex::Female, "Mujer"}}}, + {Language::Turkish, {{Sex::Male, "Erkek"}, {Sex::Female, "Kadın"}}}, + {Language::Czech, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}}, + {Language::Slovak, {{Sex::Male, "Muž"}, {Sex::Female, "Žena"}}}, + {Language::Ukrainian, {{Sex::Male, "Чоловік"}, {Sex::Female, "Жінка"}}}, + {Language::Danish, {{Sex::Male, "Mand"}, {Sex::Female, "Kvinde"}}}, + {Language::Swedish, {{Sex::Male, "Man"}, {Sex::Female, "Kvinna"}}}, + {Language::Portuguese, {{Sex::Male, "Homem"}, {Sex::Female, "Mulher"}}}, + {Language::Norwegian, {{Sex::Male, "Mann"}, {Sex::Female, "Kvinne"}}}, + {Language::Japanese, {{Sex::Male, "男性"}, {Sex::Female, "女性"}}}, + {Language::Hungarian, {{Sex::Male, "Férfi"}, {Sex::Female, "Nő"}}}, + {Language::Croatian, {{Sex::Male, "Muškarac"}, {Sex::Female, "Žena"}}}, + {Language::Greek, {{Sex::Male, "Άνδρας"}, {Sex::Female, "Γυναίκα"}}}, + {Language::Slovene, {{Sex::Male, "Moški"}, {Sex::Female, "Ženska"}}}, + {Language::Dutch, {{Sex::Male, "Man"}, {Sex::Female, "Vrouw"}}}, + {Language::Mandarin, {{Sex::Male, "男"}, {Sex::Female, "女"}}}, + {Language::Korean, {{Sex::Male, "남자"}, {Sex::Female, "여자"}}}, + {Language::Serbian, {{Sex::Male, "Мушкарац"}, {Sex::Female, "Жена"}}}, + {Language::Macedonian, {{Sex::Male, "Маж"}, {Sex::Female, "Жена"}}}, + {Language::Albanian, {{Sex::Male, "Mashkull"}, {Sex::Female, "Femër"}}}, + {Language::Latvian, {{Sex::Male, "Vīrietis"}, {Sex::Female, "Sieviete"}}}, + {Language::Belarusian, {{Sex::Male, "Мужчына"}, {Sex::Female, "Жанчына"}}}, + {Language::Estonian, {{Sex::Male, "Mees"}, {Sex::Female, "Naine"}}}, + {Language::Irish, {{Sex::Male, "fireannach"}, {Sex::Female, "baineann"}}}}; + +const std::vector countries{ + Country::Usa, Country::England, Country::Poland, Country::Italy, Country::France, + Country::Germany, Country::Russia, Country::Romania, Country::India, Country::Finland, + Country::Nepal, Country::Spain, Country::Turkey, Country::Czech, Country::Slovakia, + Country::Ukraine, Country::Denmark, Country::Sweden, Country::Brazil, Country::Norway, + Country::Japan, Country::Portugal, Country::Hungary, Country::Croatia, Country::Greece, + Country::Slovenia, Country::Austria, Country::Switzerland, Country::Belgium, Country::Netherlands, + Country::China, Country::Korea, Country::Canada, Country::Mexico, Country::Argentina, + Country::Australia, Country::Serbia, Country::Macedonia, Country::Albania, Country::Latvia, + Country::Ireland, Country::Belarus, Country::Estonia, Country::Iran, Country::Bulgaria, + Country::Moldova, Country::Lithuania, Country::Iceland, Country::Palestine, Country::Israel, + Country::Vietnam, Country::Monaco, Country::Bosnia, Country::Lebanon, Country::Syria, + Country::Malta, Country::SouthAfrica, Country::Azerbaijan, Country::Ghana, Country::Kazakhstan, + Country::Maldives, +}; + const std::map countryToPeopleNamesMapping{ {Country::England, englishPeopleNames}, {Country::France, frenchPeopleNames}, @@ -212,6 +268,19 @@ const std::map generatedTestName{ {Country::Kazakhstan, "shouldGenerateKazakhName"}, {Country::Maldives, "shouldGenerateMaldivianName"}, }; + +} + +std::string translateSex(Sex sex, Language language = Language::English) +{ + const auto sexTranslation = sexTranslations.find(language); + + if (sexTranslation == sexTranslations.end()) + { + throw std::runtime_error{"Sex not found."}; + } + + return sexTranslation->second.at(sex); } bool checkTokenFormat(const std::string& bio); @@ -614,6 +683,30 @@ std::vector> languageSexPairs = { {Language::Irish, Sex::Female}, {Language::Belarusian, Sex::Male}, {Language::Belarusian, Sex::Female}, {Language::Estonian, Sex::Male}, {Language::Estonian, Sex::Female}}; +std::string toString(Sex sex, Language language = Language::English) +{ + return translateSex(sex, language); +} + +std::string toString(Language language) +{ + static const std::map languageToStringMapping{ + {Language::English, "English"}, {Language::Polish, "Polish"}, {Language::Italian, "Italian"}, + {Language::French, "French"}, {Language::German, "German"}, {Language::Russian, "Russian"}, + {Language::Romanian, "Romanian"}, {Language::Hindi, "Hindi"}, {Language::Finnish, "Finnish"}, + {Language::Nepali, "Nepali"}, {Language::Spanish, "Spanish"}, {Language::Turkish, "Turkish"}, + {Language::Czech, "Czech"}, {Language::Slovak, "Slovak"}, {Language::Ukrainian, "Ukrainian"}, + {Language::Danish, "Danish"}, {Language::Swedish, "Swedish"}, {Language::Portuguese, "Portuguese"}, + {Language::Norwegian, "Norwegian"}, {Language::Japanese, "Japanese"}, {Language::Hungarian, "Hungarian"}, + {Language::Croatian, "Croatian"}, {Language::Greek, "Greek"}, {Language::Slovene, "Slovene"}, + {Language::Dutch, "Dutch"}, {Language::Mandarin, "Mandarin"}, {Language::Korean, "Korean"}, + {Language::Serbian, "Serbian"}, {Language::Macedonian, "Macedonian"}, {Language::Albanian, "Albanian"}, + {Language::Latvian, "Latvian"}, {Language::Irish, "Irish"}, {Language::Belarusian, "Belarusian"}, + {Language::Estonian, "Estonian"}}; + + return languageToStringMapping.at(language); +} + INSTANTIATE_TEST_SUITE_P(TestPersonSexTranslation, PersonSexSuite, testing::ValuesIn(languageSexPairs), [](const testing::TestParamInfo& info) { @@ -642,6 +735,22 @@ TEST_P(PersonSsnSuite, shouldGenerateSsn) ASSERT_EQ(ssn.size(), expectedSsnLength); } +std::string toString(SsnCountry country) +{ + std::map countryToStringMapping{ + {SsnCountry::UnitedStates, "UnitedStates"}, + {SsnCountry::UnitedKingdom, "UnitedKingdom"}, + {SsnCountry::Poland, "Poland"}, + {SsnCountry::Italy, "Italy"}, + {SsnCountry::France, "France"}, + {SsnCountry::Germany, "Germany"}, + {SsnCountry::India, "India"}, + {SsnCountry::Spain, "Spain"}, + }; + + return countryToStringMapping.at(country); +} + INSTANTIATE_TEST_SUITE_P(TestPersonSsn, PersonSsnSuite, testing::ValuesIn(supportedSsnCountries), [](const testing::TestParamInfo& info) { return "shouldGenerate" + toString(info.param) + "Ssn"; }); @@ -665,7 +774,7 @@ TEST_F(PersonPassportTest, shouldGenerateUsaPassport) ASSERT_TRUE(std::isdigit(passportNumber[6])); ASSERT_TRUE(std::isdigit(passportNumber[7])); ASSERT_TRUE(std::isdigit(passportNumber[8])); -}; +} TEST_F(PersonPassportTest, shouldGeneratePolandPassport) { @@ -681,7 +790,7 @@ TEST_F(PersonPassportTest, shouldGeneratePolandPassport) ASSERT_TRUE(std::isdigit(passportNumber[6])); ASSERT_TRUE(std::isdigit(passportNumber[7])); ASSERT_TRUE(std::isdigit(passportNumber[8])); -}; +} TEST_F(PersonPassportTest, shouldGenerateFrenchPassport) { @@ -697,7 +806,7 @@ TEST_F(PersonPassportTest, shouldGenerateFrenchPassport) ASSERT_TRUE(std::isdigit(passportNumber[6])); ASSERT_TRUE(std::isdigit(passportNumber[7])); ASSERT_TRUE(std::isdigit(passportNumber[8])); -}; +} TEST_F(PersonPassportTest, shouldGenerateRomanianPassport) { @@ -711,7 +820,7 @@ TEST_F(PersonPassportTest, shouldGenerateRomanianPassport) ASSERT_TRUE(std::isdigit(passportNumber[5])); ASSERT_TRUE(std::isdigit(passportNumber[6])); ASSERT_TRUE(std::isdigit(passportNumber[7])); -}; +} bool checkTokenFormat(const std::string& bio) { @@ -722,7 +831,7 @@ bool checkTokenFormat(const std::string& bio) const std::regex fifthRegex{R"(^(\w+\-?\w+) (\w+)$)"}; const std::regex sixthRegex{R"(^(\w+\-?\w+) (\w+) (\S+)$)"}; const std::regex seventhRegex{R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+)$)"}; - const std::regex eigthRegex{R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+) (\S+)$)"}; + const std::regex eightRegex{R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+) (\S+)$)"}; std::smatch matches; // @@ -793,7 +902,7 @@ bool checkTokenFormat(const std::string& bio) return true; } - if (std::regex_match(bio, matches, eigthRegex)) + if (std::regex_match(bio, matches, eightRegex)) { // In this case the bio is in the format {noun} {bio_supporter}, {bio_part} {emoji} so check that the value // is present in the bio_part vector. diff --git a/src/modules/person/data/SsnFormats.h b/src/modules/person/data/SsnFormats.h index 8f7493864..aed85c461 100644 --- a/src/modules/person/data/SsnFormats.h +++ b/src/modules/person/data/SsnFormats.h @@ -2,9 +2,8 @@ #include #include -#include -#include "faker-cxx/types/SsnCountry.h" +#include "faker-cxx/Person.h" namespace faker { diff --git a/src/modules/string/StringTest.cpp b/src/modules/string/StringTest.cpp index 0ab272837..8f285aac7 100644 --- a/src/modules/string/StringTest.cpp +++ b/src/modules/string/StringTest.cpp @@ -7,7 +7,7 @@ #include "gtest/gtest.h" #include "data/Characters.h" -#include "faker-cxx/types/RandomGenerator.h" +#include "faker-cxx/RandomGenerator.h" using namespace ::testing; using namespace faker; diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 6d3d1dfcc..7e2ff8d1c 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -19,6 +19,12 @@ namespace faker { namespace { +const std::map fileTypeToStringMapping{{FileType::Video, "video"}, + {FileType::Audio, "audio"}, + {FileType::Image, "image"}, + {FileType::Text, "text"}, + {FileType::Application, "application"}}; + std::string extension(const std::string& mimeType) { const auto it = mimeTypesExtensions.find(mimeType); @@ -73,8 +79,10 @@ std::string System::fileExtension(const std::optional& mimeType) { if (mimeType.has_value()) { - const auto mimeTypeName = toString(mimeType.value()); + const auto& mimeTypeName = fileTypeToStringMapping.at(mimeType.value()); + std::vector extensions; + for (const auto& mime : mimeTypes) { size_t pos = mime.find_first_of('/'); @@ -84,6 +92,7 @@ std::string System::fileExtension(const std::optional& mimeType) extensions.push_back(mime.substr(pos + 1)); } } + return Helper::arrayElement(extensions); } else @@ -96,6 +105,7 @@ std::string System::fileExtension(const std::optional& mimeType) } std::vector extensions(extensionSet.begin(), extensionSet.end()); + return Helper::arrayElement(extensions); } } diff --git a/src/modules/system/SystemTest.cpp b/src/modules/system/SystemTest.cpp index 3837bd78e..ebeb33c1b 100644 --- a/src/modules/system/SystemTest.cpp +++ b/src/modules/system/SystemTest.cpp @@ -10,6 +10,12 @@ using namespace ::testing; using namespace faker; +const std::map fileTypeToStringMapping{{FileType::Video, "video"}, + {FileType::Audio, "audio"}, + {FileType::Image, "image"}, + {FileType::Text, "text"}, + {FileType::Application, "application"}}; + class SystemTest : public Test { }; @@ -56,55 +62,64 @@ TEST_F(SystemTest, FileExtTestWithMimeTypeEnum) auto application = FileType::Application; std::vector imageExtensions; + for (const auto& mimeType : mimeTypes) { size_t pos = mimeType.find_first_of('/'); const auto ext = mimeType.substr(0, pos); - if (ext == toString(image)) + if (ext == fileTypeToStringMapping.at(image)) { imageExtensions.push_back(mimeType.substr(pos + 1)); } } + std::vector audioExtensions; + for (const auto& mimeType : mimeTypes) { size_t pos = mimeType.find_first_of('/'); const auto ext = mimeType.substr(0, pos); - if (ext == toString(audio)) + if (ext == fileTypeToStringMapping.at(audio)) { audioExtensions.push_back(mimeType.substr(pos + 1)); } } + std::vector videoExtensions; + for (const auto& mimeType : mimeTypes) { size_t pos = mimeType.find_first_of('/'); const auto ext = mimeType.substr(0, pos); - if (ext == toString(video)) + if (ext == fileTypeToStringMapping.at(video)) { videoExtensions.push_back(mimeType.substr(pos + 1)); } } std::vector textExtensions; + for (const auto& mimeType : mimeTypes) { size_t pos = mimeType.find_first_of('/'); const auto ext = mimeType.substr(0, pos); - if (ext == toString(text)) + if (ext == fileTypeToStringMapping.at(text)) { textExtensions.push_back(mimeType.substr(pos + 1)); } } + std::vector applicationExtensions; + for (const auto& mimeType : mimeTypes) { size_t pos = mimeType.find_first_of('/'); const auto ext = mimeType.substr(0, pos); - if (ext == toString(application)) + if (ext == fileTypeToStringMapping.at(application)) { applicationExtensions.push_back(mimeType.substr(pos + 1)); } } + auto imageExt = System::fileExtension(image); auto audioExt = System::fileExtension(audio); auto videoExt = System::fileExtension(video); diff --git a/src/modules/system/data/MimeTypes.h b/src/modules/system/data/MimeTypes.h index 6426970f7..813ae4425 100644 --- a/src/modules/system/data/MimeTypes.h +++ b/src/modules/system/data/MimeTypes.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include