Skip to content

Commit

Permalink
fix: make examples compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp committed Sep 20, 2024
1 parent 1999c0f commit 44c8c62
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 53 deletions.
20 changes: 10 additions & 10 deletions examples/Finalizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TEST_CASE(
mimicpp::Mock<int()> mock{};

SCOPED_EXP mock.expect_call()
| finally::returns(42);
and finally::returns(42);

REQUIRE(42 == mock());
//! [finally::returns]
Expand All @@ -38,7 +38,7 @@ TEST_CASE(

int myReturn{42};
SCOPED_EXP mock.expect_call()
| finally::returns(std::ref(myReturn));
and finally::returns(std::ref(myReturn));

REQUIRE(&myReturn == &mock());
//! [finally::returns std::ref]
Expand All @@ -56,8 +56,8 @@ TEST_CASE(
mimicpp::Mock<int&()> mock{};

SCOPED_EXP mock.expect_call()
| expect::twice() // we call the mock two times
| finally::returns(42);
and expect::twice() // we call the mock two times
and finally::returns(42);

int& result = mock();
REQUIRE(42 == result); // fine
Expand All @@ -78,7 +78,7 @@ TEST_CASE(
mimicpp::Mock<int()> mock{};

SCOPED_EXP mock.expect_call()
| finally::throws(std::runtime_error{"Something happened."});
and finally::throws(std::runtime_error{"Something happened."});

REQUIRE_THROWS_AS(
mock(),
Expand All @@ -97,7 +97,7 @@ TEST_CASE(
mimicpp::Mock<std::string()> mock{};

SCOPED_EXP mock.expect_call()
| finally::returns_result_of([] { return "Hello, World!"; });
and finally::returns_result_of([] { return "Hello, World!"; });

REQUIRE("Hello, World!" == mock());
//! [finally::returns_result_of]
Expand All @@ -114,7 +114,7 @@ TEST_CASE(
mimicpp::Mock<int(int, int)> mock{};

SCOPED_EXP mock.expect_call(1337, 42)
| finally::returns_arg<1>();
and finally::returns_arg<1>();

REQUIRE(42 == mock(1337, 42));
//! [finally::returns_param]
Expand All @@ -131,7 +131,7 @@ TEST_CASE(
mimicpp::Mock<int(int, int)> mock{};

SCOPED_EXP mock.expect_call(1337, 42)
| finally::returns_apply_result_of<0, 1>(std::plus{});
and finally::returns_apply_result_of<0, 1>(std::plus{});

REQUIRE(1379 == mock(1337, 42));
//! [finally::returns_apply_result_of]
Expand All @@ -148,7 +148,7 @@ TEST_CASE(
mimicpp::Mock<int(int, int)> mock{};

SCOPED_EXP mock.expect_call(1337, 42)
| finally::returns_apply_all_result_of(std::plus{});
and finally::returns_apply_all_result_of(std::plus{});

REQUIRE(1379 == mock(1337, 42));
//! [finally::returns_apply_all_result_of]
Expand All @@ -172,7 +172,7 @@ TEST_CASE(
mimicpp::Mock<int()> mock{};

SCOPED_EXP mock.expect_call()
| MyFinalizer{};
and MyFinalizer{};

REQUIRE(1337 == mock());
//! [custom finalizer]
Expand Down
14 changes: 7 additions & 7 deletions examples/Mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ TEST_CASE(
SECTION("Throws, when inner container is empty.")
{
SCOPED_EXP innerContainer.empty.expect_call()
| expect::times(2) // we test both, the const and non-const top() overload
| finally::returns(true);
and expect::times(2) // we test both, the const and non-const top() overload
and finally::returns(true);

MyStack<int, ContainerMock> stack{std::move(innerContainer)};

Expand All @@ -130,12 +130,12 @@ TEST_CASE(
SECTION("Returns a reference to the top element otherwise.")
{
SCOPED_EXP innerContainer.empty.expect_call()
| finally::returns(false);
and finally::returns(false);

SECTION("A const-ref, when accessed via const.")
{
SCOPED_EXP std::as_const(innerContainer).back.expect_call()
| finally::returns(42);
and finally::returns(42);

MyStack<int, ContainerMock> stack{std::move(innerContainer)};

Expand All @@ -145,7 +145,7 @@ TEST_CASE(
SECTION("A mutable ref, when accessed via non-const.")
{
SCOPED_EXP innerContainer.back.expect_call()
| finally::returns(42);
and finally::returns(42);

MyStack<int, ContainerMock> stack{std::move(innerContainer)};

Expand All @@ -162,7 +162,7 @@ TEST_CASE(
{
ContainerMock innerContainer{};
SCOPED_EXP innerContainer.empty.expect_call()
| finally::returns(true);
and finally::returns(true);

MyStack<int, ContainerMock> stack{std::move(innerContainer)};
REQUIRE_THROWS_AS(stack.pop(), std::runtime_error);
Expand All @@ -172,7 +172,7 @@ TEST_CASE(
{
ContainerMock innerContainer{};
SCOPED_EXP innerContainer.empty.expect_call()
| finally::returns(false);
and finally::returns(false);
SCOPED_EXP innerContainer.pop_back.expect_call();

MyStack<int, ContainerMock> container{std::move(innerContainer)};
Expand Down
12 changes: 6 additions & 6 deletions examples/Requirements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ TEST_CASE(
mimicpp::Mock<void(int)> mock{};

SCOPED_EXP mock.expect_call(_)
| expect::arg<0>(matches::gt(42));
and expect::arg<0>(matches::gt(42));
mock(1337);
//! [expect::arg]
}
Expand All @@ -80,7 +80,7 @@ TEST_CASE(
mimicpp::Mock<void(int)> mock{};

SCOPED_EXP mock.expect_call(le(1337))
| expect::arg<0>(matches::gt(42));
and expect::arg<0>(matches::gt(42));
mock(1337);
}

Expand All @@ -97,7 +97,7 @@ TEST_CASE(
mimicpp::Mock<void(int)> mock{};

SCOPED_EXP mock.expect_call(_) // in fact, the _ is the only built-in matcher, which isn't invertible
| expect::arg<0>(!matches::le(42)); // note the !, as this makes it an actual > test
and expect::arg<0>(!matches::le(42)); // note the !, as this makes it an actual > test
mock(1337);
//! [matcher inverted]
}
Expand All @@ -117,7 +117,7 @@ TEST_CASE(
constexpr auto isOdd = [](int val) { return 0 != val % 2; };

SCOPED_EXP mock.expect_call(_)
| expect::arg<0>(matches::predicate(isOdd));
and expect::arg<0>(matches::predicate(isOdd));
mock(1337);
//! [matcher predicate]
}
Expand All @@ -135,7 +135,7 @@ TEST_CASE(
mimicpp::Mock<void(std::span<int>)> mock{};

SCOPED_EXP mock.expect_call(_)
| expect::arg<0>(matches::range::is_sorted());
and expect::arg<0>(matches::range::is_sorted());

std::vector collection{42, 1337};
mock(collection);
Expand Down Expand Up @@ -169,7 +169,7 @@ TEST_CASE(
mimicpp::Mock<void(std::span<int>)> mock{};

SCOPED_EXP mock.expect_call(_)
| expect::arg<0>(containsMatcher);
and expect::arg<0>(containsMatcher);

std::vector collection{42, 1337};
mock(collection);
Expand Down
30 changes: 15 additions & 15 deletions examples/Sequences.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ TEST_CASE(

mimicpp::SequenceT sequence{};
SCOPED_EXP mock.expect_call(matches::ne(0))
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);
SCOPED_EXP mock.expect_call(matches::le(42))
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);

// a call with arg != 0 is expected before a call with arg <= 42
mock(42); // matches the first expectation
Expand All @@ -47,9 +47,9 @@ TEST_CASE(

mimicpp::SequenceT sequence{};
SCOPED_EXP mock2.expect_call(_) // mock2 must go first
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);
SCOPED_EXP mock1.expect_call(_) // mock1 must go second
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);

mock2(42);
mock1(1337);
Expand All @@ -73,12 +73,12 @@ TEST_CASE(

mimicpp::SequenceT sequence{};
SCOPED_EXP mock.expect_call(1337) // (3)
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);

SCOPED_EXP mock.expect_call(1337); // (4)

SCOPED_EXP mock.expect_call(42) // (5)
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);

mock(42); // matches (1), because (5) is the second element of the sequence
mock(1337); // matches (4), because it's the "youngest" available alternative
Expand All @@ -102,11 +102,11 @@ TEST_CASE(
mimicpp::SequenceT sequence1{};
mimicpp::SequenceT sequence2{};
SCOPED_EXP mock.expect_call() // (1)
| expect::in_sequence(sequence1);
and expect::in_sequence(sequence1);
SCOPED_EXP mock.expect_call() // (2)
| expect::in_sequences(sequence1, sequence2);
and expect::in_sequences(sequence1, sequence2);
SCOPED_EXP mock.expect_call() // (3)
| expect::in_sequence(sequence2);
and expect::in_sequence(sequence2);

mock(); // (1) is used here, because (3) is second in sequence2 and (2) is second in sequence1
mock(); // (2) is used here, because it's the first in both sequences now
Expand All @@ -127,10 +127,10 @@ TEST_CASE(

mimicpp::LazySequence sequence{};
SCOPED_EXP mock.expect_call() // (1)
| expect::in_sequence(sequence)
| expect::at_most(1);
and expect::in_sequence(sequence)
and expect::at_most(1);
SCOPED_EXP mock.expect_call() // (2)
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);

mock(); // matches (1)
mock(); // matches (2)
Expand All @@ -150,10 +150,10 @@ TEST_CASE(

mimicpp::GreedySequence sequence{};
SCOPED_EXP mock.expect_call() // (1)
| expect::in_sequence(sequence)
| expect::at_most(1);
and expect::in_sequence(sequence)
and expect::at_most(1);
SCOPED_EXP mock.expect_call() // (2)
| expect::in_sequence(sequence);
and expect::in_sequence(sequence);

mock(); // matches (2)
// no further call possible, because that would be out of sequence and will lead to an inapplicable match report!
Expand Down
18 changes: 9 additions & 9 deletions examples/SideEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_CASE(

std::string outText{};
SCOPED_EXP mock.expect_call(42)
| then::invoke([&] { outText = "Hello, mimic++!"; });
and then::invoke([&] { outText = "Hello, mimic++!"; });

mock(42);

Expand All @@ -36,7 +36,7 @@ TEST_CASE(

int value{42};
SCOPED_EXP mock.expect_call(42)
| then::apply_arg<0>([](auto& v) { v = 1337; });
and then::apply_arg<0>([](auto& v) { v = 1337; });

mock(value);

Expand All @@ -54,8 +54,8 @@ TEST_CASE(

int value{42};
SCOPED_EXP mock.expect_call(42)
| then::apply_arg<0>([](auto& v) { v = 1337; })
| then::apply_arg<0>([](auto& v) { v = (v == 1337 ? -1337 : -42); });
and then::apply_arg<0>([](auto& v) { v = 1337; })
and then::apply_arg<0>([](auto& v) { v = (v == 1337 ? -1337 : -42); });

mock(value);

Expand All @@ -73,9 +73,9 @@ TEST_CASE(

int outResult{};
SCOPED_EXP mock.expect_call(0, 1, 2)
| then::apply_args<1, 2, 0>( // note the index order:
// outResult is invoked as left-most param, but applied as right-most
[](int lhs, int rhs, int& out) { out = lhs + rhs; });
and then::apply_args<1, 2, 0>( // note the index order:
// outResult is invoked as left-most param, but applied as right-most
[](int lhs, int rhs, int& out) { out = lhs + rhs; });

mock(outResult, 1, 2);

Expand All @@ -93,8 +93,8 @@ TEST_CASE(

int outResult{};
SCOPED_EXP mock.expect_call(0, 42)
| then::apply_args<1, 1, 0>( // note the indices: second param is applied twice
[](int lhs, int rhs, int& out) { out = lhs + rhs; });
and then::apply_args<1, 1, 0>( // note the indices: second param is applied twice
[](int lhs, int rhs, int& out) { out = lhs + rhs; });

mock(outResult, 42);

Expand Down
12 changes: 6 additions & 6 deletions examples/Times.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ TEST_CASE(

mimicpp::Mock<void()> mock{};
SCOPED_EXP mock.expect_call()
| expect::once();
and expect::once();

mock();
//! [once]
Expand All @@ -34,7 +34,7 @@ TEST_CASE(

mimicpp::Mock<void()> mock{};
SCOPED_EXP mock.expect_call()
| expect::twice();
and expect::twice();

mock(); // not enough
mock(); // fine!
Expand All @@ -51,7 +51,7 @@ TEST_CASE(

mimicpp::Mock<void()> mock{};
SCOPED_EXP mock.expect_call()
| expect::at_least(2u);
and expect::at_least(2u);

mock(); // not enough
mock(); // fine
Expand All @@ -69,7 +69,7 @@ TEST_CASE(

mimicpp::Mock<void()> mock{};
SCOPED_EXP mock.expect_call()
| expect::at_most(2u);
and expect::at_most(2u);

mock(); // fine
mock(); // fine but exhausted!
Expand All @@ -86,7 +86,7 @@ TEST_CASE(

mimicpp::Mock<void()> mock{};
SCOPED_EXP mock.expect_call()
| expect::times(2u); // equivalent to twice()
and expect::times(2u); // equivalent to twice()

mock(); // not enough
mock(); //fine
Expand All @@ -103,7 +103,7 @@ TEST_CASE(

mimicpp::Mock<void()> mock{};
SCOPED_EXP mock.expect_call()
| expect::times(1u, 3u); // between 1 and 3 matches
and expect::times(1u, 3u); // between 1 and 3 matches

mock(); // fine
mock(); // fine
Expand Down

0 comments on commit 44c8c62

Please sign in to comment.