-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add issue_id class with generation algorithm
- the cass is needed to create issues - the algorithm belongs at least close to the issue_id class - the algorithm does _not_ belong to the application service
- Loading branch information
Showing
8 changed files
with
103 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ set(DOMAIN_SOURCES | |
application_service.cpp | ||
description.cpp | ||
domain_error.cpp | ||
issue_id.cpp | ||
title.cpp | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include "issue_id.hpp" | ||
|
||
#include <range/v3/range/conversion.hpp> | ||
#include <range/v3/view.hpp> | ||
|
||
using namespace fix::domain; | ||
using namespace std::literals; | ||
namespace rv = ranges::views; | ||
|
||
issue_id::issue_id(std::string text) : text{std::move(text)} {} | ||
|
||
issue_id issue_id::generate(title const& title, description const& description) { | ||
(void)description; | ||
// clang-format off | ||
const auto id_prefix = title.to_string() | ||
| rv::split(' ') | ||
| rv::take(4) | ||
| rv::transform([](auto&& word) { | ||
return word | rv::take(3) | rv::transform([](char c){ return std::tolower(c); }); | ||
}) | ||
| rv::join('-') | ||
| ranges::to<std::string>; | ||
// clang-format on | ||
return issue_id{id_prefix + "-0000000"s}; | ||
} | ||
|
||
std::string const& issue_id::to_string() const { | ||
return text; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef FIX_SRC_DOMAIN_ISSUE_ID_HPP | ||
#define FIX_SRC_DOMAIN_ISSUE_ID_HPP | ||
|
||
#include "description.hpp" | ||
#include "title.hpp" | ||
|
||
namespace fix::domain { | ||
|
||
class issue_id { | ||
std::string text; | ||
|
||
explicit issue_id(std::string text); | ||
|
||
public: | ||
// move-only; rule of 5 | ||
issue_id(issue_id const&) = delete; | ||
issue_id(issue_id&&) = default; | ||
issue_id& operator=(issue_id const&) = delete; | ||
issue_id& operator=(issue_id&&) = default; | ||
~issue_id() = default; | ||
|
||
static issue_id generate(title const& title, description const& description); | ||
|
||
// cppcheck-suppress functionStatic | ||
std::string const& to_string() const; | ||
}; | ||
|
||
} // namespace fix::domain | ||
|
||
#endif // FIX_SRC_DOMAIN_ISSUE_ID_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include "issue_id.hpp" | ||
|
||
#include <string> | ||
|
||
#include "description.hpp" | ||
#include "title.hpp" | ||
|
||
using namespace fix::domain; | ||
using namespace std::literals; | ||
|
||
TEST_CASE("Issue IDs can be moved, but not default-constructed or copied") { | ||
STATIC_REQUIRE(std::is_move_constructible_v<issue_id>); | ||
|
||
STATIC_REQUIRE_FALSE(std::is_copy_assignable_v<issue_id>); | ||
STATIC_REQUIRE_FALSE(std::is_copy_constructible_v<issue_id>); | ||
STATIC_REQUIRE_FALSE(std::is_default_constructible_v<issue_id>); | ||
} | ||
|
||
TEST_CASE("Issue ID is contains abbreviated first words of the title") { | ||
auto const& [the_title, the_description, id_prefix] = GENERATE( | ||
std::tuple(title::create("this is a new issue"), description{"some text"}, "thi-is-a-new"), | ||
std::tuple(title::create("My first issue in Fix"), description{"Dorem Fixum dolor sit amet"}, "my-fir-iss-in")); | ||
|
||
REQUIRE(the_title); | ||
|
||
auto const id_pattern = id_prefix + "-[0-9a-f]{7}"s; | ||
CHECK_THAT(issue_id::generate(the_title.value(), the_description).to_string(), Catch::Matches(id_pattern)); | ||
} |