Skip to content

Commit b756c6e

Browse files
committed
add description class
To create issues, we need descriptions. Contrary to the requirements, I go for narrow strings for now.
1 parent 03fca41 commit b756c6e

5 files changed

Lines changed: 60 additions & 0 deletions

File tree

src/domain/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(DOMAIN_SOURCES
22
application_service.cpp
3+
description.cpp
34
domain_error.cpp
45
title.cpp
56
)

src/domain/description.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include "description.hpp"
2+
3+
using namespace fix::domain;
4+
5+
description::description(std::string_view text) : text{text} {}
6+
7+
std::string const& description::to_string() const {
8+
return text;
9+
}

src/domain/description.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef FIX_SRC_DOMAIN_DESCRIPTION_HPP
2+
#define FIX_SRC_DOMAIN_DESCRIPTION_HPP
3+
4+
#include <string>
5+
#include <string_view>
6+
7+
#include "domain_error.hpp"
8+
9+
namespace fix::domain {
10+
11+
class description {
12+
std::string text;
13+
14+
public:
15+
explicit description(std::string_view text);
16+
std::string const& to_string() const;
17+
};
18+
19+
} // namespace fix::domain
20+
21+
#endif // FIX_SRC_DOMAIN_DESCRIPTION_HPP

test/domain/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
set(DOMAIN_TEST_SOURCES
22
application_service_test.cpp
3+
description_test.cpp
34
domain_error_test.cpp
45
title_test.cpp
56
)

test/domain/description_test.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <catch2/catch.hpp>
2+
3+
#include "description.hpp"
4+
5+
#include <string>
6+
#include <type_traits>
7+
8+
using fix::domain::description;
9+
using namespace std::literals;
10+
11+
TEST_CASE("Public construction of descriptions is only possible via copy, move") {
12+
STATIC_REQUIRE(std::is_copy_constructible_v<description>);
13+
STATIC_REQUIRE(std::is_move_constructible_v<description>);
14+
15+
STATIC_REQUIRE_FALSE(std::is_default_constructible_v<description>);
16+
}
17+
18+
TEST_CASE("Descriptions can be created from any string") {
19+
auto const description_text = GENERATE(""s, "any string"s, std::string(4000, '\1'));
20+
REQUIRE_NOTHROW(description{description_text});
21+
}
22+
23+
TEST_CASE("Descriptions can be converted back to strings") {
24+
auto const description_text = GENERATE(
25+
"some description"s, "the description:\n\t- line breaks are allowed\n\t- and other formatting as well"s);
26+
auto const the_description = description{description_text};
27+
CHECK(the_description.to_string() == description_text);
28+
}

0 commit comments

Comments
 (0)