From f36227ace30678563164d695097688c461032b48 Mon Sep 17 00:00:00 2001 From: Guru Mehar Rachaputi Date: Mon, 8 Jul 2024 18:45:56 +0200 Subject: [PATCH] test: git testcase added (#793) * test: git testcase added - testcase added for git module for code coverage - modified commit date function to just return ISO date format Signed-off-by: Guru Mehar Rachaputi * refactor: git module - branch function in git module is modified for codecoverage Signed-off-by: Guru Mehar Rachaputi --------- Signed-off-by: Guru Mehar Rachaputi --- src/modules/git/Git.cpp | 63 +++++------------------------------ tests/modules/git/GitTest.cpp | 17 ++++++++-- 2 files changed, 24 insertions(+), 56 deletions(-) diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index d4838671..c7ffd698 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -20,12 +20,10 @@ namespace faker::git std::string branch(unsigned maxIssueNum) { - switch (number::integer(1, 3)) + switch (number::integer(1, 2)) { case 1: return common::format("{}-{}", word::verb(), word::noun()); - case 2: - return common::format("{}-{}-{}", word::verb(), word::adjective(), word::noun()); default: return common::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(), word::adjective(), word::noun()); @@ -34,57 +32,18 @@ std::string branch(unsigned maxIssueNum) std::string commitDate(unsigned years) { - const auto date = faker::date::pastDate(int(years)); + const std::string pastDate = faker::date::pastDate(int(years)); - const auto dateSplit = common::split(date, "-"); - - const auto& year = dateSplit[0]; - const auto& month = dateSplit[1]; - const auto& rest = dateSplit[2]; - - const auto restSplit = common::split(rest, "T"); - - const auto& day = restSplit[0]; - - const auto time = common::split(restSplit[1], "Z")[0]; - - int timeZone = number::integer(0, 12); - - std::string timeZoneString; - - if (number::integer(0, 1)) - { - timeZoneString += "-"; - } - else - { - timeZoneString += "+"; - } - - if (timeZone <= 9) - { - timeZoneString += "0"; - } - - timeZoneString += std::to_string(timeZone * 100); - - if (!timeZone) - { - timeZoneString += "00"; - } - - return common::format("{} {} {} {} {} {}", faker::date::weekdayAbbreviatedName(), - faker::date::monthAbbreviatedNames[size_t(std::stoi(month) - 1)], day, time, year, - timeZoneString); + return pastDate; } std::string commitEntry(std::optional dateYears, std::optional shaLength, Country country) { std::string entry = "commit "; - if (shaLength) + if (shaLength.value_or(0)) { - entry += commitSha(shaLength.emplace()); + entry += commitSha(shaLength.value_or(0)); } else { @@ -96,9 +55,9 @@ std::string commitEntry(std::optional dateYears, std::optional dateYears, std::optional