Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: phone module testcase added #831

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions include/faker-cxx/phone.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ enum class PhoneNumberCountryFormat;
* @returns Random phone number based on country phone number template.
*
* @code
* faker::phone::number() // "234-532-654"
* faker::phone::number(PhoneNumberCountryFormat::Usa) // "+1 (395) 714-1494"
* @endcode
*/
FAKER_CXX_EXPORT std::string phoneNumberByCountry(PhoneNumberCountryFormat format);
FAKER_CXX_EXPORT std::string phoneNumberByCountry(std::optional<PhoneNumberCountryFormat> format = std::nullopt);

/**
* @brief Returns IMEI number.
Expand Down Expand Up @@ -325,6 +326,6 @@ enum class PhoneNumberCountryFormat
WesternSahara,
Yemen,
Zambia,
Zimbabwe
Zimbabwe,
};
}
13 changes: 7 additions & 6 deletions src/modules/phone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ std::string phoneNumberByFormat(std::optional<std::string> format)
return helper::replaceSymbolWithNumber(selectedFormat);
}

std::string phoneNumberByCountry(PhoneNumberCountryFormat format)
std::string phoneNumberByCountry(std::optional<PhoneNumberCountryFormat> format)
{
std::string countryFormat = phoneNumberFormatMap.at(format);
std::string countryFormat = (format)? phoneNumberFormatMap.at(*format) :
phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);;

if (countryFormat.empty())
{
return phoneNumberFormatMap.at(PhoneNumberCountryFormat::Default);
}
// if (countryFormat.empty())
// {
// return 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
});

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

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

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

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