diff --git a/include/faker-cxx/internet.h b/include/faker-cxx/internet.h index f976c42f..5f3fe9cf 100644 --- a/include/faker-cxx/internet.h +++ b/include/faker-cxx/internet.h @@ -81,7 +81,7 @@ FAKER_CXX_EXPORT std::string username(std::optional firstName = std */ FAKER_CXX_EXPORT std::string email(std::optional firstName = std::nullopt, std::optional lastName = std::nullopt, - std::optional emailHost = std::nullopt); + std::optional emailHost = std::nullopt, Locale locale = Locale::en_US); /** * @brief Generates an email address using the given person's name as base with example domain. @@ -96,7 +96,8 @@ FAKER_CXX_EXPORT std::string email(std::optional firstName = std::n * @endcode */ FAKER_CXX_EXPORT std::string exampleEmail(std::optional firstName = std::nullopt, - std::optional lastName = std::nullopt); + std::optional lastName = std::nullopt, + Locale locale = Locale::en_US); /** * @brief Generates a random password-like string. Do not use this method for generating actual passwords for users. @@ -201,7 +202,7 @@ FAKER_CXX_EXPORT unsigned httpStatusCode(std::optional respons * faker::internet::httpRequestHeader() // "Authorization" * @endcode */ -FAKER_CXX_EXPORT std::string_view httpRequestHeader(); +FAKER_CXX_EXPORT std::string_view httpRequestHeader(Locale locale = Locale::en_US); /** * @brief Generates a random http response header. @@ -212,7 +213,7 @@ FAKER_CXX_EXPORT std::string_view httpRequestHeader(); * faker::internet::httpResponseHeader() // "Location" * @endcode */ -FAKER_CXX_EXPORT std::string_view httpResponseHeader(); +FAKER_CXX_EXPORT std::string_view httpResponseHeader(Locale locale = Locale::en_US); /** * @brief Generates a random http media type. @@ -223,7 +224,7 @@ FAKER_CXX_EXPORT std::string_view httpResponseHeader(); * faker::internet::httpMediaType() // "application/json" * @endcode */ -FAKER_CXX_EXPORT std::string_view httpMediaType(); +FAKER_CXX_EXPORT std::string_view httpMediaType(Locale locale = Locale::en_US); /** * @brief Returns a string containing randomized ipv4 address of the given class. @@ -305,7 +306,7 @@ FAKER_CXX_EXPORT unsigned port(); * faker::internet::url() // "https://slow-timer.info" * @endcode */ -FAKER_CXX_EXPORT std::string url(const WebProtocol& webProtocol = WebProtocol::Https); +FAKER_CXX_EXPORT std::string url(const WebProtocol& webProtocol = WebProtocol::Https, Locale locale = Locale::en_US); /** * @brief Generates a random domain name. @@ -316,7 +317,7 @@ FAKER_CXX_EXPORT std::string url(const WebProtocol& webProtocol = WebProtocol::H * faker::internet::domainName() // "slow-timer.info" * @endcode */ -FAKER_CXX_EXPORT std::string domainName(); +FAKER_CXX_EXPORT std::string domainName(Locale locale = Locale::en_US); /** * @brief Generates a random domain word. @@ -338,7 +339,7 @@ FAKER_CXX_EXPORT std::string domainWord(); * faker::internet::domainSuffix() // "com" * @endcode */ -FAKER_CXX_EXPORT std::string_view domainSuffix(); +FAKER_CXX_EXPORT std::string_view domainSuffix(Locale locale = Locale::en_US); /** * @brief Generates a random username. @@ -388,5 +389,5 @@ getJWTToken(const std::optional>& header = st * faker::internet::getJWTAlgorithm(); // "HS256" * @endcode */ -FAKER_CXX_EXPORT std::string_view getJWTAlgorithm(); +FAKER_CXX_EXPORT std::string_view getJWTAlgorithm(Locale locale = Locale::en_US); } diff --git a/src/modules/internet.cpp b/src/modules/internet.cpp index 384143bc..07ef976e 100644 --- a/src/modules/internet.cpp +++ b/src/modules/internet.cpp @@ -111,6 +111,18 @@ std::string toJSON(std::map& data) namespace faker::internet { +namespace +{ +const struct InternetDefinition& getInternetDefinition(Locale locale) +{ + switch (locale) + { + default: + return enUSInternetDefinition; + } +} +} + namespace { const std::array webProtocols{"http", "https"}; @@ -194,16 +206,18 @@ std::string username(std::optional firstName, std::optional firstName, std::optional lastName, - std::optional emailHost) + std::optional emailHost, Locale locale) { + const auto& internetDefinition = getInternetDefinition(locale); return common::format("{}@{}", username(std::move(firstName), std::move(lastName)), - emailHost ? *emailHost : helper::randomElement(emailHosts)); + emailHost ? *emailHost : helper::randomElement(internetDefinition.emailHosts)); } -std::string exampleEmail(std::optional firstName, std::optional lastName) +std::string exampleEmail(std::optional firstName, std::optional lastName, Locale locale) { + const auto& internetDefinition = getInternetDefinition(locale); return common::format("{}@{}", username(std::move(firstName), std::move(lastName)), - helper::randomElement(emailExampleHosts)); + helper::randomElement(internetDefinition.emailExampleHosts)); } std::string password(int length, const PasswordOptions& options) @@ -294,19 +308,25 @@ unsigned httpStatusCode(std::optional responseType) return helper::randomElement(statusCodes); } -std::string_view httpRequestHeader() +std::string_view httpRequestHeader(Locale locale) { - return helper::randomElement(httpRequestHeaders); + const auto& internetDefinition = getInternetDefinition(locale); + + return helper::randomElement(internetDefinition.httpRequestHeaders); } -std::string_view httpResponseHeader() +std::string_view httpResponseHeader(Locale locale) { - return helper::randomElement(httpResponseHeaders); + const auto& internetDefinition = getInternetDefinition(locale); + + return helper::randomElement(internetDefinition.httpResponseHeaders); } -std::string_view httpMediaType() +std::string_view httpMediaType(Locale locale) { - return helper::randomElement(httpMediaTypes); + const auto& internetDefinition = getInternetDefinition(locale); + + return helper::randomElement(internetDefinition.httpMediaTypes); } std::string ipv4(const IPv4Class& ipv4class) @@ -396,16 +416,18 @@ unsigned port() return number::integer(65535u); } -std::string url(const WebProtocol& webProtocol) +std::string url(const WebProtocol& webProtocol, Locale locale) { + const auto& internetDefinition = getInternetDefinition(locale); + const auto protocolStr = webProtocol == WebProtocol::Https ? "https" : "http"; - return common::format("{}://{}", protocolStr, domainName()); + return common::format("{}://{}", protocolStr, domainName(locale)); } -std::string domainName() +std::string domainName(Locale locale) { - return common::format("{}.{}", domainWord(), domainSuffix()); + return common::format("{}.{}", domainWord(), domainSuffix(locale)); } std::string domainWord() @@ -413,9 +435,11 @@ std::string domainWord() return common::toLower(common::format("{}-{}", word::adjective(), word::noun())); } -std::string_view domainSuffix() +std::string_view domainSuffix(Locale locale) { - return helper::randomElement(domainSuffixes); + const auto& internetDefinition = getInternetDefinition(locale); + + return helper::randomElement(internetDefinition.domainSuffixes); } std::string anonymousUsername(unsigned maxLength) @@ -435,9 +459,11 @@ std::string anonymousUsername(unsigned maxLength) return common::format("{}{}", word::adjective(adjectiveLength), word::noun(nounLength)); } -std::string_view getJWTAlgorithm() +std::string_view getJWTAlgorithm(Locale locale) { - return helper::randomElement(jwtAlgorithms); + const auto& internetDefinition = getInternetDefinition(locale); + + return helper::randomElement(internetDefinition.jwtAlgorithms); } std::string getJWTToken(const std::optional>& header, diff --git a/src/modules/internet_data.h b/src/modules/internet_data.h index 1411a815..7400ddac 100644 --- a/src/modules/internet_data.h +++ b/src/modules/internet_data.h @@ -1,11 +1,24 @@ #pragma once #include +#include #include namespace faker::internet { -const auto domainSuffixes = std::to_array({ + +struct InternetDefinition +{ + std::span domainSuffixes; + std::span emailHosts; + std::span emailExampleHosts; + std::span httpMediaTypes; + std::span httpRequestHeaders; + std::span httpResponseHeaders; + std::span jwtAlgorithms; +}; + +const auto enUSdomainSuffixes = std::to_array({ "biz", "com", "info", @@ -14,14 +27,14 @@ const auto domainSuffixes = std::to_array({ "org", }); -const auto emailHosts = std::to_array({ +const auto enUSemailHosts = std::to_array({ "gmail.com", "hotmail.com", "outlook.com", "yahoo.com", }); -const auto emailExampleHosts = std::to_array({ +const auto enUSemailExampleHosts = std::to_array({ "example.com", "example.net", "example.org", @@ -739,7 +752,7 @@ const auto flagEmojis = std::to_array({ "🚩", }); -const auto httpMediaTypes = std::to_array({ +const auto enUShttpMediaTypes = std::to_array({ "application/gzip", "application/java-archive", "application/json", @@ -787,7 +800,7 @@ const auto httpMediaTypes = std::to_array({ "video/x-msvideo", }); -const auto httpRequestHeaders = std::to_array({ +const auto enUShttpRequestHeaders = std::to_array({ "A-IM", "Accept", "Accept-Charset", @@ -831,7 +844,7 @@ const auto httpRequestHeaders = std::to_array({ "Warning", }); -const auto httpResponseHeaders = std::to_array({ +const auto enUShttpResponseHeaders = std::to_array({ "Accept-CH", "Accept-Patch", "Accept-Ranges", @@ -878,7 +891,7 @@ const auto httpResponseHeaders = std::to_array({ "Warning", }); -const auto jwtAlgorithms = std::to_array({ +const auto enUSjwtAlgorithms = std::to_array({ "HS256", "HS384", "HS512", @@ -894,4 +907,14 @@ const auto jwtAlgorithms = std::to_array({ "none", }); +const InternetDefinition enUSInternetDefinition = { + .domainSuffixes = enUSdomainSuffixes, + .emailHosts = enUSemailHosts, + .emailExampleHosts = enUSemailExampleHosts, + .httpMediaTypes = enUShttpMediaTypes, + .httpRequestHeaders = enUShttpRequestHeaders, + .httpResponseHeaders = enUShttpResponseHeaders, + .jwtAlgorithms = enUSjwtAlgorithms, +}; + } diff --git a/tests/modules/internet_test.cpp b/tests/modules/internet_test.cpp index 6e7124d0..dec127f7 100644 --- a/tests/modules/internet_test.cpp +++ b/tests/modules/internet_test.cpp @@ -55,7 +55,19 @@ std::array deconstructIpv4String(const std::string& ipv4) } } -class InternetTest : public Test +namespace +{ +const struct InternetDefinition& getInternetDefinition(Locale locale) +{ + switch (locale) + { + default: + return enUSInternetDefinition; + } +} +} + +class InternetTest : public TestWithParam { public: InternetTest() @@ -171,13 +183,17 @@ TEST_F(InternetTest, shouldGenerateInternationalUsernames) { return generatedUsername.find(common::toLower(lastName)) != std::string::npos; })); } -TEST_F(InternetTest, shouldGenerateEmail) +TEST_P(InternetTest, shouldGenerateEmail) { + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); - const auto generatedEmail = email(); + const auto generatedEmail = email(std::nullopt, std::nullopt, std::nullopt, locale); const auto emailParts = common::split(generatedEmail, "@"); @@ -186,7 +202,7 @@ TEST_F(InternetTest, shouldGenerateEmail) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE( std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) @@ -196,11 +212,15 @@ TEST_F(InternetTest, shouldGenerateEmail) { return generatedUsername.find(common::toLower(lastName)) != std::string::npos; })); } -TEST_F(InternetTest, shouldGenerateEmailWithFirstName) +TEST_P(InternetTest, shouldGenerateEmailWithFirstName) { + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + const std::string firstName = "Tom"; - const auto generatedEmail = email(firstName); + const auto generatedEmail = email(firstName, std::nullopt, std::nullopt, locale); const auto emailParts = common::split(generatedEmail, "@"); @@ -209,7 +229,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(common::toLower(firstName)) != std::string::npos); ASSERT_TRUE( @@ -217,15 +237,19 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) { return generatedUsername.find(common::toLower(lastName)) != std::string::npos; })); } -TEST_F(InternetTest, shouldGenerateEmailWithLastName) +TEST_P(InternetTest, shouldGenerateEmailWithLastName) { std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + const std::string lastName = "Howard"; - const auto generatedEmail = email(std::nullopt, lastName); + const auto generatedEmail = email(std::nullopt, lastName, std::nullopt, locale); const auto emailParts = common::split(generatedEmail, "@"); @@ -234,7 +258,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithLastName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE( std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) @@ -242,13 +266,17 @@ TEST_F(InternetTest, shouldGenerateEmailWithLastName) ASSERT_TRUE(generatedUsername.find(common::toLower(lastName)) != std::string::npos); } -TEST_F(InternetTest, shouldGenerateEmailWithFullName) +TEST_P(InternetTest, shouldGenerateEmailWithFullName) { const std::string firstName = "Cindy"; const std::string lastName = "Young"; - const auto generatedEmail = email(firstName, lastName); + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + + const auto generatedEmail = email(firstName, lastName, std::nullopt, locale); const auto emailParts = common::split(generatedEmail, "@"); @@ -257,7 +285,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithFullName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(common::toLower(firstName)) != std::string::npos); ASSERT_TRUE(generatedUsername.find(common::toLower(lastName)) != std::string::npos); @@ -289,13 +317,17 @@ TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) { return generatedUsername.find(common::toLower(lastName)) != std::string::npos; })); } -TEST_F(InternetTest, shouldGenerateExampleEmail) +TEST_P(InternetTest, shouldGenerateExampleEmail) { + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); - const auto email = exampleEmail(); + const auto email = exampleEmail(std::nullopt, std::nullopt, locale); const auto emailParts = common::split(email, "@"); @@ -304,7 +336,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmail) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE( std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) @@ -314,11 +346,16 @@ TEST_F(InternetTest, shouldGenerateExampleEmail) { return generatedUsername.find(common::toLower(lastName)) != std::string::npos; })); } -TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) +TEST_P(InternetTest, shouldGenerateExampleEmailWithFirstName) { + + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + const std::string firstName = "Barry"; - const auto email = exampleEmail(firstName); + const auto email = exampleEmail(firstName, std::nullopt, locale); const auto emailParts = common::split(email, "@"); @@ -327,7 +364,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(common::toLower(firstName)) != std::string::npos); ASSERT_TRUE( @@ -335,15 +372,19 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) { return generatedUsername.find(common::toLower(lastName)) != std::string::npos; })); } -TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) +TEST_P(InternetTest, shouldGenerateExampleEmailWithLastName) { + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + std::vector firstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); firstNames.insert(firstNames.end(), person::englishFemaleFirstNames.begin(), person::englishFemaleFirstNames.end()); const std::string lastName = "Wilkinson"; - const auto email = exampleEmail(std::nullopt, lastName); + const auto email = exampleEmail(std::nullopt, lastName, locale); const auto emailParts = common::split(email, "@"); @@ -352,7 +393,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE( std::ranges::any_of(firstNames, [generatedUsername](const std::string_view& firstName) @@ -360,13 +401,17 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) ASSERT_TRUE(generatedUsername.find(common::toLower(lastName)) != std::string::npos); } -TEST_F(InternetTest, shouldGenerateExampleEmailWithFullName) +TEST_P(InternetTest, shouldGenerateExampleEmailWithFullName) { + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + const std::string firstName = "Walter"; const std::string lastName = "Brown"; - const auto email = exampleEmail(firstName, lastName); + const auto email = exampleEmail(firstName, lastName, locale); const auto emailParts = common::split(email, "@"); @@ -375,7 +420,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFullName) const auto& generatedUsername = emailParts[0]; const auto& generatedEmailHost = emailParts[1]; - ASSERT_TRUE(std::ranges::any_of(emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.emailExampleHosts, [generatedEmailHost](const std::string_view& emailHost) { return generatedEmailHost == emailHost; })); ASSERT_TRUE(generatedUsername.find(common::toLower(firstName)) != std::string::npos); ASSERT_TRUE(generatedUsername.find(common::toLower(lastName)) != std::string::npos); @@ -543,28 +588,37 @@ TEST_F(InternetTest, shouldGenerateHttpStatusCode) { return generatedHttpStatusCode == statusCode; })); } -TEST_F(InternetTest, shouldGenerateHttpRequestHeader) +TEST_P(InternetTest, shouldGenerateHttpRequestHeader) { - const auto generatedHttpRequestHeader = httpRequestHeader(); + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); - ASSERT_TRUE(std::ranges::any_of(httpRequestHeaders, [generatedHttpRequestHeader](const std::string_view& httpHeader) + const auto generatedHttpRequestHeader = httpRequestHeader(locale); + + ASSERT_TRUE(std::ranges::any_of(internetDefinition.httpRequestHeaders, [generatedHttpRequestHeader](const std::string_view& httpHeader) { return generatedHttpRequestHeader == httpHeader; })); } -TEST_F(InternetTest, shouldGenerateHttpResponseHeader) +TEST_P(InternetTest, shouldGenerateHttpResponseHeader) { - const auto generatedHttpResponseHeader = httpResponseHeader(); + const auto locale = GetParam(); + const auto& internetDefinition = getInternetDefinition(locale); + const auto generatedHttpResponseHeader = httpResponseHeader(locale); - ASSERT_TRUE(std::ranges::any_of(httpResponseHeaders, + ASSERT_TRUE(std::ranges::any_of(internetDefinition.httpResponseHeaders, [generatedHttpResponseHeader](const std::string_view& httpHeader) { return generatedHttpResponseHeader == httpHeader; })); } -TEST_F(InternetTest, shouldGenerateHttpMediaType) +TEST_P(InternetTest, shouldGenerateHttpMediaType) { - const auto generatedHttpMediaType = httpMediaType(); + const auto locale = GetParam(); + const auto& internetDefinition = getInternetDefinition(locale); + + const auto generatedHttpMediaType = httpMediaType(locale); - ASSERT_TRUE(std::ranges::any_of(httpMediaTypes, [generatedHttpMediaType](const std::string_view& httpMediaType) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.httpMediaTypes, [generatedHttpMediaType](const std::string_view& httpMediaType) { return generatedHttpMediaType == httpMediaType; })); } @@ -702,11 +756,15 @@ TEST_F(InternetTest, MacDefaultSeparatorOverwrite) } } -TEST_F(InternetTest, shouldGenerateDomainSuffix) +TEST_P(InternetTest, shouldGenerateDomainSuffix) { - const auto generatedDomainSuffix = domainSuffix(); + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); - ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) + const auto generatedDomainSuffix = domainSuffix(locale); + + ASSERT_TRUE(std::ranges::any_of(internetDefinition.domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) { return generatedDomainSuffix == domainSuffix; })); } @@ -717,9 +775,12 @@ TEST_F(InternetTest, shouldGenerateDomainWord) assertDomainWord(generatedDomainWord); } -TEST_F(InternetTest, shouldGenerateDomainName) +TEST_P(InternetTest, shouldGenerateDomainName) { - const auto generatedDomainName = domainName(); + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + const auto generatedDomainName = domainName(locale); const auto generatedDomainNameParts = common::split(generatedDomainName, "."); @@ -727,13 +788,18 @@ TEST_F(InternetTest, shouldGenerateDomainName) const auto& generatedDomainSuffix = generatedDomainNameParts[1]; assertDomainWord(generatedDomainWord); - ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) { return generatedDomainSuffix == domainSuffix; })); } -TEST_F(InternetTest, shouldGenerateHttpsUrl) +TEST_P(InternetTest, shouldGenerateHttpsUrl) { - const auto generatedUrl = url(); + + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + + const auto generatedUrl = url(WebProtocol::Https, locale); const auto generatedUrlParts = common::split(generatedUrl, "://"); @@ -746,14 +812,18 @@ TEST_F(InternetTest, shouldGenerateHttpsUrl) const auto& generatedDomainSuffix = generatedDomainNameParts[1]; assertDomainWord(generatedDomainWord); - ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) { return generatedDomainSuffix == domainSuffix; })); ASSERT_EQ(generatedProtocol, "https"); } -TEST_F(InternetTest, shouldGenerateHttpUrl) +TEST_P(InternetTest, shouldGenerateHttpUrl) { - const auto generatedUrl = url(WebProtocol::Http); + const auto locale = GetParam(); + + const auto& internetDefinition = getInternetDefinition(locale); + + const auto generatedUrl = url(WebProtocol::Http, locale); const auto generatedUrlParts = common::split(generatedUrl, "://"); @@ -766,7 +836,7 @@ TEST_F(InternetTest, shouldGenerateHttpUrl) const auto& generatedDomainSuffix = generatedDomainNameParts[1]; assertDomainWord(generatedDomainWord); - ASSERT_TRUE(std::ranges::any_of(domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) + ASSERT_TRUE(std::ranges::any_of(internetDefinition.domainSuffixes, [generatedDomainSuffix](const std::string_view& domainSuffix) { return generatedDomainSuffix == domainSuffix; })); ASSERT_EQ(generatedProtocol, "http"); } @@ -819,10 +889,16 @@ TEST_F(InternetTest, shouldGenerateJwtToken) ASSERT_TRUE(std::regex_match(getJWTToken(header, payload, refDate), pattern)); } -TEST_F(InternetTest, shouldGenerateJWTAlgorithm) +TEST_P(InternetTest, shouldGenerateJWTAlgorithm) { - const auto generatedJWTAlgorythm = getJWTAlgorithm(); + const auto locale = GetParam(); + const auto& internetDefinition = getInternetDefinition(locale); - ASSERT_TRUE(std::ranges::any_of(jwtAlgorithms, [generatedJWTAlgorythm](const std::string_view& JWTAlgorythm) + const auto generatedJWTAlgorythm = getJWTAlgorithm(locale); + + ASSERT_TRUE(std::ranges::any_of(internetDefinition.jwtAlgorithms, [generatedJWTAlgorythm](const std::string_view& JWTAlgorythm) { return generatedJWTAlgorythm == JWTAlgorythm; })); } + +INSTANTIATE_TEST_SUITE_P(TestInternetByLocale, InternetTest, ValuesIn(locales), + [](const TestParamInfo& paramInfo) { return toString(paramInfo.param); }); \ No newline at end of file