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

fix: fix codecov config #801

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 7 additions & 10 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
comment: yes # do not comment PR with the result

coverage:
range: 50..90 # coverage lower than 50 is red, higher than 90 green, between color code

status:
project: # settings affecting project coverage
default:
target: auto # auto % coverage target
threshold: 5% # allow for 5% reduction of coverage without failing

# do not run coverage on patch nor changes
patch: false

range: 70..90
round: down
precision: 2

comment:
layout: diff, files
6 changes: 2 additions & 4 deletions src/modules/git/git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <string>

#include "common/format_helper.h"
#include "common/string_helper.h"
#include "../date/date_data.h"
#include "faker-cxx/date.h"
#include "faker-cxx/internet.h"
#include "faker-cxx/number.h"
Expand All @@ -25,8 +23,8 @@ std::string branch(unsigned maxIssueNum)
case 1:
return common::format("{}-{}", word::verb(), word::noun());
default:
return common::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(),
word::adjective(), word::noun());
return common::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(), word::adjective(),
word::noun());
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/modules/helper/helper.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@

#include <algorithm>
#include <random>
#include <regex>
#include <string>

#include "common/algo_helper.h"
#include "common/luhn_check.h"
#include "common/string_helper.h"
#include "common/algo_helper.h"
#include "faker-cxx/number.h"

namespace faker::helper
Expand Down Expand Up @@ -83,17 +82,15 @@ std::string regexpStyleStringParse(const std::string& input)
}

int repetitions = number::integer(min, max);
data = data.substr(0, static_cast<unsigned long>(token.position())) +
common::repeat(token[1], repetitions) +
data = data.substr(0, static_cast<unsigned long>(token.position())) + common::repeat(token[1], repetitions) +
data.substr(static_cast<unsigned long>(token.position() + token.length()));
}

// Deal with repeat `{num}`
while (std::regex_search(data, token, REP_REG))
{
int repetitions = std::stoi(token[2]);
data = data.substr(0, static_cast<unsigned long>(token.position())) +
common::repeat(token[1], repetitions) +
data = data.substr(0, static_cast<unsigned long>(token.position())) + common::repeat(token[1], repetitions) +
data.substr(static_cast<unsigned long>(token.position() + token.length()));
}

Expand Down
9 changes: 4 additions & 5 deletions src/modules/internet/internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <algorithm>
#include <array>
#include <cctype>
#include <initializer_list>
#include <map>
#include <optional>
Expand Down Expand Up @@ -96,12 +95,12 @@ std::string username(std::optional<std::string> firstName, std::optional<std::st
username = common::format("{}{}{}", firstNameLower, lastNameLower, number::integer<int>(1970, 2005));
break;
case 1:
username =
common::format("{}{}{}", firstNameLower, helper::arrayElement(std::vector<std::string>{".", "_", ""}), lastNameLower);
username = common::format("{}{}{}", firstNameLower,
helper::arrayElement(std::vector<std::string>{".", "_", ""}), lastNameLower);
break;
case 2:
username =
common::format("{}{}{}", lastNameLower, helper::arrayElement(std::vector<std::string>{".", "_", ""}), firstNameLower);
username = common::format("{}{}{}", lastNameLower, helper::arrayElement(std::vector<std::string>{".", "_", ""}),
firstNameLower);
break;
}

Expand Down
5 changes: 2 additions & 3 deletions src/modules/lorem/lorem.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#include "faker-cxx/lorem.h"

#include <algorithm>
#include <cctype>
#include <string>
#include <string_view>
#include <vector>
#include <algorithm>
#include <iterator>

#include "common/format_helper.h"
#include "common/string_helper.h"
Expand Down Expand Up @@ -62,7 +61,7 @@ std::string slug(unsigned int numberOfWords)
std::vector<std::string> wordList;
wordList.reserve(numberOfWords);

std::generate_n(std::back_inserter(wordList), numberOfWords, []{ return std::string(word());});
std::generate_n(std::back_inserter(wordList), numberOfWords, [] { return std::string(word()); });

return common::joinString(wordList, "-");
}
Expand Down
53 changes: 34 additions & 19 deletions src/modules/string/string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <stdexcept>
#include <string>

