Skip to content

Commit b610046

Browse files
committed
implement length checks for title
titles may not be too long nor too short, according to the requirements
1 parent 5c239a2 commit b610046

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

src/domain/title.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
using fix::domain::title;
44

5-
bool title::create(std::string_view) { // NOLINT
6-
return false;
5+
constexpr size_t MIN_LENGTH = 6;
6+
constexpr size_t MAX_LENGTH = 120;
7+
8+
bool title::create(std::string_view text) {
9+
return (text.length() >= MIN_LENGTH) && (text.length() <= MAX_LENGTH);
710
}

src/domain/title.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace fix::domain {
77

88
class title {
99
public:
10-
static bool create(std::string_view str);
10+
static bool create(std::string_view text);
1111
};
1212

1313
} // namespace fix::domain
File renamed without changes.

test/domain/title_test.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,30 @@
22

33
#include "title.hpp"
44

5+
#include <string>
6+
57
using fix::domain::title;
8+
using namespace std::literals;
9+
10+
constexpr size_t MIN_LENGTH = 6;
11+
constexpr size_t MAX_LENGTH = 120;
612

713
TEST_CASE("Titles have restricted length") {
814
SECTION("titles may not be empty") {
915
CHECK_FALSE(title::create(""));
1016
}
11-
12-
SECTION("titles may not be too short") {}
13-
SECTION("titles may not be too long") {}
14-
SECTION("titles with a length in the allowed range can be created") {}
17+
SECTION("titles may not be too short") {
18+
CHECK_FALSE(title::create("short"));
19+
}
20+
SECTION("titles may not be too long") {
21+
const auto long_scream = std::string(MAX_LENGTH, 'a') + "h"s;
22+
CHECK_FALSE(title::create(long_scream));
23+
}
24+
SECTION("titles with a length in the allowed range can be created") {
25+
const auto valid_string = GENERATE(std::string(MIN_LENGTH, 'n'), std::string(MAX_LENGTH, 'x'), "some title with sufficient length"s);
26+
const auto title = title::create(valid_string);
27+
CHECK(title);
28+
}
1529
}
1630

1731
TEST_CASE("Titles have a restricted character set") {

0 commit comments

Comments
 (0)