Skip to content

Commit

Permalink
add description class
Browse files Browse the repository at this point in the history
To create issues, we need descriptions. Contrary to the requirements, I go for narrow strings for now.
  • Loading branch information
arnemertz committed Sep 3, 2021
1 parent 03fca41 commit b756c6e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/domain/CMakeLists.txt
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
)
Expand Down
9 changes: 9 additions & 0 deletions src/domain/description.cpp
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;
}
21 changes: 21 additions & 0 deletions src/domain/description.hpp
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
1 change: 1 addition & 0 deletions test/domain/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
set(DOMAIN_TEST_SOURCES
application_service_test.cpp
description_test.cpp
domain_error_test.cpp
title_test.cpp
)
Expand Down
28 changes: 28 additions & 0 deletions test/domain/description_test.cpp
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);
}

0 comments on commit b756c6e

Please sign in to comment.