mimic++
v10.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
GeneralPolicies.hpp
Go to the documentation of this file.
1
// Copyright Dominic (DNKpp) Koepke 2024-2026.
2
// Distributed under the Boost Software License, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at
4
// https://www.boost.org/LICENSE_1_0.txt)
5
6
#ifndef MIMICPP_EXPECTATION_POLICIES_GENERAL_POLICIES_HPP
7
#define MIMICPP_EXPECTATION_POLICIES_GENERAL_POLICIES_HPP
8
9
#pragma once
10
11
#include "
mimic++/Fwd.hpp
"
12
#include "
mimic++/config/Config.hpp
"
13
#include "
mimic++/expectation/Common.hpp
"
14
#include "
mimic++/printing/StatePrinter.hpp
"
15
#include "
mimic++/utilities/C++23Backports.hpp
"
16
17
#ifndef MIMICPP_DETAIL_IS_MODULE
18
#include <iterator>
19
#include <optional>
20
#include <utility>
21
#endif
22
23
namespace
mimicpp::detail
24
{
25
[[nodiscard]]
26
constexpr
bool
is_matching(
Constness
const
lhs,
Constness
const
rhs)
noexcept
27
{
28
return
std::cmp_not_equal(0,
util::to_underlying
(lhs) &
util::to_underlying
(rhs));
29
}
30
31
[[nodiscard]]
32
constexpr
bool
is_matching(
ValueCategory
const
lhs,
ValueCategory
const
rhs)
noexcept
33
{
34
return
std::cmp_not_equal(0,
util::to_underlying
(lhs) &
util::to_underlying
(rhs));
35
}
36
}
37
38
namespace
mimicpp::expectation::policies
39
{
40
class
InitFinalize
41
{
42
public
:
43
template
<
typename
Return,
typename
... Args>
44
static
constexpr
void
finalize_call
(
call::Info<Return, Args...>
const
&)
noexcept
45
{
46
}
47
};
48
49
template
<ValueCategory expected>
50
class
Category
51
{
52
public
:
53
[[nodiscard]]
54
static
constexpr
bool
is_satisfied
() noexcept
55
{
56
return
true
;
57
}
58
59
template
<
typename
Return,
typename
... Args>
60
[[nodiscard]]
61
static
MatchResult
matches
(
call::Info<Return, Args...>
const
& info)
noexcept
62
{
63
if
(mimicpp::detail::is_matching(info.fromCategory, expected))
64
{
65
return
MatchSuccess
{.description = describe()};
66
}
67
68
return
MatchFailure
{.description = describe()};
69
}
70
71
template
<
typename
Return,
typename
... Args>
72
static
constexpr
void
consume
([[maybe_unused]]
call::Info<Return, Args...>
const
& info)
noexcept
73
{
74
MIMICPP_ASSERT
(mimicpp::detail::is_matching(info.fromCategory, expected),
"Call does not match."
);
75
}
76
77
private
:
78
[[nodiscard]]
79
static
auto
describe()
80
{
81
if
constexpr
(
ValueCategory::any
!= expected)
82
{
83
StringStreamT
stream{};
84
stream <<
"expect: from "
;
85
mimicpp::print
(std::ostreambuf_iterator{stream}, expected);
86
stream <<
" category overload"
;
87
88
return
std::move(stream).str();
89
}
90
else
91
{
92
return
std::nullopt;
93
}
94
}
95
};
96
97
template
<Constness constness>
98
class
Constness
99
{
100
public
:
101
[[nodiscard]]
102
static
constexpr
bool
is_satisfied
() noexcept
103
{
104
return
true
;
105
}
106
107
template
<
typename
Return,
typename
... Args>
108
[[nodiscard]]
109
static
MatchResult
matches
(
call::Info<Return, Args...>
const
& info)
noexcept
110
{
111
if
(mimicpp::detail::is_matching(info.fromConstness, constness))
112
{
113
return
MatchSuccess
{.description = describe()};
114
}
115
116
return
MatchFailure
{.description = describe()};
117
}
118
119
template
<
typename
Return,
typename
... Args>
120
static
constexpr
void
consume
([[maybe_unused]]
call::Info<Return, Args...>
const
& info)
noexcept
121
{
122
MIMICPP_ASSERT
(mimicpp::detail::is_matching(info.fromConstness, constness),
"Call does not match."
);
123
}
124
125
private
:
126
[[nodiscard]]
127
static
auto
describe()
128
{
129
if
constexpr
(
mimicpp::Constness::any
!= constness)
130
{
131
StringStreamT
stream{};
132
stream <<
"expect: from "
;
133
mimicpp::print
(std::ostreambuf_iterator{stream}, constness);
134
stream <<
" qualified overload"
;
135
136
return
std::move(stream).str();
137
}
138
else
139
{
140
return
std::nullopt;
141
}
142
}
143
};
144
}
145
146
#endif
Config.hpp
MIMICPP_ASSERT
#define MIMICPP_ASSERT(condition, msg)
Definition
Config.hpp:54
Fwd.hpp
StatePrinter.hpp
mimicpp::call::Info
Definition
Call.hpp:27
mimicpp::expectation::policies::Category
Definition
GeneralPolicies.hpp:51
mimicpp::expectation::policies::Category::is_satisfied
static constexpr bool is_satisfied() noexcept
Definition
GeneralPolicies.hpp:54
mimicpp::expectation::policies::Category::matches
static MatchResult matches(call::Info< Return, Args... > const &info) noexcept
Definition
GeneralPolicies.hpp:61
mimicpp::expectation::policies::Category::consume
static constexpr void consume(call::Info< Return, Args... > const &info) noexcept
Definition
GeneralPolicies.hpp:72
mimicpp::expectation::policies::Constness
Definition
GeneralPolicies.hpp:99
mimicpp::expectation::policies::Constness::matches
static MatchResult matches(call::Info< Return, Args... > const &info) noexcept
Definition
GeneralPolicies.hpp:109
mimicpp::expectation::policies::Constness::consume
static constexpr void consume(call::Info< Return, Args... > const &info) noexcept
Definition
GeneralPolicies.hpp:120
mimicpp::expectation::policies::Constness::is_satisfied
static constexpr bool is_satisfied() noexcept
Definition
GeneralPolicies.hpp:102
mimicpp::expectation::policies::InitFinalize
Definition
GeneralPolicies.hpp:41
mimicpp::expectation::policies::InitFinalize::finalize_call
static constexpr void finalize_call(call::Info< Return, Args... > const &) noexcept
Definition
GeneralPolicies.hpp:44
Common.hpp
mimicpp::print
constexpr printing::PrintFn print
Functional object, converting the given object to its textual representation.
Definition
Print.hpp:183
mimicpp::expectation::policies
Definition
ArgumentList.hpp:24
mimicpp::expectation::MatchResult
std::variant< MatchSuccess, MatchFailure > MatchResult
Definition
Common.hpp:41
mimicpp::util::to_underlying
constexpr std::underlying_type_t< T > to_underlying(T const value) noexcept
Definition
C++23Backports.hpp:62
mimicpp::ValueCategory
ValueCategory
Definition
Fwd.hpp:34
mimicpp::ValueCategory::any
@ any
Definition
Fwd.hpp:37
mimicpp::StringStreamT
std::basic_ostringstream< CharT, CharTraitsT > StringStreamT
Definition
Format.hpp:38
mimicpp::Constness
Constness
Definition
Fwd.hpp:27
mimicpp::Constness::any
@ any
Definition
Fwd.hpp:30
mimicpp::expectation::MatchFailure
Definition
Common.hpp:35
mimicpp::expectation::MatchSuccess
Definition
Common.hpp:27
C++23Backports.hpp
mimic++
expectation
policies
GeneralPolicies.hpp
Generated on
for mimic++ by
1.18.0