diff --git a/include/faker-cxx/git.h b/include/faker-cxx/git.h index ed8255e2f..e1ad1f028 100644 --- a/include/faker-cxx/git.h +++ b/include/faker-cxx/git.h @@ -14,7 +14,7 @@ struct FAKER_CXX_EXPORT Author std::string email; }; -enum class BranchIssueNum +enum class BranchIssueType { WithoutIssueNumber, WithIssueNumber, @@ -23,7 +23,7 @@ enum class BranchIssueNum /** * @brief Returns a random branch name. * - * @param issueNum The optional issue number in branch name. + * @param issueType The optional branch issue type. * @param maxIssueNum The maximum issue number in branch name. Defaults to `100`. * * @returns Branch name. @@ -32,7 +32,8 @@ enum class BranchIssueNum * faker::git::branch() // "capitalize-bus" * @endcode */ -FAKER_CXX_EXPORT std::string branch(std::optional issueNum = std::nullopt, unsigned maxIssueNum = 100); +FAKER_CXX_EXPORT std::string branch(std::optional issueType = std::nullopt, + unsigned maxIssueNum = 100); /** * @brief Generates a random date in form of string. diff --git a/src/modules/git.cpp b/src/modules/git.cpp index ae89a2355..367f78d93 100644 --- a/src/modules/git.cpp +++ b/src/modules/git.cpp @@ -14,18 +14,18 @@ namespace faker::git { -std::string branch(std::optional issueNum, unsigned maxIssueNum) +std::string branch(std::optional issueType, unsigned maxIssueNum) { - const auto issue = issueNum ? *issueNum : BranchIssueNum::WithIssueNumber; + const auto targetIssueType = issueType ? *issueType : BranchIssueType::WithIssueNumber; std::string generatedBranch; - switch (issue) + switch (targetIssueType) { - case BranchIssueNum::WithoutIssueNumber: + case BranchIssueType::WithoutIssueNumber: generatedBranch = common::format("{}-{}", word::verb(), word::noun()); break; - case BranchIssueNum::WithIssueNumber: + case BranchIssueType::WithIssueNumber: generatedBranch = common::format("{}-{}-{}-{}", number::integer(unsigned(1), maxIssueNum), word::verb(), word::adjective(), word::noun()); break; diff --git a/tests/modules/git_test.cpp b/tests/modules/git_test.cpp index 49869feb7..909e8d7fc 100644 --- a/tests/modules/git_test.cpp +++ b/tests/modules/git_test.cpp @@ -50,30 +50,15 @@ TEST_F(GitTest, shouldGenerateBranch) TEST_F(GitTest, branchWithIssueNumTest) { - auto testValue = unsigned(number::integer(2, 100)); + const auto testValue = unsigned(number::integer(2, 100)); - std::vector branchElements; - - bool numberAtFront = false; - - int number; + const auto randomBranch = branch(BranchIssueType::WithIssueNumber, testValue); - while (!numberAtFront) - { - branchElements = common::split(branch(BranchIssueNum::WithIssueNumber, testValue), "-"); + const auto branchElements = common::split(randomBranch, "-"); - try - { - number = std::stoi(branchElements[0]); - numberAtFront = true; - } - catch (...) - { - continue; - } - } + const auto issueNumber = std::stoi(branchElements[0]); - ASSERT_TRUE(1 <= number && number <= int(testValue)); + ASSERT_TRUE(1 <= issueNumber && issueNumber <= int(testValue)); } TEST_F(GitTest, branchWithoutIssueNumTest) @@ -82,7 +67,7 @@ TEST_F(GitTest, branchWithoutIssueNumTest) std::vector branchElements; - branchElements = common::split(branch(BranchIssueNum::WithoutIssueNumber, testValue), "-"); + branchElements = common::split(branch(BranchIssueType::WithoutIssueNumber, testValue), "-"); const auto& generatedVerb = branchElements[0]; const auto& generatedNoun = branchElements[1];