6#ifndef MIMICPP_REPORTS_HPP
7#define MIMICPP_REPORTS_HPP
80 template <pr
int_iterator OutIter>
81 OutIter print_times_state(OutIter out,
const std::size_t current,
const std::size_t min,
const std::size_t max)
83 const auto verbalizeValue = [](OutIter o,
const std::size_t value) {
86 case 0:
return format::format_to(std::move(o),
"never");
87 case 1:
return format::format_to(std::move(o),
"once");
88 case 2:
return format::format_to(std::move(o),
"twice");
89 default:
return format::format_to(std::move(o),
"{} times", value);
95 out = format::format_to(
97 "already saturated (matched ");
98 out = verbalizeValue(std::move(out), current);
99 return format::format_to(std::move(out),
")");
104 return format::format_to(
106 "accepts further matches (matched {} out of {} times)",
111 const auto verbalizeInterval = [verbalizeValue](OutIter o,
const std::size_t start,
const std::size_t end) {
114 return format::format_to(
116 "between {} and {} times",
121 o = format::format_to(std::move(o),
"exactly ");
122 return verbalizeValue(std::move(o), end);
125 out = format::format_to(std::move(out),
"matched ");
126 out = verbalizeValue(std::move(out), current);
127 out = format::format_to(std::move(out),
" - ");
128 out = verbalizeInterval(std::move(out), min, max);
129 return format::format_to(std::move(out),
" is expected");
132 struct control_state_printer
134 template <pr
int_iterator OutIter>
137 out = print_times_state(
143 if (
const auto sequenceCount = std::ranges::ssize(state.
sequenceRatings);
146 out = format::format_to(
148 ",\n\tand is the current element of {} sequence(s).",
155 template <pr
int_iterator OutIter>
158 out = print_times_state(
166 return format::format_to(
168 ",\n\tbut is not the current element of {} sequence(s) ({} total).",
173 template <pr
int_iterator OutIter>
176 out = print_times_state(
182 if (
const auto sequenceCount = std::ranges::ssize(state.
sequences);
185 out = format::format_to(
187 ",\n\tand is part of {} sequence(s).",
240 template <
typename Return,
typename... Params>
245 .returnTypeIndex =
typeid(Return),
246 .argDetails = std::apply(
248 return std::vector<CallReport::Arg>{
250 .typeIndex =
typeid(Params),
265 template <pr
int_iterator OutIter>
268 out = format::format_to(
274 out = format::format_to(
278 out = format::format_to(
281 "value category: {}\n"
289 out = format::format_to(
292 for (
const std::size_t i : std::views::iota(0u, std::ranges::size(report.
argDetails)))
294 out = format::format_to(
336 class detail::Printer<ExpectationReport>
339 template <pr
int_iterator OutIter>
340 static OutIter
print(OutIter out,
const ExpectationReport& report)
342 out = format::format_to(
344 "Expectation report:\n");
346 if (report.sourceLocation)
348 out = format::format_to(
353 *report.sourceLocation);
354 out = format::format_to(
359 if (report.timesDescription)
361 out = format::format_to(
364 *report.timesDescription);
367 if (std::ranges::any_of(
368 report.expectationDescriptions,
369 [](
const auto& desc) { return desc.has_value(); }))
371 out = format::format_to(
374 for (
const auto& desc : report.expectationDescriptions
375 | std::views::filter([](
const auto& desc) { return desc.has_value(); }))
377 out = format::format_to(
384 if (report.finalizerDescription)
386 out = format::format_to(
389 *report.finalizerDescription);
460 if (!std::holds_alternative<state_applicable>(report.controlReport))
469 class detail::Printer<MatchReport>
472 template <pr
int_iterator OutIter>
473 static OutIter
print(OutIter out,
const MatchReport& report)
475 std::vector<StringT> matchedExpectationDescriptions{};
476 std::vector<StringT> unmatchedExpectationDescriptions{};
478 for (
const auto& [isMatching, description] : report.expectationReports)
484 matchedExpectationDescriptions.emplace_back(*description);
488 unmatchedExpectationDescriptions.emplace_back(*description);
496 out = format::format_to(
498 "Matched expectation: {{\n");
502 out = format::format_to(
504 "Inapplicable, but otherwise matched expectation: {{\n"
507 std::bind_front(control_state_printer{}, std::move(out)),
508 report.controlReport);
509 out = format::format_to(std::move(out),
"\n");
513 out = format::format_to(
515 "Unmatched expectation: {{\n");
524 if (report.sourceLocation)
526 out = format::format_to(
531 *report.sourceLocation);
532 out = format::format_to(
537 if (!std::ranges::empty(unmatchedExpectationDescriptions))
539 out = format::format_to(
542 for (
const auto& desc : unmatchedExpectationDescriptions)
544 out = format::format_to(
551 if (!std::ranges::empty(matchedExpectationDescriptions))
553 out = format::format_to(
556 for (
const auto& desc : matchedExpectationDescriptions)
558 out = format::format_to(
565 return format::format_to(
Definition Reports.hpp:206
std::type_index typeIndex
Definition Reports.hpp:208
friend bool operator==(const Arg &, const Arg &)=default
StringT stateString
Definition Reports.hpp:209
Contains the extracted info from a typed call::Info.
Definition Reports.hpp:203
std::type_index returnTypeIndex
Definition Reports.hpp:215
friend bool operator==(const CallReport &lhs, const CallReport &rhs)
Definition Reports.hpp:222
Constness fromConstness
Definition Reports.hpp:219
ValueCategory fromCategory
Definition Reports.hpp:218
std::vector< Arg > argDetails
Definition Reports.hpp:216
std::source_location fromLoc
Definition Reports.hpp:217
Contains the extracted info from a typed expectation.
Definition Reports.hpp:316
std::optional< StringT > finalizerDescription
Definition Reports.hpp:319
std::optional< StringT > timesDescription
Definition Reports.hpp:320
std::optional< std::source_location > sourceLocation
Definition Reports.hpp:318
std::vector< std::optional< StringT > > expectationDescriptions
Definition Reports.hpp:321
friend bool operator==(const ExpectationReport &lhs, const ExpectationReport &rhs)
Definition Reports.hpp:324
Information a used expectation policy.
Definition Reports.hpp:421
std::optional< StringT > description
Definition Reports.hpp:424
friend bool operator==(const Expectation &, const Expectation &)=default
bool isMatching
Definition Reports.hpp:423
Information about the used finalizer.
Definition Reports.hpp:408
std::optional< StringT > description
Definition Reports.hpp:410
friend bool operator==(const Finalize &, const Finalize &)=default
Contains the detailed information for match outcomes.
Definition Reports.hpp:402
std::vector< Expectation > expectationReports
Definition Reports.hpp:433
Finalize finalizeReport
Definition Reports.hpp:431
friend bool operator==(const MatchReport &lhs, const MatchReport &rhs)
Definition Reports.hpp:436
control_state_t controlReport
Definition Reports.hpp:432
std::optional< std::source_location > sourceLocation
Definition Reports.hpp:430
ValueCategory fromCategory
Definition Call.hpp:46
std::source_location fromSourceLocation
Definition Call.hpp:48
ArgListT args
Definition Call.hpp:45
Constness fromConstness
Definition Call.hpp:47
MatchResult evaluate_match_report(const MatchReport &report) noexcept
Determines, whether a match report actually denotes a full, inapplicable or no match.
Definition Reports.hpp:453
CallReport make_call_report(const call::Info< Return, Params... > &callInfo)
Generates the call report for a given call info.
Definition Reports.hpp:242
std::variant< state_inapplicable, state_applicable, state_saturated > control_state_t
Definition Reports.hpp:73
constexpr detail::PrintFn print
Functional object, converting the given object to its textual representation.
Definition Printer.hpp:593
Definition BoostTest.hpp:20
MatchResult
Definition Fwd.hpp:330
void unreachable()
Invokes undefined behavior.
Definition Utility.hpp:89
constexpr bool is_same_source_location(const std::source_location &lhs, const std::source_location &rhs) noexcept
Definition Utility.hpp:40
ValueCategory
Definition Fwd.hpp:30
Constness
Definition Fwd.hpp:23
std::basic_string< CharT, CharTraitsT > StringT
Definition Fwd.hpp:342
Definition Reports.hpp:52
std::vector< sequence::rating > sequenceRatings
Definition Reports.hpp:56
int count
Definition Reports.hpp:55
int min
Definition Reports.hpp:53
friend bool operator==(const state_applicable &, const state_applicable &)=default
int max
Definition Reports.hpp:54
Definition Reports.hpp:40
std::vector< sequence::rating > sequenceRatings
Definition Reports.hpp:44
int count
Definition Reports.hpp:43
friend bool operator==(const state_inapplicable &, const state_inapplicable &)=default
int min
Definition Reports.hpp:41
int max
Definition Reports.hpp:42
std::vector< sequence::Tag > inapplicableSequences
Definition Reports.hpp:45
Definition Reports.hpp:63
int max
Definition Reports.hpp:65
std::vector< sequence::Tag > sequences
Definition Reports.hpp:67
int count
Definition Reports.hpp:66
friend bool operator==(const state_saturated &, const state_saturated &)=default
int min
Definition Reports.hpp:64