Skip to content

Commit

Permalink
test: phone module testcase added
Browse files Browse the repository at this point in the history
* test case added to phone module for code coverage

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 committed Jul 24, 2024
1 parent b427d69 commit d102574
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
3 changes: 2 additions & 1 deletion include/faker-cxx/phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ enum class PhoneNumberCountryFormat
WesternSahara,
Yemen,
Zambia,
Zimbabwe
Zimbabwe,
Empty
};
}
4 changes: 2 additions & 2 deletions src/modules/phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ std::string phoneNumberByFormat(std::optional<std::string> format)

std::string phoneNumberByCountry(PhoneNumberCountryFormat format)
{
std::string countryFormat = phoneNumberFormatMap.at(format);
std::string countryFormat = (format == PhoneNumberCountryFormat::Empty)? "" : phoneNumberFormatMap.at(format);

if (countryFormat.empty())
{
return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);
countryFormat = phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);
}

return helper::replaceSymbolWithNumber(countryFormat);
Expand Down
2 changes: 1 addition & 1 deletion src/modules/phone_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ const auto phoneNumbers = std::to_array<std::string_view>({
"+212 (###) ####", // Western Sahara
"+967 (###) ###-####", // Yemen
"+260 (###) ###-####", // Zambia
"+263 (###) ####" // Zimbabwe
"+263 (###) ####", // Zimbabwe
});

}
10 changes: 10 additions & 0 deletions tests/modules/phone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ TEST_F(PhoneTest, NumberWithCountryFormat)
ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber));
}

TEST_F(PhoneTest, NumberWithEmptyCountryFormat)
{
const auto generatedPhoneNumber = phoneNumberByCountry(PhoneNumberCountryFormat::Empty);

std::cout << generatedPhoneNumber << std::endl;

EXPECT_FALSE(generatedPhoneNumber.empty());
ASSERT_TRUE(isStringNumericWithSpecialChars(generatedPhoneNumber));
}

TEST_F(PhoneTest, IMEIGeneration)
{
auto generatedImei = imei();
Expand Down

0 comments on commit d102574

Please sign in to comment.