diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1645052b1..cc4550d7c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,6 +58,12 @@ Please avoid working directly on the ``main`` branch. Before making changes, make sure you have `clang-format` installed. If you're using Visual Studio Code, you can install the `clang-format` extension. + If you want to format all files in project manually, you can run the following script: + + ```sh + ./scripts/format_code.sh + ``` + 3. **Make commits of logical units:** This means that each commit should contain a complete and coherent piece of work that can be understood independently @@ -78,7 +84,7 @@ inadvertently broken anything. Even if you think your changes are isolated, ther with other parts of the codebase. 6. **If you've added a new file to your project with non-Latin characters, ensure that the file encoding is set to -Unicode (UTF-8 without signature) - Codepage 65001 in Microsoft Visual Studio Code:** + Unicode (UTF-8 without signature) - Codepage 65001 in Microsoft Visual Studio Code:** If a file contains non-Latin characters (such as characters from Chinese, Arabic, or many other non-Latin alphabets), it's important to save the file with the correct encoding to ensure that the characters are displayed correctly. In @@ -121,8 +127,10 @@ Follow the steps below to build the project: "windows-msvc-release-shared" - Windows MSVC Release Shared library ``` - For instance, if you are in Ubuntu and want to build using GCC in Debug mode and static library (faker-cxx.a), you should use the - preset `unixlike-gcc-debug=static`. The `unixlike-clang-` preset should work for both Linux and macOS when using the CLang + For instance, if you are in Ubuntu and want to build using GCC in Debug mode and static library (faker-cxx.a), you + should use the + preset `unixlike-gcc-debug=static`. The `unixlike-clang-` preset should work for both Linux and macOS when using the + CLang compiler. The `-S .` option in the following command specifies the source directory: @@ -164,22 +172,26 @@ The faker-cxx project uses formated string feature, which can be solved by: - [fmt](https://github.com/fmtlib/fmt) library - [std::format](https://en.cppreference.com/w/cpp/utility/format/format) -The `std::format` requires C++20 standard support from the compiler. The feature is checked via CMake when building the project. +The `std::format` requires C++20 standard support from the compiler. The feature is checked via CMake when building the +project. In case available, the option `USE_STD_FORMAT` will be available: ```sh cmake -S . --preset unixlike-gcc-debug-static -DUSE_STD_FORMAT=ON ``` -In case `std::format` is not available, faker-cxx will use `fmt` library instead. It can be used as external dependency via -git submodules, or consumed from your system (installed by Conan or system package manager). In order to manage the way to +In case `std::format` is not available, faker-cxx will use `fmt` library instead. It can be used as external dependency +via +git submodules, or consumed from your system (installed by Conan or system package manager). In order to manage the way +to acquire `fmt`, the CMake option `USE_SYSTEM_DEPENDENCIES` manages if should be used from system, or from git submodule: ```sh cmake -S . --preset unixlike-gcc-debug-static -DUSE_SYSTEM_DEPENDENCIES=OFF // Install from submodule ``` -In case passing `USE_STD_FORMAT=ON` and `std::format` is not available, CMake will try to use `fmt` library automatically. +In case passing `USE_STD_FORMAT=ON` and `std::format` is not available, CMake will try to use `fmt` library +automatically. Then, in case not finding `fmt`, it will fail. ### Testing the Project with CMake/CTest @@ -211,7 +223,8 @@ As alternative, tests and be built and validated using Bazel as well. Follow the ### Installing the Project -When wanting to install those generated artifacts like headers files and library, you can use CMake to operate as installer as well: +When wanting to install those generated artifacts like headers files and library, you can use CMake to operate as +installer as well: ```sh cmake --build --preset unixlike-gcc-debug-static --target install @@ -219,15 +232,17 @@ When wanting to install those generated artifacts like headers files and library By default, CMake will install in the subfolder `install` in the source folder. -In order to change the installation folder, you can use [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) to configure the destination folder: +In order to change the installation folder, you can +use [CMAKE_INSTALL_PREFIX](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) to configure the +destination folder: ```sh cmake -S . --preset unixlike-gcc-debug-static -DCMAKE_INSTALL_PREFIX=/opt/faker-cxx cmake --build --preset unixlike-gcc-debug-static --target install ``` -This configuration will install all artifacts in `/opt/faker-cxx`. The permission to write in the folder should be granted before executing the installation command. - +This configuration will install all artifacts in `/opt/faker-cxx`. The permission to write in the folder should be +granted before executing the installation command. ## Submitting Changes @@ -275,7 +290,7 @@ PR titles are written in following convention: `type: subject` Allowed types are: | type | description | -| -------- | ------------------------------------------------------------------------- | +|----------|---------------------------------------------------------------------------| | feat | A new feature is introduced | | fix | A bug was fixed | | chore | No user affected code changes were made | diff --git a/include/faker-cxx/location.h b/include/faker-cxx/location.h index 771087ee3..56950fb37 100644 --- a/include/faker-cxx/location.h +++ b/include/faker-cxx/location.h @@ -4,29 +4,11 @@ #include #include "faker-cxx/export.h" -#include "types/precision.h" +#include "faker-cxx/types/locale.h" +#include "faker-cxx/types/precision.h" namespace faker::location { -enum class AddressCountry -{ - Australia, - Brazil, - Czech, - Denmark, - Estonia, - Finland, - France, - Germany, - India, - Italy, - Poland, - Russia, - Spain, - Ukraine, - Usa, -}; - /** * @brief Returns a random country name. * @@ -50,9 +32,9 @@ FAKER_CXX_EXPORT std::string_view country(); FAKER_CXX_EXPORT std::string_view countryCode(); /** - * @brief Returns a random state for a given country. + * @brief Returns a random state for a given locale. * - * @param country The country to generate state from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns State. * @@ -60,12 +42,12 @@ FAKER_CXX_EXPORT std::string_view countryCode(); * faker::location::state() // "Arizona" * @endcode */ -FAKER_CXX_EXPORT std::string_view state(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string_view state(Locale locale = Locale::en_US); /** - * @brief Returns a random city for given country. + * @brief Returns a random city for given locale. * - * @param country The country to generate city from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns City. * @@ -73,12 +55,12 @@ FAKER_CXX_EXPORT std::string_view state(AddressCountry country = AddressCountry: * faker::location::city() // "Boston" * @endcode */ -FAKER_CXX_EXPORT std::string city(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string city(Locale locale = Locale::en_US); /** - * @brief Returns a random zip code for given country. + * @brief Returns a random zip code for given locale. * - * @param country The country to generate zip code from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns Zip code. * @@ -87,12 +69,12 @@ FAKER_CXX_EXPORT std::string city(AddressCountry country = AddressCountry::Usa); * faker::location::zipCode(Country::Poland) // "31-881" * @endcode */ -FAKER_CXX_EXPORT std::string zipCode(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string zipCode(Locale locale = Locale::en_US); /** - * @brief Returns a random street address for given country. + * @brief Returns a random street address for given locale. * - * @param country The country to generate street address from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns Street address including building number and street name. * @@ -100,12 +82,12 @@ FAKER_CXX_EXPORT std::string zipCode(AddressCountry country = AddressCountry::Us * faker::location::streetAddress() // "34830 Erdman Hollow" * @endcode */ -FAKER_CXX_EXPORT std::string streetAddress(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string streetAddress(Locale locale = Locale::en_US); /** - * @brief Returns a random street for given country. + * @brief Returns a random street for given locale. * - * @param country The country to generate street from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns Street name. * @@ -113,12 +95,12 @@ FAKER_CXX_EXPORT std::string streetAddress(AddressCountry country = AddressCount * faker::location::street() // "Schroeder Isle" * @endcode */ -FAKER_CXX_EXPORT std::string street(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string street(Locale locale = Locale::en_US); /** - * @brief Returns a random building number for given country. + * @brief Returns a random building number for given locale. * - * @param country The country to generate building number from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns Building number. * @@ -126,13 +108,13 @@ FAKER_CXX_EXPORT std::string street(AddressCountry country = AddressCountry::Usa * faker::location::buildingNumber() // "505" * @endcode */ -FAKER_CXX_EXPORT std::string buildingNumber(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string buildingNumber(Locale locale = Locale::en_US); /** - * @brief Returns a random secondary address number for given country. + * @brief Returns a random secondary address number for given locale. * This refers to a specific location at a given address such as an apartment or room number * - * @param country The country to generate building number from. Defaults to `Country::Usa`. + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns Secondary address. * @@ -140,7 +122,7 @@ FAKER_CXX_EXPORT std::string buildingNumber(AddressCountry country = AddressCoun * faker::location::secondaryAddress() // "Apt. 861" * @endcode */ -FAKER_CXX_EXPORT std::string secondaryAddress(AddressCountry country = AddressCountry::Usa); +FAKER_CXX_EXPORT std::string secondaryAddress(Locale locale = Locale::en_US); /** * @brief Generates a random latitude. diff --git a/include/faker-cxx/person.h b/include/faker-cxx/person.h index 6893e4509..bcbaf3418 100644 --- a/include/faker-cxx/person.h +++ b/include/faker-cxx/person.h @@ -5,7 +5,6 @@ #include #include "faker-cxx/export.h" -#include "types/country.h" #include "types/locale.h" namespace faker::person diff --git a/include/faker-cxx/types/country.h b/include/faker-cxx/types/country.h deleted file mode 100644 index cbcec904c..000000000 --- a/include/faker-cxx/types/country.h +++ /dev/null @@ -1,69 +0,0 @@ -#pragma once - -namespace faker -{ -enum class Country -{ - Albania, - Argentina, - Australia, - Austria, - Azerbaijan, - Belarus, - Belgium, - Bosnia, - Brazil, - Bulgaria, - Canada, - China, - Croatia, - Czech, - Denmark, - England, - Estonia, - Finland, - France, - Germany, - Ghana, - Greece, - Hungary, - Iceland, - India, - Iran, - Ireland, - Israel, - Italy, - Japan, - Kazakhstan, - Korea, - Latvia, - Lebanon, - Lithuania, - Macedonia, - Maldives, - Malta, - Mexico, - Moldova, - Monaco, - Nepal, - Netherlands, - Norway, - Palestine, - Poland, - Portugal, - Romania, - Russia, - Serbia, - Slovakia, - Slovenia, - SouthAfrica, - Spain, - Sweden, - Switzerland, - Syria, - Turkey, - Ukraine, - Usa, - Vietnam, -}; -} diff --git a/scripts/format_code.sh b/scripts/format_code.sh new file mode 100755 index 000000000..836c7910e --- /dev/null +++ b/scripts/format_code.sh @@ -0,0 +1 @@ +clang-format src/**/*.cpp src/**/*.h include/**/*.h -i -style=file diff --git a/src/modules/location.cpp b/src/modules/location.cpp index 1149126fb..0fec2ab20 100644 --- a/src/modules/location.cpp +++ b/src/modules/location.cpp @@ -17,83 +17,59 @@ namespace faker::location { namespace { -CountryAddressesInfo getAddresses(const AddressCountry& country) +CountryAddressesInfo getAddresses(const Locale& locale) { - switch (country) + switch (locale) { - case AddressCountry::Usa: + case Locale::en_US: + case Locale::es_US: return usaAddresses; - case AddressCountry::Poland: + case Locale::pl_PL: return polandAddresses; - case AddressCountry::Russia: + case Locale::ru_RU: return russiaAddresses; - case AddressCountry::France: + case Locale::fr_FR: return franceAddresses; - case AddressCountry::Ukraine: + case Locale::uk_UA: return ukraineAddresses; - case AddressCountry::Italy: + case Locale::it_IT: return italyAddresses; - case AddressCountry::Germany: + case Locale::de_DE: return germanyAddresses; - case AddressCountry::Czech: + case Locale::cs_CZ: return czechAddresses; - case AddressCountry::Australia: + case Locale::en_AU: return australiaAddresses; - case AddressCountry::India: + case Locale::as_IN: + case Locale::bn_IN: + case Locale::en_IN: + case Locale::gu_IN: + case Locale::hi_IN: + case Locale::kn_IN: + case Locale::ks_IN: + case Locale::ml_IN: + case Locale::mr_IN: + case Locale::or_IN: + case Locale::pa_IN: + case Locale::sa_IN: + case Locale::ta_IN: + case Locale::te_IN: return indiaAddresses; - case AddressCountry::Denmark: + case Locale::da_DK: return denmarkAddresses; - case AddressCountry::Spain: + case Locale::ca_ES: + case Locale::es_ES: return spainAddresses; - case AddressCountry::Brazil: + case Locale::pt_BR: return brazilAddresses; - case AddressCountry::Finland: + case Locale::fi_FI: return finlandAddresses; - case AddressCountry::Estonia: + case Locale::et_EE: return estoniaAddresses; default: return usaAddresses; } } - -Locale getLocale(const AddressCountry& addressCountry) -{ - switch (addressCountry) - { - case AddressCountry::Usa: - return Locale::en_US; - case AddressCountry::Poland: - return Locale::pl_PL; - case AddressCountry::Russia: - return Locale::ru_RU; - case AddressCountry::France: - return Locale::fr_FR; - case AddressCountry::Ukraine: - return Locale::uk_UA; - case AddressCountry::Italy: - return Locale::it_IT; - case AddressCountry::Germany: - return Locale::de_DE; - case AddressCountry::Czech: - return Locale::cs_CZ; - case AddressCountry::Australia: - return Locale::en_AU; - case AddressCountry::India: - return Locale::hi_IN; - case AddressCountry::Denmark: - return Locale::da_DK; - case AddressCountry::Spain: - return Locale::es_ES; - case AddressCountry::Brazil: - return Locale::pt_BR; - case AddressCountry::Finland: - return Locale::fi_FI; - case AddressCountry::Estonia: - return Locale::et_EE; - default: - return Locale::en_US; - } -} } std::string_view country() @@ -106,93 +82,98 @@ std::string_view countryCode() return helper::randomElement(countryCodes); } -std::string_view state(AddressCountry country) +std::string_view state(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); + + if (localeAddresses.states.empty()) + { + return {}; + } - return helper::randomElement(countryAddresses.states); + return helper::randomElement(localeAddresses.states); } -std::string city(AddressCountry country) +std::string city(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); - const auto cityFormat = static_cast(helper::randomElement(countryAddresses.cityFormats)); + const auto cityFormat = static_cast(helper::randomElement(localeAddresses.cityFormats)); const auto dataGeneratorsMapping = std::unordered_map>{ - {"firstName", [&country]() { return static_cast(person::firstName(getLocale(country))); }}, - {"lastName", [&country]() { return static_cast(person::lastName(getLocale(country))); }}, + {"firstName", [&locale]() { return static_cast(person::firstName(locale)); }}, + {"lastName", [&locale]() { return static_cast(person::lastName(locale)); }}, {"cityName", - [&countryAddresses]() { return static_cast(helper::randomElement(countryAddresses.cities)); }}, - {"cityPrefix", [&countryAddresses]() - { return static_cast(helper::randomElement(countryAddresses.cityPrefixes)); }}, - {"citySuffix", [&countryAddresses]() - { return static_cast(helper::randomElement(countryAddresses.citySuffixes)); }}}; + [&localeAddresses]() { return static_cast(helper::randomElement(localeAddresses.cities)); }}, + {"cityPrefix", [&localeAddresses]() + { return static_cast(helper::randomElement(localeAddresses.cityPrefixes)); }}, + {"citySuffix", [&localeAddresses]() + { return static_cast(helper::randomElement(localeAddresses.citySuffixes)); }}}; return common::fillTokenValues(cityFormat, dataGeneratorsMapping); } -std::string zipCode(AddressCountry country) +std::string zipCode(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); - return helper::replaceSymbolWithNumber(static_cast(countryAddresses.zipCodeFormat)); + return helper::replaceSymbolWithNumber(static_cast(localeAddresses.zipCodeFormat)); } -std::string streetAddress(AddressCountry country) +std::string streetAddress(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); const auto dataGeneratorsMapping = std::unordered_map>{ - {"buildingNumber", [&country]() { return buildingNumber(country); }}, - {"street", [&country]() { return street(country); }}, - {"secondaryAddress", [&country]() { return secondaryAddress(country); }}}; + {"buildingNumber", [&locale]() { return buildingNumber(locale); }}, + {"street", [&locale]() { return street(locale); }}, + {"secondaryAddress", [&locale]() { return secondaryAddress(locale); }}}; - const auto addressFormat = static_cast(helper::randomElement(countryAddresses.addressFormats)); + const auto addressFormat = static_cast(helper::randomElement(localeAddresses.addressFormats)); return common::fillTokenValues(addressFormat, dataGeneratorsMapping); } -std::string street(AddressCountry country) +std::string street(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); - const auto streetFormat = static_cast(helper::randomElement(countryAddresses.streetFormats)); + const auto streetFormat = static_cast(helper::randomElement(localeAddresses.streetFormats)); const auto dataGeneratorsMapping = std::unordered_map>{ - {"firstName", [&country]() { return static_cast(person::firstName(getLocale(country))); }}, - {"lastName", [&country]() { return static_cast(person::lastName(getLocale(country))); }}, - {"streetName", [&countryAddresses]() - { return static_cast(helper::randomElement(countryAddresses.streetNames)); }}, - {"streetPrefix", [&countryAddresses]() - { return static_cast(helper::randomElement(countryAddresses.streetPrefixes)); }}, - {"streetSuffix", [&countryAddresses]() - { return static_cast(helper::randomElement(countryAddresses.streetSuffixes)); }}}; + {"firstName", [&locale]() { return static_cast(person::firstName(locale)); }}, + {"lastName", [&locale]() { return static_cast(person::lastName(locale)); }}, + {"streetName", + [&localeAddresses]() { return static_cast(helper::randomElement(localeAddresses.streetNames)); }}, + {"streetPrefix", [&localeAddresses]() + { return static_cast(helper::randomElement(localeAddresses.streetPrefixes)); }}, + {"streetSuffix", [&localeAddresses]() + { return static_cast(helper::randomElement(localeAddresses.streetSuffixes)); }}}; return common::fillTokenValues(streetFormat, dataGeneratorsMapping); } -std::string buildingNumber(AddressCountry country) +std::string buildingNumber(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); const auto buildingNumberFormat = - static_cast(helper::randomElement(countryAddresses.buildingNumberFormats)); + static_cast(helper::randomElement(localeAddresses.buildingNumberFormats)); return helper::replaceSymbolWithNumber(buildingNumberFormat); } -std::string secondaryAddress(AddressCountry country) +std::string secondaryAddress(Locale locale) { - const auto& countryAddresses = getAddresses(country); + const auto& localeAddresses = getAddresses(locale); - if (countryAddresses.secondaryAddressFormats.empty()) + if (localeAddresses.secondaryAddressFormats.empty()) { return ""; } const auto secondaryAddressFormat = - static_cast(helper::randomElement(countryAddresses.secondaryAddressFormats)); + static_cast(helper::randomElement(localeAddresses.secondaryAddressFormats)); return helper::replaceSymbolWithNumber(secondaryAddressFormat); } diff --git a/src/modules/person.cpp b/src/modules/person.cpp index 01007193b..1a2da3607 100644 --- a/src/modules/person.cpp +++ b/src/modules/person.cpp @@ -238,9 +238,8 @@ std::string fullName(Locale locale, std::optional sex) weightedElements.reserve(peopleNames.nameFormats.size()); std::transform(peopleNames.nameFormats.begin(), peopleNames.nameFormats.end(), std::back_inserter(weightedElements), - [](const NameFormat& nameFormat) { - return helper::WeightedElement{nameFormat.weight, nameFormat.format}; - }); + [](const NameFormat& nameFormat) + { return helper::WeightedElement{nameFormat.weight, nameFormat.format}; }); const auto nameFormat = static_cast(helper::weightedRandomElement(weightedElements)); diff --git a/src/modules/person_data.h b/src/modules/person_data.h index ee05e65ae..ce4acc804 100644 --- a/src/modules/person_data.h +++ b/src/modules/person_data.h @@ -11874,68 +11874,4 @@ const NameFormats vietnameseNameFormats{{"{firstName} {lastName}", 1}}; const PeopleNames vietnamesePeopleNames{{vietnameseMaleFirstNames, vietnameseLastNames, {}, {}}, {vietnameseFemaleFirstNames, vietnameseLastNames, {}, {}}, vietnameseNameFormats}; - -const std::unordered_map PeopleNames{ - {Country::England, englishPeopleNames}, - {Country::France, frenchPeopleNames}, - {Country::Germany, germanPeopleNames}, - {Country::Italy, italianPeopleNames}, - {Country::Poland, polishPeopleNames}, - {Country::Russia, russianPeopleNames}, - {Country::Romania, romanianPeopleNames}, - {Country::India, indianPeopleNames}, - {Country::Finland, finnishPeopleNames}, - {Country::Spain, spanishPeopleNames}, - {Country::Turkey, turkishPeopleNames}, - {Country::Czech, czechPeopleNames}, - {Country::Slovakia, slovakPeopleNames}, - {Country::Ukraine, ukrainianPeopleNames}, - {Country::Denmark, danishPeopleNames}, - {Country::Sweden, swedishPeopleNames}, - {Country::Usa, usaPeopleNames}, - {Country::Brazil, brazilianPeopleNames}, - {Country::Norway, norwegianPeopleNames}, - {Country::Japan, japanesePeopleNames}, - {Country::Portugal, portuguesePeopleNames}, - {Country::Hungary, hungarianPeopleNames}, - {Country::Croatia, croatianPeopleNames}, - {Country::Greece, greekPeopleNames}, - {Country::Slovenia, slovenianPeopleNames}, - {Country::Austria, austrianPeopleNames}, - {Country::Switzerland, swissPeopleNames}, - {Country::Belgium, belgianPeopleNames}, - {Country::Netherlands, dutchPeopleNames}, - {Country::China, chinesePeopleNames}, - {Country::Korea, koreanPeopleNames}, - {Country::Canada, canadianPeopleNames}, - {Country::Mexico, mexicanPeopleNames}, - {Country::Argentina, argentinianPeopleNames}, - {Country::Australia, australianPeopleNames}, - {Country::Serbia, serbianPeopleNames}, - {Country::Macedonia, macedonianPeopleNames}, - {Country::Latvia, latvianPeopleNames}, - {Country::Ireland, irishPeopleNames}, - {Country::Belarus, belarusianPeopleNames}, - {Country::Estonia, estonianPeopleNames}, - {Country::Albania, albanianPeopleNames}, - {Country::Iran, persianPeopleNames}, - {Country::Bulgaria, bulgarianPeopleNames}, - {Country::Moldova, moldovanPeopleNames}, - {Country::Lithuania, lithuanianPeopleNames}, - {Country::Iceland, icelandicPeopleNames}, - {Country::Palestine, palestinianPeopleNames}, - {Country::Israel, israeliPeopleNames}, - {Country::Vietnam, vietnamesePeopleNames}, - {Country::Monaco, monacanPeopleNames}, - {Country::Bosnia, bosnianPeopleNames}, - {Country::Lebanon, lebanesePeopleNames}, - {Country::Syria, syrianPeopleNames}, - {Country::Malta, maltesePeopleNames}, - {Country::SouthAfrica, southAfricanPeopleNames}, - {Country::Azerbaijan, azerbaijaniPeopleNames}, - {Country::Ghana, ghanaianPeopleNames}, - {Country::Kazakhstan, kazakhPeopleNames}, - {Country::Maldives, maldiviansPeopleNames}, -}; - } diff --git a/tests/modules/location_test.cpp b/tests/modules/location_test.cpp index 12a911950..d382375cb 100644 --- a/tests/modules/location_test.cpp +++ b/tests/modules/location_test.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include #include "gtest/gtest.h" @@ -19,72 +18,62 @@ using namespace faker::location; namespace { -const std::vector addressCountries{ - AddressCountry::Usa, AddressCountry::Poland, AddressCountry::France, AddressCountry::Russia, - AddressCountry::Ukraine, AddressCountry::Italy, AddressCountry::Germany, AddressCountry::Czech, - AddressCountry::India, AddressCountry::Denmark, AddressCountry::Australia, AddressCountry::Spain, - AddressCountry::Brazil, AddressCountry::Finland, AddressCountry::Estonia, -}; - -CountryAddressesInfo getAddresses(const AddressCountry& country) +CountryAddressesInfo getAddresses(const Locale& locale) { - switch (country) + switch (locale) { - case AddressCountry::Usa: + case Locale::en_US: + case Locale::es_US: return usaAddresses; - case AddressCountry::Poland: + case Locale::pl_PL: return polandAddresses; - case AddressCountry::Russia: + case Locale::ru_RU: return russiaAddresses; - case AddressCountry::France: + case Locale::fr_FR: return franceAddresses; - case AddressCountry::Ukraine: + case Locale::uk_UA: return ukraineAddresses; - case AddressCountry::Italy: + case Locale::it_IT: return italyAddresses; - case AddressCountry::Germany: + case Locale::de_DE: return germanyAddresses; - case AddressCountry::Czech: + case Locale::cs_CZ: return czechAddresses; - case AddressCountry::Australia: + case Locale::en_AU: return australiaAddresses; - case AddressCountry::India: + case Locale::as_IN: + case Locale::bn_IN: + case Locale::en_IN: + case Locale::gu_IN: + case Locale::hi_IN: + case Locale::kn_IN: + case Locale::ks_IN: + case Locale::ml_IN: + case Locale::mr_IN: + case Locale::or_IN: + case Locale::pa_IN: + case Locale::sa_IN: + case Locale::ta_IN: + case Locale::te_IN: return indiaAddresses; - case AddressCountry::Denmark: + case Locale::da_DK: return denmarkAddresses; - case AddressCountry::Spain: + case Locale::ca_ES: + case Locale::es_ES: return spainAddresses; - case AddressCountry::Brazil: + case Locale::pt_BR: return brazilAddresses; - case AddressCountry::Finland: + case Locale::fi_FI: return finlandAddresses; - case AddressCountry::Estonia: + case Locale::et_EE: return estoniaAddresses; default: return usaAddresses; } } - -const std::unordered_map generatedTestName{ - {AddressCountry::Usa, "shouldGenerateAmericanAddress"}, - {AddressCountry::France, "shouldGenerateFrenchAddress"}, - {AddressCountry::Poland, "shouldGeneratePolishAddress"}, - {AddressCountry::Russia, "shouldGenerateRussianAddress"}, - {AddressCountry::Ukraine, "shouldGenerateUkrainianAddress"}, - {AddressCountry::Italy, "shouldGenerateItalianAddress"}, - {AddressCountry::Germany, "shouldGenerateGermanAddress"}, - {AddressCountry::Czech, "shouldGenerateCzechAddress"}, - {AddressCountry::Australia, "shouldGenerateAustraliaAddress"}, - {AddressCountry::India, "shouldGenerateIndiaAddress"}, - {AddressCountry::Denmark, "shouldGenerateDenmarkAddress"}, - {AddressCountry::Spain, "shouldGenerateSpainAddress"}, - {AddressCountry::Brazil, "shouldGenerateBrazilAddress"}, - {AddressCountry::Finland, "shouldGenerateFinlandAddress"}, - {AddressCountry::Estonia, "shouldGenerateEstoniaAddress"}, -}; } -class LocationTest : public TestWithParam +class LocationTest : public TestWithParam { public: static bool checkIfZipCode(const std::string& zipCode) @@ -124,16 +113,11 @@ TEST_P(LocationTest, shouldGenerateState) const auto& countryAddresses = getAddresses(country); - // TODO: remove - if (country == AddressCountry::Estonia) - { - return; - } - const auto generatedState = state(country); ASSERT_TRUE(std::ranges::any_of(countryAddresses.states, [&generatedState](const std::string_view& state) - { return state == generatedState; })); + { return state == generatedState; }) || + generatedState.empty()); } TEST_P(LocationTest, shouldGenerateCity) @@ -144,7 +128,7 @@ TEST_P(LocationTest, shouldGenerateCity) const auto generatedCity = city(country); - if (country == location::AddressCountry::Brazil) + if (country == Locale::pt_BR) { const auto generatedCityElements = common::split(generatedCity, " "); @@ -260,9 +244,8 @@ TEST_P(LocationTest, shouldGenerateSecondaryAddress) })); } -INSTANTIATE_TEST_SUITE_P(TestLocationByCountries, LocationTest, ValuesIn(addressCountries), - [](const TestParamInfo& paramInfo) - { return generatedTestName.at(paramInfo.param); }); +INSTANTIATE_TEST_SUITE_P(TestLocationByCountries, LocationTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); TEST_F(LocationTest, shouldGenerateUsaStreet) { @@ -315,7 +298,7 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) TEST_F(LocationTest, shouldGeneratePolandStreet) { - const auto generatedStreet = street(AddressCountry::Poland); + const auto generatedStreet = street(Locale::pl_PL); const auto generatedStreetElements = common::split(generatedStreet, " "); @@ -331,7 +314,7 @@ TEST_F(LocationTest, shouldGeneratePolandStreet) TEST_F(LocationTest, shouldGeneratePolandStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Poland); + const auto generatedStreetAddress = streetAddress(Locale::pl_PL); ASSERT_TRUE(std::ranges::any_of(polandStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); @@ -341,7 +324,7 @@ TEST_F(LocationTest, shouldGeneratePolandStreetAddress) TEST_F(LocationTest, shouldGenerateRussiaStreet) { - const auto generatedStreet = street(AddressCountry::Russia); + const auto generatedStreet = street(Locale::ru_RU); const auto generatedStreetElements = common::split(generatedStreet, " "); @@ -368,7 +351,7 @@ TEST_F(LocationTest, shouldGenerateRussiaStreet) TEST_F(LocationTest, shouldGenerateRussiaStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Russia); + const auto generatedStreetAddress = streetAddress(Locale::ru_RU); std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); @@ -389,7 +372,7 @@ TEST_F(LocationTest, shouldGenerateRussiaStreetAddress) TEST_F(LocationTest, shouldGenerateFranceStreet) { - const auto generatedStreet = street(AddressCountry::France); + const auto generatedStreet = street(Locale::fr_FR); const auto generatedStreetElements = common::split(generatedStreet, " "); @@ -406,7 +389,7 @@ TEST_F(LocationTest, shouldGenerateFranceStreet) TEST_F(LocationTest, shouldGenerateFranceStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::France); + const auto generatedStreetAddress = streetAddress(Locale::fr_FR); const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); @@ -518,7 +501,7 @@ TEST_F(LocationTest, shouldGenerateTimeZone) TEST_F(LocationTest, shouldGenerateUkraineStreet) { - const auto generatedStreet = street(AddressCountry::Ukraine); + const auto generatedStreet = street(Locale::uk_UA); const auto generatedStreetElements = common::split(generatedStreet, " "); @@ -550,7 +533,7 @@ TEST_F(LocationTest, shouldGenerateUkraineStreet) TEST_F(LocationTest, shouldGenerateUkraineStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Ukraine); + const auto generatedStreetAddress = streetAddress(Locale::uk_UA); ASSERT_TRUE(std::ranges::any_of(ukraineStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); @@ -575,7 +558,7 @@ TEST_F(LocationTest, shouldGenerateUkraineStreetAddress) TEST_F(LocationTest, shouldGenerateItalyStreet) { - const auto generatedStreet = street(AddressCountry::Italy); + const auto generatedStreet = street(Locale::it_IT); const auto generatedStreetElements = common::split(generatedStreet, " "); @@ -598,7 +581,7 @@ TEST_F(LocationTest, shouldGenerateItalyStreet) TEST_F(LocationTest, shouldGenerateItalyStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Italy); + const auto generatedStreetAddress = streetAddress(Locale::it_IT); ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetAddress](const std::string_view& prefix) { return generatedStreetAddress.find(prefix) != std::string::npos; })); @@ -616,7 +599,7 @@ TEST_F(LocationTest, shouldGenerateItalyStreetAddress) TEST_F(LocationTest, shouldGenerateGermanyStreet) { - const auto generatedStreet = street(AddressCountry::Germany); + const auto generatedStreet = street(Locale::de_DE); ASSERT_TRUE(std::ranges::any_of(germanyStreetNames, [&generatedStreet](const std::string_view& streetName) { return streetName == generatedStreet; })); @@ -624,7 +607,7 @@ TEST_F(LocationTest, shouldGenerateGermanyStreet) TEST_F(LocationTest, shouldGenerateGermanyStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Germany); + const auto generatedStreetAddress = streetAddress(Locale::de_DE); ASSERT_TRUE(std::ranges::any_of(germanyStreetNames, [&generatedStreetAddress](const std::string_view& streetName) { return generatedStreetAddress.find(streetName) != std::string::npos; })); @@ -632,7 +615,7 @@ TEST_F(LocationTest, shouldGenerateGermanyStreetAddress) TEST_F(LocationTest, shouldGenerateCzechStreet) { - const auto generatedStreet = street(AddressCountry::Czech); + const auto generatedStreet = street(Locale::cs_CZ); ASSERT_TRUE(std::ranges::any_of(czechStreetNames, [&generatedStreet](const std::string_view& streetName) { return streetName == generatedStreet; })); @@ -640,7 +623,7 @@ TEST_F(LocationTest, shouldGenerateCzechStreet) TEST_F(LocationTest, shouldGenerateCzechStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Czech); + const auto generatedStreetAddress = streetAddress(Locale::cs_CZ); ASSERT_TRUE(std::ranges::any_of(czechStreetNames, [&generatedStreetAddress](const std::string_view& streetName) { return generatedStreetAddress.find(streetName) != std::string::npos; })); @@ -648,7 +631,7 @@ TEST_F(LocationTest, shouldGenerateCzechStreetAddress) TEST_F(LocationTest, shouldGenerateAustraliaStreet) { - const auto generatedStreet = street(AddressCountry::Australia); + const auto generatedStreet = street(Locale::en_AU); std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); @@ -665,7 +648,7 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreet) TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Australia); + const auto generatedStreetAddress = streetAddress(Locale::en_AU); const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); @@ -692,7 +675,7 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) TEST_F(LocationTest, shouldGenerateIndiaStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::India); + const auto generatedStreetAddress = streetAddress(Locale::hi_IN); const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); @@ -709,7 +692,7 @@ TEST_F(LocationTest, shouldGenerateIndiaStreetAddress) TEST_F(LocationTest, shouldGenerateDenmarkStreet) { - const auto generatedStreet = street(AddressCountry::Denmark); + const auto generatedStreet = street(Locale::da_DK); ASSERT_TRUE(std::ranges::any_of(denmarkStreetNames, [&generatedStreet](const std::string_view& streetName) { return streetName == generatedStreet; })); @@ -717,7 +700,7 @@ TEST_F(LocationTest, shouldGenerateDenmarkStreet) TEST_F(LocationTest, shouldGenerateDenmarkStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Denmark); + const auto generatedStreetAddress = streetAddress(Locale::da_DK); ASSERT_TRUE(std::ranges::any_of(denmarkStreetNames, [&generatedStreetAddress](const std::string_view& streetName) { return generatedStreetAddress.find(streetName) != std::string::npos; })); @@ -725,7 +708,7 @@ TEST_F(LocationTest, shouldGenerateDenmarkStreetAddress) TEST_F(LocationTest, shouldGenerateSpainStreet) { - const auto generatedStreet = street(AddressCountry::Spain); + const auto generatedStreet = street(Locale::es_ES); std::vector firstNames(person::spanishMaleFirstNames.begin(), person::spanishMaleFirstNames.end()); @@ -741,7 +724,7 @@ TEST_F(LocationTest, shouldGenerateSpainStreet) TEST_F(LocationTest, shouldGenerateSpainStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Spain); + const auto generatedStreetAddress = streetAddress(Locale::es_ES); ASSERT_TRUE(std::ranges::any_of(spainStreetSuffixes, [&generatedStreetAddress](const std::string_view& suffix) { return generatedStreetAddress.find(suffix) != std::string::npos; })); @@ -759,7 +742,7 @@ TEST_F(LocationTest, shouldGenerateSpainStreetAddress) TEST_F(LocationTest, shouldGenerateFinlandStreet) { - const auto generatedStreet = street(AddressCountry::Finland); + const auto generatedStreet = street(Locale::fi_FI); const auto generatedStreetElements = common::split(generatedStreet, " "); @@ -784,7 +767,7 @@ TEST_F(LocationTest, shouldGenerateFinlandStreet) TEST_F(LocationTest, shouldGenerateFinlandStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Finland); + const auto generatedStreetAddress = streetAddress(Locale::fi_FI); ASSERT_TRUE(std::ranges::any_of(finlandStreetSuffixes, [&generatedStreetAddress](const std::string_view& suffix) { return generatedStreetAddress.find(suffix) != std::string::npos; })); @@ -802,7 +785,7 @@ TEST_F(LocationTest, shouldGenerateFinlandStreetAddress) TEST_F(LocationTest, shouldGenerateEstoniaStreet) { - const auto generatedStreet = street(AddressCountry::Estonia); + const auto generatedStreet = street(Locale::et_EE); ASSERT_TRUE(std::ranges::any_of(estoniaStreetNames, [&generatedStreet](const std::string_view& streetName) { return generatedStreet.find(streetName) != std::string::npos; })); @@ -810,7 +793,7 @@ TEST_F(LocationTest, shouldGenerateEstoniaStreet) TEST_F(LocationTest, shouldGenerateEstoniaStreetAddress) { - const auto generatedStreetAddress = streetAddress(AddressCountry::Estonia); + const auto generatedStreetAddress = streetAddress(Locale::et_EE); ASSERT_TRUE(std::ranges::any_of(estoniaStreetNames, [&generatedStreetAddress](const std::string_view& streetName) { return generatedStreetAddress.find(streetName) != std::string::npos; }));