From 3ce3bbf8efc31668ed6a00859d7a62f5c144437a Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Mon, 1 Jul 2024 04:19:30 +0200 Subject: [PATCH 1/2] refactor: stringhelper module - stringhelper module migration from class to functions within common namespace - modified reference to functions and variables from stringhelper module in all dependent modules Signed-off-by: Guru Mehar Rachaputi --- src/common/StringHelper.cpp | 16 ++++----- src/common/StringHelper.h | 20 +++++------ src/modules/git/Git.cpp | 6 ++-- src/modules/hacker/Hacker.cpp | 4 +-- src/modules/helper/Helper.cpp | 4 +-- src/modules/internet/Internet.cpp | 4 +-- src/modules/lorem/Lorem.cpp | 8 ++--- src/modules/system/System.cpp | 4 +-- tests/common/StringHelperTest.cpp | 22 ++++++------ tests/modules/color/ColorTest.cpp | 22 ++++++------ tests/modules/commerce/CommerceTest.cpp | 2 +- tests/modules/company/CompanyTest.cpp | 2 +- tests/modules/date/DateTest.cpp | 2 +- tests/modules/finance/FinanceTest.cpp | 4 +-- tests/modules/git/GitTest.cpp | 6 ++-- tests/modules/image/ImageTest.cpp | 2 +- tests/modules/internet/InternetTest.cpp | 32 ++++++++--------- tests/modules/location/LocationTest.cpp | 48 ++++++++++++------------- tests/modules/lorem/LoremTest.cpp | 21 +++++------ tests/modules/person/PersonTest.cpp | 2 +- tests/modules/word/WordTest.cpp | 3 +- 21 files changed, 116 insertions(+), 118 deletions(-) diff --git a/src/common/StringHelper.cpp b/src/common/StringHelper.cpp index f8ac83474..45bc40263 100644 --- a/src/common/StringHelper.cpp +++ b/src/common/StringHelper.cpp @@ -5,9 +5,9 @@ #include #include -namespace faker +namespace faker::common::StringHelper { -std::vector StringHelper::split(const std::string& data, const std::string& separator) +std::vector split(const std::string& data, const std::string& separator) { size_t positionStart = 0; size_t positionEnd; @@ -28,7 +28,7 @@ std::vector StringHelper::split(const std::string& data, const std: return result; } -std::string StringHelper::joinString(const std::vector& data, const std::string& separator) +std::string joinString(const std::vector& data, const std::string& separator) { switch (data.size()) { @@ -51,7 +51,7 @@ std::string StringHelper::joinString(const std::vector& data, const } } -std::string StringHelper::join(const std::vector& data, const std::string& separator) +std::string join(const std::vector& data, const std::string& separator) { switch (data.size()) { @@ -74,7 +74,7 @@ std::string StringHelper::join(const std::vector& data, const } } -std::string StringHelper::repeat(const std::string& data, int repetition) +std::string repeat(const std::string& data, int repetition) { std::string result; @@ -88,7 +88,7 @@ std::string StringHelper::repeat(const std::string& data, int repetition) return result; } -std::string StringHelper::toLower(const std::string& data) +std::string toLower(const std::string& data) { std::string lowerData{data}; @@ -97,12 +97,12 @@ std::string StringHelper::toLower(const std::string& data) return lowerData; } -bool StringHelper::isPunctuation(char c) +bool isPunctuation(char c) { return (c == '.' || c == ',' || c == '!' || c == '?' || c == ';' || c == ':'); } -std::string StringHelper::removePunctuation(const std::string& word) +std::string removePunctuation(const std::string& word) { std::string result{word}; diff --git a/src/common/StringHelper.h b/src/common/StringHelper.h index 9c1b96049..b7a24cc90 100644 --- a/src/common/StringHelper.h +++ b/src/common/StringHelper.h @@ -4,17 +4,13 @@ #include #include "faker-cxx/Export.h" -namespace faker +namespace faker::common::StringHelper { -class StringHelper -{ -public: - FAKER_CXX_EXPORT static std::vector split(const std::string& data, const std::string& separator = " "); - FAKER_CXX_EXPORT static std::string joinString(const std::vector& data, const std::string& separator = " "); - FAKER_CXX_EXPORT static std::string join(const std::vector& data, const std::string& separator = " "); - FAKER_CXX_EXPORT static std::string repeat(const std::string& data, int repetition); - FAKER_CXX_EXPORT static std::string toLower(const std::string& data); - FAKER_CXX_EXPORT static bool isPunctuation(char c); - FAKER_CXX_EXPORT static std::string removePunctuation(const std::string& word); -}; + FAKER_CXX_EXPORT std::vector split(const std::string& data, const std::string& separator = " "); + FAKER_CXX_EXPORT std::string joinString(const std::vector& data, const std::string& separator = " "); + FAKER_CXX_EXPORT std::string join(const std::vector& data, const std::string& separator = " "); + FAKER_CXX_EXPORT std::string repeat(const std::string& data, int repetition); + FAKER_CXX_EXPORT std::string toLower(const std::string& data); + FAKER_CXX_EXPORT bool isPunctuation(char c); + FAKER_CXX_EXPORT std::string removePunctuation(const std::string& word); } diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 671601866..757f14692 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -36,17 +36,17 @@ std::string commitDate(unsigned years) { const auto date = faker::date::pastDate(int(years)); - const auto dateSplit = StringHelper::split(date, "-"); + const auto dateSplit = common::StringHelper::split(date, "-"); const auto& year = dateSplit[0]; const auto& month = dateSplit[1]; const auto& rest = dateSplit[2]; - const auto restSplit = StringHelper::split(rest, "T"); + const auto restSplit = common::StringHelper::split(rest, "T"); const auto& day = restSplit[0]; - const auto time = StringHelper::split(restSplit[1], "Z")[0]; + const auto time = common::StringHelper::split(restSplit[1], "Z")[0]; int timeZone = number::integer(0, 12); diff --git a/src/modules/hacker/Hacker.cpp b/src/modules/hacker/Hacker.cpp index f7d0d4c38..c526e2b10 100644 --- a/src/modules/hacker/Hacker.cpp +++ b/src/modules/hacker/Hacker.cpp @@ -36,13 +36,13 @@ std::string_view ingverb() std::string phrase() { - const auto splitRandomPhrase = StringHelper::split(static_cast(helper::arrayElement(phrases))); + const auto splitRandomPhrase = common::StringHelper::split(static_cast(helper::arrayElement(phrases))); std::string phrase; for (const auto& word : splitRandomPhrase) { - const auto normalizedWord = StringHelper::removePunctuation(word); + const auto normalizedWord = common::StringHelper::removePunctuation(word); if (normalizedWord == "{abbreviation}") { diff --git a/src/modules/helper/Helper.cpp b/src/modules/helper/Helper.cpp index 176283047..bc526d797 100644 --- a/src/modules/helper/Helper.cpp +++ b/src/modules/helper/Helper.cpp @@ -84,7 +84,7 @@ std::string regexpStyleStringParse(const std::string& input) int repetitions = number::integer(min, max); data = data.substr(0, static_cast(token.position())) + - StringHelper::repeat(token[1], repetitions) + + common::StringHelper::repeat(token[1], repetitions) + data.substr(static_cast(token.position() + token.length())); } @@ -93,7 +93,7 @@ std::string regexpStyleStringParse(const std::string& input) { int repetitions = std::stoi(token[2]); data = data.substr(0, static_cast(token.position())) + - StringHelper::repeat(token[1], repetitions) + + common::StringHelper::repeat(token[1], repetitions) + data.substr(static_cast(token.position() + token.length())); } diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index b1802afa7..092423c4b 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -275,7 +275,7 @@ std::string ipv6() ipv6Parts.push_back(string::hexadecimal(4, HexCasing::Lower, HexPrefix::None)); } - return StringHelper::joinString(ipv6Parts, ":"); + return common::StringHelper::joinString(ipv6Parts, ":"); } std::string mac(const std::string& sep) @@ -321,7 +321,7 @@ std::string domainName() std::string domainWord() { - return StringHelper::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun())); + return common::StringHelper::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun())); } std::string_view domainSuffix() diff --git a/src/modules/lorem/Lorem.cpp b/src/modules/lorem/Lorem.cpp index 2ddf02a24..0296b1451 100644 --- a/src/modules/lorem/Lorem.cpp +++ b/src/modules/lorem/Lorem.cpp @@ -28,7 +28,7 @@ std::string words(unsigned numberOfWords) words.push_back(word()); } - return StringHelper::join(words, " "); + return common::StringHelper::join(words, " "); } std::string sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords) @@ -52,7 +52,7 @@ std::string sentences(unsigned minNumberOfSentences, unsigned maxNumberOfSentenc sentences.push_back(sentence()); } - return StringHelper::joinString(sentences, " "); + return common::StringHelper::joinString(sentences, " "); } std::string slug(unsigned int numberOfWords) @@ -65,7 +65,7 @@ std::string slug(unsigned int numberOfWords) words.push_back(std::string(word())); } - return StringHelper::joinString(words, "-"); + return common::StringHelper::joinString(words, "-"); } std::string paragraph(unsigned int minNumberOfSentences, unsigned int maxNumberOfSentences) @@ -85,7 +85,7 @@ std::string paragraphs(unsigned int minNumberOfParagraphs, unsigned int maxNumbe paragraphs.push_back(paragraph()); } - return StringHelper::joinString(paragraphs, "\n"); + return common::StringHelper::joinString(paragraphs, "\n"); } } diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index e4724edf2..f2b182374 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -60,7 +60,7 @@ std::string fileName(const FileOptions& options) randomExtensions.push_back(fileExtension()); } - extensionsStr = "." + StringHelper::joinString(randomExtensions, "."); + extensionsStr = "." + common::StringHelper::joinString(randomExtensions, "."); } else { @@ -72,7 +72,7 @@ std::string fileName(const FileOptions& options) randomExtensions.push_back(fileExtension()); } - extensionsStr = "." + StringHelper::joinString(randomExtensions, "."); + extensionsStr = "." + common::StringHelper::joinString(randomExtensions, "."); } } diff --git a/tests/common/StringHelperTest.cpp b/tests/common/StringHelperTest.cpp index d613ff3c3..c6d03329a 100644 --- a/tests/common/StringHelperTest.cpp +++ b/tests/common/StringHelperTest.cpp @@ -14,7 +14,7 @@ class StringHelperTest : public Test TEST_F(StringHelperTest, splitStringBySpace) { - const auto result = StringHelper::split("faker cxx open source"); + const auto result = common::StringHelper::split("faker cxx open source"); ASSERT_EQ(result.size(), 4); ASSERT_EQ(result[0], "faker"); @@ -25,7 +25,7 @@ TEST_F(StringHelperTest, splitStringBySpace) TEST_F(StringHelperTest, splitStringByNewLine) { - const auto result = StringHelper::split("faker\ncxx\nopen\nsource", "\n"); + const auto result = common::StringHelper::split("faker\ncxx\nopen\nsource", "\n"); ASSERT_EQ(result.size(), 4); ASSERT_EQ(result[0], "faker"); @@ -38,7 +38,7 @@ TEST_F(StringHelperTest, joinStringViewsIntoVectorBySpace) { const std::vector input{"Join", "faker", "development!"}; - const auto result = StringHelper::join(input); + const auto result = common::StringHelper::join(input); ASSERT_EQ(result, "Join faker development!"); } @@ -47,7 +47,7 @@ TEST_F(StringHelperTest, joinStringViewsIntoVectorByNewLine) { const std::vector input{"Join", "faker", "development!"}; - const auto result = StringHelper::join(input, "\n"); + const auto result = common::StringHelper::join(input, "\n"); ASSERT_EQ(result, "Join\nfaker\ndevelopment!"); } @@ -56,7 +56,7 @@ TEST_F(StringHelperTest, joinStringsIntoVectorBySpace) { const std::vector input{"Join", "faker", "development!"}; - const auto result = StringHelper::joinString(input); + const auto result = common::StringHelper::joinString(input); ASSERT_EQ(result, "Join faker development!"); } @@ -65,7 +65,7 @@ TEST_F(StringHelperTest, joinStringsIntoVectorByNewLine) { const std::vector input{"Join", "faker", "development!"}; - const auto result = StringHelper::joinString(input, "\n"); + const auto result = common::StringHelper::joinString(input, "\n"); ASSERT_EQ(result, "Join\nfaker\ndevelopment!"); } @@ -75,7 +75,7 @@ TEST_F(StringHelperTest, repeatString) const std::string data = "hello "; const int repetition = 3; - const std::string result = StringHelper::repeat(data, repetition); + const std::string result = common::StringHelper::repeat(data, repetition); ASSERT_EQ(result, "hello hello hello "); } @@ -84,7 +84,7 @@ TEST_F(StringHelperTest, toLower) { const std::string data = "HeLlo!"; - const std::string result = StringHelper::toLower(data); + const std::string result = common::StringHelper::toLower(data); ASSERT_EQ(result, "hello!"); } @@ -94,19 +94,19 @@ TEST_F(StringHelperTest, IsPunctuation) std::string punctuation = ".,;:!?"; for (char c : punctuation) { - EXPECT_TRUE(StringHelper::isPunctuation(c)); + EXPECT_TRUE(common::StringHelper::isPunctuation(c)); } std::string notPunctuation = "abc123"; for (char c : notPunctuation) { - EXPECT_FALSE(StringHelper::isPunctuation(c)); + EXPECT_FALSE(common::StringHelper::isPunctuation(c)); } } TEST_F(StringHelperTest, RemovePunctuation) { std::string input = "Hello, World!"; - std::string result = StringHelper::removePunctuation(input); + std::string result = common::StringHelper::removePunctuation(input); EXPECT_EQ(result, "Hello World"); } diff --git a/tests/modules/color/ColorTest.cpp b/tests/modules/color/ColorTest.cpp index ded954999..f30ea1a46 100644 --- a/tests/modules/color/ColorTest.cpp +++ b/tests/modules/color/ColorTest.cpp @@ -33,7 +33,7 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithoutAlpha) { const auto generatedRgbColor = rgb(); - const auto rgbNumbers = StringHelper::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " "); + const auto rgbNumbers = common::StringHelper::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " "); int red, green, blue; std::from_chars(rgbNumbers[0].data(), rgbNumbers[0].data() + rgbNumbers[0].size(), red); @@ -51,7 +51,7 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithAlpha) { const auto generatedRgbaColor = rgb(true); - const auto rgbaNumbers = StringHelper::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " "); + const auto rgbaNumbers = common::StringHelper::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " "); int red, green, blue, alpha; std::from_chars(rgbaNumbers[0].data(), rgbaNumbers[0].data() + rgbaNumbers[0].size(), red); @@ -98,7 +98,7 @@ TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) TEST_F(ColorTest, shouldGenerateHslWithoutAlpha) { const auto generatedHslColor = hsl(); - const auto hslValues = StringHelper::split(generatedHslColor.substr(4, generatedHslColor.size() - 1), " "); + const auto hslValues = common::StringHelper::split(generatedHslColor.substr(4, generatedHslColor.size() - 1), " "); int hue, staturation, lightness; @@ -116,7 +116,7 @@ TEST_F(ColorTest, shouldGenerateHslWithoutAlpha) TEST_F(ColorTest, shouldGenerateHslWithAlpha) { const auto generatedHslaColor = hsl(true); - const auto hslValues = StringHelper::split(generatedHslaColor.substr(5, generatedHslaColor.size() - 1), " "); + const auto hslValues = common::StringHelper::split(generatedHslaColor.substr(5, generatedHslaColor.size() - 1), " "); int hue, saturation, lightness; @@ -138,7 +138,7 @@ TEST_F(ColorTest, shouldGenerateHslWithAlpha) TEST_F(ColorTest, shouldGenerateLchWithoutAlpha) { const auto generatedLchColor = lch(); - const auto lchValues = StringHelper::split(generatedLchColor.substr(4, generatedLchColor.size() - 1), " "); + const auto lchValues = common::StringHelper::split(generatedLchColor.substr(4, generatedLchColor.size() - 1), " "); int luminance, chroma, hue; @@ -156,7 +156,7 @@ TEST_F(ColorTest, shouldGenerateLchWithoutAlpha) TEST_F(ColorTest, shouldGenerateLchWithAlpha) { const auto generatedLchaColor = lch(true); - const auto lchValues = StringHelper::split(generatedLchaColor.substr(5, generatedLchaColor.size() - 1), " "); + const auto lchValues = common::StringHelper::split(generatedLchaColor.substr(5, generatedLchaColor.size() - 1), " "); int luminance, chroma, hue; @@ -178,7 +178,7 @@ TEST_F(ColorTest, shouldGenerateLchWithAlpha) TEST_F(ColorTest, shouldGenerateCmykColor) { const auto generatedCmykColor = cmyk(); - const auto cmykValues = StringHelper::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " "); + const auto cmykValues = common::StringHelper::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " "); auto offset = cmykValues[0].size(); const auto cyan = std::stod(cmykValues[0], &offset); @@ -200,7 +200,7 @@ TEST_F(ColorTest, shouldGenerateCmykColor) TEST_F(ColorTest, shouldGenerateLabColor) { const auto generatedLabColor = lab(); - const auto labValues = StringHelper::split(generatedLabColor.substr(4, generatedLabColor.size() - 1), " "); + const auto labValues = common::StringHelper::split(generatedLabColor.substr(4, generatedLabColor.size() - 1), " "); auto offset = labValues[0].size(); const auto lightness = std::stod(labValues[0], &offset); @@ -219,7 +219,7 @@ TEST_F(ColorTest, shouldGenerateLabColor) TEST_F(ColorTest, shouldGenerateHsb) { const auto generatedHsbColor = hsb(); - const auto hsbValues = StringHelper::split(generatedHsbColor.substr(4, generatedHsbColor.size() - 1), " "); + const auto hsbValues = common::StringHelper::split(generatedHsbColor.substr(4, generatedHsbColor.size() - 1), " "); int hue, saturation, brightness; @@ -237,7 +237,7 @@ TEST_F(ColorTest, shouldGenerateHsb) TEST_F(ColorTest, shouldGenerateHsv) { const auto generatedHsvColor = hsv(); - const auto hsvValues = StringHelper::split(generatedHsvColor.substr(4, generatedHsvColor.size() - 1), " "); + const auto hsvValues = common::StringHelper::split(generatedHsvColor.substr(4, generatedHsvColor.size() - 1), " "); int hue, saturation, brightness; @@ -255,7 +255,7 @@ TEST_F(ColorTest, shouldGenerateHsv) TEST_F(ColorTest, shouldGenerateYuv) { const auto generatedYuvColor = yuv(); - const auto yuvValues = StringHelper::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " "); + const auto yuvValues = common::StringHelper::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " "); int luminance, chrominanceBlueColor, chrominanceRedColor; diff --git a/tests/modules/commerce/CommerceTest.cpp b/tests/modules/commerce/CommerceTest.cpp index d7f80bcf2..5bf9673f7 100644 --- a/tests/modules/commerce/CommerceTest.cpp +++ b/tests/modules/commerce/CommerceTest.cpp @@ -60,7 +60,7 @@ TEST_F(CommerceTest, shouldGenerateProductFullName) { const auto generatedProductFullName = productFullName(); - const auto productFullNameElements = StringHelper::split(generatedProductFullName, " "); + const auto productFullNameElements = common::StringHelper::split(generatedProductFullName, " "); const auto& generatedProductAdjective = productFullNameElements[0]; const auto& generatedProductMaterial = productFullNameElements[1]; diff --git a/tests/modules/company/CompanyTest.cpp b/tests/modules/company/CompanyTest.cpp index 29c54282e..ee1798695 100644 --- a/tests/modules/company/CompanyTest.cpp +++ b/tests/modules/company/CompanyTest.cpp @@ -23,7 +23,7 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) { const auto companyName = name(); - const auto companyNameElements = StringHelper::split(companyName, " "); + const auto companyNameElements = common::StringHelper::split(companyName, " "); std::vector expectedFirstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); diff --git a/tests/modules/date/DateTest.cpp b/tests/modules/date/DateTest.cpp index 0da87c3fe..1e975fd75 100644 --- a/tests/modules/date/DateTest.cpp +++ b/tests/modules/date/DateTest.cpp @@ -335,7 +335,7 @@ TEST_F(DateTest, shouldGenerateRandomTimezone) TEST_F(DateTest, shouldGenerateRandomTime) { const auto generatedTime = time(); - const auto generatedTimeParts = StringHelper::split(generatedTime, ":"); + const auto generatedTimeParts = common::StringHelper::split(generatedTime, ":"); ASSERT_EQ(generatedTimeParts.size(), 2); diff --git a/tests/modules/finance/FinanceTest.cpp b/tests/modules/finance/FinanceTest.cpp index c48f684da..96817a2bc 100644 --- a/tests/modules/finance/FinanceTest.cpp +++ b/tests/modules/finance/FinanceTest.cpp @@ -176,7 +176,7 @@ TEST_F(FinanceTest, shouldGenerateAmount) auto offset = generatedAmount.size(); const auto amountAsFloat = std::stof(generatedAmount, &offset); - const auto generatedAmountParts = StringHelper::split(generatedAmount, "."); + const auto generatedAmountParts = common::StringHelper::split(generatedAmount, "."); ASSERT_EQ(generatedAmountParts.size(), 2); ASSERT_EQ(generatedAmountParts[1].size(), 2); @@ -217,7 +217,7 @@ TEST_F(FinanceTest, shouldGenerateAmountWithSymbol) const auto amountAsFloat = std::stof(generatedAmount.substr(currencySymbol.size())); - const auto generatedAmountParts = StringHelper::split(generatedAmount, "."); + const auto generatedAmountParts = common::StringHelper::split(generatedAmount, "."); ASSERT_TRUE(generatedAmount.starts_with(currencySymbol)); ASSERT_EQ(generatedAmountParts.size(), 2); diff --git a/tests/modules/git/GitTest.cpp b/tests/modules/git/GitTest.cpp index a96814093..add70b219 100644 --- a/tests/modules/git/GitTest.cpp +++ b/tests/modules/git/GitTest.cpp @@ -41,7 +41,7 @@ std::string GitTest::generateShaRegex() TEST_F(GitTest, shouldGenerateBranch) { const auto generatedBranch = branch(); - const auto branchSplit = StringHelper::split(generatedBranch, "-").size(); + const auto branchSplit = common::StringHelper::split(generatedBranch, "-").size(); ASSERT_TRUE(2 <= branchSplit && branchSplit <= 7); } @@ -50,7 +50,7 @@ TEST_F(GitTest, branchIssueNumTest) { auto testValue = unsigned(number::integer(2, 100)); - std::vector branchElements = StringHelper::split(branch(testValue), "-"); + std::vector branchElements = common::StringHelper::split(branch(testValue), "-"); bool numberAtFront = false; @@ -58,7 +58,7 @@ TEST_F(GitTest, branchIssueNumTest) while (!numberAtFront) { - branchElements = StringHelper::split(branch(testValue), "-"); + branchElements = common::StringHelper::split(branch(testValue), "-"); try { diff --git a/tests/modules/image/ImageTest.cpp b/tests/modules/image/ImageTest.cpp index 0e7101c8f..68a6f4c1f 100644 --- a/tests/modules/image/ImageTest.cpp +++ b/tests/modules/image/ImageTest.cpp @@ -62,7 +62,7 @@ TEST_F(ImageTest, shouldGenerateDimensions) { const auto generatedDimensions = dimensions(); - const auto split_dimensions = StringHelper::split(generatedDimensions, "x"); + const auto split_dimensions = common::StringHelper::split(generatedDimensions, "x"); const auto width_dimension = std::stoi(split_dimensions[0]); diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index f137369a2..e3efb73b0 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -45,7 +45,7 @@ constexpr unsigned int classCSecondSection = 168u; std::array deconstructIpv4String(const std::string& ipv4) { - const auto ipParts = StringHelper::split(ipv4, "."); + const auto ipParts = common::StringHelper::split(ipv4, "."); std::array result{static_cast(stoi(ipParts[0])), static_cast(stoi(ipParts[1])), static_cast(stoi(ipParts[2])), @@ -172,7 +172,7 @@ TEST_F(InternetTest, shouldGenerateEmail) const auto generatedEmail = email(); - const auto emailParts = StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::StringHelper::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -193,7 +193,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) const auto generatedEmail = email(firstName); - const auto emailParts = StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::StringHelper::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -217,7 +217,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithLastName) const auto generatedEmail = email(std::nullopt, lastName); - const auto emailParts = StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::StringHelper::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -239,7 +239,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithFullName) const auto generatedEmail = email(firstName, lastName); - const auto emailParts = StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::StringHelper::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -262,7 +262,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) const auto generatedEmail = email(std::nullopt, std::nullopt, emailHost); - const auto emailParts = StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::StringHelper::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -284,7 +284,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmail) const auto email = exampleEmail(); - const auto emailParts = StringHelper::split(email, "@"); + const auto emailParts = common::StringHelper::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -305,7 +305,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) const auto email = exampleEmail(firstName); - const auto emailParts = StringHelper::split(email, "@"); + const auto emailParts = common::StringHelper::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -329,7 +329,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) const auto email = exampleEmail(std::nullopt, lastName); - const auto emailParts = StringHelper::split(email, "@"); + const auto emailParts = common::StringHelper::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -351,7 +351,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFullName) const auto email = exampleEmail(firstName, lastName); - const auto emailParts = StringHelper::split(email, "@"); + const auto emailParts = common::StringHelper::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -629,7 +629,7 @@ TEST_F(InternetTest, shouldGenerateIpv6) { const auto generatedIpv6 = ipv6(); - const auto generatedIpv6Parts = StringHelper::split(generatedIpv6, ":"); + const auto generatedIpv6Parts = common::StringHelper::split(generatedIpv6, ":"); ASSERT_EQ(generatedIpv6Parts.size(), 8); @@ -680,7 +680,7 @@ TEST_F(InternetTest, shouldGenerateDomainName) { const auto generatedDomainName = domainName(); - const auto generatedDomainNameParts = StringHelper::split(generatedDomainName, "."); + const auto generatedDomainNameParts = common::StringHelper::split(generatedDomainName, "."); const auto& generatedDomainWord = generatedDomainNameParts[0]; const auto& generatedDomainSuffix = generatedDomainNameParts[1]; @@ -694,12 +694,12 @@ TEST_F(InternetTest, shouldGenerateHttpsUrl) { const auto generatedUrl = url(); - const auto generatedUrlParts = StringHelper::split(generatedUrl, "://"); + const auto generatedUrlParts = common::StringHelper::split(generatedUrl, "://"); const auto& generatedProtocol = generatedUrlParts[0]; const auto& generatedDomainName = generatedUrlParts[1]; - const auto generatedDomainNameParts = StringHelper::split(generatedDomainName, "."); + const auto generatedDomainNameParts = common::StringHelper::split(generatedDomainName, "."); const auto& generatedDomainWord = generatedDomainNameParts[0]; const auto& generatedDomainSuffix = generatedDomainNameParts[1]; @@ -714,12 +714,12 @@ TEST_F(InternetTest, shouldGenerateHttpUrl) { const auto generatedUrl = url(WebProtocol::Http); - const auto generatedUrlParts = StringHelper::split(generatedUrl, "://"); + const auto generatedUrlParts = common::StringHelper::split(generatedUrl, "://"); const auto& generatedProtocol = generatedUrlParts[0]; const auto& generatedDomainName = generatedUrlParts[1]; - const auto generatedDomainNameParts = StringHelper::split(generatedDomainName, "."); + const auto generatedDomainNameParts = common::StringHelper::split(generatedDomainName, "."); const auto& generatedDomainWord = generatedDomainNameParts[0]; const auto& generatedDomainSuffix = generatedDomainNameParts[1]; diff --git a/tests/modules/location/LocationTest.cpp b/tests/modules/location/LocationTest.cpp index 0ef70a8c0..092f4ba60 100644 --- a/tests/modules/location/LocationTest.cpp +++ b/tests/modules/location/LocationTest.cpp @@ -147,7 +147,7 @@ TEST_P(LocationTest, shouldGenerateCity) if (country == location::AddressCountry::Brazil) { - const auto generatedCityElements = StringHelper::split(generatedCity, " "); + const auto generatedCityElements = common::StringHelper::split(generatedCity, " "); const auto& generatedCityPrefix = generatedCityElements[0]; @@ -269,7 +269,7 @@ TEST_F(LocationTest, shouldGenerateUsaStreet) { const auto generatedStreet = street(); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedFirstOrLastName = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; @@ -292,7 +292,7 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) { const auto generatedStreetAddress = streetAddress(); - const auto generatedStreetAddressElements = StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedFirstOrLastName = generatedStreetAddressElements[1]; @@ -318,11 +318,11 @@ TEST_F(LocationTest, shouldGeneratePolandStreet) { const auto generatedStreet = street(AddressCountry::Poland); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetName = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_TRUE(std::ranges::any_of(polandStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); @@ -344,11 +344,11 @@ TEST_F(LocationTest, shouldGenerateRussiaStreet) { const auto generatedStreet = street(AddressCountry::Russia); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); @@ -392,11 +392,11 @@ TEST_F(LocationTest, shouldGenerateFranceStreet) { const auto generatedStreet = street(AddressCountry::France); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_GE(generatedStreetElements.size(), 2); ASSERT_TRUE(std::ranges::any_of(franceStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) @@ -409,12 +409,12 @@ TEST_F(LocationTest, shouldGenerateFranceStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::France); - const auto generatedStreetAddressElements = StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetPrefix = generatedStreetAddressElements[1]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); + common::StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); ASSERT_GE(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 4); @@ -448,7 +448,7 @@ TEST_F(LocationTest, shouldGenerateLatitude) auto offset = generatedLatitude.size(); const auto latitudeAsFloat = std::stof(generatedLatitude, &offset); - const auto generatedLatitudeParts = StringHelper::split(generatedLatitude, "."); + const auto generatedLatitudeParts = common::StringHelper::split(generatedLatitude, "."); ASSERT_EQ(generatedLatitudeParts.size(), 2); ASSERT_EQ(generatedLatitudeParts[1].size(), 4); @@ -463,7 +463,7 @@ TEST_F(LocationTest, shouldGenerateLatitudeWithSpecifiedPrecision) auto offset = generatedLatitude.size(); const auto latitudeAsFloat = std::stof(generatedLatitude, &offset); - const auto generatedLatitudeParts = StringHelper::split(generatedLatitude, "."); + const auto generatedLatitudeParts = common::StringHelper::split(generatedLatitude, "."); ASSERT_EQ(generatedLatitudeParts.size(), 2); ASSERT_EQ(generatedLatitudeParts[1].size(), 3); @@ -478,7 +478,7 @@ TEST_F(LocationTest, shouldGenerateLongitude) auto offset = generatedLongitude.size(); const auto longitudeAsFloat = std::stof(generatedLongitude, &offset); - const auto generatedLongitudeParts = StringHelper::split(generatedLongitude, "."); + const auto generatedLongitudeParts = common::StringHelper::split(generatedLongitude, "."); ASSERT_EQ(generatedLongitudeParts.size(), 2); ASSERT_EQ(generatedLongitudeParts[1].size(), 4); @@ -493,7 +493,7 @@ TEST_F(LocationTest, shouldGenerateLongitudeWithSpecifiedPrecision) auto offset = generatedLongitude.size(); const auto longitudeAsFloat = std::stof(generatedLongitude, &offset); - const auto generatedLongitudeParts = StringHelper::split(generatedLongitude, "."); + const auto generatedLongitudeParts = common::StringHelper::split(generatedLongitude, "."); ASSERT_EQ(generatedLongitudeParts.size(), 2); ASSERT_EQ(generatedLongitudeParts[1].size(), 6); @@ -521,11 +521,11 @@ TEST_F(LocationTest, shouldGenerateUkraineStreet) { const auto generatedStreet = street(AddressCountry::Ukraine); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_TRUE(std::ranges::any_of(ukraineStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) @@ -578,11 +578,11 @@ TEST_F(LocationTest, shouldGenerateItalyStreet) { const auto generatedStreet = street(AddressCountry::Italy); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); @@ -668,11 +668,11 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::Australia); - const auto generatedStreetAddressElements = StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); + common::StringHelper::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); @@ -695,11 +695,11 @@ TEST_F(LocationTest, shouldGenerateIndiaStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::India); - const auto generatedStreetAddressElements = StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetSuffix = - StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); + common::StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); ASSERT_GE(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(!generatedBuildingNumber.empty()); @@ -762,7 +762,7 @@ TEST_F(LocationTest, shouldGenerateFinlandStreet) { const auto generatedStreet = street(AddressCountry::Finland); - const auto generatedStreetElements = StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; diff --git a/tests/modules/lorem/LoremTest.cpp b/tests/modules/lorem/LoremTest.cpp index ba06b15c6..47dcbefda 100644 --- a/tests/modules/lorem/LoremTest.cpp +++ b/tests/modules/lorem/LoremTest.cpp @@ -10,6 +10,7 @@ #include "lorem/LoremData.h" using namespace ::testing; +using namespace::faker; using namespace faker::lorem; class LoremTest : public Test @@ -31,7 +32,7 @@ TEST_F(LoremTest, shouldGenerateWords) const auto generatedWords = words(numberOfWords); - const auto separatedWords = faker::StringHelper::split(generatedWords, " "); + const auto separatedWords = common::StringHelper::split(generatedWords, " "); ASSERT_EQ(separatedWords.size(), numberOfWords); ASSERT_TRUE(std::ranges::all_of( @@ -50,7 +51,7 @@ TEST_F(LoremTest, shouldGenerateSentence) const auto sentenceWithoutEndingDot = generatedSentence.substr(0, generatedSentence.size() - 1); - const auto sentenceWords = faker::StringHelper::split(sentenceWithoutEndingDot, " "); + const auto sentenceWords = common::StringHelper::split(sentenceWithoutEndingDot, " "); ASSERT_TRUE(std::isupper(generatedSentence[0])); ASSERT_TRUE(generatedSentence.ends_with(".")); @@ -69,7 +70,7 @@ TEST_F(LoremTest, shouldGenerateSentences) { const auto generatedSentences = sentences(); - const auto separatedSentences = faker::StringHelper::split(generatedSentences, ". "); + const auto separatedSentences = common::StringHelper::split(generatedSentences, ". "); for (auto sentence : separatedSentences) { @@ -77,7 +78,7 @@ TEST_F(LoremTest, shouldGenerateSentences) ASSERT_TRUE(std::isupper(sentence[0])); - const auto sentenceWords = faker::StringHelper::split(sentence, " "); + const auto sentenceWords = common::StringHelper::split(sentence, " "); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); @@ -96,7 +97,7 @@ TEST_F(LoremTest, shouldGenerateSlug) { const auto generatedSlug = slug(3); - const auto separatedWords = faker::StringHelper::split(generatedSlug, "-"); + const auto separatedWords = common::StringHelper::split(generatedSlug, "-"); ASSERT_EQ(separatedWords.size(), 3); ASSERT_TRUE(std::ranges::all_of( @@ -113,7 +114,7 @@ TEST_F(LoremTest, shouldGenerateParagraph) { const auto generatedParagraph = paragraph(); - const auto separatedSentences = faker::StringHelper::split(generatedParagraph, ". "); + const auto separatedSentences = common::StringHelper::split(generatedParagraph, ". "); for (auto sentence : separatedSentences) { @@ -121,7 +122,7 @@ TEST_F(LoremTest, shouldGenerateParagraph) ASSERT_TRUE(std::isupper(sentence[0])); - const auto sentenceWords = faker::StringHelper::split(sentence, " "); + const auto sentenceWords = common::StringHelper::split(sentence, " "); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); @@ -140,11 +141,11 @@ TEST_F(LoremTest, shouldGenerateParagraphs) { const auto generatedParagraphs = paragraphs(); - const auto separatedParagraphs = faker::StringHelper::split(generatedParagraphs, "\n"); + const auto separatedParagraphs = common::StringHelper::split(generatedParagraphs, "\n"); for (const auto& generatedParagraph : separatedParagraphs) { - const auto separatedSentences = faker::StringHelper::split(generatedParagraph, ". "); + const auto separatedSentences = common::StringHelper::split(generatedParagraph, ". "); for (auto sentence : separatedSentences) { @@ -152,7 +153,7 @@ TEST_F(LoremTest, shouldGenerateParagraphs) ASSERT_TRUE(std::isupper(sentence[0])); - const auto sentenceWords = faker::StringHelper::split(sentence, " "); + const auto sentenceWords = common::StringHelper::split(sentence, " "); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); diff --git a/tests/modules/person/PersonTest.cpp b/tests/modules/person/PersonTest.cpp index ac2968ed4..8ee8ca11d 100644 --- a/tests/modules/person/PersonTest.cpp +++ b/tests/modules/person/PersonTest.cpp @@ -477,7 +477,7 @@ TEST_F(PersonTest, shouldGenerateJobTitle) { const auto generatedJobTitle = jobTitle(); - const auto jobTitleElements = StringHelper::split(generatedJobTitle, " "); + const auto jobTitleElements = common::StringHelper::split(generatedJobTitle, " "); const auto& generatedJobDescriptor = jobTitleElements[0]; const auto& generatedJobArea = jobTitleElements[1]; diff --git a/tests/modules/word/WordTest.cpp b/tests/modules/word/WordTest.cpp index 57f6d595a..72dce5962 100644 --- a/tests/modules/word/WordTest.cpp +++ b/tests/modules/word/WordTest.cpp @@ -10,6 +10,7 @@ #include "word/WordData.h" using namespace faker::word; +using namespace faker; using namespace ::testing; class WordTest : public Test @@ -213,7 +214,7 @@ TEST_F(WordTest, shouldGenerateWords) { const auto generatedWords = words(5); - const auto separatedWords = faker::StringHelper::split(generatedWords, " "); + const auto separatedWords = common::StringHelper::split(generatedWords, " "); ASSERT_TRUE(std::ranges::all_of(separatedWords, [](const std::string& separatedWord) { return std::ranges::find(_allWords, separatedWord) != _allWords.end(); })); From 15096f65e7afefafc9e0b1fa2c914115f0ddb694 Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Mon, 1 Jul 2024 13:17:35 +0200 Subject: [PATCH 2/2] refactor: Stringhelper module - stringhelper module namespace changed from "common::stringhelper" to "common" Signed-off-by: Guru Mehar Rachaputi --- src/common/StringHelper.cpp | 2 +- src/common/StringHelper.h | 2 +- src/modules/git/Git.cpp | 6 ++-- src/modules/hacker/Hacker.cpp | 4 +-- src/modules/helper/Helper.cpp | 4 +-- src/modules/internet/Internet.cpp | 4 +-- src/modules/lorem/Lorem.cpp | 8 ++--- src/modules/system/System.cpp | 4 +-- tests/common/StringHelperTest.cpp | 22 ++++++------ tests/modules/color/ColorTest.cpp | 22 ++++++------ tests/modules/commerce/CommerceTest.cpp | 2 +- tests/modules/company/CompanyTest.cpp | 2 +- tests/modules/date/DateTest.cpp | 2 +- tests/modules/finance/FinanceTest.cpp | 4 +-- tests/modules/git/GitTest.cpp | 6 ++-- tests/modules/image/ImageTest.cpp | 2 +- tests/modules/internet/InternetTest.cpp | 32 ++++++++--------- tests/modules/location/LocationTest.cpp | 48 ++++++++++++------------- tests/modules/lorem/LoremTest.cpp | 20 +++++------ tests/modules/person/PersonTest.cpp | 2 +- tests/modules/word/WordTest.cpp | 2 +- 21 files changed, 100 insertions(+), 100 deletions(-) diff --git a/src/common/StringHelper.cpp b/src/common/StringHelper.cpp index 45bc40263..c4e52dfb2 100644 --- a/src/common/StringHelper.cpp +++ b/src/common/StringHelper.cpp @@ -5,7 +5,7 @@ #include #include -namespace faker::common::StringHelper +namespace faker::common { std::vector split(const std::string& data, const std::string& separator) { diff --git a/src/common/StringHelper.h b/src/common/StringHelper.h index b7a24cc90..22c21ada7 100644 --- a/src/common/StringHelper.h +++ b/src/common/StringHelper.h @@ -4,7 +4,7 @@ #include #include "faker-cxx/Export.h" -namespace faker::common::StringHelper +namespace faker::common { FAKER_CXX_EXPORT std::vector split(const std::string& data, const std::string& separator = " "); FAKER_CXX_EXPORT std::string joinString(const std::vector& data, const std::string& separator = " "); diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 757f14692..fb9589a4c 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -36,17 +36,17 @@ std::string commitDate(unsigned years) { const auto date = faker::date::pastDate(int(years)); - const auto dateSplit = common::StringHelper::split(date, "-"); + const auto dateSplit = common::split(date, "-"); const auto& year = dateSplit[0]; const auto& month = dateSplit[1]; const auto& rest = dateSplit[2]; - const auto restSplit = common::StringHelper::split(rest, "T"); + const auto restSplit = common::split(rest, "T"); const auto& day = restSplit[0]; - const auto time = common::StringHelper::split(restSplit[1], "Z")[0]; + const auto time = common::split(restSplit[1], "Z")[0]; int timeZone = number::integer(0, 12); diff --git a/src/modules/hacker/Hacker.cpp b/src/modules/hacker/Hacker.cpp index c526e2b10..14811547b 100644 --- a/src/modules/hacker/Hacker.cpp +++ b/src/modules/hacker/Hacker.cpp @@ -36,13 +36,13 @@ std::string_view ingverb() std::string phrase() { - const auto splitRandomPhrase = common::StringHelper::split(static_cast(helper::arrayElement(phrases))); + const auto splitRandomPhrase = common::split(static_cast(helper::arrayElement(phrases))); std::string phrase; for (const auto& word : splitRandomPhrase) { - const auto normalizedWord = common::StringHelper::removePunctuation(word); + const auto normalizedWord = common::removePunctuation(word); if (normalizedWord == "{abbreviation}") { diff --git a/src/modules/helper/Helper.cpp b/src/modules/helper/Helper.cpp index bc526d797..cabe73d01 100644 --- a/src/modules/helper/Helper.cpp +++ b/src/modules/helper/Helper.cpp @@ -84,7 +84,7 @@ std::string regexpStyleStringParse(const std::string& input) int repetitions = number::integer(min, max); data = data.substr(0, static_cast(token.position())) + - common::StringHelper::repeat(token[1], repetitions) + + common::repeat(token[1], repetitions) + data.substr(static_cast(token.position() + token.length())); } @@ -93,7 +93,7 @@ std::string regexpStyleStringParse(const std::string& input) { int repetitions = std::stoi(token[2]); data = data.substr(0, static_cast(token.position())) + - common::StringHelper::repeat(token[1], repetitions) + + common::repeat(token[1], repetitions) + data.substr(static_cast(token.position() + token.length())); } diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 092423c4b..4de8246d8 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -275,7 +275,7 @@ std::string ipv6() ipv6Parts.push_back(string::hexadecimal(4, HexCasing::Lower, HexPrefix::None)); } - return common::StringHelper::joinString(ipv6Parts, ":"); + return common::joinString(ipv6Parts, ":"); } std::string mac(const std::string& sep) @@ -321,7 +321,7 @@ std::string domainName() std::string domainWord() { - return common::StringHelper::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun())); + return common::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun())); } std::string_view domainSuffix() diff --git a/src/modules/lorem/Lorem.cpp b/src/modules/lorem/Lorem.cpp index 0296b1451..395abed12 100644 --- a/src/modules/lorem/Lorem.cpp +++ b/src/modules/lorem/Lorem.cpp @@ -28,7 +28,7 @@ std::string words(unsigned numberOfWords) words.push_back(word()); } - return common::StringHelper::join(words, " "); + return common::join(words, " "); } std::string sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords) @@ -52,7 +52,7 @@ std::string sentences(unsigned minNumberOfSentences, unsigned maxNumberOfSentenc sentences.push_back(sentence()); } - return common::StringHelper::joinString(sentences, " "); + return common::joinString(sentences, " "); } std::string slug(unsigned int numberOfWords) @@ -65,7 +65,7 @@ std::string slug(unsigned int numberOfWords) words.push_back(std::string(word())); } - return common::StringHelper::joinString(words, "-"); + return common::joinString(words, "-"); } std::string paragraph(unsigned int minNumberOfSentences, unsigned int maxNumberOfSentences) @@ -85,7 +85,7 @@ std::string paragraphs(unsigned int minNumberOfParagraphs, unsigned int maxNumbe paragraphs.push_back(paragraph()); } - return common::StringHelper::joinString(paragraphs, "\n"); + return common::joinString(paragraphs, "\n"); } } diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index f2b182374..9d45f6f24 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -60,7 +60,7 @@ std::string fileName(const FileOptions& options) randomExtensions.push_back(fileExtension()); } - extensionsStr = "." + common::StringHelper::joinString(randomExtensions, "."); + extensionsStr = "." + common::joinString(randomExtensions, "."); } else { @@ -72,7 +72,7 @@ std::string fileName(const FileOptions& options) randomExtensions.push_back(fileExtension()); } - extensionsStr = "." + common::StringHelper::joinString(randomExtensions, "."); + extensionsStr = "." + common::joinString(randomExtensions, "."); } } diff --git a/tests/common/StringHelperTest.cpp b/tests/common/StringHelperTest.cpp index c6d03329a..503f63aa3 100644 --- a/tests/common/StringHelperTest.cpp +++ b/tests/common/StringHelperTest.cpp @@ -14,7 +14,7 @@ class StringHelperTest : public Test TEST_F(StringHelperTest, splitStringBySpace) { - const auto result = common::StringHelper::split("faker cxx open source"); + const auto result = common::split("faker cxx open source"); ASSERT_EQ(result.size(), 4); ASSERT_EQ(result[0], "faker"); @@ -25,7 +25,7 @@ TEST_F(StringHelperTest, splitStringBySpace) TEST_F(StringHelperTest, splitStringByNewLine) { - const auto result = common::StringHelper::split("faker\ncxx\nopen\nsource", "\n"); + const auto result = common::split("faker\ncxx\nopen\nsource", "\n"); ASSERT_EQ(result.size(), 4); ASSERT_EQ(result[0], "faker"); @@ -38,7 +38,7 @@ TEST_F(StringHelperTest, joinStringViewsIntoVectorBySpace) { const std::vector input{"Join", "faker", "development!"}; - const auto result = common::StringHelper::join(input); + const auto result = common::join(input); ASSERT_EQ(result, "Join faker development!"); } @@ -47,7 +47,7 @@ TEST_F(StringHelperTest, joinStringViewsIntoVectorByNewLine) { const std::vector input{"Join", "faker", "development!"}; - const auto result = common::StringHelper::join(input, "\n"); + const auto result = common::join(input, "\n"); ASSERT_EQ(result, "Join\nfaker\ndevelopment!"); } @@ -56,7 +56,7 @@ TEST_F(StringHelperTest, joinStringsIntoVectorBySpace) { const std::vector input{"Join", "faker", "development!"}; - const auto result = common::StringHelper::joinString(input); + const auto result = common::joinString(input); ASSERT_EQ(result, "Join faker development!"); } @@ -65,7 +65,7 @@ TEST_F(StringHelperTest, joinStringsIntoVectorByNewLine) { const std::vector input{"Join", "faker", "development!"}; - const auto result = common::StringHelper::joinString(input, "\n"); + const auto result = common::joinString(input, "\n"); ASSERT_EQ(result, "Join\nfaker\ndevelopment!"); } @@ -75,7 +75,7 @@ TEST_F(StringHelperTest, repeatString) const std::string data = "hello "; const int repetition = 3; - const std::string result = common::StringHelper::repeat(data, repetition); + const std::string result = common::repeat(data, repetition); ASSERT_EQ(result, "hello hello hello "); } @@ -84,7 +84,7 @@ TEST_F(StringHelperTest, toLower) { const std::string data = "HeLlo!"; - const std::string result = common::StringHelper::toLower(data); + const std::string result = common::toLower(data); ASSERT_EQ(result, "hello!"); } @@ -94,19 +94,19 @@ TEST_F(StringHelperTest, IsPunctuation) std::string punctuation = ".,;:!?"; for (char c : punctuation) { - EXPECT_TRUE(common::StringHelper::isPunctuation(c)); + EXPECT_TRUE(common::isPunctuation(c)); } std::string notPunctuation = "abc123"; for (char c : notPunctuation) { - EXPECT_FALSE(common::StringHelper::isPunctuation(c)); + EXPECT_FALSE(common::isPunctuation(c)); } } TEST_F(StringHelperTest, RemovePunctuation) { std::string input = "Hello, World!"; - std::string result = common::StringHelper::removePunctuation(input); + std::string result = common::removePunctuation(input); EXPECT_EQ(result, "Hello World"); } diff --git a/tests/modules/color/ColorTest.cpp b/tests/modules/color/ColorTest.cpp index f30ea1a46..cc44fbacf 100644 --- a/tests/modules/color/ColorTest.cpp +++ b/tests/modules/color/ColorTest.cpp @@ -33,7 +33,7 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithoutAlpha) { const auto generatedRgbColor = rgb(); - const auto rgbNumbers = common::StringHelper::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " "); + const auto rgbNumbers = common::split(generatedRgbColor.substr(4, generatedRgbColor.size() - 1), " "); int red, green, blue; std::from_chars(rgbNumbers[0].data(), rgbNumbers[0].data() + rgbNumbers[0].size(), red); @@ -51,7 +51,7 @@ TEST_F(ColorTest, shouldGenerateRgbColorWithAlpha) { const auto generatedRgbaColor = rgb(true); - const auto rgbaNumbers = common::StringHelper::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " "); + const auto rgbaNumbers = common::split(generatedRgbaColor.substr(5, generatedRgbaColor.size() - 1), " "); int red, green, blue, alpha; std::from_chars(rgbaNumbers[0].data(), rgbaNumbers[0].data() + rgbaNumbers[0].size(), red); @@ -98,7 +98,7 @@ TEST_F(ColorTest, shouldGenerateHexColorWithAlpha) TEST_F(ColorTest, shouldGenerateHslWithoutAlpha) { const auto generatedHslColor = hsl(); - const auto hslValues = common::StringHelper::split(generatedHslColor.substr(4, generatedHslColor.size() - 1), " "); + const auto hslValues = common::split(generatedHslColor.substr(4, generatedHslColor.size() - 1), " "); int hue, staturation, lightness; @@ -116,7 +116,7 @@ TEST_F(ColorTest, shouldGenerateHslWithoutAlpha) TEST_F(ColorTest, shouldGenerateHslWithAlpha) { const auto generatedHslaColor = hsl(true); - const auto hslValues = common::StringHelper::split(generatedHslaColor.substr(5, generatedHslaColor.size() - 1), " "); + const auto hslValues = common::split(generatedHslaColor.substr(5, generatedHslaColor.size() - 1), " "); int hue, saturation, lightness; @@ -138,7 +138,7 @@ TEST_F(ColorTest, shouldGenerateHslWithAlpha) TEST_F(ColorTest, shouldGenerateLchWithoutAlpha) { const auto generatedLchColor = lch(); - const auto lchValues = common::StringHelper::split(generatedLchColor.substr(4, generatedLchColor.size() - 1), " "); + const auto lchValues = common::split(generatedLchColor.substr(4, generatedLchColor.size() - 1), " "); int luminance, chroma, hue; @@ -156,7 +156,7 @@ TEST_F(ColorTest, shouldGenerateLchWithoutAlpha) TEST_F(ColorTest, shouldGenerateLchWithAlpha) { const auto generatedLchaColor = lch(true); - const auto lchValues = common::StringHelper::split(generatedLchaColor.substr(5, generatedLchaColor.size() - 1), " "); + const auto lchValues = common::split(generatedLchaColor.substr(5, generatedLchaColor.size() - 1), " "); int luminance, chroma, hue; @@ -178,7 +178,7 @@ TEST_F(ColorTest, shouldGenerateLchWithAlpha) TEST_F(ColorTest, shouldGenerateCmykColor) { const auto generatedCmykColor = cmyk(); - const auto cmykValues = common::StringHelper::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " "); + const auto cmykValues = common::split(generatedCmykColor.substr(5, generatedCmykColor.size() - 1), " "); auto offset = cmykValues[0].size(); const auto cyan = std::stod(cmykValues[0], &offset); @@ -200,7 +200,7 @@ TEST_F(ColorTest, shouldGenerateCmykColor) TEST_F(ColorTest, shouldGenerateLabColor) { const auto generatedLabColor = lab(); - const auto labValues = common::StringHelper::split(generatedLabColor.substr(4, generatedLabColor.size() - 1), " "); + const auto labValues = common::split(generatedLabColor.substr(4, generatedLabColor.size() - 1), " "); auto offset = labValues[0].size(); const auto lightness = std::stod(labValues[0], &offset); @@ -219,7 +219,7 @@ TEST_F(ColorTest, shouldGenerateLabColor) TEST_F(ColorTest, shouldGenerateHsb) { const auto generatedHsbColor = hsb(); - const auto hsbValues = common::StringHelper::split(generatedHsbColor.substr(4, generatedHsbColor.size() - 1), " "); + const auto hsbValues = common::split(generatedHsbColor.substr(4, generatedHsbColor.size() - 1), " "); int hue, saturation, brightness; @@ -237,7 +237,7 @@ TEST_F(ColorTest, shouldGenerateHsb) TEST_F(ColorTest, shouldGenerateHsv) { const auto generatedHsvColor = hsv(); - const auto hsvValues = common::StringHelper::split(generatedHsvColor.substr(4, generatedHsvColor.size() - 1), " "); + const auto hsvValues = common::split(generatedHsvColor.substr(4, generatedHsvColor.size() - 1), " "); int hue, saturation, brightness; @@ -255,7 +255,7 @@ TEST_F(ColorTest, shouldGenerateHsv) TEST_F(ColorTest, shouldGenerateYuv) { const auto generatedYuvColor = yuv(); - const auto yuvValues = common::StringHelper::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " "); + const auto yuvValues = common::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " "); int luminance, chrominanceBlueColor, chrominanceRedColor; diff --git a/tests/modules/commerce/CommerceTest.cpp b/tests/modules/commerce/CommerceTest.cpp index 5bf9673f7..e66eb095b 100644 --- a/tests/modules/commerce/CommerceTest.cpp +++ b/tests/modules/commerce/CommerceTest.cpp @@ -60,7 +60,7 @@ TEST_F(CommerceTest, shouldGenerateProductFullName) { const auto generatedProductFullName = productFullName(); - const auto productFullNameElements = common::StringHelper::split(generatedProductFullName, " "); + const auto productFullNameElements = common::split(generatedProductFullName, " "); const auto& generatedProductAdjective = productFullNameElements[0]; const auto& generatedProductMaterial = productFullNameElements[1]; diff --git a/tests/modules/company/CompanyTest.cpp b/tests/modules/company/CompanyTest.cpp index ee1798695..4205823c9 100644 --- a/tests/modules/company/CompanyTest.cpp +++ b/tests/modules/company/CompanyTest.cpp @@ -23,7 +23,7 @@ TEST_F(CompanyTest, shouldGenerateCompanyName) { const auto companyName = name(); - const auto companyNameElements = common::StringHelper::split(companyName, " "); + const auto companyNameElements = common::split(companyName, " "); std::vector expectedFirstNames(person::englishMaleFirstNames.begin(), person::englishMaleFirstNames.end()); diff --git a/tests/modules/date/DateTest.cpp b/tests/modules/date/DateTest.cpp index 1e975fd75..00a240f92 100644 --- a/tests/modules/date/DateTest.cpp +++ b/tests/modules/date/DateTest.cpp @@ -335,7 +335,7 @@ TEST_F(DateTest, shouldGenerateRandomTimezone) TEST_F(DateTest, shouldGenerateRandomTime) { const auto generatedTime = time(); - const auto generatedTimeParts = common::StringHelper::split(generatedTime, ":"); + const auto generatedTimeParts = common::split(generatedTime, ":"); ASSERT_EQ(generatedTimeParts.size(), 2); diff --git a/tests/modules/finance/FinanceTest.cpp b/tests/modules/finance/FinanceTest.cpp index 96817a2bc..f55af8d17 100644 --- a/tests/modules/finance/FinanceTest.cpp +++ b/tests/modules/finance/FinanceTest.cpp @@ -176,7 +176,7 @@ TEST_F(FinanceTest, shouldGenerateAmount) auto offset = generatedAmount.size(); const auto amountAsFloat = std::stof(generatedAmount, &offset); - const auto generatedAmountParts = common::StringHelper::split(generatedAmount, "."); + const auto generatedAmountParts = common::split(generatedAmount, "."); ASSERT_EQ(generatedAmountParts.size(), 2); ASSERT_EQ(generatedAmountParts[1].size(), 2); @@ -217,7 +217,7 @@ TEST_F(FinanceTest, shouldGenerateAmountWithSymbol) const auto amountAsFloat = std::stof(generatedAmount.substr(currencySymbol.size())); - const auto generatedAmountParts = common::StringHelper::split(generatedAmount, "."); + const auto generatedAmountParts = common::split(generatedAmount, "."); ASSERT_TRUE(generatedAmount.starts_with(currencySymbol)); ASSERT_EQ(generatedAmountParts.size(), 2); diff --git a/tests/modules/git/GitTest.cpp b/tests/modules/git/GitTest.cpp index add70b219..9c68d714b 100644 --- a/tests/modules/git/GitTest.cpp +++ b/tests/modules/git/GitTest.cpp @@ -41,7 +41,7 @@ std::string GitTest::generateShaRegex() TEST_F(GitTest, shouldGenerateBranch) { const auto generatedBranch = branch(); - const auto branchSplit = common::StringHelper::split(generatedBranch, "-").size(); + const auto branchSplit = common::split(generatedBranch, "-").size(); ASSERT_TRUE(2 <= branchSplit && branchSplit <= 7); } @@ -50,7 +50,7 @@ TEST_F(GitTest, branchIssueNumTest) { auto testValue = unsigned(number::integer(2, 100)); - std::vector branchElements = common::StringHelper::split(branch(testValue), "-"); + std::vector branchElements = common::split(branch(testValue), "-"); bool numberAtFront = false; @@ -58,7 +58,7 @@ TEST_F(GitTest, branchIssueNumTest) while (!numberAtFront) { - branchElements = common::StringHelper::split(branch(testValue), "-"); + branchElements = common::split(branch(testValue), "-"); try { diff --git a/tests/modules/image/ImageTest.cpp b/tests/modules/image/ImageTest.cpp index 68a6f4c1f..3c42d9386 100644 --- a/tests/modules/image/ImageTest.cpp +++ b/tests/modules/image/ImageTest.cpp @@ -62,7 +62,7 @@ TEST_F(ImageTest, shouldGenerateDimensions) { const auto generatedDimensions = dimensions(); - const auto split_dimensions = common::StringHelper::split(generatedDimensions, "x"); + const auto split_dimensions = common::split(generatedDimensions, "x"); const auto width_dimension = std::stoi(split_dimensions[0]); diff --git a/tests/modules/internet/InternetTest.cpp b/tests/modules/internet/InternetTest.cpp index e3efb73b0..eef940120 100644 --- a/tests/modules/internet/InternetTest.cpp +++ b/tests/modules/internet/InternetTest.cpp @@ -45,7 +45,7 @@ constexpr unsigned int classCSecondSection = 168u; std::array deconstructIpv4String(const std::string& ipv4) { - const auto ipParts = common::StringHelper::split(ipv4, "."); + const auto ipParts = common::split(ipv4, "."); std::array result{static_cast(stoi(ipParts[0])), static_cast(stoi(ipParts[1])), static_cast(stoi(ipParts[2])), @@ -172,7 +172,7 @@ TEST_F(InternetTest, shouldGenerateEmail) const auto generatedEmail = email(); - const auto emailParts = common::StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -193,7 +193,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithFirstName) const auto generatedEmail = email(firstName); - const auto emailParts = common::StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -217,7 +217,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithLastName) const auto generatedEmail = email(std::nullopt, lastName); - const auto emailParts = common::StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -239,7 +239,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithFullName) const auto generatedEmail = email(firstName, lastName); - const auto emailParts = common::StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -262,7 +262,7 @@ TEST_F(InternetTest, shouldGenerateEmailWithSpecifiedEmailHost) const auto generatedEmail = email(std::nullopt, std::nullopt, emailHost); - const auto emailParts = common::StringHelper::split(generatedEmail, "@"); + const auto emailParts = common::split(generatedEmail, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -284,7 +284,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmail) const auto email = exampleEmail(); - const auto emailParts = common::StringHelper::split(email, "@"); + const auto emailParts = common::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -305,7 +305,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFirstName) const auto email = exampleEmail(firstName); - const auto emailParts = common::StringHelper::split(email, "@"); + const auto emailParts = common::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -329,7 +329,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithLastName) const auto email = exampleEmail(std::nullopt, lastName); - const auto emailParts = common::StringHelper::split(email, "@"); + const auto emailParts = common::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -351,7 +351,7 @@ TEST_F(InternetTest, shouldGenerateExampleEmailWithFullName) const auto email = exampleEmail(firstName, lastName); - const auto emailParts = common::StringHelper::split(email, "@"); + const auto emailParts = common::split(email, "@"); ASSERT_EQ(emailParts.size(), 2); @@ -629,7 +629,7 @@ TEST_F(InternetTest, shouldGenerateIpv6) { const auto generatedIpv6 = ipv6(); - const auto generatedIpv6Parts = common::StringHelper::split(generatedIpv6, ":"); + const auto generatedIpv6Parts = common::split(generatedIpv6, ":"); ASSERT_EQ(generatedIpv6Parts.size(), 8); @@ -680,7 +680,7 @@ TEST_F(InternetTest, shouldGenerateDomainName) { const auto generatedDomainName = domainName(); - const auto generatedDomainNameParts = common::StringHelper::split(generatedDomainName, "."); + const auto generatedDomainNameParts = common::split(generatedDomainName, "."); const auto& generatedDomainWord = generatedDomainNameParts[0]; const auto& generatedDomainSuffix = generatedDomainNameParts[1]; @@ -694,12 +694,12 @@ TEST_F(InternetTest, shouldGenerateHttpsUrl) { const auto generatedUrl = url(); - const auto generatedUrlParts = common::StringHelper::split(generatedUrl, "://"); + const auto generatedUrlParts = common::split(generatedUrl, "://"); const auto& generatedProtocol = generatedUrlParts[0]; const auto& generatedDomainName = generatedUrlParts[1]; - const auto generatedDomainNameParts = common::StringHelper::split(generatedDomainName, "."); + const auto generatedDomainNameParts = common::split(generatedDomainName, "."); const auto& generatedDomainWord = generatedDomainNameParts[0]; const auto& generatedDomainSuffix = generatedDomainNameParts[1]; @@ -714,12 +714,12 @@ TEST_F(InternetTest, shouldGenerateHttpUrl) { const auto generatedUrl = url(WebProtocol::Http); - const auto generatedUrlParts = common::StringHelper::split(generatedUrl, "://"); + const auto generatedUrlParts = common::split(generatedUrl, "://"); const auto& generatedProtocol = generatedUrlParts[0]; const auto& generatedDomainName = generatedUrlParts[1]; - const auto generatedDomainNameParts = common::StringHelper::split(generatedDomainName, "."); + const auto generatedDomainNameParts = common::split(generatedDomainName, "."); const auto& generatedDomainWord = generatedDomainNameParts[0]; const auto& generatedDomainSuffix = generatedDomainNameParts[1]; diff --git a/tests/modules/location/LocationTest.cpp b/tests/modules/location/LocationTest.cpp index 092f4ba60..67bbe7b5b 100644 --- a/tests/modules/location/LocationTest.cpp +++ b/tests/modules/location/LocationTest.cpp @@ -147,7 +147,7 @@ TEST_P(LocationTest, shouldGenerateCity) if (country == location::AddressCountry::Brazil) { - const auto generatedCityElements = common::StringHelper::split(generatedCity, " "); + const auto generatedCityElements = common::split(generatedCity, " "); const auto& generatedCityPrefix = generatedCityElements[0]; @@ -269,7 +269,7 @@ TEST_F(LocationTest, shouldGenerateUsaStreet) { const auto generatedStreet = street(); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedFirstOrLastName = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; @@ -292,7 +292,7 @@ TEST_F(LocationTest, shouldGenerateUsaStreetAddress) { const auto generatedStreetAddress = streetAddress(); - const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedFirstOrLastName = generatedStreetAddressElements[1]; @@ -318,11 +318,11 @@ TEST_F(LocationTest, shouldGeneratePolandStreet) { const auto generatedStreet = street(AddressCountry::Poland); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetName = - common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_TRUE(std::ranges::any_of(polandStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); @@ -344,11 +344,11 @@ TEST_F(LocationTest, shouldGenerateRussiaStreet) { const auto generatedStreet = street(AddressCountry::Russia); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); std::vector firstNames(person::russianMaleFirstNames.begin(), person::russianMaleFirstNames.end()); @@ -392,11 +392,11 @@ TEST_F(LocationTest, shouldGenerateFranceStreet) { const auto generatedStreet = street(AddressCountry::France); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_GE(generatedStreetElements.size(), 2); ASSERT_TRUE(std::ranges::any_of(franceStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) @@ -409,12 +409,12 @@ TEST_F(LocationTest, shouldGenerateFranceStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::France); - const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetPrefix = generatedStreetAddressElements[1]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); + common::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); ASSERT_GE(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 4); @@ -448,7 +448,7 @@ TEST_F(LocationTest, shouldGenerateLatitude) auto offset = generatedLatitude.size(); const auto latitudeAsFloat = std::stof(generatedLatitude, &offset); - const auto generatedLatitudeParts = common::StringHelper::split(generatedLatitude, "."); + const auto generatedLatitudeParts = common::split(generatedLatitude, "."); ASSERT_EQ(generatedLatitudeParts.size(), 2); ASSERT_EQ(generatedLatitudeParts[1].size(), 4); @@ -463,7 +463,7 @@ TEST_F(LocationTest, shouldGenerateLatitudeWithSpecifiedPrecision) auto offset = generatedLatitude.size(); const auto latitudeAsFloat = std::stof(generatedLatitude, &offset); - const auto generatedLatitudeParts = common::StringHelper::split(generatedLatitude, "."); + const auto generatedLatitudeParts = common::split(generatedLatitude, "."); ASSERT_EQ(generatedLatitudeParts.size(), 2); ASSERT_EQ(generatedLatitudeParts[1].size(), 3); @@ -478,7 +478,7 @@ TEST_F(LocationTest, shouldGenerateLongitude) auto offset = generatedLongitude.size(); const auto longitudeAsFloat = std::stof(generatedLongitude, &offset); - const auto generatedLongitudeParts = common::StringHelper::split(generatedLongitude, "."); + const auto generatedLongitudeParts = common::split(generatedLongitude, "."); ASSERT_EQ(generatedLongitudeParts.size(), 2); ASSERT_EQ(generatedLongitudeParts[1].size(), 4); @@ -493,7 +493,7 @@ TEST_F(LocationTest, shouldGenerateLongitudeWithSpecifiedPrecision) auto offset = generatedLongitude.size(); const auto longitudeAsFloat = std::stof(generatedLongitude, &offset); - const auto generatedLongitudeParts = common::StringHelper::split(generatedLongitude, "."); + const auto generatedLongitudeParts = common::split(generatedLongitude, "."); ASSERT_EQ(generatedLongitudeParts.size(), 2); ASSERT_EQ(generatedLongitudeParts[1].size(), 6); @@ -521,11 +521,11 @@ TEST_F(LocationTest, shouldGenerateUkraineStreet) { const auto generatedStreet = street(AddressCountry::Ukraine); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_TRUE(std::ranges::any_of(ukraineStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) @@ -578,11 +578,11 @@ TEST_F(LocationTest, shouldGenerateItalyStreet) { const auto generatedStreet = street(AddressCountry::Italy); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); + common::join({generatedStreetElements.begin() + 1, generatedStreetElements.end()}); ASSERT_TRUE(std::ranges::any_of(italyStreetPrefixes, [&generatedStreetPrefix](const std::string_view& streetPrefix) { return streetPrefix == generatedStreetPrefix; })); @@ -668,11 +668,11 @@ TEST_F(LocationTest, shouldGenerateAustraliaStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::Australia); - const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); + common::join({generatedStreetAddressElements.begin() + 1, generatedStreetAddressElements.end()}); std::vector firstNames(person::australianMaleFirstNames.begin(), person::australianMaleFirstNames.end()); @@ -695,11 +695,11 @@ TEST_F(LocationTest, shouldGenerateIndiaStreetAddress) { const auto generatedStreetAddress = streetAddress(AddressCountry::India); - const auto generatedStreetAddressElements = common::StringHelper::split(generatedStreetAddress, " "); + const auto generatedStreetAddressElements = common::split(generatedStreetAddress, " "); const auto& generatedBuildingNumber = generatedStreetAddressElements[0]; const auto& generatedStreetSuffix = - common::StringHelper::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); + common::join({generatedStreetAddressElements.begin() + 2, generatedStreetAddressElements.end()}); ASSERT_GE(generatedStreetAddressElements.size(), 3); ASSERT_TRUE(!generatedBuildingNumber.empty()); @@ -762,7 +762,7 @@ TEST_F(LocationTest, shouldGenerateFinlandStreet) { const auto generatedStreet = street(AddressCountry::Finland); - const auto generatedStreetElements = common::StringHelper::split(generatedStreet, " "); + const auto generatedStreetElements = common::split(generatedStreet, " "); const auto& generatedStreetPrefix = generatedStreetElements[0]; const auto& generatedStreetSuffix = generatedStreetElements[1]; diff --git a/tests/modules/lorem/LoremTest.cpp b/tests/modules/lorem/LoremTest.cpp index 47dcbefda..4c6d6eddf 100644 --- a/tests/modules/lorem/LoremTest.cpp +++ b/tests/modules/lorem/LoremTest.cpp @@ -32,7 +32,7 @@ TEST_F(LoremTest, shouldGenerateWords) const auto generatedWords = words(numberOfWords); - const auto separatedWords = common::StringHelper::split(generatedWords, " "); + const auto separatedWords = common::split(generatedWords, " "); ASSERT_EQ(separatedWords.size(), numberOfWords); ASSERT_TRUE(std::ranges::all_of( @@ -51,7 +51,7 @@ TEST_F(LoremTest, shouldGenerateSentence) const auto sentenceWithoutEndingDot = generatedSentence.substr(0, generatedSentence.size() - 1); - const auto sentenceWords = common::StringHelper::split(sentenceWithoutEndingDot, " "); + const auto sentenceWords = common::split(sentenceWithoutEndingDot, " "); ASSERT_TRUE(std::isupper(generatedSentence[0])); ASSERT_TRUE(generatedSentence.ends_with(".")); @@ -70,7 +70,7 @@ TEST_F(LoremTest, shouldGenerateSentences) { const auto generatedSentences = sentences(); - const auto separatedSentences = common::StringHelper::split(generatedSentences, ". "); + const auto separatedSentences = common::split(generatedSentences, ". "); for (auto sentence : separatedSentences) { @@ -78,7 +78,7 @@ TEST_F(LoremTest, shouldGenerateSentences) ASSERT_TRUE(std::isupper(sentence[0])); - const auto sentenceWords = common::StringHelper::split(sentence, " "); + const auto sentenceWords = common::split(sentence, " "); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); @@ -97,7 +97,7 @@ TEST_F(LoremTest, shouldGenerateSlug) { const auto generatedSlug = slug(3); - const auto separatedWords = common::StringHelper::split(generatedSlug, "-"); + const auto separatedWords = common::split(generatedSlug, "-"); ASSERT_EQ(separatedWords.size(), 3); ASSERT_TRUE(std::ranges::all_of( @@ -114,7 +114,7 @@ TEST_F(LoremTest, shouldGenerateParagraph) { const auto generatedParagraph = paragraph(); - const auto separatedSentences = common::StringHelper::split(generatedParagraph, ". "); + const auto separatedSentences = common::split(generatedParagraph, ". "); for (auto sentence : separatedSentences) { @@ -122,7 +122,7 @@ TEST_F(LoremTest, shouldGenerateParagraph) ASSERT_TRUE(std::isupper(sentence[0])); - const auto sentenceWords = common::StringHelper::split(sentence, " "); + const auto sentenceWords = common::split(sentence, " "); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); @@ -141,11 +141,11 @@ TEST_F(LoremTest, shouldGenerateParagraphs) { const auto generatedParagraphs = paragraphs(); - const auto separatedParagraphs = common::StringHelper::split(generatedParagraphs, "\n"); + const auto separatedParagraphs = common::split(generatedParagraphs, "\n"); for (const auto& generatedParagraph : separatedParagraphs) { - const auto separatedSentences = common::StringHelper::split(generatedParagraph, ". "); + const auto separatedSentences = common::split(generatedParagraph, ". "); for (auto sentence : separatedSentences) { @@ -153,7 +153,7 @@ TEST_F(LoremTest, shouldGenerateParagraphs) ASSERT_TRUE(std::isupper(sentence[0])); - const auto sentenceWords = common::StringHelper::split(sentence, " "); + const auto sentenceWords = common::split(sentence, " "); ASSERT_TRUE(sentenceWords.size() >= 3 && sentenceWords.size() <= 10); diff --git a/tests/modules/person/PersonTest.cpp b/tests/modules/person/PersonTest.cpp index 8ee8ca11d..8eb0001c5 100644 --- a/tests/modules/person/PersonTest.cpp +++ b/tests/modules/person/PersonTest.cpp @@ -477,7 +477,7 @@ TEST_F(PersonTest, shouldGenerateJobTitle) { const auto generatedJobTitle = jobTitle(); - const auto jobTitleElements = common::StringHelper::split(generatedJobTitle, " "); + const auto jobTitleElements = common::split(generatedJobTitle, " "); const auto& generatedJobDescriptor = jobTitleElements[0]; const auto& generatedJobArea = jobTitleElements[1]; diff --git a/tests/modules/word/WordTest.cpp b/tests/modules/word/WordTest.cpp index 72dce5962..fa3212ff8 100644 --- a/tests/modules/word/WordTest.cpp +++ b/tests/modules/word/WordTest.cpp @@ -214,7 +214,7 @@ TEST_F(WordTest, shouldGenerateWords) { const auto generatedWords = words(5); - const auto separatedWords = common::StringHelper::split(generatedWords, " "); + const auto separatedWords = common::split(generatedWords, " "); ASSERT_TRUE(std::ranges::all_of(separatedWords, [](const std::string& separatedWord) { return std::ranges::find(_allWords, separatedWord) != _allWords.end(); }));