Skip to content

Commit

Permalink
Merge branch 'main' into albania_people_names
Browse files Browse the repository at this point in the history
  • Loading branch information
MikelKokoshi authored Nov 23, 2023
2 parents 779d44d + 28cd5e9 commit 27d5599
Show file tree
Hide file tree
Showing 27 changed files with 1,086 additions and 102 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ build-linux-gxx
build-linux-clang
#clangd index files
.cache/
#vim swap files
*.sw?
68 changes: 68 additions & 0 deletions docs/apple_clang++_compilation_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

# Building from Sources with Clang 16 on macOS

This guide provides instructions on how to build from sources using Clang 16 on a macOS system.

## 1. Install Clang 16

Clang is part of the LLVM project and can be installed on macOS using Homebrew, a popular package manager.

First, ensure you have Homebrew installed. If not, install Homebrew by running the following in the Terminal:

```bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

Then, install LLVM (which includes Clang) with:

```bash
brew install llvm@16
```

## 2. Prepare Build Directory

Clone the desired repository and set up the build environment:

```bash
git clone https://github.com/cieslarmichal/faker-cxx.git
cd faker-cxx
git submodule update --init --recursive
mkdir build
cd build
```

## 3. CMake Setup with Clang 16

Before proceeding, ensure CMake is installed. If not, install it using Homebrew:

```bash
brew install cmake
```

Then, set up CMake for building with Clang 16:

```bash
cmake .. -DCMAKE_CXX_COMPILER=/opt/homebrew/opt/llvm@16/bin/clang++
```

⚠️ **Warning:** Ensure that the path `/opt/homebrew/opt/llvm@16/bin/clang++` is valid on your system. If this path is not correct, replace it with the correct path to your Clang 16 compiler. You can find the correct path by using the command `brew --prefix llvm@16`. Adjust the CMake command accordingly.

## 4. Build

Finally, build the project:

```bash
make
```

## 5. Run

After building, you can run the built executable:

```bash
./faker-cxx-UT
```

---

**Note:** This guide assumes a standard installation of Homebrew and the default paths it uses. If your Homebrew or LLVM installation paths are different, you will need to adjust the commands accordingly. Remember that paths and specific commands might vary depending on your system configuration and the versions of the tools installed.
9 changes: 8 additions & 1 deletion include/faker-cxx/Internet.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ enum class IPv4Class
C
};

struct PasswordOptions {
bool upperLetters = true;
bool lowerLetters = true;
bool numbers = true;
bool symbols = true;
};

class Internet
{
public:
Expand Down Expand Up @@ -100,7 +107,7 @@ class Internet
* Internet::password(25) // "xv8vDu*wM!Rg0$zd0kH%8p!WY"
* @endcode
*/
static std::string password(int length = 15);
static std::string password(int length = 15, PasswordOptions options = {});

/**
* @brief Returns a random emoji.
Expand Down
34 changes: 33 additions & 1 deletion include/faker-cxx/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ std::string generateAtleastString(const GuaranteeMap& guarantee);

class String
{
private:
static std::string generateStringWithGuarantee(GuaranteeMap& guarantee, std::set<char>& targetCharacters,
unsigned int length);

public:
/**
* @brief Generates an Universally Unique Identifier with version 4.
Expand Down Expand Up @@ -232,7 +236,21 @@ class String
* String::binary(8) // "0b01110101"
* @endcode
*/
static std::string binary(GuaranteeMap&& guarantee = {}, unsigned length = 1);
static std::string binary(unsigned length = 1);

/**
* @brief Generates a binary string.
*
* @param guarantee A map specifying char count constraints if any
* @param length The number of digits to generate. Defaults to `1`.
*
* @returns Binary string.
*
* @code
* String::binary({'1',{7,8}}, 8) // "0b11110111"
* @endcode
*/
static std::string binary(GuaranteeMap&& guarantee, unsigned length = 1);

/**
* @brief Generates an octal string.
Expand All @@ -246,5 +264,19 @@ class String
* @endcode
*/
static std::string octal(unsigned length = 1);

/**
* @brief Generates an octal string.
*
* @param guarantee A map specifying char count constraints if any
* @param length The number of digits to generate. Defaults to `1`.
*
* @returns Octal string.
*
* @code
* String::octal({'4',{4,5}}, 8) // "0o42444041"
* @endcode
*/
static std::string octal(GuaranteeMap&& guarantee, unsigned length = 1);
};
}
11 changes: 10 additions & 1 deletion include/faker-cxx/types/Country.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ enum class Country
Serbia,
Macedonia,
Albania,
Latvia,
Ireland,
Belarus,
Estonia,
};

const std::vector<Country> countries{
Expand All @@ -57,7 +61,8 @@ const std::vector<Country> countries{
Country::Japan, Country::Portugal, Country::Hungary, Country::Croatia, Country::Greece,
Country::Slovenia, Country::Austria, Country::Switzerland, Country::Belgium, Country::Nederlands,
Country::China, Country::Korea, Country::Canada, Country::Mexico, Country::Argentina,
Country::Australia, Country::Serbia, Country::Macedonia, Country::Albania,
Country::Australia, Country::Serbia, Country::Macedonia, Country::Albania, Country::Latvia, Country::Ireland,
Country::Belarus, Country::Estonia,
};

inline std::string toString(Country country)
Expand Down Expand Up @@ -102,6 +107,10 @@ inline std::string toString(Country country)
{Country::Serbia, "Serbia"},
{Country::Macedonia, "Macedonia"},
{Country::Albania, "Albania"},
{Country::Latvia, "Latvia"},
{Country::Ireland, "Ireland"},
{Country::Belarus, "Belarus"},
{Country::Estonia, "Estonia"},
};

return countryToStringMapping.at(country);
Expand Down
25 changes: 18 additions & 7 deletions src/modules/internet/Internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "faker-cxx/String.h"
#include "faker-cxx/Word.h"
#include "fmt/format.h"
#include "../string/data/Characters.h"

namespace faker
{
Expand Down Expand Up @@ -93,16 +94,26 @@ std::string Internet::exampleEmail(std::optional<std::string> firstName, std::op
Helper::arrayElement<std::string>(emailExampleHosts));
}

std::string Internet::password(int length)
std::string Internet::password(int length, PasswordOptions options)
{
const std::string passwordCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~`!@#$%^&*()_-+={[}]|:;\"'<,>.?/";
std::string characters;

