Skip to content

Commit

Permalink
add areacode functions (#522)
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-bodhi committed Apr 4, 2024
1 parent e998e8a commit dea3dc1
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
11 changes: 11 additions & 0 deletions include/faker-cxx/Phone.h
Expand Up @@ -83,6 +83,17 @@ class Phone
*/
static std::string imei();

/**
* @brief returns a random country area code
*
* @returns Random country area code
*
* @code
* Phone::areaCode() // "+1"
* @endcode
*/
static std::string areaCode();

private:
static std::map<PhoneNumberCountryFormat, std::string> createPhoneNumberFormatMap();
static std::map<PhoneNumberCountryFormat, std::string> phoneNumberFormatMap;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/phone/Phone.cpp
Expand Up @@ -2,6 +2,7 @@

#include <string>

#include "data/AreaCodes.h"
#include "data/PhoneData.h"
#include "data/PhoneNumbers.h"
#include "faker-cxx/Helper.h"
Expand Down Expand Up @@ -73,4 +74,9 @@ std::map<PhoneNumberCountryFormat, std::string> Phone::createPhoneNumberFormatMa

return formatMap;
}

std::string Phone::areaCode()
{
return Helper::arrayElement(faker::data::areaCodes);
}
}
10 changes: 9 additions & 1 deletion src/modules/phone/PhoneTest.cpp
Expand Up @@ -6,8 +6,9 @@

#include "gtest/gtest.h"

#include "data/AreaCodes.h"
#include "data/PhoneData.h"
#include "data/PhoneNumbers.h"

using namespace ::testing;
using namespace faker;

Expand Down Expand Up @@ -92,3 +93,10 @@ TEST_F(PhoneTest, ManufacturerGeneration)
[generatedManufacturer](const std::string& manufacturer)
{ return manufacturer == generatedManufacturer; }));
}

TEST_F(PhoneTest, AreaCodeGeneration)
{
std::string areaCode = Phone::areaCode();
ASSERT_TRUE(std::ranges::any_of(faker::data::areaCodes.begin(), faker::data::areaCodes.end(),
[areaCode](const std::string& code) { return code == areaCode; }));
}
30 changes: 30 additions & 0 deletions src/modules/phone/data/AreaCodes.h
@@ -0,0 +1,30 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
namespace data
{
const std::vector<std::string> areaCodes = {
"+1", "+144", "+20", "+210", "+211", "+212", "+213", "+214", "+215", "+216", "+217", "+218", "+219", "+220",
"+221", "+222", "+223", "+224", "+225", "+226", "+227", "+228", "+229", "+230", "+231", "+232", "+233", "+234",
"+235", "+236", "+237", "+238", "+239", "+240", "+241", "+242", "+243", "+244", "+245", "+246", "+247", "+248",
"+249", "+250", "+251", "+252", "+253", "+254", "+255", "+256", "+257", "+258", "+259", "+260", "+261", "+262",
"+263", "+264", "+265", "+266", "+267", "+268", "+269", "+27", "+28", "+290", "+291", "+292", "+293", "+294",
"+295", "+296", "+297", "+298", "+299", "+30", "+31", "+32", "+33", "+34", "+350", "+351", "+352", "+353",
"+354", "+355", "+356", "+357", "+358", "+359", "+36", "+370", "+371", "+373", "+374", "+375", "+377", "+38",
"+380", "+381", "+385", "+387", "+389", "+39", "+40", "+41", "+42", "+43", "+44", "+45", "+46", "+47",
"+48", "+49", "+500", "+501", "+502", "+503", "+504", "+505", "+506", "+507", "+508", "+509", "+51", "+52",
"+53", "+54", "+55", "+56", "+57", "+58", "+590", "+591", "+592", "+593", "+594", "+595", "+596", "+597",
"+598", "+599", "+60", "+61", "+62", "+63", "+64", "+65", "+66", "+670", "+671", "+672", "+673", "+674",
"+675", "+676", "+677", "+678", "+679", "+680", "+681", "+682", "+683", "+684", "+685", "+686", "+687", "+688",
"+689", "+690", "+691", "+692", "+7", "+808", "+809", "+81", "+82", "+84", "+850", "+852", "+853", "+855",
"+856", "+86", "+871", "+872", "+873", "+874", "+880", "+886", "+90 ", "+91", "+92", "+93", "+94", "+95",
"+960", "+961", "+962", "+963", "+964", "+965", "+966", "+967", "+968", "+969", "+971", "+972", "+973", "+974",
"+975", "+976", "+977", "+98", "+993", "+994", "+995",
};
}
}

0 comments on commit dea3dc1

Please sign in to comment.