-
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.
To create issues, we need descriptions. Contrary to the requirements, I go for narrow strings for now.
- Loading branch information
Showing
5 changed files
with
60 additions
and
0 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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
set(DOMAIN_SOURCES | ||
application_service.cpp | ||
description.cpp | ||
domain_error.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "description.hpp" | ||
|
||
using namespace fix::domain; | ||
|
||
description::description(std::string_view text) : text{text} {} | ||
|
||
std::string const& description::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,21 @@ | ||
#ifndef FIX_SRC_DOMAIN_DESCRIPTION_HPP | ||
#define FIX_SRC_DOMAIN_DESCRIPTION_HPP | ||
|
||
#include <string> | ||
#include <string_view> | ||
|
||
#include "domain_error.hpp" | ||
|
||
namespace fix::domain { | ||
|
||
class description { | ||
std::string text; | ||
|
||
public: | ||
explicit description(std::string_view text); | ||
std::string const& to_string() const; | ||
}; | ||
|
||
} // namespace fix::domain | ||
|
||
#endif // FIX_SRC_DOMAIN_DESCRIPTION_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include "description.hpp" | ||
|
||
#include <string> | ||
#include <type_traits> | ||
|
||
using fix::domain::description; | ||
using namespace std::literals; | ||
|
||
TEST_CASE("Public construction of descriptions is only possible via copy, move") { | ||
STATIC_REQUIRE(std::is_copy_constructible_v<description>); | ||
STATIC_REQUIRE(std::is_move_constructible_v<description>); | ||
|
||
STATIC_REQUIRE_FALSE(std::is_default_constructible_v<description>); | ||
} | ||
|
||
TEST_CASE("Descriptions can be created from any string") { | ||
auto const description_text = GENERATE(""s, "any string"s, std::string(4000, '\1')); | ||
REQUIRE_NOTHROW(description{description_text}); | ||
} | ||
|
||
TEST_CASE("Descriptions can be converted back to strings") { | ||
auto const description_text = GENERATE( | ||
"some description"s, "the description:\n\t- line breaks are allowed\n\t- and other formatting as well"s); | ||
auto const the_description = description{description_text}; | ||
CHECK(the_description.to_string() == description_text); | ||
} |