Skip to content

Commit

Permalink
feat: Added locale for movies (#1000)
Browse files Browse the repository at this point in the history
* Added module constructor to both header (defination and the declaration

* Reverting the changes as they are directly pushed into main

* Added constructor for en-us locale

* Implemented en_us for movies

* Fixed tests and removed faker submodule

* Instantiated google verification in Movie module

* Fixed build issues

* Fixed comment for the doxygen
  • Loading branch information
SgtApone117 authored Dec 2, 2024
1 parent 525a755 commit 96e0263
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 48 deletions.
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
[submodule "externals/fmt"]
path = externals/fmt
url = https://github.com/fmtlib/fmt.git

21 changes: 20 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -274,7 +293,7 @@
"configurePreset": "windows-msvc-debug-shared",
"configuration": "Debug"
}
],
],
"testPresets": [
{
"name": "test-common",
Expand Down
26 changes: 19 additions & 7 deletions include/faker-cxx/movie.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
#include <string_view>

#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.
*
* @code
* 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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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);
}
48 changes: 36 additions & 12 deletions src/modules/movie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
35 changes: 28 additions & 7 deletions src/modules/movie_data.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
#pragma once

#include <array>
#include <span>
#include <string_view>

#include "faker-cxx/movie.h"

namespace faker::movie
{
const auto actors = std::to_array<std::string_view>({

struct MovieDefinition
{
std::span<const std::string_view> actors;
std::span<const std::string_view> actresses;
std::span<const std::string_view> directors;
std::span<const std::string_view> genres;
std::span<const std::string_view> movies;
std::span<const std::string_view> tvShows;
};

// "en-us"
const auto enUSactors = std::to_array<std::string_view>({
"Aamir Khan",
"Abbott and Costello",
"Adel Imam",
Expand Down Expand Up @@ -309,7 +322,7 @@ const auto actors = std::to_array<std::string_view>({
"Yves Montand",
});

const auto actresses = std::to_array<std::string_view>({
const auto enUSactresses = std::to_array<std::string_view>({
"Agnes Moorehead",
"Aishwarya Rai",
"Alida Valli",
Expand Down Expand Up @@ -612,7 +625,7 @@ const auto actresses = std::to_array<std::string_view>({
"Zhang Ziyi",
});

const auto directors = std::to_array<std::string_view>({
const auto enUSdirectors = std::to_array<std::string_view>({
"Abbas Kiarostami",
"Abel Gance",
"Agnès Varda",
Expand Down Expand Up @@ -915,10 +928,10 @@ const auto directors = std::to_array<std::string_view>({
"Éric Rohmer",
});

const auto movieGenres = std::to_array<std::string_view>(
const auto enUSmovieGenres = std::to_array<std::string_view>(
{"Action", "Comedy", "Drama", "Fantasy", "Horror", "Mystery", "Romance", "Thriller", "Western"});

const auto movies = std::to_array<std::string_view>({
const auto enUSmovies = std::to_array<std::string_view>({
"12 Angry Men",
"2001: A Space Odyssey",
"",
Expand Down Expand Up @@ -1171,7 +1184,7 @@ const auto movies = std::to_array<std::string_view>({
"Yôjinbô",
});

const auto tvShows = std::to_array<std::string_view>({
const auto enUStvShows = std::to_array<std::string_view>({
"Africa",
"Apocalypse: The Second World War",
"Arcane",
Expand Down Expand Up @@ -1296,4 +1309,12 @@ const auto tvShows = std::to_array<std::string_view>({
"When They See Us",
});

}
const MovieDefinition enUSmoviesDefinitions = {
.actors = enUSactors,
.actresses = enUSactresses,
.directors = enUSdirectors,
.genres = enUSmovieGenres,
.movies = enUSmovies,
.tvShows = enUStvShows,
};
}
Loading

0 comments on commit 96e0263

Please sign in to comment.