Skip to content

Commit

Permalink
feat: adding locale to word module (#932)
Browse files Browse the repository at this point in the history
* generating a new adjetive signature for adding information of locale

* adding more tables

* adding new function wordsL

* adding more words to data

* change functions names, fixing test not passing

* adding check if locale is in map or not

* signature for functions

* generating all test

* using en_US words structure for general functions

* using span for main structures of data

* adding portuguese words

* adding french words

* adding test

* modify changelog

* adding parametrized test

* fixing use fmt and GTest from System

* spelling

* reverting modification in internet.cpp

* spell correction

* using correct function in test

* check if the locale is defined using idiomsMapSpan structure, if not using default en_US.

* unsing auto in parameterized tests

* change functions descriptions

* removing duplicate functions

* removing extre newlines in tests

* adding const in test values.

* removing option in words with (length<=256), and s capture the dataset in the test
  • Loading branch information
gustavobastian authored Oct 3, 2024
1 parent 80f7796 commit 3aef81d
Show file tree
Hide file tree
Showing 6 changed files with 30,169 additions and 113 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file
* added locale to `weather` module
* added locale to `color` module
* added locale to `vehicle` module
* added locale to `word` module

## v3.0.0 (28.08.2024)

Expand Down
76 changes: 58 additions & 18 deletions include/faker-cxx/word.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
#include "faker-cxx/export.h"
#include "faker-cxx/helper.h"

#include "faker-cxx/types/locale.h"

namespace faker::word
{

/**
* @brief Returns a random .
*
* @param length The expected length of the .
* If no with given length will be found, it will return a random .
* If no word with given length will be found or length is 0, it will return a random size word.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Random sample word.
*
Expand All @@ -23,12 +27,13 @@ namespace faker::word
* faker::word::sample(5) // "spell"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);

/**
* @brief Returns a string containing a number of space separated random words.
*
* @param numberOfWords The number of words to generate.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Random words separated with spaces.
*
Expand All @@ -37,13 +42,16 @@ FAKER_CXX_EXPORT std::string_view sample(std::optional<unsigned> length = std::n
* faker::word::words(5) // "before hourly patiently dribble equal"
* @endcode
*/
FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1);
FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1,const Locale locale = Locale::en_US);



/**
* @brief Returns a random adjective.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no adjective with given length will be found or length is 0, it will return a random size adjective.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Adjective.
*
Expand All @@ -52,13 +60,31 @@ FAKER_CXX_EXPORT std::string words(unsigned numberOfWords = 1);
* faker::word::adjective(3) // "bad"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random adjective, using locale.
*
* @param length The expected length of the word.
* If no adjective with given length will be found or length is 0, it will return a random size adjective.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Adjective.
*
* @code
* faker::word::adjective() // "complete"
* faker::word::adjective(3) // "bad"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adjectiveLocale(unsigned length = 0,const Locale locale = Locale::en_US);

/**
* @brief Returns a random adverb.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no adverb with given length will be found or length is 0, it will return a random size adverb.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Adverb.
*
Expand All @@ -67,13 +93,15 @@ FAKER_CXX_EXPORT std::string_view adjective(std::optional<unsigned> length = std
* faker::word::adverb(5) // "almost"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random conjunction.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* @param length The expected length of the word.
* If no conjunction with given length will be found or length is 0, it will return a random size conjunction.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Conjunction.
*
Expand All @@ -82,13 +110,16 @@ FAKER_CXX_EXPORT std::string_view adverb(std::optional<unsigned> length = std::n
* faker::word::conjunction(6) // "indeed"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);



/**
* @brief Returns a random interjection.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no interjection with given length is found or length is 0, it will return a random size interjection.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Interjection.
*
Expand All @@ -97,13 +128,16 @@ FAKER_CXX_EXPORT std::string_view conjunction(std::optional<unsigned> length = s
* faker::word::interjection(4) // "yuck"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);



/**
* @brief Returns a random noun.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no noun with given length is found or length is 0, it will return a random size noun.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Noun.
*
Expand All @@ -112,13 +146,15 @@ FAKER_CXX_EXPORT std::string_view interjection(std::optional<unsigned> length =
* faker::word::noun(8) // "distance"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random preposition.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no preposition with given length is found or length is 0, it will return a random size preposition.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Preposition.
*
Expand All @@ -127,13 +163,15 @@ FAKER_CXX_EXPORT std::string_view noun(std::optional<unsigned> length = std::nul
* faker::word::preposition(4) // "from"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns a random verb.
*
* @param length The expected length of the word.
* If no word with given length will be found, it will return a random word.
* If no verb with given length is found or length is 0, it will return a random size verb.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Verb.
*
Expand All @@ -142,12 +180,14 @@ FAKER_CXX_EXPORT std::string_view preposition(std::optional<unsigned> length = s
* faker::word::verb(9) // "stabilise"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nullopt);
FAKER_CXX_EXPORT std::string_view verb(std::optional<unsigned> length = std::nullopt,const Locale locale = Locale::en_US);


/**
* @brief Returns random element of length
*
* @param length The length of the elements to be picked from
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @ range The range of elements
*
Expand Down
Loading

0 comments on commit 3aef81d

Please sign in to comment.