std::string password;
if (options.upperLetters) {
characters += faker::upperCharacters;
}
if (options.lowerLetters) {
characters += faker::lowerCharacters;
}
if (options.numbers) {
characters += faker::numericCharacters;
}
if (options.symbols) {
characters += faker::symbolCharacters;
}

for (int i = 0; i < length; i++)
{
password += Helper::arrayElement<char>(passwordCharacters);
std::string password;
for (int i = 0; i < length; ++i) {
password += Helper::arrayElement<char>(characters);
}

return password;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/person/Person.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "data/argentina/ArgentinianPeopleNames.h"
#include "data/australia/AustralianPeopleNames.h"
#include "data/austria/AustrianPeopleNames.h"
#include "data/belarus/BelarusianPeopleNames.h"
#include "data/belgium/BelgianPeopleNames.h"
#include "data/brazil/BrazilianPeopleNames.h"
#include "data/canada/CanadianPeopleNames.h"
Expand All @@ -17,6 +18,7 @@
#include "data/czech/CzechPeopleNames.h"
#include "data/denmark/DanishPeopleNames.h"
#include "data/england/EnglishPeopleNames.h"
#include "data/estonia/EstonianPeopleNames.h"
#include "data/finland/FinnishPeopleNames.h"
#include "data/france/FrenchPeopleNames.h"
#include "data/Gender.h"
Expand All @@ -25,11 +27,13 @@
#include "data/Hobbies.h"
#include "data/hungary/HungarianPeopleNames.h"
#include "data/india/IndianPeopleNames.h"
#include "data/ireland/IrishPeopleNames.h"
#include "data/italy/ItalianPeopleNames.h"
#include "data/japan/JapanesePeopleNames.h"
#include "data/JobTitles.h"
#include "data/korea/KoreanPeopleNames.h"
#include "data/Languages.h"
#include "data/latvia/LatvianPeopleNames.h"
#include "data/macedonia/MacedonianPeopleNames.h"
#include "data/mexico/MexicanPeopleNames.h"
#include "data/Nationalities.h"
Expand Down Expand Up @@ -79,6 +83,8 @@ const std::map<Country, PeopleNames> countryToPeopleNamesMapping{
{Country::Canada, canadianPeopleNames}, {Country::Mexico, mexicanPeopleNames},
{Country::Argentina, argentinianPeopleNames}, {Country::Australia, australianPeopleNames},
{Country::Serbia, serbianPeopleNames}, {Country::Macedonia, macedonianPeopleNames},
{Country::Latvia, latvianPeopleNames}, {Country::Ireland, irishPeopleNames},
{Country::Belarus, belarusianPeopleNames}, {Country::Estonia, estonianPeopleNames},
{Country::Albania, albanianPeopleNames},
};

Expand Down
10 changes: 9 additions & 1 deletion src/modules/person/PersonTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
#include "data/argentina/ArgentinianPeopleNames.h"
#include "data/australia/AustralianPeopleNames.h"
#include "data/austria/AustrianPeopleNames.h"
#include "data/belarus/BelarusianPeopleNames.h"
#include "data/belgium/BelgianPeopleNames.h"
#include "data/canada/CanadianPeopleNames.h"
#include "data/china/ChinesePeopleNames.h"
#include "data/croatia/CroatianPeopleNames.h"
#include "data/czech/CzechPeopleNames.h"
#include "data/denmark/DanishPeopleNames.h"
#include "data/england/EnglishPeopleNames.h"
#include "data/estonia/EstonianPeopleNames.h"
#include "data/finland/FinnishPeopleNames.h"
#include "data/france/FrenchPeopleNames.h"
#include "data/Gender.h"
Expand All @@ -24,11 +26,13 @@
#include "data/Hobbies.h"
#include "data/hungary/HungarianPeopleNames.h"
#include "data/india/IndianPeopleNames.h"
#include "data/ireland/IrishPeopleNames.h"
#include "data/italy/ItalianPeopleNames.h"
#include "data/japan/JapanesePeopleNames.h"
#include "data/JobTitles.h"
#include "data/korea/KoreanPeopleNames.h"
#include "data/Languages.h"
#include "data/latvia/LatvianPeopleNames.h"
#include "data/macedonia/MacedonianPeopleNames.h"
#include "data/mexico/MexicanPeopleNames.h"
#include "data/Nationalities.h"
Expand Down Expand Up @@ -79,7 +83,9 @@ const std::map<Country, PeopleNames> countryToPeopleNamesMapping{
{Country::Canada, canadianPeopleNames}, {Country::Mexico, mexicanPeopleNames},
{Country::Argentina, argentinianPeopleNames}, {Country::Australia, australianPeopleNames},
{Country::Serbia, serbianPeopleNames}, {Country::Macedonia, macedonianPeopleNames},
{Country::Albania, albanianPeopleNames},
{Country::Latvia, latvianPeopleNames}, {Country::Ireland, irishPeopleNames},
{Country::Belarus, belarusianPeopleNames}, {Country::Estonia, estonianPeopleNames},
{Country::Albania, albanianPeopleNames},
};

const std::map<Country, std::string> generatedTestName{
Expand All @@ -102,6 +108,8 @@ const std::map<Country, std::string> generatedTestName{
{Country::Canada, "shouldGenerateCanadianName"}, {Country::Mexico, "shouldGenerateMexicanName"},
{Country::Argentina, "shouldGenerateArgentinianName"}, {Country::Australia, "shouldGenerateAustralianName"},
{Country::Serbia, "shouldGenerateSerbianName"}, {Country::Macedonia, "shouldGenerateMacedonianName"},
{Country::Latvia, "shouldGenerateLatvianName"}, {Country::Ireland, "shouldGenerateIrishName"},
{Country::Belarus, "shouldGenerateBelarusianName"}, {Country::Estonia, "shouldGenerateEstonianName"},
{Country::Albania, "shouldGenerateAlbanianName"},
};
}
Expand Down
Loading

0 comments on commit 27d5599

Please sign in to comment.