diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f11f5fb..50aae0d7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ set(FAKER_SOURCES src/modules/food/FoodData.cpp src/modules/git/Git.cpp src/modules/hacker/Hacker.cpp + src/modules/hacker/HackerData.cpp src/modules/helper/Helper.cpp src/modules/image/Image.cpp src/modules/internet/Internet.cpp diff --git a/include/faker-cxx/Hacker.h b/include/faker-cxx/Hacker.h index 9213c32c0..f8d72ab89 100644 --- a/include/faker-cxx/Hacker.h +++ b/include/faker-cxx/Hacker.h @@ -1,6 +1,6 @@ #pragma once -#include +#include namespace faker { @@ -16,7 +16,7 @@ class Hacker * Hacker::abbreviation() // "TCP" * @endcode */ - static std::string abbreviation(); + static std::string_view abbreviation(); /** * @brief Returns a random adjective. @@ -27,7 +27,7 @@ class Hacker * Hacker::adjective() // "open-source" * @endcode */ - static std::string adjective(); + static std::string_view adjective(); /** * @brief Returns a random noun. @@ -38,7 +38,7 @@ class Hacker * Hacker::noun() // "coder" * @endcode */ - static std::string noun(); + static std::string_view noun(); /** * @brief Returns a random verb. @@ -49,7 +49,7 @@ class Hacker * Hacker::verb() // "run" * @endcode */ - static std::string verb(); + static std::string_view verb(); /** * @brief Returns a random ingverb. @@ -60,7 +60,7 @@ class Hacker * Hacker::ingverb() // "backing up" * @endcode */ - static std::string ingverb(); + static std::string_view ingverb(); /** * @brief Returns a random phrase. diff --git a/include/faker-cxx/Image.h b/include/faker-cxx/Image.h index 5311db08e..9683567b6 100644 --- a/include/faker-cxx/Image.h +++ b/include/faker-cxx/Image.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include namespace faker { @@ -23,7 +23,7 @@ class Image Technics, Transport }; - + /** * @brief Generates a real image url with `https://loremflickr.com/`. * @@ -72,6 +72,6 @@ class Image * @code * Image::type() // "png" */ - static std::string type(); + static std::string_view type(); }; } diff --git a/src/modules/hacker/Hacker.cpp b/src/modules/hacker/Hacker.cpp index 6eb96ca7a..c469840ed 100644 --- a/src/modules/hacker/Hacker.cpp +++ b/src/modules/hacker/Hacker.cpp @@ -1,74 +1,74 @@ #include "faker-cxx/Hacker.h" -#include - #include "../../common/StringHelper.h" -#include "data/Abbreviations.h" -#include "data/Adjectives.h" -#include "data/Ingverbs.h" -#include "data/Nouns.h" -#include "data/Phrases.h" -#include "data/Verbs.h" +#include "faker-cxx/Helper.h" +#include "HackerData.h" namespace faker { -std::string Hacker::abbreviation() +std::string_view Hacker::abbreviation() { - return faker::Helper::arrayElement(faker::abbreviations); + return Helper::arrayElement(abbreviations); } -std::string Hacker::adjective() +std::string_view Hacker::adjective() { - return faker::Helper::arrayElement(faker::adjectives); + return Helper::arrayElement(adjectives); } -std::string Hacker::noun() +std::string_view Hacker::noun() { - return faker::Helper::arrayElement(faker::nouns); + return Helper::arrayElement(nouns); } -std::string Hacker::verb() +std::string_view Hacker::verb() { - return faker::Helper::arrayElement(faker::verbs); + return Helper::arrayElement(verbs); } -std::string Hacker::ingverb() +std::string_view Hacker::ingverb() { - return faker::Helper::arrayElement(faker::ingverbs); + return Helper::arrayElement(ingverbs); } std::string Hacker::phrase() { - auto splitRandomPhrase = StringHelper::split(faker::Helper::arrayElement(faker::phrases)); - std::string ret; + const auto splitRandomPhrase = StringHelper::split(static_cast(Helper::arrayElement(phrases))); + + std::string phrase; - for (auto& word : splitRandomPhrase) + for (const auto& word : splitRandomPhrase) { - word = StringHelper::removePunctuation(word); - if (word == "{abbreviation}") + const auto normalizedWord = StringHelper::removePunctuation(word); + + if (normalizedWord == "{abbreviation}") + { + phrase += abbreviation(); + } + else if (normalizedWord == "{adjective}") { - word = abbreviation(); + phrase += adjective(); } - else if (word == "{adjective}") + else if (normalizedWord == "{noun}") { - word = adjective(); + phrase += noun(); } - else if (word == "{noun}") + else if (normalizedWord == "{verb}") { - word = noun(); + phrase += verb(); } - else if (word == "{verb}") + else if (normalizedWord == "{ingverb}") { - word = verb(); + phrase += ingverb(); } - else if (word == "{ingverb}") + else { - word = ingverb(); + phrase += normalizedWord; } - ret += word + " "; + phrase += " "; } - return ret; + return phrase; } } diff --git a/src/modules/hacker/HackerData.cpp b/src/modules/hacker/HackerData.cpp new file mode 100644 index 000000000..5a09eb9be --- /dev/null +++ b/src/modules/hacker/HackerData.cpp @@ -0,0 +1,44 @@ +#include "HackerData.h" + +namespace faker +{ +const std::array abbreviations = { + "e.g.", "i.e.", "etc.", "Mr.", "Mrs.", "Ms.", "Dr.", "Prof.", + "Ave.", "St.", "A.M.", "P.M.", "USA", "UK", "CEO", "CFO", +}; + +const std::array adjectives = { + "auxiliary", "primary", "back-end", "digital", "open-source", "virtual", "cross-platform", "redundant", + "online", "haptic", "multi-byte", "bluetooth", "wireless", "1080p", "neural", "optical", +}; + +const std::array ingverbs = { + "backing up", "bypassing", "hacking", "overriding", "compressing", "copying", "navigating", "indexing", + "connecting", "generating", "quantifying", "calculating", "synthesizing", "transmitting", "programming", "parsing", +}; + +const std::array nouns = { + "driver", "protocol", "bandwidth", "panel", "microchip", "program", "port", "card", + "array", "interface", "system", "sensor", "firewall", "hard drive", "pixel", "alarm", +}; + +const std::array phrases = { + "If we {verb} the {noun}, we can get to the {abbreviation} {noun} through the {adjective} " + "{abbreviation} {noun}!", + "We need to {verb} the {adjective} {abbreviation} {noun}!", + "Try to {verb} the {abbreviation} {noun}, maybe it will {verb} the {adjective} {noun}!", + "You can't {verb} the {noun} without {ingverb} the {adjective} {abbreviation} {noun}!", + "Use the {adjective} {abbreviation} {noun}, then you can {verb} the {adjective} {noun}!", + "The {abbreviation} {noun} is down, {verb} the {adjective} {noun} so we can {verb} the " + "{abbreviation} {noun}!", + "{ingverb} the {noun} won't do anything, we need to {verb} the {adjective} {abbreviation} " + "{noun}!", + "I'll {verb} the {adjective} {abbreviation} {noun}, that should {noun} the {abbreviation} " + "{noun}!", +}; + +const std::array verbs = { + "back up", "bypass", "hack", "override", "compress", "copy", "navigate", "index", + "connect", "generate", "quantify", "calculate", "synthesize", "transmit", "program", "parse", +}; +} diff --git a/src/modules/hacker/HackerData.h b/src/modules/hacker/HackerData.h new file mode 100644 index 000000000..3d264b575 --- /dev/null +++ b/src/modules/hacker/HackerData.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include + +namespace faker +{ +extern const std::array abbreviations; +extern const std::array adjectives; +extern const std::array ingverbs; +extern const std::array nouns; +extern const std::array phrases; +extern const std::array verbs; +} diff --git a/src/modules/hacker/data/Abbreviations.h b/src/modules/hacker/data/Abbreviations.h deleted file mode 100644 index a048b9278..000000000 --- a/src/modules/hacker/data/Abbreviations.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector abbreviations = { - "e.g.", "i.e.", "etc.", "Mr.", "Mrs.", "Ms.", "Dr.", "Prof.", - "Ave.", "St.", "A.M.", "P.M.", "USA", "UK", "CEO", "CFO", -}; -} diff --git a/src/modules/hacker/data/Adjectives.h b/src/modules/hacker/data/Adjectives.h deleted file mode 100644 index 6cacc6a6c..000000000 --- a/src/modules/hacker/data/Adjectives.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector adjectives = { - "auxiliary", "primary", "back-end", "digital", "open-source", "virtual", "cross-platform", "redundant", - "online", "haptic", "multi-byte", "bluetooth", "wireless", "1080p", "neural", "optical", -}; -} diff --git a/src/modules/hacker/data/Ingverbs.h b/src/modules/hacker/data/Ingverbs.h deleted file mode 100644 index 8afe2c55b..000000000 --- a/src/modules/hacker/data/Ingverbs.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector ingverbs = { - "backing up", "bypassing", "hacking", "overriding", "compressing", "copying", "navigating", "indexing", - "connecting", "generating", "quantifying", "calculating", "synthesizing", "transmitting", "programming", "parsing", -}; -} diff --git a/src/modules/hacker/data/Nouns.h b/src/modules/hacker/data/Nouns.h deleted file mode 100644 index e446dc9b2..000000000 --- a/src/modules/hacker/data/Nouns.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector nouns = { - "driver", "protocol", "bandwidth", "panel", "microchip", "program", "port", "card", - "array", "interface", "system", "sensor", "firewall", "hard drive", "pixel", "alarm", -}; -} diff --git a/src/modules/hacker/data/Phrases.h b/src/modules/hacker/data/Phrases.h deleted file mode 100644 index fb3de7adb..000000000 --- a/src/modules/hacker/data/Phrases.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include -#include - -#include "Abbreviations.h" -#include "Adjectives.h" -#include "faker-cxx/Helper.h" -#include "Ingverbs.h" -#include "Nouns.h" -#include "Verbs.h" - -namespace faker -{ -const std::vector phrases = { - "If we {verb} the {noun}, we can get to the {abbreviation} {noun} through the {adjective} {abbreviation} {noun}!", - "We need to {verb} the {adjective} {abbreviation} {noun}!", - "Try to {verb} the {abbreviation} {noun}, maybe it will {verb} the {adjective} {noun}!", - "You can't {verb} the {noun} without {ingverb} the {adjective} {abbreviation} {noun}!", - "Use the {adjective} {abbreviation} {noun}, then you can {verb} the {adjective} {noun}!", - "The {abbreviation} {noun} is down, {verb} the {adjective} {noun} so we can {verb} the {abbreviation} {noun}!", - "{ingverb} the {noun} won't do anything, we need to {verb} the {adjective} {abbreviation} {noun}!", - "I'll {verb} the {adjective} {abbreviation} {noun}, that should {noun} the {abbreviation} {noun}!", -}; -} diff --git a/src/modules/hacker/data/Verbs.h b/src/modules/hacker/data/Verbs.h deleted file mode 100644 index f62bde23f..000000000 --- a/src/modules/hacker/data/Verbs.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector verbs = { - "back up", "bypass", "hack", "override", "compress", "copy", "navigate", "index", - "connect", "generate", "quantify", "calculate", "synthesize", "transmit", "program", "parse", -}; -} diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index a1b256529..669994fcc 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -1,9 +1,9 @@ #include "faker-cxx/Image.h" +#include #include #include "../../common/FormatHelper.h" -#include "data/Type.h" #include "faker-cxx/Helper.h" #include "faker-cxx/Number.h" @@ -11,6 +11,9 @@ namespace faker { namespace { +const std::array imageTypes = {"ai", "bmp", "eps", "gif", "heif", "indd", "jpeg", "jpg", + "pdf", "png", "psd", "raw", "svg", "tiff", "webp"}; + std::unordered_map imageCategoryToLoremFlickrStringMapping = { {Image::ImageCategory::Animals, "animals"}, {Image::ImageCategory::Business, "business"}, {Image::ImageCategory::Cats, "cats"}, {Image::ImageCategory::City, "city"}, @@ -41,7 +44,7 @@ std::string Image::dimensions() return FormatHelper::format("{}x{}", Number::integer(1, 32720), Number::integer(1, 17280)); } -std::string Image::type() +std::string_view Image::type() { return Helper::arrayElement(imageTypes); } diff --git a/src/modules/image/data/Type.h b/src/modules/image/data/Type.h deleted file mode 100644 index 02553f96a..000000000 --- a/src/modules/image/data/Type.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -namespace faker -{ -const std::vector imageTypes = {"ai", "bmp", "eps", "gif", "heif", "indd", "jpeg", "jpg", - "pdf", "png", "psd", "raw", "svg", "tiff", "webp"}; -} diff --git a/tests/modules/datatype/DatatypeTest.cpp b/tests/modules/datatype/DatatypeTest.cpp index dbec3007f..1030a982c 100644 --- a/tests/modules/datatype/DatatypeTest.cpp +++ b/tests/modules/datatype/DatatypeTest.cpp @@ -23,15 +23,15 @@ TEST_F(DatatypeTest, shouldGenerateBoolean) TEST_F(DatatypeTest, BooleanWithProbTest) { - bool result2 = Datatype::boolean(0.3); + const auto result2 = Datatype::boolean(0.3); EXPECT_TRUE(result2 || !result2); - bool result3 = Datatype::boolean(0.8); + const auto result3 = Datatype::boolean(0.8); EXPECT_TRUE(result3 || !result3); - bool result4 = Datatype::boolean(0.0); + const auto result4 = Datatype::boolean(0.0); EXPECT_FALSE(result4); - bool result5 = Datatype::boolean(1.0); + const auto result5 = Datatype::boolean(1.0); EXPECT_TRUE(result5); } diff --git a/tests/modules/finance/FinanceTest.cpp b/tests/modules/finance/FinanceTest.cpp index d96c65dd9..c960f8d21 100644 --- a/tests/modules/finance/FinanceTest.cpp +++ b/tests/modules/finance/FinanceTest.cpp @@ -394,7 +394,9 @@ TEST_F(FinanceTest, shouldGenerateEthereumAddress) TEST_F(FinanceTest, shouldGenerateExpirationDate) { const auto expirationDate = Finance::creditCardExpirationDate(); - int tenthPlaceYear = std::stoi(expirationDate.substr(3, 2)); + + const int tenthPlaceYear = std::stoi(expirationDate.substr(3, 2)); + ASSERT_TRUE(tenthPlaceYear >= 24); } diff --git a/tests/modules/git/GitTest.cpp b/tests/modules/git/GitTest.cpp index 7949463dd..3bc74a690 100644 --- a/tests/modules/git/GitTest.cpp +++ b/tests/modules/git/GitTest.cpp @@ -48,9 +48,13 @@ TEST_F(GitTest, shouldGenerateBranch) TEST_F(GitTest, branchIssueNumTest) { auto testValue = unsigned(faker::Number::integer(2, 100)); + std::vector branch = faker::StringHelper::split(Git::branch(testValue), "-"); + bool numberAtFront = false; + int number; + while (!numberAtFront) { branch = faker::StringHelper::split(Git::branch(testValue), "-"); @@ -71,6 +75,7 @@ TEST_F(GitTest, branchIssueNumTest) TEST_F(GitTest, shouldGenerateCommitDate) { const std::regex dateRegex("^" + GitTest::DATE_REGEX + "$"); + ASSERT_TRUE(std::regex_match(Git::commitDate(), dateRegex)); } @@ -79,28 +84,36 @@ TEST_F(GitTest, shouldGenerateCommitEntry) const std::regex entryRegex("^commit " + GitTest::generateShaRegex() + "\nAuthor: [A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+ .+@[0-9a-zA-Z]+\\.[0-9a-zA-Z]+\nDate: " + GitTest::DATE_REGEX + "\n\n\t" + GitTest::MESSAGE_REGEX + "$"); + ASSERT_TRUE(std::regex_match(Git::commitEntry(), entryRegex)); } TEST_F(GitTest, shouldGenerateCommitMessage) { const std::regex messageRegex("^" + GitTest::MESSAGE_REGEX + "$"); - std::string temp = Git::commitMessage(); + + const auto temp = Git::commitMessage(); + ASSERT_TRUE(std::regex_match(temp, messageRegex)); } TEST_F(GitTest, shouldGenerateCommitSha) { - unsigned length = 40; + const unsigned length = 40; + const std::regex shaRegex("^" + GitTest::generateShaRegex(length) + "$"); + ASSERT_TRUE(std::regex_match(Git::commitSha(length), shaRegex)); } TEST_F(GitTest, shouldGenerateAuthor) { - Git::Author generatedAuthor = Git::author(); + const auto generatedAuthor = Git::author(); + const std::regex nameRegex(NAME_REGEX); + const std::regex emailRegex(EMAIL_REGEX); + ASSERT_TRUE(std::regex_match(generatedAuthor.name, nameRegex)); ASSERT_TRUE(std::regex_match(generatedAuthor.email, emailRegex)); } diff --git a/tests/modules/hacker/HackerTest.cpp b/tests/modules/hacker/HackerTest.cpp index 287bd122e..136e76066 100644 --- a/tests/modules/hacker/HackerTest.cpp +++ b/tests/modules/hacker/HackerTest.cpp @@ -1,15 +1,10 @@ #include "faker-cxx/Hacker.h" #include -#include #include "gtest/gtest.h" -#include "hacker/data/Abbreviations.h" -#include "hacker/data/Adjectives.h" -#include "hacker/data/Ingverbs.h" -#include "hacker/data/Nouns.h" -#include "hacker/data/Verbs.h" +#include "hacker/HackerData.h" using namespace ::testing; using namespace faker; @@ -21,49 +16,51 @@ class HackerTest : public Test TEST_F(HackerTest, shouldGenerateAbbreviation) { - std::string generatedAbbreviation = Hacker::abbreviation(); + const auto generatedAbbreviation = Hacker::abbreviation(); - ASSERT_TRUE(std::ranges::any_of(abbreviations, [generatedAbbreviation](const std::string& abbreviation) + ASSERT_TRUE(std::ranges::any_of(abbreviations, [generatedAbbreviation](const std::string_view& abbreviation) { return abbreviation == generatedAbbreviation; })); } TEST_F(HackerTest, shouldGenerateAdjective) { - std::string generatedAdjective = Hacker::adjective(); + const auto generatedAdjective = Hacker::adjective(); - ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string& adjective) + ASSERT_TRUE(std::ranges::any_of(adjectives, [generatedAdjective](const std::string_view& adjective) { return adjective == generatedAdjective; })); } TEST_F(HackerTest, shouldGenerateNoun) { - std::string generatedNoun = Hacker::noun(); + const auto generatedNoun = Hacker::noun(); - ASSERT_TRUE(std::ranges::any_of(nouns, [generatedNoun](const std::string& noun) { return noun == generatedNoun; })); + ASSERT_TRUE( + std::ranges::any_of(nouns, [generatedNoun](const std::string_view& noun) { return noun == generatedNoun; })); } TEST_F(HackerTest, shouldGenerateVerb) { - std::string generatedVerb = Hacker::verb(); + const auto generatedVerb = Hacker::verb(); - ASSERT_TRUE(std::ranges::any_of(verbs, [generatedVerb](const std::string& verb) { return verb == generatedVerb; })); + ASSERT_TRUE( + std::ranges::any_of(verbs, [generatedVerb](const std::string_view& verb) { return verb == generatedVerb; })); } TEST_F(HackerTest, shouldGenerateIngverb) { - std::string generatedIngverb = Hacker::ingverb(); + const auto generatedIngverb = Hacker::ingverb(); - ASSERT_TRUE(std::ranges::any_of(ingverbs, [generatedIngverb](const std::string& ingverb) + ASSERT_TRUE(std::ranges::any_of(ingverbs, [generatedIngverb](const std::string_view& ingverb) { return ingverb == generatedIngverb; })); } TEST_F(HackerTest, shouldGeneratePhrase) { - std::string generatedPhrase = Hacker::phrase(); + const auto generatedPhrase = Hacker::phrase(); bool hasAdjective, hasNoun, hasVerb, hasAbbreviation; hasAdjective = hasNoun = hasVerb = hasAbbreviation = false; - for (const std::string& adj : adjectives) + for (const std::string_view& adj : adjectives) { if (generatedPhrase.find(adj) != std::string::npos) { @@ -72,7 +69,7 @@ TEST_F(HackerTest, shouldGeneratePhrase) } } - for (const std::string& noun : nouns) + for (const std::string_view& noun : nouns) { if (generatedPhrase.find(noun) != std::string::npos) { @@ -81,7 +78,7 @@ TEST_F(HackerTest, shouldGeneratePhrase) } } - for (const std::string& verb : verbs) + for (const std::string_view& verb : verbs) { if (generatedPhrase.find(verb) != std::string::npos) { @@ -90,7 +87,7 @@ TEST_F(HackerTest, shouldGeneratePhrase) } } - for (const std::string& abbreviation : abbreviations) + for (const std::string_view& abbreviation : abbreviations) { if (generatedPhrase.find(abbreviation) != std::string::npos) { diff --git a/tests/modules/helper/HelperTest.cpp b/tests/modules/helper/HelperTest.cpp index f30acc972..c043154c1 100644 --- a/tests/modules/helper/HelperTest.cpp +++ b/tests/modules/helper/HelperTest.cpp @@ -18,7 +18,7 @@ TEST_F(HelperTest, ArrayElement) { std::vector data{"hello", "world"}; - std::string result = Helper::arrayElement(data); + const auto result = Helper::arrayElement(data); ASSERT_TRUE(std::ranges::any_of(data, [&result](const std::string& element) { return result == element; })); } @@ -34,7 +34,7 @@ TEST_F(HelperTest, ArrayElementSpan) { std::vector data{"hello", "world"}; - std::string result = Helper::arrayElement(std::span(data)); + const auto result = Helper::arrayElement(std::span(data)); ASSERT_TRUE(std::ranges::any_of(data, [&result](const std::string& element) { return result == element; })); } @@ -74,7 +74,7 @@ TEST_F(HelperTest, ShuffleString) { std::string input = "Hello World!"; - std::string result = Helper::shuffleString(input); + const auto result = Helper::shuffleString(input); ASSERT_TRUE( std::ranges::all_of(input, [&result](char character) { return result.find(character) != std::string::npos; })); @@ -109,7 +109,8 @@ TEST_F(HelperTest, SetElementEmptyData) TEST_F(HelperTest, ReplaceSymbolWithNumber) { std::string input = "123#456!"; - std::string result = Helper::replaceSymbolWithNumber(input); + + const auto result = Helper::replaceSymbolWithNumber(input); ASSERT_TRUE(std::ranges::all_of(result, ::isdigit)); } @@ -117,22 +118,23 @@ TEST_F(HelperTest, ReplaceSymbolWithNumber) TEST_F(HelperTest, RegexpStyleStringParse) { std::string input = "#{5}[2-4]test[1-3]"; - std::string result = Helper::regexpStyleStringParse(input); + + const auto result = Helper::regexpStyleStringParse(input); ASSERT_EQ(result.size(), 11); } TEST_F(HelperTest, ReplaceCreditCardSymbols) { - std::string result_default = Helper::replaceCreditCardSymbols(); + const auto result_default = Helper::replaceCreditCardSymbols(); ASSERT_EQ(result_default.size(), 24); ASSERT_EQ(result_default[4], '-'); ASSERT_EQ(result_default[9], '-'); ASSERT_EQ(result_default[14], '-'); ASSERT_EQ(result_default[19], '-'); - std::string format_custom = "1234-[4-9]-##!!-L"; - std::string result_custom = Helper::replaceCreditCardSymbols(format_custom); + const auto format_custom = "1234-[4-9]-##!!-L"; + const auto result_custom = Helper::replaceCreditCardSymbols(format_custom); std::regex custom_format_regex("1234-[4-9]-\\d{2}[2-9]{2}-\\d"); ASSERT_TRUE(std::regex_match(result_custom, custom_format_regex)); diff --git a/tests/modules/image/ImageTest.cpp b/tests/modules/image/ImageTest.cpp index 0635005e8..2c9354a77 100644 --- a/tests/modules/image/ImageTest.cpp +++ b/tests/modules/image/ImageTest.cpp @@ -1,12 +1,12 @@ #include "faker-cxx/Image.h" #include -#include +#include +#include #include "gtest/gtest.h" #include "common/StringHelper.h" -#include "image/data/Type.h" using namespace ::testing; using namespace faker; @@ -60,19 +60,24 @@ TEST_F(ImageTest, shouldGenerateDimensions) { const auto dimensions = Image::dimensions(); - std::vector split_dimensions = StringHelper::split(dimensions, "x"); + const auto split_dimensions = StringHelper::split(dimensions, "x"); + + const auto width_dimension = std::stoi(split_dimensions[0]); - auto width_dimension = std::stoi(split_dimensions[0]); ASSERT_TRUE(width_dimension >= 1 && width_dimension <= 32720); - auto height_dimension = std::stoi(split_dimensions[1]); + const auto height_dimension = std::stoi(split_dimensions[1]); + ASSERT_TRUE(height_dimension >= 1 && height_dimension <= 17280); } TEST_F(ImageTest, shouldGenerateType) { + const std::array imageTypes = {"ai", "bmp", "eps", "gif", "heif", "indd", "jpeg", "jpg", + "pdf", "png", "psd", "raw", "svg", "tiff", "webp"}; + const auto generatedType = Image::type(); - ASSERT_TRUE( - std::ranges::any_of(imageTypes, [generatedType](const std::string& type) { return type == generatedType; })); + ASSERT_TRUE(std::ranges::any_of(imageTypes, + [generatedType](const std::string_view& type) { return type == generatedType; })); }