From 99f02647811abeb4578df952ee749d5357a63b0b Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Tue, 2 Jul 2024 19:53:53 +0200 Subject: [PATCH] refactor: formathelper module - formathelper module migration from class to functions within common namespace - modified reference to functions and variables from formathelper module in all dependent modules Signed-off-by: Guru Mehar Rachaputi --- src/common/FormatHelper.cpp | 26 +++++++++++++------------- src/common/FormatHelper.h | 16 ++++++---------- src/modules/color/Color.cpp | 22 +++++++++++----------- src/modules/commerce/Commerce.cpp | 2 +- src/modules/company/Company.cpp | 12 ++++++------ src/modules/date/Date.cpp | 4 ++-- src/modules/finance/Finance.cpp | 2 +- src/modules/git/Git.cpp | 16 ++++++++-------- src/modules/image/Image.cpp | 8 ++++---- src/modules/internet/Internet.cpp | 22 +++++++++++----------- src/modules/location/Location.cpp | 10 +++++----- src/modules/lorem/Lorem.cpp | 2 +- src/modules/person/Person.cpp | 6 +++--- src/modules/string/String.cpp | 2 +- src/modules/system/System.cpp | 2 +- src/modules/vehicle/Vehicle.cpp | 6 +++--- tests/common/FormatHelperTest.cpp | 11 ++++++----- 17 files changed, 83 insertions(+), 86 deletions(-) diff --git a/src/common/FormatHelper.cpp b/src/common/FormatHelper.cpp index b9baa7b77..35d38c54d 100644 --- a/src/common/FormatHelper.cpp +++ b/src/common/FormatHelper.cpp @@ -10,7 +10,7 @@ namespace faker // TODO: change to std::function std::string -FormatHelper::fillTokenValues(const std::string& format, +common::fillTokenValues(const std::string& format, std::unordered_map> tokenValueGenerators) { std::string filledFormat; @@ -31,7 +31,7 @@ FormatHelper::fillTokenValues(const std::string& format, if (foundTokenGenerator == tokenValueGenerators.end()) { - throw std::runtime_error{FormatHelper::format("Generator not found for token {}.", token)}; + throw std::runtime_error{common::format("Generator not found for token {}.", token)}; } filledFormat += foundTokenGenerator->second(); @@ -47,7 +47,7 @@ FormatHelper::fillTokenValues(const std::string& format, return filledFormat; } -std::string FormatHelper::fillTokenValues( +std::string common::fillTokenValues( const std::string& format, std::unordered_map> tokenValueGenerators) { @@ -69,7 +69,7 @@ std::string FormatHelper::fillTokenValues( if (foundTokenGenerator == tokenValueGenerators.end()) { - throw std::runtime_error{FormatHelper::format("Generator not found for token {}.", token)}; + throw std::runtime_error{common::format("Generator not found for token {}.", token)}; } filledFormat += foundTokenGenerator->second(); @@ -85,26 +85,26 @@ std::string FormatHelper::fillTokenValues( return filledFormat; } -std::string FormatHelper::precisionFormat(Precision precision, double value) +std::string common::precisionFormat(Precision precision, double value) { switch (precision) { case Precision::ZeroDp: - return FormatHelper::format("{:.0f}", value); + return common::format("{:.0f}", value); case Precision::OneDp: - return FormatHelper::format("{:.1f}", value); + return common::format("{:.1f}", value); case Precision::TwoDp: - return FormatHelper::format("{:.2f}", value); + return common::format("{:.2f}", value); case Precision::ThreeDp: - return FormatHelper::format("{:.3f}", value); + return common::format("{:.3f}", value); case Precision::FourDp: - return FormatHelper::format("{:.4f}", value); + return common::format("{:.4f}", value); case Precision::FiveDp: - return FormatHelper::format("{:.5f}", value); + return common::format("{:.5f}", value); case Precision::SixDp: - return FormatHelper::format("{:.6f}", value); + return common::format("{:.6f}", value); case Precision::SevenDp: - return FormatHelper::format("{:.7f}", value); + return common::format("{:.7f}", value); default: throw std::invalid_argument("Invalid precision"); } diff --git a/src/common/FormatHelper.h b/src/common/FormatHelper.h index 941b752ae..6b77f1816 100644 --- a/src/common/FormatHelper.h +++ b/src/common/FormatHelper.h @@ -16,33 +16,29 @@ #endif -namespace faker +namespace faker::common { -class FormatHelper -{ -public: #if !defined(USE_STD_FORMAT) template - static std::string format(fmt::format_string fmt, Args&&... args) + std::string format(fmt::format_string fmt, Args&&... args) { return fmt::format(fmt, std::forward(args)...); } #else template - static std::string format(std::format_string fmt, Args&&... args) + std::string format(std::format_string fmt, Args&&... args) { return std::format(fmt, std::forward(args)...); } #endif - FAKER_CXX_EXPORT static std::string precisionFormat(Precision precision, double value); + FAKER_CXX_EXPORT std::string precisionFormat(Precision precision, double value); - FAKER_CXX_EXPORT static std::string + FAKER_CXX_EXPORT std::string fillTokenValues(const std::string& format, std::unordered_map> tokenValueGenerators); - FAKER_CXX_EXPORT static std::string + FAKER_CXX_EXPORT std::string fillTokenValues(const std::string& format, std::unordered_map> tokenValueGenerators); -}; } diff --git a/src/modules/color/Color.cpp b/src/modules/color/Color.cpp index 01d11a19a..614efe182 100644 --- a/src/modules/color/Color.cpp +++ b/src/modules/color/Color.cpp @@ -25,12 +25,12 @@ std::string rgb(bool includeAlpha) if (!includeAlpha) { - return FormatHelper::format("rgb({}, {}, {})", red, green, blue); + return common::format("rgb({}, {}, {})", red, green, blue); } std::floating_point auto alpha = number::decimal(1.0); - return FormatHelper::format("rgba({}, {}, {}, {:.2f})", red, green, blue, alpha); + return common::format("rgba({}, {}, {}, {:.2f})", red, green, blue, alpha); } std::string hex(HexCasing casing, HexPrefix prefix, bool includeAlpha) @@ -46,12 +46,12 @@ std::string hsl(bool include_alpha) if (!include_alpha) { - return FormatHelper::format("hsl({}, {}, {})", hue, saturation, lightness); + return common::format("hsl({}, {}, {})", hue, saturation, lightness); } std::floating_point auto alpha = number::decimal(1.0); - return FormatHelper::format("hsla({}, {}, {}, {:.2f})", hue, saturation, lightness, alpha); + return common::format("hsla({}, {}, {}, {:.2f})", hue, saturation, lightness, alpha); } std::string lch(bool include_alpha) @@ -62,12 +62,12 @@ std::string lch(bool include_alpha) if (!include_alpha) { - return FormatHelper::format("lch({}, {}, {})", luminance, chroma, hue); + return common::format("lch({}, {}, {})", luminance, chroma, hue); } std::floating_point auto alpha = number::decimal(1.0); - return FormatHelper::format("lcha({}, {}, {}, {:.2f})", luminance, chroma, hue, alpha); + return common::format("lcha({}, {}, {}, {:.2f})", luminance, chroma, hue, alpha); } std::string cmyk() @@ -77,7 +77,7 @@ std::string cmyk() std::floating_point auto yellow = number::decimal(1.); std::floating_point auto key = number::decimal(1.); - return FormatHelper::format("cmyk({:.2f}, {:.2f}, {:.2f}, {:.2f})", cyan, magenta, yellow, key); + return common::format("cmyk({:.2f}, {:.2f}, {:.2f}, {:.2f})", cyan, magenta, yellow, key); } std::string lab() @@ -86,7 +86,7 @@ std::string lab() std::floating_point auto red_green = number::decimal(-128.0, 128.0); std::floating_point auto blue_yellow = number::decimal(-128.0, 128.0); - return FormatHelper::format("lab({:.2f}, {:.2f}, {:.2f})", lightness, red_green, blue_yellow); + return common::format("lab({:.2f}, {:.2f}, {:.2f})", lightness, red_green, blue_yellow); } std::string hsb() @@ -95,7 +95,7 @@ std::string hsb() std::integral auto saturation = number::integer(100); std::integral auto brightness = number::integer(100); - return FormatHelper::format("hsb({}, {}, {})", hue, saturation, brightness); + return common::format("hsb({}, {}, {})", hue, saturation, brightness); } std::string hsv() @@ -104,7 +104,7 @@ std::string hsv() std::integral auto saturation = number::integer(100); std::integral auto value = number::integer(100); - return FormatHelper::format("hsv({}, {}, {})", hue, saturation, value); + return common::format("hsv({}, {}, {})", hue, saturation, value); } std::string yuv() @@ -113,7 +113,7 @@ std::string yuv() std::integral auto chrominance_blue = number::integer(255); std::integral auto chrominance_red = number::integer(255); - return FormatHelper::format("yuv({}, {}, {})", luminance, chrominance_blue, chrominance_red); + return common::format("yuv({}, {}, {})", luminance, chrominance_blue, chrominance_red); } } diff --git a/src/modules/commerce/Commerce.cpp b/src/modules/commerce/Commerce.cpp index d0240de77..9097abf83 100644 --- a/src/modules/commerce/Commerce.cpp +++ b/src/modules/commerce/Commerce.cpp @@ -37,7 +37,7 @@ std::string_view productName() std::string productFullName() { - return FormatHelper::format("{} {} {}", productAdjective(), productMaterial(), productName()); + return common::format("{} {} {}", productAdjective(), productMaterial(), productName()); } std::string EAN13() diff --git a/src/modules/company/Company.cpp b/src/modules/company/Company.cpp index 96d8715e5..d0d606566 100644 --- a/src/modules/company/Company.cpp +++ b/src/modules/company/Company.cpp @@ -18,17 +18,17 @@ std::string name() switch (number::integer(3)) { case 0: - companyName = FormatHelper::format("{} {}", person::lastName(), helper::arrayElement(companySuffixes)); + companyName = common::format("{} {}", person::lastName(), helper::arrayElement(companySuffixes)); break; case 1: - companyName = FormatHelper::format("{} {} {}", person::firstName(), person::lastName(), person::jobArea()); + companyName = common::format("{} {} {}", person::firstName(), person::lastName(), person::jobArea()); break; case 2: companyName = - FormatHelper::format("{} {} {} Services", person::firstName(), person::lastName(), person::jobArea()); + common::format("{} {} {} Services", person::firstName(), person::lastName(), person::jobArea()); break; case 3: - companyName = FormatHelper::format("{} {} {} {}", person::firstName(), person::lastName(), person::jobArea(), + companyName = common::format("{} {} {} {}", person::firstName(), person::lastName(), person::jobArea(), helper::arrayElement(companySuffixes)); break; } @@ -48,7 +48,7 @@ std::string_view industry() std::string buzzPhrase() { - return FormatHelper::format("{} {} {}", buzzVerb(), buzzAdjective(), buzzNoun()); + return common::format("{} {} {}", buzzVerb(), buzzAdjective(), buzzNoun()); } std::string_view buzzAdjective() @@ -68,7 +68,7 @@ std::string_view buzzVerb() std::string catchPhrase() { - return FormatHelper::format("{} {} {}", catchPhraseAdjective(), catchPhraseDescriptor(), catchPhraseNoun()); + return common::format("{} {} {}", catchPhraseAdjective(), catchPhraseDescriptor(), catchPhraseNoun()); } std::string_view catchPhraseAdjective() diff --git a/src/modules/date/Date.cpp b/src/modules/date/Date.cpp index 6fe23a422..0ca20f34b 100644 --- a/src/modules/date/Date.cpp +++ b/src/modules/date/Date.cpp @@ -40,7 +40,7 @@ std::string betweenDate(const auto& from, const auto& to, DateFormat dateFormat) { if (from > to) { - throw std::runtime_error{FormatHelper::format("Start date is greater than end date. {{from: {}, to: {}}}", + throw std::runtime_error{common::format("Start date is greater than end date. {{from: {}, to: {}}}", serializeTimePoint(from, dateFormat), serializeTimePoint(to, dateFormat))}; } @@ -180,7 +180,7 @@ unsigned int second() std::string time() { - return FormatHelper::format("{:02}:{:02}", hour(), minute()); + return common::format("{:02}:{:02}", hour(), minute()); } unsigned int dayOfMonth() diff --git a/src/modules/finance/Finance.cpp b/src/modules/finance/Finance.cpp index 16f4eb705..aac3116ff 100644 --- a/src/modules/finance/Finance.cpp +++ b/src/modules/finance/Finance.cpp @@ -48,7 +48,7 @@ std::string amount(double min, double max, Precision precision, const std::strin std::string result{symbol}; - result += FormatHelper::precisionFormat(precision, generatedNumber); + result += common::precisionFormat(precision, generatedNumber); return result; } diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index fb9589a4c..68b1ee3e3 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -23,11 +23,11 @@ std::string branch(unsigned maxIssueNum) switch (number::integer(1, 3)) { case 1: - return FormatHelper::format("{}-{}", word::verb(), word::noun()); + return common::format("{}-{}", word::verb(), word::noun()); case 2: - return FormatHelper::format("{}-{}-{}", word::verb(), word::adjective(), word::noun()); + return common::format("{}-{}-{}", word::verb(), word::adjective(), word::noun()); default: - return FormatHelper::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(), + return common::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(), word::adjective(), word::noun()); } } @@ -73,7 +73,7 @@ std::string commitDate(unsigned years) timeZoneString += "00"; } - return FormatHelper::format("{} {} {} {} {} {}", faker::date::weekdayAbbreviatedName(), + return common::format("{} {} {} {} {} {}", faker::date::weekdayAbbreviatedName(), faker::date::monthAbbreviatedNames[size_t(std::stoi(month) - 1)], day, time, year, timeZoneString); } @@ -115,13 +115,13 @@ std::string commitMessage() switch (number::integer(1, 4)) { case 1: - return FormatHelper::format("{} {}", word::verb(), word::noun()); + return common::format("{} {}", word::verb(), word::noun()); case 2: - return FormatHelper::format("{} {} {}", word::verb(), word::adjective(), word::noun()); + return common::format("{} {} {}", word::verb(), word::adjective(), word::noun()); case 3: - return FormatHelper::format("{} {} {}", word::verb(), word::noun(), word::adverb()); + return common::format("{} {} {}", word::verb(), word::noun(), word::adverb()); default: - return FormatHelper::format("{} {} {} {}", word::verb(), word::adjective(), word::noun(), word::adverb()); + return common::format("{} {} {} {}", word::verb(), word::adjective(), word::noun(), word::adverb()); } } diff --git a/src/modules/image/Image.cpp b/src/modules/image/Image.cpp index 64d78bb5e..11c039dc6 100644 --- a/src/modules/image/Image.cpp +++ b/src/modules/image/Image.cpp @@ -29,20 +29,20 @@ std::string imageUrl(unsigned int width, unsigned int height, std::optional(100000000)); + return common::format("https://avatars.githubusercontent.com/u/{}", number::integer(100000000)); } std::string dimensions() { - return FormatHelper::format("{}x{}", number::integer(1, 32720), number::integer(1, 17280)); + return common::format("{}x{}", number::integer(1, 32720), number::integer(1, 17280)); } std::string_view type() diff --git a/src/modules/internet/Internet.cpp b/src/modules/internet/Internet.cpp index 4de8246d8..6c5b10158 100644 --- a/src/modules/internet/Internet.cpp +++ b/src/modules/internet/Internet.cpp @@ -90,15 +90,15 @@ std::string username(std::optional firstNameInit, std::optional(2)) { case 0: - username = FormatHelper::format("{}{}{}", firstName, lastName, number::integer(999)); + username = common::format("{}{}{}", firstName, lastName, number::integer(999)); break; case 1: - username = FormatHelper::format("{}{}{}", firstName, + username = common::format("{}{}{}", firstName, helper::arrayElement(std::vector{".", "_", ""}), lastName); break; case 2: username = - FormatHelper::format("{}{}{}{}", firstName, helper::arrayElement(std::vector{".", "_", ""}), + common::format("{}{}{}{}", firstName, helper::arrayElement(std::vector{".", "_", ""}), lastName, number::integer(99)); break; } @@ -109,13 +109,13 @@ std::string username(std::optional firstNameInit, std::optional firstName, std::optional lastName, std::optional emailHost) { - return FormatHelper::format("{}@{}", username(std::move(firstName), std::move(lastName)), + return common::format("{}@{}", username(std::move(firstName), std::move(lastName)), emailHost ? *emailHost : helper::arrayElement(emailHosts)); } std::string exampleEmail(std::optional firstName, std::optional lastName) { - return FormatHelper::format("{}@{}", username(std::move(firstName), std::move(lastName)), + return common::format("{}@{}", username(std::move(firstName), std::move(lastName)), helper::arrayElement(emailExampleHosts)); } @@ -248,7 +248,7 @@ std::string ipv4(const IPv4Class& ipv4class) } } - return FormatHelper::format("{}.{}.{}.{}", sectors[0], sectors[1], sectors[2], sectors[3]); + return common::format("{}.{}.{}.{}", sectors[0], sectors[1], sectors[2], sectors[3]); } std::string ipv4(const std::array& baseIpv4Address, const std::array& generationMask) @@ -261,7 +261,7 @@ std::string ipv4(const std::array& baseIpv4Address, const std:: sectors[i] |= (baseIpv4Address[i] & generationMask[i]); } - return FormatHelper::format("{}.{}.{}.{}", sectors[0], sectors[1], sectors[2], sectors[3]); + return common::format("{}.{}.{}.{}", sectors[0], sectors[1], sectors[2], sectors[3]); } std::string ipv6() @@ -311,17 +311,17 @@ std::string url(const WebProtocol& webProtocol) { const auto protocol = webProtocol == WebProtocol::Https ? "https" : "http"; - return FormatHelper::format("{}://{}", protocol, domainName()); + return common::format("{}://{}", protocol, domainName()); } std::string domainName() { - return FormatHelper::format("{}.{}", domainWord(), domainSuffix()); + return common::format("{}.{}", domainWord(), domainSuffix()); } std::string domainWord() { - return common::toLower(FormatHelper::format("{}-{}", word::adjective(), word::noun())); + return common::toLower(common::format("{}-{}", word::adjective(), word::noun())); } std::string_view domainSuffix() @@ -343,7 +343,7 @@ std::string anonymousUsername(unsigned maxLength) const auto nounLength = maxLength - adjectiveLength; - return FormatHelper::format("{}{}", word::adjective(adjectiveLength), word::noun(nounLength)); + return common::format("{}{}", word::adjective(adjectiveLength), word::noun(nounLength)); } } diff --git a/src/modules/location/Location.cpp b/src/modules/location/Location.cpp index 5184c1c8f..cc46aa208 100644 --- a/src/modules/location/Location.cpp +++ b/src/modules/location/Location.cpp @@ -128,7 +128,7 @@ std::string city(AddressCountry country) {"citySuffix", [&countryAddresses]() { return static_cast(helper::arrayElement(countryAddresses.citySuffixes)); }}}; - return FormatHelper::fillTokenValues(cityFormat, dataGeneratorsMapping); + return common::fillTokenValues(cityFormat, dataGeneratorsMapping); } std::string zipCode(AddressCountry country) @@ -149,7 +149,7 @@ std::string streetAddress(AddressCountry country) const auto addressFormat = static_cast(helper::arrayElement(countryAddresses.addressFormats)); - return FormatHelper::fillTokenValues(addressFormat, dataGeneratorsMapping); + return common::fillTokenValues(addressFormat, dataGeneratorsMapping); } std::string street(AddressCountry country) @@ -168,7 +168,7 @@ std::string street(AddressCountry country) {"streetSuffix", [&countryAddresses]() { return static_cast(helper::arrayElement(countryAddresses.streetSuffixes)); }}}; - return FormatHelper::fillTokenValues(streetFormat, dataGeneratorsMapping); + return common::fillTokenValues(streetFormat, dataGeneratorsMapping); } std::string buildingNumber(AddressCountry country) @@ -200,14 +200,14 @@ std::string latitude(Precision precision) { const std::floating_point auto latitude = number::decimal(-90.0, 90.0); - return FormatHelper::precisionFormat(precision, latitude); + return common::precisionFormat(precision, latitude); } std::string longitude(Precision precision) { const std::floating_point auto longitude = number::decimal(-180.0, 180.0); - return FormatHelper::precisionFormat(precision, longitude); + return common::precisionFormat(precision, longitude); } std::string_view direction() diff --git a/src/modules/lorem/Lorem.cpp b/src/modules/lorem/Lorem.cpp index 395abed12..5b3566cc5 100644 --- a/src/modules/lorem/Lorem.cpp +++ b/src/modules/lorem/Lorem.cpp @@ -37,7 +37,7 @@ std::string sentence(unsigned minNumberOfWords, unsigned maxNumberOfWords) const auto sentenceWords = words(numberOfWords); - return FormatHelper::format("{}{}.", static_cast(std::toupper(sentenceWords[0])), sentenceWords.substr(1)); + return common::format("{}{}.", static_cast(std::toupper(sentenceWords[0])), sentenceWords.substr(1)); } std::string sentences(unsigned minNumberOfSentences, unsigned maxNumberOfSentences) diff --git a/src/modules/person/Person.cpp b/src/modules/person/Person.cpp index 042287399..5ac41f4a8 100644 --- a/src/modules/person/Person.cpp +++ b/src/modules/person/Person.cpp @@ -243,7 +243,7 @@ std::string fullName(std::optional countryOpt, std::optional sex) {"prefix", [&country, &sex]() { return std::string{prefix(country, sex)}; }}, {"suffix", [&country, &sex]() { return std::string{suffix(country, sex)}; }}}; - return FormatHelper::fillTokenValues(nameFormat, dataGeneratorsMapping); + return common::fillTokenValues(nameFormat, dataGeneratorsMapping); } std::string_view prefix(std::optional countryOpt, std::optional sex) @@ -330,7 +330,7 @@ std::string bio() {"noun", []() { return word::noun(); }}, {"emoji", []() { return internet::emoji(); }}}; - return FormatHelper::fillTokenValues(randomBioFormat, dataGeneratorsMapping); + return common::fillTokenValues(randomBioFormat, dataGeneratorsMapping); } std::string_view sex(std::optional languageOpt) @@ -360,7 +360,7 @@ std::string_view gender() std::string jobTitle() { - return FormatHelper::format("{} {} {}", jobDescriptor(), jobArea(), jobType()); + return common::format("{} {} {}", jobDescriptor(), jobArea(), jobType()); } std::string_view jobDescriptor() diff --git a/src/modules/string/String.cpp b/src/modules/string/String.cpp index 59318f73e..0fdbc0451 100644 --- a/src/modules/string/String.cpp +++ b/src/modules/string/String.cpp @@ -328,7 +328,7 @@ std::string hexadecimal(std::optional min, std::optional max) defaultMax = max.value(); } - return FormatHelper::format("{:x}", number::integer(defaultMin, defaultMax)); + return common::format("{:x}", number::integer(defaultMin, defaultMax)); } std::string hexadecimal(GuaranteeMap&& guarantee, unsigned int length, HexCasing casing, HexPrefix prefix) diff --git a/src/modules/system/System.cpp b/src/modules/system/System.cpp index 9d45f6f24..317cee8bd 100644 --- a/src/modules/system/System.cpp +++ b/src/modules/system/System.cpp @@ -176,7 +176,7 @@ std::string semver() const int minor = number::integer(9); const int patch = number::integer(9); - return FormatHelper::format("{}.{}.{}", major, minor, patch); + return common::format("{}.{}.{}", major, minor, patch); } std::string networkInterface(const std::optional& options) diff --git a/src/modules/vehicle/Vehicle.cpp b/src/modules/vehicle/Vehicle.cpp index 9949fce60..a125c1425 100644 --- a/src/modules/vehicle/Vehicle.cpp +++ b/src/modules/vehicle/Vehicle.cpp @@ -43,14 +43,14 @@ std::string_view type() std::string vehicleName() { - return FormatHelper::format("{} {}", manufacturer(), model()); + return common::format("{} {}", manufacturer(), model()); } std::string vin() { std::string exclude_characters{"oiqOIQ"}; - return FormatHelper::format("{}{}{}{}", string::alphanumeric(10, string::StringCasing::Upper, exclude_characters), + return common::format("{}{}{}{}", string::alphanumeric(10, string::StringCasing::Upper, exclude_characters), string::alpha(1, string::StringCasing::Upper, exclude_characters), string::alphanumeric(1, string::StringCasing::Upper, exclude_characters), number::integer(10000, 99999)); @@ -58,7 +58,7 @@ std::string vin() std::string vrm() { - return FormatHelper::format("{}{}{}", string::alpha(2, string::StringCasing::Upper), string::numeric(2, true), + return common::format("{}{}{}", string::alpha(2, string::StringCasing::Upper), string::numeric(2, true), string::alpha(3, string::StringCasing::Upper)); } diff --git a/tests/common/FormatHelperTest.cpp b/tests/common/FormatHelperTest.cpp index 7100dcc04..adf40c6d9 100644 --- a/tests/common/FormatHelperTest.cpp +++ b/tests/common/FormatHelperTest.cpp @@ -9,6 +9,7 @@ using namespace ::testing; using namespace faker; +using namespace faker::common; class FormatHelperTest : public Test { @@ -25,7 +26,7 @@ TEST_F(FormatHelperTest, fillFormatTokensData) {"cxx", []() { return "faker"; }}, {"library", []() { return "hello"; }}}; - const auto result = FormatHelper::fillTokenValues(format, dataGeneratorsMapping); + const auto result = fillTokenValues(format, dataGeneratorsMapping); const auto expectedResult = "library cxx-faker hello"; @@ -39,12 +40,12 @@ TEST_F(FormatHelperTest, givenTokensWithNotDefinedGenerator_shouldThrow) const auto dataGeneratorsMapping = std::unordered_map>{ {"hello", []() { return "library"; }}, {"faker", []() { return "cxx"; }}, {"cxx", []() { return "faker"; }}}; - ASSERT_THROW(FormatHelper::fillTokenValues(format, dataGeneratorsMapping), std::runtime_error); + ASSERT_THROW(fillTokenValues(format, dataGeneratorsMapping), std::runtime_error); } TEST_F(FormatHelperTest, shouldFormat) { - EXPECT_EQ(FormatHelper::format("{}", 1), "1"); - EXPECT_EQ(FormatHelper::format("{} {}", "Hello", "World"), "Hello World"); - EXPECT_EQ(FormatHelper::format("{0} {1}", "Hello", "World"), "Hello World"); + EXPECT_EQ(format("{}", 1), "1"); + EXPECT_EQ(format("{} {}", "Hello", "World"), "Hello World"); + EXPECT_EQ(format("{0} {1}", "Hello", "World"), "Hello World"); }