Skip to content

Commit

Permalink
add location module (#50)
Browse files Browse the repository at this point in the history
* add address module

* add git submodule initialization in github workflow
  • Loading branch information
cieslarmichal authored Jul 17, 2023
1 parent 7a8044d commit 1c5317e
Show file tree
Hide file tree
Showing 48 changed files with 1,792 additions and 140 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/buildAndTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ jobs:
&& sudo launchpad-getkeys \
&& sudo apt-get update -y \
&& sudo apt-get install -y lld-16 ninja-build build-essential libstdc++-13-dev \
clang-16 clang-tools-16 llvm-16 lcov libgtest-dev
clang-16 clang-tools-16 llvm-16 lcov
- name: Initialize submodules
run: git submodule update --init --recursive

- name: Configure CMake
run: |
Expand Down
32 changes: 7 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED YES)

option(BUILD_TESTS DEFAULT ON)

if(MSVC)
if (MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /permissive-")
else()
else ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wconversion -Wformat -Werror")
endif()
endif ()

set(LIBRARY_NAME faker-cxx)

set(FAKER_HEADERS
include/faker-cxx/types/Country.h
include/faker-cxx/types/Hex.h
include/faker-cxx/types/Sex.h
include/faker-cxx/Book.h
include/faker-cxx/Color.h
include/faker-cxx/Commerce.h
include/faker-cxx/Company.h
include/faker-cxx/Datatype.h
include/faker-cxx/Date.h
include/faker-cxx/Finance.h
include/faker-cxx/Helper.h
include/faker-cxx/Internet.h
include/faker-cxx/Lorem.h
include/faker-cxx/Number.h
include/faker-cxx/Person.h
include/faker-cxx/String.h
include/faker-cxx/Word.h
)

set(FAKER_SOURCES
src/Book.cpp
src/Color.cpp
Expand All @@ -46,6 +26,7 @@ set(FAKER_SOURCES
src/Finance.cpp
src/Helper.cpp
src/Internet.cpp
src/Location.cpp
src/Lorem.cpp
src/Number.cpp
src/Person.cpp
Expand All @@ -63,6 +44,7 @@ set(FAKER_UT_SOURCES
src/DateTest.cpp
src/FinanceTest.cpp
src/InternetTest.cpp
src/LocationTest.cpp
src/LoremTest.cpp
src/NumberTest.cpp
src/PersonTest.cpp
Expand All @@ -71,13 +53,13 @@ set(FAKER_UT_SOURCES
src/WordTest.cpp
)

add_library(${LIBRARY_NAME} ${FAKER_SOURCES} ${FAKER_HEADERS})
add_library(${LIBRARY_NAME} ${FAKER_SOURCES})

target_include_directories(${LIBRARY_NAME}
INTERFACE
"${CMAKE_CURRENT_LIST_DIR}/include"
PRIVATE
${CMAKE_CURRENT_LIST_DIR}
"${CMAKE_CURRENT_LIST_DIR}/include"
)

if (BUILD_TESTS)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ target_link_libraries(main faker-cxx)
## 💎 Modules

- 🌐 Internet - Generate emails, usernames, passwords, images urls.
- 🌍 Location - Generate countries, cities, zip codes, street addresses.
- 🧑 Person - Generate first, last names, job titles, genders, sex.
- 🛒 Commerce - Generate commerce department, product name, sku, price.
- 📅 Date - Generate past, future dates.
Expand Down
25 changes: 12 additions & 13 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

### 🏦 Finance:

- [ ] support for more countries in Finance::iban()
- [ ] support for more countries in Finance::bic()
- [ ] support for more iban countries
- [ ] support for more bic countries
- [ ] credit card number
- [ ] credit card CVV
- [ ] bitcoin address
Expand All @@ -19,6 +19,7 @@
- [x] job title
- [x] job type
- [x] prefix
- [ ] locales

### 📞 Phone:

Expand Down Expand Up @@ -47,17 +48,14 @@

### 🌍 Location:

- [ ] building number
- [ ] city
- [ ] country
- [ ] country code
- [ ] latitude
- [ ] longitude
- [ ] state
- [ ] street
- [ ] street address
- [ ] time zone
- [ ] zip code
- [x] country
- [x] state
- [x] city
- [x] zip code
- [x] street
- [x] street address
- [x] building number
- [ ] locales

### 🖊️ Lorem:

Expand All @@ -84,6 +82,7 @@
- [x] buzz phrase
- [x] type
- [x] industry
- [ ] locales

### 👕 Commerce:

Expand Down
8 changes: 5 additions & 3 deletions include/faker-cxx/Finance.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <optional>
#include <string>

#include "faker-cxx/types/BicCountry.h"
#include "faker-cxx/types/IbanCountry.h"
#include "types/Country.h"

namespace faker
Expand Down Expand Up @@ -64,7 +66,7 @@ class Finance
* Finance::iban(IbanCountry::Poland) // "PL61109010140000071219812874"
* @endcode
*/
static std::string iban(std::optional<Country> country = std::nullopt);
static std::string iban(std::optional<IbanCountry> country = std::nullopt);

/**
* Generates a random bic.
Expand All @@ -75,10 +77,10 @@ class Finance
* @returns BIC.
*
* @code
* Finance::bic(IbanCountry::Poland) // "BREXPLPWMUL"
* Finance::bic(BicCountry::Poland) // "BREXPLPWMUL"
* @endcode
*/
static std::string bic(std::optional<Country> country = std::nullopt);
static std::string bic(std::optional<BicCountry> country = std::nullopt);

/**
* Generates a random account number.
Expand Down
100 changes: 100 additions & 0 deletions include/faker-cxx/Location.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#pragma once

#include <string>

#include "types/Country.h"

namespace faker
{
class Location
{
public:
/**
* @brief Returns a random country name.
*
* @returns Country name.
*
* @code
* Location::country() // "Poland"
* @endcode
*/
static std::string country();

/**
* @brief Returns a random USA state.
*
* @returns USA state.
*
* @code
* Location::state() // "Arizona"
* @endcode
*/
static std::string state();

/**
* @brief Returns a random city for given country.
*
* @param country The country to generate city from. Defaults to `Country::Usa`.
*
* @returns City.
*
* @code
* Location::city() // "Boston"
* @endcode
*/
static std::string city(Country country = Country::Usa);

/**
* @brief Returns a random zip code for given country.
*
* @param country The country to generate zip code from. Defaults to `Country::Usa`.
*
* @returns Zip code.
*
* @code
* Location::zipCode() // "47683-9880"
* Location::zipCode(Country::Poland) // "31-881"
* @endcode
*/
static std::string zipCode(Country country = Country::Usa);

/**
* @brief Returns a random street address for given country.
*
* @param country The country to generate street address from. Defaults to `Country::Usa`.
*
* @returns Street address including building number and street name.
*
* @code
* Location::streetAddress() // "34830 Erdman Hollow"
* @endcode
*/
static std::string streetAddress(Country country = Country::Usa);

/**
* @brief Returns a random street for given country.
*
* @param country The country to generate street from. Defaults to `Country::Usa`.
*
* @returns Street name.
*
* @code
* Location::street() // "Schroeder Isle"
* @endcode
*/
static std::string street(Country country = Country::Usa);

/**
* @brief Returns a random building number for given country.
*
* @param country The country to generate building number from. Defaults to `Country::Usa`.
*
* @returns Building number.
*
* @code
* Location::buildingNumber() // "505"
* @endcode
*/
static std::string buildingNumber(Country country = Country::Usa);
};
}
14 changes: 14 additions & 0 deletions include/faker-cxx/types/BicCountry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

#include <vector>

namespace faker
{
enum class BicCountry
{
Poland,
};

const std::vector<BicCountry> supportedBicCountries{BicCountry::Poland};

}
1 change: 1 addition & 0 deletions include/faker-cxx/types/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace faker
{
enum class Country
{
Usa,
Poland,
France,
Germany,
Expand Down
18 changes: 18 additions & 0 deletions include/faker-cxx/types/IbanCountry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <vector>

namespace faker
{
enum class IbanCountry
{
Poland,
France,
Germany,
Italy
};

const std::vector<IbanCountry> supportedIbanCountries{IbanCountry::Poland, IbanCountry::France, IbanCountry::Germany,
IbanCountry::Italy};

}
6 changes: 3 additions & 3 deletions src/Book.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "include/faker-cxx/Book.h"
#include "faker-cxx/Book.h"

#include "data/book/Authors.h"
#include "data/book/Genres.h"
#include "data/book/Publishers.h"
#include "data/book/Titles.h"
#include "include/faker-cxx/Helper.h"
#include "include/faker-cxx/String.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/String.h"

namespace faker
{
Expand Down
2 changes: 1 addition & 1 deletion src/BookTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "include/faker-cxx/Book.h"
#include "faker-cxx/Book.h"

#include "gtest/gtest.h"

Expand Down
8 changes: 4 additions & 4 deletions src/Color.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "include/faker-cxx/Color.h"
#include "faker-cxx/Color.h"

#include <format>
#include <sstream>

#include "data/Colors.h"
#include "include/faker-cxx/Helper.h"
#include "include/faker-cxx/Number.h"
#include "include/faker-cxx/String.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"
#include "faker-cxx/String.h"

namespace faker
{
Expand Down
2 changes: 1 addition & 1 deletion src/ColorTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "include/faker-cxx/Color.h"
#include "faker-cxx/Color.h"

#include "gtest/gtest.h"

Expand Down
8 changes: 4 additions & 4 deletions src/Commerce.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "include/faker-cxx/Commerce.h"
#include "faker-cxx/Commerce.h"

#include <format>

#include "data/Commerce.h"
#include "include/faker-cxx/Finance.h"
#include "include/faker-cxx/Helper.h"
#include "include/faker-cxx/String.h"
#include "faker-cxx/Finance.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/String.h"

namespace faker
{
Expand Down
2 changes: 1 addition & 1 deletion src/CommerceTest.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "include/faker-cxx/Commerce.h"
#include "faker-cxx/Commerce.h"

#include "gtest/gtest.h"

Expand Down
6 changes: 3 additions & 3 deletions src/Company.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "include/faker-cxx/Company.h"
#include "faker-cxx/Company.h"

#include <format>

Expand All @@ -11,8 +11,8 @@
#include "data/company/CompanyTypes.h"
#include "data/company/Industries.h"
#include "data/company/Suffixes.h"
#include "include/faker-cxx/Helper.h"
#include "include/faker-cxx/Person.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Person.h"

namespace faker
{
Expand Down
Loading

0 comments on commit 1c5317e

Please sign in to comment.