diff --git a/include/faker-cxx/Git.h b/include/faker-cxx/Git.h index 9371073ed..7e4aca73c 100644 --- a/include/faker-cxx/Git.h +++ b/include/faker-cxx/Git.h @@ -5,84 +5,79 @@ #include "faker-cxx/types/Country.h" -namespace faker +namespace faker::git { -class Git +struct Author { -public: - struct Author - { - std::string name; - std::string email; - }; + std::string name; + std::string email; +}; - /** - * @brief Returns a random branch name. - * - * @param maxIssueNum The maximum issue number in branch name. Defaults to `100`. - * @returns Branch name. - * - * @code - * Git::branch() // "capitalize-bus" - * @endcode - */ - static std::string branch(unsigned maxIssueNum = 100); +/** + * @brief Returns a random branch name. + * + * @param maxIssueNum The maximum issue number in branch name. Defaults to `100`. + * @returns Branch name. + * + * @code + * git::branch() // "capitalize-bus" + * @endcode + */ +std::string branch(unsigned maxIssueNum = 100); - /** - * @brief Generates a random date in form of string. - * - * @param years The range of years the date may be in the past. Defaults to `15`. - * @returns Commit date. - * - * @code - * Git::commitDate() // "Mon Jan 17 15:05:53 2022 +1100" - * @endcode - */ - static std::string commitDate(unsigned years = 15); +/** + * @brief Generates a random date in form of string. + * + * @param years The range of years the date may be in the past. Defaults to `15`. + * @returns Commit date. + * + * @code + * git::commitDate() // "Mon Jan 17 15:05:53 2022 +1100" + * @endcode + */ +std::string commitDate(unsigned years = 15); - /** - * @brief Generates a random commit entry in form of string. - * - * @param dateYears The range of years the date may be in the past. Defaults to `15`. - * @param shaLength The length of output SHA hash. Defaults to `40`. - * @param country The country set for name generating. Defaults to `England` (could be random, if there was a - random language generator). - * @returns Commit entry. - * - * @code - * Git::commitEntry() // "commit 9cbc41bb8ce0438c8de9cb25a1c6ad33441d8aca - Author: Rachel McLaughlin Rachel_McLaughlin@gmail.com - Date: Mon Jan 17 15:05:53 2022 +1100 +/** + * @brief Generates a random commit entry in form of string. + * + * @param dateYears The range of years the date may be in the past. Defaults to `15`. + * @param shaLength The length of output SHA hash. Defaults to `40`. + * @param country The country set for name generating. Defaults to `England` (could be random, if there was a + random language generator). + * @returns Commit entry. + * + * @code + * git::commitEntry() // "commit 9cbc41bb8ce0438c8de9cb25a1c6ad33441d8aca + Author: Rachel McLaughlin Rachel_McLaughlin@gmail.com + Date: Mon Jan 17 15:05:53 2022 +1100 - spawn polyp" - * @endcode - */ - static std::string commitEntry(std::optional dateYears = std::nullopt, - std::optional shaLength = std::nullopt, - Country country = Country::England); + spawn polyp" + * @endcode + */ +std::string commitEntry(std::optional dateYears = std::nullopt, + std::optional shaLength = std::nullopt, Country country = Country::England); - /** - * @brief Generates a random commit message. - * - * @returns Commit message. - * - * @code - * Git::commitMessage() // "spawn polyp" - * @endcode - */ - static std::string commitMessage(); +/** + * @brief Generates a random commit message. + * + * @returns Commit message. + * + * @code + * git::commitMessage() // "spawn polyp" + * @endcode + */ +std::string commitMessage(); - /** - * @brief Returns a random SHA hash. - * - * @param length The length of output SHA hash. Defaults to `40`. - * - * @returns SHA hash. - * - * @code - * Git::commitSha() // "9cbc41bb8ce0438c8de9cb25a1c6ad33441d8aca" - * @endcode - */ - static std::string commitSha(unsigned length = 40); -}; +/** + * @brief Returns a random SHA hash. + * + * @param length The length of output SHA hash. Defaults to `40`. + * + * @returns SHA hash. + * + * @code + * git::commitSha() // "9cbc41bb8ce0438c8de9cb25a1c6ad33441d8aca" + * @endcode + */ +std::string commitSha(unsigned length = 40); } diff --git a/src/modules/git/Git.cpp b/src/modules/git/Git.cpp index 1df887ab1..80f64b6b9 100644 --- a/src/modules/git/Git.cpp +++ b/src/modules/git/Git.cpp @@ -15,10 +15,10 @@ #include "faker-cxx/types/Hex.h" #include "faker-cxx/Word.h" -namespace faker +namespace faker::git { -std::string Git::branch(unsigned maxIssueNum) +std::string branch(unsigned maxIssueNum) { switch (Number::integer(1, 3)) { @@ -32,7 +32,7 @@ std::string Git::branch(unsigned maxIssueNum) } } -std::string Git::commitDate(unsigned years) +std::string commitDate(unsigned years) { const auto date = faker::date::pastDate(int(years)); @@ -74,10 +74,11 @@ std::string Git::commitDate(unsigned years) } return FormatHelper::format("{} {} {} {} {} {}", faker::date::weekdayAbbreviatedName(), - faker::date::monthAbbreviatedNames[size_t(std::stoi(month) - 1)], day, time, year, timeZoneString); + faker::date::monthAbbreviatedNames[size_t(std::stoi(month) - 1)], day, time, year, + timeZoneString); } -std::string Git::commitEntry(std::optional dateYears, std::optional shaLength, Country country) +std::string commitEntry(std::optional dateYears, std::optional shaLength, Country country) { std::string entry = "commit "; @@ -109,7 +110,7 @@ std::string Git::commitEntry(std::optional dateYears, std::optional branch = faker::StringHelper::split(Git::branch(testValue), "-"); + std::vector branchElements = StringHelper::split(branch(testValue), "-"); bool numberAtFront = false; @@ -57,10 +58,11 @@ TEST_F(GitTest, branchIssueNumTest) while (!numberAtFront) { - branch = faker::StringHelper::split(Git::branch(testValue), "-"); + branchElements = StringHelper::split(branch(testValue), "-"); + try { - number = std::stoi(branch[0]); + number = std::stoi(branchElements[0]); numberAtFront = true; } catch (...) @@ -76,7 +78,7 @@ TEST_F(GitTest, shouldGenerateCommitDate) { const std::regex dateRegex("^" + GitTest::DATE_REGEX + "$"); - ASSERT_TRUE(std::regex_match(Git::commitDate(), dateRegex)); + ASSERT_TRUE(std::regex_match(commitDate(), dateRegex)); } TEST_F(GitTest, shouldGenerateCommitEntry) @@ -85,14 +87,14 @@ TEST_F(GitTest, shouldGenerateCommitEntry) "\nAuthor: [A-Z][a-zA-Z]+ [A-Z][a-zA-Z]+ .+@[0-9a-zA-Z]+\\.[0-9a-zA-Z]+\nDate: " + GitTest::DATE_REGEX + "\n\n\t" + GitTest::MESSAGE_REGEX + "$"); - ASSERT_TRUE(std::regex_match(Git::commitEntry(), entryRegex)); + ASSERT_TRUE(std::regex_match(commitEntry(), entryRegex)); } TEST_F(GitTest, shouldGenerateCommitMessage) { const std::regex messageRegex("^" + GitTest::MESSAGE_REGEX + "$"); - const auto temp = Git::commitMessage(); + const auto temp = commitMessage(); ASSERT_TRUE(std::regex_match(temp, messageRegex)); } @@ -103,5 +105,5 @@ TEST_F(GitTest, shouldGenerateCommitSha) const std::regex shaRegex("^" + GitTest::generateShaRegex(length) + "$"); - ASSERT_TRUE(std::regex_match(Git::commitSha(length), shaRegex)); + ASSERT_TRUE(std::regex_match(commitSha(length), shaRegex)); }