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

Issue#452 #470

Merged
merged 9 commits into from
Jan 17, 2024
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ target_include_directories(
INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include"
PRIVATE "${CMAKE_CURRENT_LIST_DIR}/include")

if(APPLE)
if(APPLE OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_LESS 12))

add_subdirectory(externals/fmt)
set(FMT_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/externals/fmt/include")
target_link_libraries(${LIBRARY_NAME} PRIVATE fmt)
Expand All @@ -140,7 +142,10 @@ if(BUILD_FAKER_TESTS)
target_link_libraries(${LIBRARY_NAME}-UT PRIVATE gtest_main gmock_main
faker-cxx)

if(APPLE)
if(APPLE OR (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12))

target_link_libraries(${LIBRARY_NAME}-UT PRIVATE fmt)
target_include_directories(
${LIBRARY_NAME}-UT
PRIVATE ${FMT_INCLUDE_DIR} ${GTEST_INCLUDE_DIR}
Expand Down
4 changes: 2 additions & 2 deletions include/faker-cxx/Internet.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <array>
#include <optional>
#include <string>

#include "types/Country.h"
#include "types/EmojiType.h"

Expand Down Expand Up @@ -57,8 +58,7 @@ class Internet
* @endcode
*/
static std::string username(std::optional<std::string> firstName = std::nullopt,
std::optional<std::string> lastName = std::nullopt,
Country country = Country::Usa);
std::optional<std::string> lastName = std::nullopt, Country country = Country::Usa);

/**
* @brief Generates an email address using the given person's name as base.
Expand Down
3 changes: 2 additions & 1 deletion include/faker-cxx/types/AddressCountry.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace faker
Denmark,
Spain,
Brazil,
Finland
Finland,
Estonia
};

const std::vector<AddressCountry> addressCountries{
Expand Down
4 changes: 2 additions & 2 deletions src/common/FormatHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <vector>

#if defined(__APPLE__) || defined(__MINGW32__)
#if defined(__APPLE__) || defined(__MINGW32__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
#include <fmt/format.h>
#else
#include <format>
Expand All @@ -16,7 +16,7 @@ namespace faker
class FormatHelper
{
public:
#if defined(__APPLE__) || defined(__MINGW32__)
#if defined(__APPLE__) || defined(__MINGW32__) || (defined(__GNUC__) && (__GNUC__ < 12) && !defined(__clang__))
template <typename... Args>
static std::string format(fmt::format_string<Args...> fmt, Args&&... args)
{
Expand Down
3 changes: 3 additions & 0 deletions src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "faker-cxx/String.h"
#include "data/india/IndiaAddresses.h"
#include "data/denmark/DenmarkAddresses.h"
#include "data/estonia/EstoniaAddresses.h"

namespace faker
{
Expand All @@ -37,6 +38,7 @@ namespace faker
{AddressCountry::Australia, australiaAddresses}, {AddressCountry::India, indiaAddresses},
{AddressCountry::Denmark, denmarkAddresses}, {AddressCountry::Spain, spainAddresses},
{AddressCountry::Brazil, brazilAddresses}, {AddressCountry::Finland, finlandAddresses},
{AddressCountry::Estonia, estoniaAddresses},
};

const std::map<AddressCountry, Country> countryAddressToCountryMapping{
Expand All @@ -47,6 +49,7 @@ namespace faker
{AddressCountry::Australia, Country::Australia}, {AddressCountry::India, Country::India},
{AddressCountry::Denmark, Country::Denmark}, {AddressCountry::Spain, Country::Spain},
{AddressCountry::Brazil, Country::Brazil}, {AddressCountry::Finland, Country::Finland},
{AddressCountry::Estonia, Country::Estonia},
};
}

Expand Down
27 changes: 25 additions & 2 deletions src/modules/location/LocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include "../person/data/australia/AustralianLastNames.h"
#include "../person/data/finland/FinnishFirstNames.h"
#include "../person/data/finland/FinnishLastNames.h"
#include "../person/data/estonia/EstonianFirstNames.h"
#include "../person/data/estonia/EstonianLastNames.h"
#include "../string/data/Characters.h"
#include "data/Countries.h"
#include "data/CountryAddresses.h"
Expand All @@ -40,6 +42,7 @@
#include "data/spain/SpainAddresses.h"
#include "data/brazil/BrazilAddresses.h"
#include "data/finland/FinlandAddresses.h"
#include "data/estonia/EstoniaAddresses.h"

using namespace ::testing;
using namespace faker;
Expand All @@ -54,6 +57,7 @@ namespace
{AddressCountry::Australia, australiaAddresses}, {AddressCountry::India, indiaAddresses},
{AddressCountry::Denmark, denmarkAddresses}, {AddressCountry::Spain, spainAddresses},
{AddressCountry::Brazil, brazilAddresses}, {AddressCountry::Finland, finlandAddresses},
{AddressCountry::Estonia, estoniaAddresses},
};

const std::map<AddressCountry, std::string> generatedTestName{
Expand All @@ -71,6 +75,7 @@ namespace
{AddressCountry::Spain, "shouldGenerateSpainAddress"},
{AddressCountry::Brazil, "shouldGenerateBrazilAddress"},
{AddressCountry::Finland, "shouldGenerateFinlandAddress"},
{AddressCountry::Estonia, "shouldGenerateEstoniaAddress"},
};
}

Expand Down Expand Up @@ -701,7 +706,8 @@ TEST_F(LocationTest, shouldGenerateIndiaStreetAddress)
TEST_F(LocationTest, shouldGenerateDenmarkStreet)
{
const auto generatedStreet = Location::street(AddressCountry::Denmark);



ASSERT_TRUE(std::ranges::any_of(denmarkStreetNames, [&generatedStreet](const std::string& streetName)
{ return streetName == generatedStreet; }));
}
Expand Down Expand Up @@ -790,4 +796,21 @@ TEST_F(LocationTest, shouldGenerateFinlandStreetAddress)
{ return generatedStreetAddress.find(firstName) != std::string::npos; }) ||
std::ranges::any_of(lastNames, [&generatedStreetAddress](const std::string& lastName)
{ return generatedStreetAddress.find(lastName) != std::string::npos; }));
}
}


TEST_F(LocationTest, shouldGenerateEstoniaStreet)
{
const auto generatedStreet = Location::street(AddressCountry::Estonia);

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

TEST_F(LocationTest, shouldGenerateEstoniaStreetAddress)
{
const auto generatedStreetAddress = Location::streetAddress(AddressCountry::Estonia);

ASSERT_TRUE(std::ranges::any_of(estoniaStreetNames, [&generatedStreetAddress](const std::string& streetName)
{ return generatedStreetAddress.find(streetName) != std::string::npos; }));
}
35 changes: 35 additions & 0 deletions src/modules/location/data/estonia/EstoniaAddresses.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include "../CountryAddresses.h"
#include "EstoniaCities.h"
#include "EstoniaCounties.h"
#include "EstoniaStreetNames.h"
#include "EstoniaStreetSuffixes.h"

namespace faker {

const std::string estoniaZipCodeFormat{"#####"};

const std::vector<std::string> estoniaAddressFormats{"{street} {buildingNumber}"};

const std::vector<std::string> estoniaBuildingNumberFormats{"###", "##", "#"};

const std::vector<std::string> estoniaStreetFormats{"{streetName} {streetSuffix}"};

const std::vector<std::string> estoniaCityFormats{"{cityName}"};

const CountryAddresses estoniaAddresses{estoniaZipCodeFormat,
estoniaAddressFormats,
{},
estoniaStreetFormats,
{},
estoniaStreetNames,
estoniaStreetSuffixes,
estoniaBuildingNumberFormats,
estoniaCityFormats,
{},
estoniaCities,
{},
{},
estoniaCounties};
}
17 changes: 17 additions & 0 deletions src/modules/location/data/estonia/EstoniaCities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> estoniaCities{
"Tallinn",
"Tartu",
"Narva",
"Pärnu",
"Kohtla-Järve",

};

}
28 changes: 28 additions & 0 deletions src/modules/location/data/estonia/EstoniaCounties.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> estoniaCounties {

"Harju",
"Hiiu",
"Ida-Viru",
"Jõgeva",
"Järva",
"Lääne",
"Lääne-Viru",
"Põlva",
"Pärnu",
"Rapla",
"Saare",
"Tartu",
"Valga",
"Viljandi",
"Võru",

};

}
42 changes: 42 additions & 0 deletions src/modules/location/data/estonia/EstoniaStreetNames.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> estoniaStreetNames{
"Laagna",
"Punane",
"Paepargi",
"Pae",
"Peterburi",
"Valukoja",
"Betooni",
"Sõpruse",
"Mustamäe",
"Tuisu",
"Külmallika",
"Tammi",
"Koore",
"Kuubi",
"Okka",
"Vaba",
"Tähe",
"Õnne",
"Aleksandri",
"Kalevi",
"Turu",
"Tähe",
"Lina",
"Õnne",
"Era",
"Vanemuise",
"Tiigi",
"Tiigi",
"Juhan Liivi",
"K. A. Hermanni",
"Veski",
};

}
18 changes: 18 additions & 0 deletions src/modules/location/data/estonia/EstoniaStreetSuffixes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <string>
#include <vector>

namespace faker
{
const std::vector<std::string> estoniaStreetSuffixes {
"Tänav",
"tn",
"Tee",
"Allee",
"Plats",
"Käik",
"Põik",
};

}
Loading