C++Spec 1.0.0
BDD testing for C++
Loading...
Searching...
No Matches
match.hpp
Go to the documentation of this file.
1
2#pragma once
3#include <regex>
4#include <string>
5
7
8namespace CppSpec::Matchers {
9
10template <typename A>
11class Match : MatcherBase<A, std::regex> {
12 public:
13 explicit Match(Expectation<A>& expectation, std::string expected)
14 : MatcherBase<A, std::regex>(expectation, std::regex(expected)) {}
15
16 explicit Match(Expectation<A>& expectation, std::regex expected)
17 : MatcherBase<A, std::regex>(expectation, expected) {}
18
19 std::string verb() override { return "match"; }
20
21 bool match() override {
22 std::smatch temp_match;
23 return std::regex_match(this->actual(), temp_match, this->expected());
24 }
25};
26
27template <typename A>
28class MatchPartial : public MatcherBase<A, std::regex> {
29 public:
30 explicit MatchPartial(Expectation<A>& expectation, std::string expected)
31 : MatcherBase<A, std::regex>(expectation, std::regex(expected)) {}
32
33 explicit MatchPartial(Expectation<A>& expectation, std::regex expected)
34 : MatcherBase<A, std::regex>(expectation, expected) {}
35
36 std::string description() override { return "partially match " + Pretty::to_word(this->expected()); }
37
38 bool match() override { return std::regex_match(this->actual(), this->expected()); }
39};
40
41} // namespace CppSpec::Matchers
Wraps the target of an expectation.
Definition expectation.hpp:47
std::string description() override
Get the description of the Matcher.
Definition match.hpp:36
Definition have_error.hpp:9
Contains the base class for all Matchers.
static std::string to_word(const T &item)
Formats an object as a string when operator<< is available.
Definition pretty_matchers.hpp:122