Skip to content

Commit d9f6820

Browse files
committed
Fix copy construtors and expectation_spec
1 parent 049dc65 commit d9f6820

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

include/expectations/expectation.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Expectation : public Child {
3838

3939
public:
4040
Expectation(Expectation const &copy)
41-
: // Child(((Expectation)copy).get_parent())
41+
: Child(copy.get_parent()),
4242
target(copy.target),
4343
block(copy.block),
4444
has_block(copy.has_block),

include/matchers/basematcher.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ class BaseMatcher : public Runnable, public Pretty {
2222
Expectation<Actual> expectation;
2323

2424
public:
25+
BaseMatcher(BaseMatcher<Actual, Expected> const &copy)
26+
: Runnable(copy.get_parent()),
27+
message(copy.message),
28+
expected(copy.expected),
29+
expectation(copy.expectation){};
30+
2531
BaseMatcher(Expectation<Actual> &expectation)
2632
: Runnable(*expectation.get_parent()), // We want the parent of the
2733
// matcher to be the `it` block,

include/runnable.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Child {
3434
public:
3535
Child(){};
3636
explicit Child(Child* parent) : parent(parent){};
37+
explicit Child(const Child* parent) : parent(const_cast<Child*>(parent)){};
3738
explicit Child(Child& parent) : parent(&parent){};
3839

3940
/**
@@ -44,6 +45,7 @@ class Child {
4445

4546
/** @brief Get the Child's parent. */
4647
Child* get_parent() { return parent; }
48+
const Child* get_parent() const { return const_cast<Child*>(parent); }
4749

4850
/** @brief Set the Child's parent */
4951
void set_parent(Child* parent) { this->parent = parent; }
@@ -79,6 +81,8 @@ class Runnable : public Child {
7981
public:
8082
Runnable(){};
8183
explicit Runnable(Child& parent) : Child(parent){};
84+
explicit Runnable(Child* parent) : Child(parent){};
85+
explicit Runnable(const Child* parent) : Child(parent){};
8286
virtual bool run() = 0;
8387
};
8488

spec/expectations/expectation_spec.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
// Very simple int<=>int custom matcher
44
struct CustomMatcher : public Matchers::BaseMatcher<int, int> {
5-
CustomMatcher(CustomMatcher const &copy)
6-
: Matchers::BaseMatcher<int,int>(((CustomMatcher)copy).get_expectation(),
7-
((CustomMatcher)copy).get_expected()){};
85
CustomMatcher(Expectations::Expectation<int> &expectation, int expected)
96
: Matchers::BaseMatcher<int,int>(expectation, expected){};
107
bool match() { return get_expected() == get_actual(); }
@@ -14,7 +11,7 @@ describe expectation_spec("Expectation", $ {
1411
context("Extensible .to", _ {
1512
it("accepts a custom BaseMatcher subclass", _ {
1613
auto e = expect(2);
17-
e.to(CustomMatcher(e, 4));
14+
e.to(CustomMatcher(e, 2));
1815
});
1916
});
2017
});

0 commit comments

Comments
 (0)