#include "common/format_helper.h"
#include "common/algo_helper.h"
#include "common/format_helper.h"
#include "faker-cxx/helper.h"
#include "faker-cxx/number.h"
#include "faker-cxx/types/hex.h"
Expand Down Expand Up @@ -96,21 +96,22 @@ bool isValidGuarantee(GuaranteeMap& guarantee, std::set<char>& targetCharacters,
{
unsigned int atleastCountSum{};
unsigned int atmostCountSum{};

for (auto& it : guarantee)
{
// if a char in guarantee is not in char set, it is an invalid guarantee
if (std::find(targetCharacters.begin(), targetCharacters.end(), it.first) == targetCharacters.end())
{
return false;
}
atleastCountSum += it.second.atLeastCount;
atmostCountSum += it.second.atMostCount;
}
// if atleastCount sums up greater than total length of string, it is an invalid guarantee
// if all chars in targetCharacters are mapped in guarantee, we need to check for validity of atmostCount
// if atmostCount sumps up less than total length of string, it in an invalid guarantee

if (atleastCountSum > length || (guarantee.size() == targetCharacters.size() && atmostCountSum < length))
{
return false;
}

return true;
}

Expand Down Expand Up @@ -139,11 +140,12 @@ std::string sample(unsigned int length)
std::string sample(GuaranteeMap&& guarantee, unsigned int length)
{
auto targetCharacters = utf16CharSet;
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

return generateStringWithGuarantee(guarantee, targetCharacters, length);
}

Expand All @@ -162,15 +164,17 @@ std::string fromCharacters(const std::string& characters, unsigned int length)
std::string fromCharacters(GuaranteeMap&& guarantee, const std::string& characters, unsigned length)
{
std::set<char> targetCharacters;

for (auto character : characters)
{
targetCharacters.insert(character);
}
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

return generateStringWithGuarantee(guarantee, targetCharacters, length);
}

Expand Down Expand Up @@ -201,11 +205,12 @@ std::string alpha(unsigned length, StringCasing casing, const std::string& exclu
std::string alpha(GuaranteeMap&& guarantee, unsigned int length, StringCasing casing)
{
auto targetCharacters = stringCasingToAlphaCharSetMapping.at(casing);
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

return generateStringWithGuarantee(guarantee, targetCharacters, length);
}

Expand Down Expand Up @@ -236,13 +241,16 @@ std::string alphanumeric(unsigned int length, StringCasing casing, const std::st
std::string alphanumeric(GuaranteeMap&& guarantee, unsigned length, StringCasing casing)
{
auto targetCharacters = digitSet;

auto charSet = stringCasingToAlphaCharSetMapping.at(casing);

targetCharacters.merge(charSet);
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

return generateStringWithGuarantee(guarantee, targetCharacters, length);
}

Expand All @@ -268,7 +276,6 @@ std::string numeric(unsigned int length, bool allowLeadingZeros)

std::string numeric(GuaranteeMap&& guarantee, const unsigned length, bool allowLeadingZeros)
{
// if leading zero not allowed, atleastCount of '0' cannot be equal to length
if (!allowLeadingZeros)
{
auto it = guarantee.find('0');
Expand All @@ -277,24 +284,29 @@ std::string numeric(GuaranteeMap&& guarantee, const unsigned length, bool allowL
throw std::invalid_argument{"Invalid guarantee."};
}
}

auto targetCharacters = digitSet;
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

if (allowLeadingZeros)
{
return generateStringWithGuarantee(guarantee, targetCharacters, length);
// if leading zero not allowed, pick first digit a non-zero
}
else
{
auto firstChar = std::to_string(number::integer(1, 9));

auto it = guarantee.find(firstChar[0]);

if (it != guarantee.end())
{
// decrement possible number of uses as we just used it as first char
--it->second.atMostCount;
}

return firstChar + generateStringWithGuarantee(guarantee, targetCharacters, length - 1);
}
}
Expand Down Expand Up @@ -336,30 +348,33 @@ std::string hexadecimal(std::optional<int> min, std::optional<int> max)
std::string hexadecimal(GuaranteeMap&& guarantee, unsigned int length, HexCasing casing, HexPrefix prefix)
{
std::set<char> targetCharacters = hexCasingToCharSetMapping.at(casing);
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

const auto& hexadecimalPrefix = hexPrefixToStringMapping.at(prefix);

return hexadecimalPrefix + generateStringWithGuarantee(guarantee, targetCharacters, length);
}

std::string binary(unsigned int length)
{
std::string binaryNumber;

for (unsigned int i = 0; i < length; ++i)
{
binaryNumber += static_cast<char>(number::integer(1));
}

return "0b" + binaryNumber;
}

std::string binary(GuaranteeMap&& guarantee, unsigned int length)
{
// numbers used by binary representation
std::set<char> targetCharacters{'0', '1'};
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
Expand All @@ -371,24 +386,24 @@ std::string binary(GuaranteeMap&& guarantee, unsigned int length)
std::string octal(unsigned int length)
{
std::string octalNumber;

for (unsigned int i = 0; i < length; ++i)
{
octalNumber += static_cast<char>(number::integer(7));
}

return "0o" + octalNumber;
}

std::string octal(GuaranteeMap&& guarantee, unsigned int length)
{
// numbers used by octal representation
std::set<char> targetCharacters{'0', '1', '2', '3', '4', '5', '6', '7'};
// throw if guarantee is invalid

if (!isValidGuarantee(guarantee, targetCharacters, length))
{
throw std::invalid_argument{"Invalid guarantee."};
}

return "0o" + generateStringWithGuarantee(guarantee, targetCharacters, length);
}

}
5 changes: 2 additions & 3 deletions tests/common/format_helper_test.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include "format_helper.h"

#include <functional>
#include <stdexcept>
#include <string>
#include <unordered_map>

#include "gtest/gtest.h"

#include "format_helper.h"

using namespace ::testing;
using namespace faker;
using namespace faker::common;
Expand Down
Loading