Skip to content

Commit

Permalink
first commit (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaScant authored Oct 15, 2024
1 parent 0d34cfe commit 96f15b0
Showing 1 changed file with 31 additions and 30 deletions.
61 changes: 31 additions & 30 deletions tests/modules/person_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,22 +625,22 @@ TEST_F(PersonPassportTest, shouldGenerateRomanianPassport)

bool checkTokenFormat(const std::string& bio)
{
const std::regex firstRegex{R"(^(\w+\s?\w+)$)"};
const std::regex secondRegex{R"(^(\w+\s?\w+), (\w+\s?\w+)$)"};
const std::regex thirdRegex{R"(^(\w+\s?\w+), (\w+\s?\w+), (\w+\s?\w+)$)"};
const std::regex fourthRegex{R"(^(\w+\s?\w+), (\w+\s?\w+), (\w+\s?\w+), (\S+)$)"};
const std::regex fifthRegex{R"(^(\w+\-?\w+) (\w+)$)"};
const std::regex sixthRegex{R"(^(\w+\-?\w+) (\w+) (\S+)$)"};
const std::regex seventhRegex{R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+)$)"};
const std::regex eightRegex{R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+) (\S+)$)"};
const std::regex firstRegex(R"(^(\w+\s?\w+)$)");
const std::regex secondRegex(R"(^(\w+\s?\w+), (\w+\s?\w+)$)");
const std::regex thirdRegex(R"(^(\w+\s?\w+), (\w+\s?\w+), (\w+\s?\w+)$)");
const std::regex fourthRegex(R"(^(\w+\s?\w+), (\w+\s?\w+), (\w+\s?\w+), (\S+)$)");
const std::regex fifthRegex(R"(^(\w+\-?\w+) (\w+)$)");
const std::regex sixthRegex(R"(^(\w+\-?\w+) (\w+) (\S+)$)");
const std::regex seventhRegex(R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+)$)");
const std::regex eightRegex(R"(^(\w+\-?\w+) (\w+), (\w+\s?\w+) (\S+)$)");

std::smatch matches;
//
if (std::regex_match(bio, matches, firstRegex))
{
// In this case the bio is in the format {bio_part} so check that the value is present in the bio_part
// vector.
if (std::find(bioParts.begin(), bioParts.end(), std::string{matches[0]}) != bioParts.end())
if (std::find(bioParts.begin(), bioParts.end(), std::string(matches[0])) != bioParts.end())
{
return true;
}
Expand All @@ -650,8 +650,8 @@ bool checkTokenFormat(const std::string& bio)
{
// In this case the bio is in the format {bio_part}, {bio_part} so check that the value is present in the
// bio_part vector.
if (std::find(bioParts.begin(), bioParts.end(), std::string{matches[1]}) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[2]}) != bioParts.end())
if (std::find(bioParts.begin(), bioParts.end(), std::string(matches[1])) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[2])) != bioParts.end())
{
return true;
}
Expand All @@ -661,60 +661,61 @@ bool checkTokenFormat(const std::string& bio)
{
// In this case the bio is in the format {bio_part}, {bio_part}, {bio_part} so check that the value is
// present in the bio_part vector.
if (std::find(bioParts.begin(), bioParts.end(), std::string{matches[1]}) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[2]}) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[3]}) != bioParts.end())
if (std::find(bioParts.begin(), bioParts.end(), std::string(matches[1])) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[2])) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[3])) != bioParts.end())
return true;
}

if (std::regex_match(bio, matches, fourthRegex))
{
// In this case the bio is in the format {bio_part}, {bio_part}, {bio_part}, {emoji} so check that the value
// is present in the bio_part vector.
if (std::find(bioParts.begin(), bioParts.end(), std::string{matches[1]}) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[2]}) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[3]}) != bioParts.end() &&
internet::checkIfEmojiIsValid(std::string{matches[4]}))
if (std::find(bioParts.begin(), bioParts.end(), std::string(matches[1])) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[2])) != bioParts.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[3])) != bioParts.end() &&
internet::checkIfEmojiIsValid(std::string(matches[4])))
return true;
}

if (std::regex_match(bio, matches, fifthRegex))
{
// In this case the bio is in the format {noun} {bio_supporter} so check that the value is present
// in the bio_part vector.
if (std::find(word::nouns.begin(), word::nouns.end(), std::string{matches[1]}) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string{matches[2]}) != bioSupporters.end())
if (std::find(word::nouns.begin(), word::nouns.end(), std::string(matches[1])) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string(matches[2])) != bioSupporters.end())
return true;
}

if (std::regex_match(bio, matches, sixthRegex))
{
// In this case the bio is in the format {noun} {bio_supporter} {emoji} so check that the value is present
// in the bio_part vector.
if (std::find(word::nouns.begin(), word::nouns.end(), std::string{matches[1]}) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string{matches[2]}) != bioSupporters.end() &&
internet::checkIfEmojiIsValid(std::string{matches[3]}))
if (std::find(word::nouns.begin(), word::nouns.end(), std::string(matches[1])) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string(matches[2])) != bioSupporters.end() &&
internet::checkIfEmojiIsValid(std::string(matches[3])))
return true;
}


if (std::regex_match(bio, matches, seventhRegex))
{
// In this case the bio is in the format {noun} {bio_supporter}, {bio_part} so check that the value is
// present in the bio_part vector.
if (std::find(word::nouns.begin(), word::nouns.end(), std::string{matches[1]}) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string{matches[2]}) != bioSupporters.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[3]}) != bioParts.end())
if (std::find(word::nouns.begin(), word::nouns.end(), std::string(matches[1])) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string(matches[2])) != bioSupporters.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[3])) != bioParts.end())
return true;
}

if (std::regex_match(bio, matches, eightRegex))
{
// In this case the bio is in the format {noun} {bio_supporter}, {bio_part} {emoji} so check that the value
// is present in the bio_part vector.
if (std::find(word::nouns.begin(), word::nouns.end(), std::string{matches[1]}) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string{matches[2]}) != bioSupporters.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string{matches[3]}) != bioParts.end() &&
internet::checkIfEmojiIsValid(std::string{matches[4]}))
if (std::find(word::nouns.begin(), word::nouns.end(), std::string(matches[1])) != word::nouns.end() &&
std::find(bioSupporters.begin(), bioSupporters.end(), std::string(matches[2])) != bioSupporters.end() &&
std::find(bioParts.begin(), bioParts.end(), std::string(matches[3])) != bioParts.end() &&
internet::checkIfEmojiIsValid(std::string(matches[4])))
return true;
}

Expand Down

0 comments on commit 96f15b0

Please sign in to comment.