From 2d63faf79c8b7578efdd7749ad5b70ccf13d813b Mon Sep 17 00:00:00 2001 From: DoubleTricot <75956635+dubloom@users.noreply.github.com> Date: Fri, 23 Aug 2024 11:58:15 +0200 Subject: [PATCH 1/4] feat: create e-sport module (#870) Co-authored-by: Louis Tricot --- include/faker-cxx/esport.h | 64 +++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 ++ src/modules/esport.cpp | 35 +++++++++++++++++++ src/modules/esport_data.h | 46 +++++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/modules/esport_test.cpp | 55 ++++++++++++++++++++++++++++++ 6 files changed, 203 insertions(+) create mode 100644 include/faker-cxx/esport.h create mode 100644 src/modules/esport.cpp create mode 100644 src/modules/esport_data.h create mode 100644 tests/modules/esport_test.cpp diff --git a/include/faker-cxx/esport.h b/include/faker-cxx/esport.h new file mode 100644 index 000000000..6aff10c00 --- /dev/null +++ b/include/faker-cxx/esport.h @@ -0,0 +1,64 @@ +#pragma once + +#include + +#include "faker-cxx/export.h" + +namespace faker::esport +{ + +/** + * @brief Returns a random player name. + * + * @return Player name. + * + * @code + * faker::esport::player() // "Faker" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view player(); + +/** + * @brief Returns a random esport team. + * + * @return Esport team. + * + * @code + * faker::esport::team() // "Karmine Corp" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view team(); + +/** + * @brief Returns a random esport league. + * + * @return Esport League. + * + * @code + * faker::esport::league() // "LEC" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view league(); + +/** + * @brief Returns a random esport event. + * + * @return Esport Event. + * + * @code + * faker::esport::event() // "Faker" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view event(); + +/** + * @brief Returns a random competitive video game. + * + * @return Competitive video game. + * + * @code + * faker::esport::game() // "Rocket League" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view game(); +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2ffc2f22d..cdb5309b9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(FAKER_SOURCES modules/plant.cpp modules/science.cpp modules/sport.cpp + modules/esport.cpp modules/string.cpp modules/system.cpp modules/vehicle.cpp @@ -77,6 +78,7 @@ set(FAKER_HEADERS modules/phone_data.h modules/color_data.h modules/lorem_data.h + modules/esport_data.h ) target_sources(${CMAKE_PROJECT_NAME} PRIVATE ${FAKER_SOURCES} ${FAKER_HEADERS}) diff --git a/src/modules/esport.cpp b/src/modules/esport.cpp new file mode 100644 index 000000000..9cb377ddb --- /dev/null +++ b/src/modules/esport.cpp @@ -0,0 +1,35 @@ +#include "faker-cxx/esport.h" + +#include + +#include "esport_data.h" +#include "faker-cxx/helper.h" + +namespace faker::esport +{ +std::string_view player() +{ + return helper::randomElement(players); +} + +std::string_view team() +{ + return helper::randomElement(teams); +} + +std::string_view league() +{ + return helper::randomElement(leagues); +} + +std::string_view event() +{ + return helper::randomElement(events); +} + +std::string_view game() +{ + return helper::randomElement(games); +} + +} \ No newline at end of file diff --git a/src/modules/esport_data.h b/src/modules/esport_data.h new file mode 100644 index 000000000..f7d976ddb --- /dev/null +++ b/src/modules/esport_data.h @@ -0,0 +1,46 @@ +#pragma once + +#include +#include + +namespace faker::esport +{ +const auto players = std::to_array( + {"Adam", "Alvaro", "Brokenblade", "Canna", "Caps", "Carzzy", "Closer", "Comp", "Elyoya", + "Finn", "Flakked", "Fresskowy", "Hans Sama", "Humanoid", "Hylissang", "Ice", "IgNar", "Irrelevant", + "Isma", "Jackies", "Jankos", "Juhan", "Jun", "Labrov", "Larssen", "Luon", "Lyncas", + "Markoon", "Mikyx", "Myrwn", "Nisqy", "Noah", "Oscarinin", "Patrik", "Photon", "Rahel", + "Razork", "Sheo", "Supa", "Targamas", "Th3Antonio", "Trymbi", "Upset", "Vetheo", "Vladi", + "Wunder", "Yike", "Zoelys", "Zwyroo", "nuc", "Aiming", "Andil", "Bdd", "BeryL", + "Bulldog", "Calix", "Callme", "Canyon", "Casting", "Chovy", "Clear", "Clozer", "Cuzz", + "DDoiV", "Deft", "Delight", "DnDn", "Doran", "DuDu", "Duro", "Envyy", "Execute", + "FATE", "Faker", "Fisher", "Frog", "GuGer", "Gumayusi", "Hena", "Jiwoo", "Karis", + "Kellin", "Keria", "Kiin", "Kyeahoo", "Leaper", "Lehends", "Lucid", "Mihile", "Moham", + "Morgan", "Oner", "Paduck", "Peanut", "PerfecT", "Peyz", "Pleata", "Pollu", "Pullbae", + "Pyosik", "Quantum", "Raptor", "Rascal", "Samver", "SeTab", "ShowMaker", "Sponge", "Sylvie", + "Teddy", "Viper", "Vital", "YoungJae", "Zeka", "Zeus", "kingen"}); + +const auto teams = std::to_array( + {"Team Liquid", "G2 Esports", "OpTic Gaming", "Natus Vincere", "Astralis", "NRG", + "7figures Esports", "HEROIC", "Faze Clan", "Fnatic", "Virtus.pro", "Ninjas in Pyjamas", + "CompLexity", "TSM", "BIG", "Karmine Corp", "Cloud9", "Evil Geniuses", + "Team VItality", "Mouz", "100 Thieves", "NaVi", "Team Secret", "Vitality", + "Gambit Esports", "BDS", "Gentle Mates"}); + +const auto leagues = std::to_array( + {"LEC", "LPL", "LCK", "LCS NA", "LFL", "PUBG Mobile Super League", "VCT", "VCT GC", "F1 Esports Series", + "Overwatch League", "Superliga", "Prime League", "TCL", "Call of Duty League", "RLCS"}); + +const auto events = + std::to_array({"MSI", "EMEA Masters", "League of Legends World Championship", "EWC", + "The International", "Fortnite World Cup", "Six Invitational", "Capcom X Cup", + "VCT Masters" + "RLCS Major", + "IEM"}); + +const auto games = std::to_array({"Valorant", "League Of Legend", "Rocket League", "Fifa", + "Overwatch", "CSGO", "Fortnite", "Dota 2", + "Street Fighter," + "Apex Legends", + "TFT", "PUBG", "Call of Duty"}); +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1ce3ac856..4fab2e751 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -37,6 +37,7 @@ set(FAKER_UT_SOURCES modules/plant_test.cpp modules/science_test.cpp modules/sport_test.cpp + modules/esport_test.cpp modules/string_test.cpp modules/system_test.cpp modules/vehicle_test.cpp diff --git a/tests/modules/esport_test.cpp b/tests/modules/esport_test.cpp new file mode 100644 index 000000000..d75d80b97 --- /dev/null +++ b/tests/modules/esport_test.cpp @@ -0,0 +1,55 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "esport_data.h" +#include "faker-cxx/esport.h" + +using namespace ::testing; +using namespace faker::esport; + +class EsportTest : public Test +{ +public: +}; + +TEST_F(EsportTest, shouldGeneratePlayer) +{ + const auto generatedPlayer = player(); + + ASSERT_TRUE(std::ranges::any_of(players, [generatedPlayer](const std::string_view& player) + { return generatedPlayer == player; })); +} + +TEST_F(EsportTest, shouldGenerateTeam) +{ + const auto generatedTeam = team(); + + ASSERT_TRUE( + std::ranges::any_of(teams, [generatedTeam](const std::string_view& team) { return generatedTeam == team; })); +} + +TEST_F(EsportTest, shouldGenerateLeague) +{ + const auto generatedLeague = league(); + + ASSERT_TRUE(std::ranges::any_of(leagues, [generatedLeague](const std::string_view& league) + { return generatedLeague == league; })); +} + +TEST_F(EsportTest, shouldGenerateEvent) +{ + const auto generatedEvent = event(); + + ASSERT_TRUE(std::ranges::any_of(events, [generatedEvent](const std::string_view& event) + { return generatedEvent == event; })); +} + +TEST_F(EsportTest, shouldGenerateGame) +{ + const auto generatedGame = game(); + + ASSERT_TRUE( + std::ranges::any_of(games, [generatedGame](const std::string_view& game) { return generatedGame == game; })); +} From 0ef4c5e56f74c3a81432e8ff0f990b33677237a3 Mon Sep 17 00:00:00 2001 From: DoubleTricot <75956635+dubloom@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:18:38 +0200 Subject: [PATCH 2/4] feat: create video module (#871) Co-authored-by: Louis Tricot --- README.md | 2 + include/faker-cxx/video.h | 85 +++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 + src/modules/video.cpp | 44 +++++++++++++++++ src/modules/video_data.h | 91 ++++++++++++++++++++++++++++++++++++ tests/CMakeLists.txt | 1 + tests/modules/video_test.cpp | 72 ++++++++++++++++++++++++++++ 7 files changed, 297 insertions(+) create mode 100644 include/faker-cxx/video.h create mode 100644 src/modules/video.cpp create mode 100644 src/modules/video_data.h create mode 100644 tests/modules/video_test.cpp diff --git a/README.md b/README.md index c75bc3fb1..14eccfa26 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ int main() - 📚 Lorem - lorem words, sentences, paragraphs - đŸĨ Medicine - conditions, medical tests, specialties - đŸŽĨ Movie - actors, actresses, genres, movie titles +- 🎞ī¸ Video - format name, file extension, video codec, audio codec, resolution, aspect ratio, video url - đŸŽļ Music - artists, song names, genres - đŸ”ĸ Number - random integers, floating point numbers - 🧑 Person - first, last names, job titles, hobby, genders, sex, nationality, language @@ -115,6 +116,7 @@ int main() - đŸ’ģ System - file paths, file extensions, file names, directories, semantic version - 🚗 Vehicle - vehicle types, makes, models, fuel types, license plates - 🎮 Video game - title, genre, platform, studio +- 🕹ī¸ Esport - player, team, league, event, game - 🌤ī¸ Weather - temperature, pressure, humidity, weather description - đŸ’Ŧ Word - sample words, nouns, verbs diff --git a/include/faker-cxx/video.h b/include/faker-cxx/video.h new file mode 100644 index 000000000..8ce815c42 --- /dev/null +++ b/include/faker-cxx/video.h @@ -0,0 +1,85 @@ +#pragma once + +#include + +#include "faker-cxx/export.h" + +namespace faker::video +{ +/** + * @brief Returns a random format name . + * + * @returns Format name. + * + * @code + * faker::video::formatName() // "Ogg Video" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view formatName(); + +/** + * @brief Returns a random file extension. + * + * @returns File extension. + * + * @code + * faker::video::fileExtension() // ".webm" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view fileExtension(); + +/** + * @brief Returns a random video codec. + * + * @returns Video codec. + * + * @code + * faker::video::videoCodec() // "VP8" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view videoCodec(); + +/** + * @brief Returns a random audio codec. + * + * @returns Audio Codec. + * + * @code + * faker::video::audioCodec() // "Vorbis" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view audioCodec(); + +/** + * @brief Returns a random resolution. + * + * @returns Resolution. + * + * @code + * faker::video::resolution() // "240p" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view resolution(); + +/** + * @brief Returns a random aspect ratio. + * + * @returns Aspect Ratio. + * + * @code + * faker::video::aspectRatio() // "16:9" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view aspectRatio(); + +/** + * @brief Returns a random video Url. + * + * @returns Video Url. + * + * @code + * faker::video::videoUrl() // "https://youtu.be/_7ONEaabK90" + * @endcode + */ +FAKER_CXX_EXPORT std::string_view videoUrl(); +} \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cdb5309b9..bc98fa770 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,6 +36,7 @@ set(FAKER_SOURCES modules/system.cpp modules/vehicle.cpp modules/video_game.cpp + modules/video.cpp modules/weather.cpp modules/word.cpp common/format_helper.cpp @@ -57,6 +58,7 @@ set(FAKER_HEADERS modules/book_data.h modules/string_data.h modules/video_game_data.h + modules/video_data.h modules/medicine_data.h modules/vehicle_data.h modules/hacker_data.h diff --git a/src/modules/video.cpp b/src/modules/video.cpp new file mode 100644 index 000000000..80bfe7291 --- /dev/null +++ b/src/modules/video.cpp @@ -0,0 +1,44 @@ +#include "faker-cxx/video.h" + +#include + +#include "faker-cxx/helper.h" +#include "video_data.h" + +namespace faker::video +{ +std::string_view formatName() +{ + return helper::randomElement(formatNames); +} + +std::string_view fileExtension() +{ + return helper::randomElement(fileExtensions); +} + +std::string_view videoCodec() +{ + return helper::randomElement(videoCodecs); +} + +std::string_view audioCodec() +{ + return helper::randomElement(audioCodecs); +} + +std::string_view resolution() +{ + return helper::randomElement(resolutions); +} + +std::string_view aspectRatio() +{ + return helper::randomElement(aspectRatios); +} + +std::string_view videoUrl() +{ + return helper::randomElement(videoUrls); +} +} \ No newline at end of file diff --git a/src/modules/video_data.h b/src/modules/video_data.h new file mode 100644 index 000000000..8547a45b1 --- /dev/null +++ b/src/modules/video_data.h @@ -0,0 +1,91 @@ +#pragma once + +#include +#include + +namespace faker::video +{ +const auto formatNames = std::to_array({"WebM", + "Matroska", + "Flash Video (FLV)", + "F4V", + "Vob", + "Ogg Video", + "Dirac", + "GIF", + "Video alternative to GIF", + "Multiple-image Network Graphics", + "AVI", + "MPEG Transport Stream", + "QuickTime File Format", + "Windows Media Video", + "Raw video format", + "RealMedia (RM)", + "RealMedia Variable Bitrate (RMVB)", + "VivoActive (VIV)", + "Advanced Systems Format (ASF)", + "AMV video format", + "MPEG-4 Part 14 (MP4)", + "MPEG-1", + "MPEG-2", + "M4V", + "SVI", + "3GPP", + "3GPP2", + "Material Exchange Format (MXF)", + "ROQ", + "Nullsoft Streaming Video (NSV)"}); + +const auto fileExtensions = std::to_array( + {".webm", ".mkv", ".flv", ".vob", ".ogv", ".ogg", ".drc", ".gif", ".gifv", ".mng", ".avi", ".MTS", ".M2TS", + ".TS", ".mov", ".qt", ".wmv", ".yuv", ".rm", ".rmvb", ".viv", ".asf", ".amv", ".mp4", ".m4p", ".m4v", + ".mpg", ".mp2", ".mpeg", ".mpe", ".mpv", ".m2v", ".svi", ".3gp", ".3g2", ".mxf", ".roq", ".nsv"}); + +const auto videoCodecs = std::to_array( + {"VP8", "VP9", "AV1", "VP6", "Sorenson Spark", "H.264", "H.262/MPEG-2 Part 2", "MPEG-1 Part 2", "Theora", "Dirac", + "H.263", "Motion JPEG", "H.265", "MPEG-4 Part 2", "MPEG-1 Part 2", "H.262", "RealVideo"}); + +const auto audioCodecs = std::to_array({"Vorbis", + "Opus", + "MP3", + "ADPCM", + "Nellymoser", + "Speex", + "AAC", + "PCM", + "DTS", + "MPEG-1 Audio Layer II (MP2)", + "Dolby Digital (AC-3)", + "FLAC", + "AMR-NB", + "AMR-WB", + "AMR-WB+", + "HE-AAC v1", + "Enhanced aacPlus (HE-AAC v2)", + "RealAudio", + "G.723 ADPCM", + "IMA", + "Dolby AC-4", + "Sipro ACELP.net", + "Advanced Audio Coding", + "G.723 ADPCM audio", + "EVRC", + "SMV", + "VMR-WB"}); + +const auto resolutions = + std::to_array({"240p", "360p", "480p", "720p", "1080p", "1440p", "4K", "8k"}); + +const auto aspectRatios = std::to_array( + {"1:1", "4:3", "14:9", "16:10", "16:9", "1.85:1", "2.00:1", "2.40:1", "32:0", "21:9"}); + +const auto videoUrls = std::to_array( + {"https://youtu.be/_7ONEaabK90", "https://youtu.be/Jb4prVsXkZU", "https://youtu.be/XC1iWDz2gkk", + "https://youtu.be/YjxgM4Wvcts", "https://youtu.be/9RGPe-rYlnQ", "https://youtu.be/a91oTLx-1No", + "https://youtu.be/f21UCwIfgZk", "https://youtu.be/TvAuyIinmpI", "https://youtu.be/oavMtUWDBTM", + "https://youtu.be/hMnk7lh9M3o", "https://youtu.be/tpr8oqyjKIc", "https://youtu.be/idRjqi8JC2U", + "https://youtu.be/4-94JhLEiN0", "https://youtu.be/t7JCh7PHoDc", "https://youtu.be/AXOa66-k9MA", + "https://youtu.be/TE4eplsFSms", "https://youtu.be/04v_v1gnyO8", "https://youtu.be/pIsae6YdRjw", + "https://youtu.be/NHE7migQN7U", "https://youtu.be/FJ3oHpup-pk", "https://youtu.be/6JFVKnrE_d8"}); + +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4fab2e751..0bc3a7afc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -43,6 +43,7 @@ set(FAKER_UT_SOURCES modules/vehicle_test.cpp modules/version_test.cpp modules/video_game_test.cpp + modules/video_test.cpp modules/weather_test.cpp modules/word_test.cpp modules/word_data_test.cpp diff --git a/tests/modules/video_test.cpp b/tests/modules/video_test.cpp new file mode 100644 index 000000000..896f8a7c8 --- /dev/null +++ b/tests/modules/video_test.cpp @@ -0,0 +1,72 @@ +#include +#include + +#include "gtest/gtest.h" + +#include "faker-cxx/video.h" +#include "video_data.h" + +using namespace ::testing; +using namespace faker; +using namespace faker::video; + +class VideoTest : public Test +{ +public: +}; + +TEST_F(VideoTest, shouldGenerateFormatName) +{ + const auto generatedFormatName = formatName(); + + ASSERT_TRUE(std::ranges::any_of(formatNames, [generatedFormatName](const std::string_view& formatName) + { return formatName == generatedFormatName; })); +} + +TEST_F(VideoTest, shouldGenerateFileExtension) +{ + const auto generatedFileExtension = fileExtension(); + + ASSERT_TRUE(std::ranges::any_of(fileExtensions, [generatedFileExtension](const std::string_view& fileExtension) + { return fileExtension == generatedFileExtension; })); +} + +TEST_F(VideoTest, shouldGenerateVideoCodec) +{ + const auto generatedVideoCodec = videoCodec(); + + ASSERT_TRUE(std::ranges::any_of(videoCodecs, [generatedVideoCodec](const std::string_view& videoCodec) + { return videoCodec == generatedVideoCodec; })); +} + +TEST_F(VideoTest, shouldGeneratedAudioCodec) +{ + const auto generatedAudioCodec = audioCodec(); + + ASSERT_TRUE(std::ranges::any_of(audioCodecs, [generatedAudioCodec](const std::string_view& audioCodec) + { return audioCodec == generatedAudioCodec; })); +} + +TEST_F(VideoTest, shouldGenerateResolution) +{ + const auto generatedResolution = resolution(); + + ASSERT_TRUE(std::ranges::any_of(resolutions, [generatedResolution](const std::string_view& resolution) + { return resolution == generatedResolution; })); +} + +TEST_F(VideoTest, shouldGenerateAspectRatio) +{ + const auto generatedAspectRatio = aspectRatio(); + + ASSERT_TRUE(std::ranges::any_of(aspectRatios, [generatedAspectRatio](const std::string_view& aspectRatio) + { return aspectRatio == generatedAspectRatio; })); +} + +TEST_F(VideoTest, shouldGenerateVideoUrl) +{ + const auto generatedVideoUrl = videoUrl(); + + ASSERT_TRUE(std::ranges::any_of(videoUrls, [generatedVideoUrl](const std::string_view& videoUrl) + { return videoUrl == generatedVideoUrl; })); +} \ No newline at end of file From 9cd009a958068548970d1b48c2c70ed0d9dc9d39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blar?= Date: Wed, 28 Aug 2024 00:33:38 +0200 Subject: [PATCH 3/4] feat: add formatting script (#873) * feat: add formatting script * docs: mention code formatting script in contributing guide --- CONTRIBUTING.md | 39 +++++++++++++++++++++++++++------------ scripts/format_code.sh | 1 + src/modules/person.cpp | 5 ++--- 3 files changed, 30 insertions(+), 15 deletions(-) create mode 100755 scripts/format_code.sh 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/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/person.cpp b/src/modules/person.cpp index eca729cbb..ac0d5c3d8 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)); From 9977bf3431ab5cf6b5037f7d9d8c60e3087a290b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Cie=C5=9Blar?= Date: Wed, 28 Aug 2024 01:07:36 +0200 Subject: [PATCH 4/4] feat: add locale to location module (#874) --- include/faker-cxx/location.h | 64 ++++------- include/faker-cxx/person.h | 1 - include/faker-cxx/types/country.h | 69 ------------ src/modules/location.cpp | 173 +++++++++++++----------------- src/modules/person_data.h | 64 ----------- tests/modules/location_test.cpp | 143 +++++++++++------------- 6 files changed, 163 insertions(+), 351 deletions(-) delete mode 100644 include/faker-cxx/types/country.h 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 f7ca984bd..e06d7c081 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/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_data.h b/src/modules/person_data.h index 92b501deb..e4321653b 100644 --- a/src/modules/person_data.h +++ b/src/modules/person_data.h @@ -11861,68 +11861,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; }));