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

feat: added mexico location data #974

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/modules/location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ CountryAddressesInfo getAddresses(const Locale& locale)
return portugalAddresses;
case Locale::he_IL:
return israelAddresses;
case Locale::mx_MX:
return mexicoAddresses;
default:
return usaAddresses;
}
Expand Down
175 changes: 175 additions & 0 deletions src/modules/location_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -8060,6 +8060,181 @@ const CountryAddressesInfo italyAddresses{
(italyStates),
};

// Mexico

const auto mexicoCities = std::to_array<std::string_view>({
"Acapulco",
"Aguascalientes",
"Apizaco",
"Celaya",
"Chihuahua",
"Chilpancingo",
"Ciudad Juarez",
"Ciudad de Mexico",
"Colima",
"Cuernavaca",
"Culiacán",
"Delicias",
"Durango",
"Guadalajara",
"Guadalupe",
"Gomez Palacio",
"Hermosillo",
"Iguala",
"Irapuato",
"La Paz",
"León ato",
"Los Mochis",
"Mazatlán",
"Mérida",
"Mexicali",
"Minatitlán",
"Monterrey",
"Morelia",
"Nogales",
"Pachuca",
"Puebla".
"Puerto Vallarta",
"Querétaro",
"Reynosa",
"Rosarito",
"Saltillo",
"San Luis Potosí",
"San Nicolás de los Garza",
"San Pedro Garza García",
"Tapachula",
"Tepic",
"Tijuana",
"Toluca",
"Torreón",
"Tuxla Gutiérrez",
"Veracruz",
"Xalapa",
"Zacatecas",
"Zihuatanejo",
});

const auto mexicoStates = std::to_array<std::string_view>({
"Aguascalientes",
"Baja California",
"Baja California Sur",
"Campeche",
"Chiapas",
"Chihuahua",
"Coahuila",
"Colima",
"Durango",
"Guanajuato",
"Guerrero",
"Hidalgo",
"Jalisco",
"Ciudad de México (CDMX)",
"Michoacán",
"Morelos",
"Nayarit",
"Nuevo León",
"Oaxaca",
"Puebla",
"Querétaro",
"Quintana Roo",
"San Luis Potosí",
"Sinaloa",
"Sonora",
"Tabasco",
"Tamaulipas",
"Tlaxcala",
"Veracruz",
"Yucatán",
"Zacatecas",
});

const auto mexicoStreetNames = std::to_array<std::string_view>({
"Avenida Reforma",
"Avenida Insurgentes",
"Calle 5 de Febrero",
"Avenida Juárez",
"Calle Morelos",
"Calle Madero",
"Avenida de los Insurgentes",
"Avenida Zaragoza",
"Calle Hidalgo",
"Calle Prolongación Madero",
"Avenida Lázaro Cárdenas",
"Calle Benito Juárez",
"Calle Francisco I. Madero",
"Calle Pino Suárez",
"Avenida Tulum",
"Avenida México",
"Calle 16 de Septiembre",
"Calle Juárez",
"Avenida 20 de Noviembre",
"Calle Reforma",
"Avenida Veracruz",
"Calle Guerrero",
"Calle Oaxaca",
"Avenida 5 de Febrero",
"Avenida Constitución",
"Calle Lázaro Cárdenas",
"Calle Libertad",
"Calle Emiliano Zapata",
"Avenida Pino Suárez",
"Calle Ramon Ramirez",
"Avenida Independencia",
});

const auto mexicoStreetPrefixes =
std::to_array<std::string_view>({
"Calle",
"Avenida",
"Colonia",
"Paseo",
"Plaza",
});

const std::string_view mexicoZipCodeFormat{"#####"};

const auto mexicoAddressFormats =
std::to_array<std::string_view>({
"{street} {buildingNumber} {secondaryAddress}",
"{street} {buildingNumber})",
});

const auto mexicoSecondaryAddressFormats = std::to_array<std::string_view>({
"Piso. #",
"Apto. #",
});

const auto mexicoBuildingNumberFormats = std::to_array<std::string_view>({
"#",
"##",
"###",
});

const auto mexicoStreetFormats =
std::to_array<std::string_view>({
"{streetSuffix} {streetName}",
});

const auto mexicoCityFormats = std::to_array<std::string_view>({
"{cityName}",
});

const CountryAddressesInfo mexicoAddresses{
mexicoZipCodeFormat,
(mexicoAddressFormats),
(mexicoSecondaryAddressFormats),
(mexicoStreetFormats),
{},
{mexicoStreetNames},
(mexicoStreetSuffixes),
(mexicoBuildingNumberFormats),
(mexicoCityFormats),
{},
(mexicoCities),
{},
(mexicoStates),
};

// Poland

const auto polandCities = std::to_array<std::string_view>({
Expand Down
45 changes: 44 additions & 1 deletion tests/modules/location_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ CountryAddressesInfo getAddresses(const Locale& locale)
return portugalAddresses;
case Locale::he_IL:
return israelAddresses;
case Locale::mx_MX:
return mexicoAddresses;
default:
return usaAddresses;
}
Expand Down Expand Up @@ -1102,4 +1104,45 @@ TEST_F(LocationTest, shouldGenerateIsraelStreetAddress)
{ return streetPrefix == generatedStreetPrefix; }));
ASSERT_TRUE(std::ranges::any_of(israelStreetNames, [&generatedStreetName](const std::string_view& streetName)
{ return streetName == generatedStreetName; }));
}
}

TEST_F(LocationTest, shouldGenerateMexicoStreet)
{
const auto generatedStreet = street(Locale::mx_MX);

ASSERT_TRUE(std::ranges::any_of(mexicoStreetNames, [&generatedStreet](const std::string_view& street)
{ return generatedStreet.find(street) != std::string::npos; }));
}

TEST_F(LocationTest, shouldGenerateMexicoStreetAddress)
{
const auto generatedStreetAddress = streetAddress(Locale::mx_MX);

const auto generatedAddresses = common::split(generatedStreetAddress, ", ");
const auto generatedStreetAddressElements = common::split(generatedAddresses[0], " ");

const auto& generatedBuildingNumber = generatedStreetAddressElements[generatedStreetAddressElements.size() - 1];
const auto& generatedStreetSuffix = generatedStreetAddressElements[generatedStreetAddressElements.size() - 2];
const auto& generatedStreet =
common::join({generatedStreetAddressElements.begin(), generatedStreetAddressElements.end() - 2});

if (generatedAddresses.size() > 1)
{
const auto& generatedSecondaryAddressParts = common::split(generatedAddresses[1], " ");

const auto& generatedUnitNumber = generatedSecondaryAddressParts[generatedSecondaryAddressParts.size() - 1];

ASSERT_TRUE(generatedUnitNumber.size() == 1 || generatedUnitNumber.size() == 3);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedUnitNumber));
}

ASSERT_TRUE(!generatedBuildingNumber.empty() && generatedBuildingNumber.size() <= 3);
ASSERT_TRUE(checkIfAllCharactersAreNumeric(generatedBuildingNumber));

ASSERT_TRUE(std::ranges::any_of(mexicoStreetNames, [&generatedStreet](const std::string_view& streetName)
{ return generatedStreet.find(streetName) != std::string::npos; }));

ASSERT_TRUE(std::ranges::any_of(mexicoStreetSuffixes,
[&generatedStreetSuffix](const std::string_view& streetSuffix)
{ return generatedStreetSuffix.find(streetSuffix) != std::string::npos; }));
}
Loading