diff --git a/.gitmodules b/.gitmodules index 8d680e1b8..0222bacd1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,4 +4,3 @@ [submodule "externals/fmt"] path = externals/fmt url = https://github.com/fmtlib/fmt.git - diff --git a/CMakePresets.json b/CMakePresets.json index cc5a38e32..a66af6338 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -199,6 +199,25 @@ "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "BUILD_SHARED_LIBS": "ON" } + }, + { + "name": "Enter\\", + "description": "", + "displayName": "", + "inherits": [ + "unixlike-gcc-debug-static" + ] + }, + { + "name": "Enter", + "description": "", + "displayName": "", + "inherits": [ + "unixlike-gcc-debug-static", + "unixlike-gcc-debug-shared", + "unixlike-gcc-release-static", + "unixlike-gcc-release-shared" + ] } ], "buildPresets": [ @@ -274,7 +293,7 @@ "configurePreset": "windows-msvc-debug-shared", "configuration": "Debug" } - ], + ], "testPresets": [ { "name": "test-common", diff --git a/externals/googletest b/externals/googletest index 5ed218639..35d0c3656 160000 --- a/externals/googletest +++ b/externals/googletest @@ -1 +1 @@ -Subproject commit 5ed21863955149a5a877a53d7d5045b6919090ed +Subproject commit 35d0c365609296fa4730d62057c487e3cfa030ff diff --git a/include/faker-cxx/movie.h b/include/faker-cxx/movie.h index dce7e6652..4a272f03f 100644 --- a/include/faker-cxx/movie.h +++ b/include/faker-cxx/movie.h @@ -3,11 +3,14 @@ #include #include "faker-cxx/export.h" +#include "faker-cxx/types/locale.h" namespace faker::movie { /** - * @brief Returns a random movie genre. + * @brief Returns a random movie genre + * + * @param locale The locale. Defaults to `Locale::en_US`. * * @returns Movie genre. * @@ -15,9 +18,11 @@ namespace faker::movie * faker::movie::genre() // "Drama" * @endcode */ -FAKER_CXX_EXPORT std::string_view genre(); +FAKER_CXX_EXPORT std::string_view genre(Locale locale = Locale::en_US); /** + * @param locale The locale. Defaults to `Locale::en_US`. + * * @brief Returns a random movie title. * * @returns Movie title. @@ -26,9 +31,10 @@ FAKER_CXX_EXPORT std::string_view genre(); * faker::movie::movieTitle() // "Pulp Fiction" * @endcode */ -FAKER_CXX_EXPORT std::string_view movieTitle(); +FAKER_CXX_EXPORT std::string_view movieTitle(Locale locale = Locale::en_US); /** + * @param locale The locale. Defaults to `Locale::en_US`. * @brief Returns a random tv show. * * @returns Tv show. @@ -37,9 +43,11 @@ FAKER_CXX_EXPORT std::string_view movieTitle(); * faker::movie::tvShow() // "The Sopranos" * @endcode */ -FAKER_CXX_EXPORT std::string_view tvShow(); +FAKER_CXX_EXPORT std::string_view tvShow(Locale locale = Locale::en_US); /** + * @param locale The locale. Defaults to `Locale::en_US`. + * * @brief Returns a random movie director name. * * @returns Movie director name. @@ -48,9 +56,11 @@ FAKER_CXX_EXPORT std::string_view tvShow(); * faker::movie::director() // "Quentin Tarantino" * @endcode */ -FAKER_CXX_EXPORT std::string_view director(); +FAKER_CXX_EXPORT std::string_view director(Locale locale = Locale::en_US); /** + * @param locale The locale. Defaults to `Locale::en_US`. + * * @brief Returns a random actor name. * * @returns Actor name. @@ -59,9 +69,11 @@ FAKER_CXX_EXPORT std::string_view director(); * faker::movie::actor() // "John Travolta" * @endcode */ -FAKER_CXX_EXPORT std::string_view actor(); +FAKER_CXX_EXPORT std::string_view actor(Locale locale = Locale::en_US); /** + * @param locale The locale. Defaults to `Locale::en_US`. + * * @brief Returns a random actress name. * * @returns Actress name. @@ -70,5 +82,5 @@ FAKER_CXX_EXPORT std::string_view actor(); * faker::movie::actress() // "Scarlett Johansson" * @endcode */ -FAKER_CXX_EXPORT std::string_view actress(); +FAKER_CXX_EXPORT std::string_view actress(Locale locale = Locale::en_US); } diff --git a/src/modules/movie.cpp b/src/modules/movie.cpp index 55141af1d..09a4b9068 100644 --- a/src/modules/movie.cpp +++ b/src/modules/movie.cpp @@ -7,34 +7,58 @@ namespace faker::movie { -std::string_view genre() +namespace { - return helper::randomElement(movieGenres); +const struct MovieDefinition& getMovie(Locale locale) +{ + switch (locale) + { + default: + return enUSmoviesDefinitions; + } +} } -std::string_view movieTitle() +std::string_view genre(Locale locale) { - return helper::randomElement(movies); + const auto& movie = getMovie(locale); + + return helper::randomElement(movie.genres); } -std::string_view tvShow() +std::string_view movieTitle(Locale locale) { - return helper::randomElement(tvShows); + const auto& movie = getMovie(locale); + + return helper::randomElement(movie.movies); } -std::string_view director() +std::string_view tvShow(Locale locale) { - return helper::randomElement(directors); + const auto& movie = getMovie(locale); + + return helper::randomElement(movie.tvShows); } -std::string_view actor() +std::string_view director(Locale locale) { - return helper::randomElement(actors); + const auto& movie = getMovie(locale); + + return helper::randomElement(movie.directors); } -std::string_view actress() +std::string_view actor(Locale locale) { - return helper::randomElement(actresses); + const auto& movie = getMovie(locale); + + return helper::randomElement(movie.actors); +} + +std::string_view actress(Locale locale) +{ + const auto& movie = getMovie(locale); + + return helper::randomElement(movie.actresses); } } \ No newline at end of file diff --git a/src/modules/movie_data.h b/src/modules/movie_data.h index 54412f39a..9cd7d0332 100644 --- a/src/modules/movie_data.h +++ b/src/modules/movie_data.h @@ -1,13 +1,26 @@ #pragma once #include +#include #include #include "faker-cxx/movie.h" namespace faker::movie { -const auto actors = std::to_array({ + +struct MovieDefinition +{ + std::span actors; + std::span actresses; + std::span directors; + std::span genres; + std::span movies; + std::span tvShows; +}; + +// "en-us" +const auto enUSactors = std::to_array({ "Aamir Khan", "Abbott and Costello", "Adel Imam", @@ -309,7 +322,7 @@ const auto actors = std::to_array({ "Yves Montand", }); -const auto actresses = std::to_array({ +const auto enUSactresses = std::to_array({ "Agnes Moorehead", "Aishwarya Rai", "Alida Valli", @@ -612,7 +625,7 @@ const auto actresses = std::to_array({ "Zhang Ziyi", }); -const auto directors = std::to_array({ +const auto enUSdirectors = std::to_array({ "Abbas Kiarostami", "Abel Gance", "Agnès Varda", @@ -915,10 +928,10 @@ const auto directors = std::to_array({ "Éric Rohmer", }); -const auto movieGenres = std::to_array( +const auto enUSmovieGenres = std::to_array( {"Action", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Romance", "Thriller", "Western"}); -const auto movies = std::to_array({ +const auto enUSmovies = std::to_array({ "12 Angry Men", "2001: A Space Odyssey", "8½", @@ -1171,7 +1184,7 @@ const auto movies = std::to_array({ "Yôjinbô", }); -const auto tvShows = std::to_array({ +const auto enUStvShows = std::to_array({ "Africa", "Apocalypse: The Second World War", "Arcane", @@ -1296,4 +1309,12 @@ const auto tvShows = std::to_array({ "When They See Us", }); +const MovieDefinition enUSmoviesDefinitions = { + .actors = enUSactors, + .actresses = enUSactresses, + .directors = enUSdirectors, + .genres = enUSmovieGenres, + .movies = enUSmovies, + .tvShows = enUStvShows, +}; } \ No newline at end of file diff --git a/tests/modules/movie_test.cpp b/tests/modules/movie_test.cpp index b1533db67..73b28dfcf 100644 --- a/tests/modules/movie_test.cpp +++ b/tests/modules/movie_test.cpp @@ -7,57 +7,98 @@ #include "movie_data.h" using namespace ::testing; +using namespace faker; using namespace faker::movie; -class MovieTest : public Test +namespace +{ +const struct MovieDefinition& getMovie(Locale locale) +{ + switch (locale) + { + default: + return enUSmoviesDefinitions; + } +} +} + +class MovieTest : public TestWithParam { public: }; -TEST_F(MovieTest, shouldGenerateGenre) +TEST_P(MovieTest, shouldGenerateGenreLocale) { - const auto generatedGenre = genre(); + const auto locale = GetParam(); - ASSERT_TRUE(std::ranges::any_of(movieGenres, [generatedGenre](const std::string_view& genre) + const auto& movie = getMovie(locale); + + const auto& generatedGenre = genre(locale); + + ASSERT_TRUE(std::ranges::any_of(movie.genres, [generatedGenre](const std::string_view& genre) { return generatedGenre == genre; })); } -TEST_F(MovieTest, shouldGenerateMovieTitle) +TEST_P(MovieTest, shouldGenerateMovieTitleLocale) { - const auto generatedMovieTitle = movieTitle(); + const auto locale = GetParam(); + + const auto& movie = getMovie(locale); - ASSERT_TRUE(std::ranges::any_of(movies, [generatedMovieTitle](const std::string_view& movieTitle) + const auto generatedMovieTitle = movieTitle(locale); + + ASSERT_TRUE(std::ranges::any_of(movie.movies, [generatedMovieTitle](const std::string_view& movieTitle) { return generatedMovieTitle == movieTitle; })); } -TEST_F(MovieTest, shouldGenerateTvShow) +TEST_P(MovieTest, shouldGenerateTvShowLocale) { - const auto generatedTvShow = tvShow(); + const auto locale = GetParam(); + + const auto& movie = getMovie(locale); - ASSERT_TRUE(std::ranges::any_of(tvShows, [generatedTvShow](const std::string_view& tvShow) + const auto generatedTvShow = tvShow(locale); + + ASSERT_TRUE(std::ranges::any_of(movie.tvShows, [generatedTvShow](const std::string_view& tvShow) { return generatedTvShow == tvShow; })); } -TEST_F(MovieTest, shouldGenerateDirector) +TEST_P(MovieTest, shouldGenerateDirectorLocale) { - const auto generatedDirector = director(); + const auto locale = GetParam(); + + const auto& movie = getMovie(locale); + + const auto generatedDirector = director(locale); - ASSERT_TRUE(std::ranges::any_of(directors, [generatedDirector](const std::string_view& director) + ASSERT_TRUE(std::ranges::any_of(movie.directors, [generatedDirector](const std::string_view& director) { return generatedDirector == director; })); } -TEST_F(MovieTest, shouldGenerateActor) +TEST_P(MovieTest, shouldGenerateActorLocale) { - const auto generatedActor = actor(); + const auto locale = GetParam(); + + const auto& movie = getMovie(locale); + + const auto generatedActor = actor(locale); - ASSERT_TRUE(std::ranges::any_of(actors, [generatedActor](const std::string_view& actor) + ASSERT_TRUE(std::ranges::any_of(movie.actors, [generatedActor](const std::string_view& actor) { return generatedActor == actor; })); } -TEST_F(MovieTest, shouldGenerateActress) +TEST_P(MovieTest, shouldGenerateActressLocale) { - const auto generatedActress = actress(); + const auto locale = GetParam(); - ASSERT_TRUE(std::ranges::any_of(actresses, [generatedActress](const std::string_view& actress) + const auto& movie = getMovie(locale); + + const auto generatedActress = actress(locale); + + ASSERT_TRUE(std::ranges::any_of(movie.actresses, [generatedActress](const std::string_view& actress) { return generatedActress == actress; })); } + +INSTANTIATE_TEST_SUITE_P(TestMovieByLocale, MovieTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); +