6#ifndef MIMICPP_MATCHERS_RANGE_MATCHERS_HPP
7#define MIMICPP_MATCHERS_RANGE_MATCHERS_HPP
37 template <std::ranges::forward_range Range,
typename Comparator = std::equal_to<>>
39 constexpr auto eq(Range&& expected, Comparator comparator = Comparator{})
42 [comp = std::move(comparator)]<
typename Target>(Target&& target,
auto&
range)
43 requires std::predicate<
45 std::ranges::range_reference_t<Target>,
46 std::ranges::range_reference_t<Range>>
48 return std::ranges::equal(
54 "elements are not {}",
55 std::make_tuple(std::views::all(std::forward<Range>(expected)))};
65 template <std::ranges::forward_range Range,
typename Comparator = std::equal_to<>>
67 constexpr auto unordered_eq(Range&& expected, Comparator comparator = Comparator{})
70 [comp = std::move(comparator)]<
typename Target>(Target&& target,
auto&
range)
71 requires std::predicate<
73 std::ranges::range_reference_t<Target>,
74 std::ranges::range_reference_t<Range>>
76 return std::ranges::is_permutation(
81 "is a permutation of {}",
82 "is not a permutation of {}",
83 std::make_tuple(std::views::all(std::forward<Range>(expected)))};
91 template <
typename Relation = std::ranges::less>
93 constexpr auto is_sorted(Relation relation = Relation{})
96 [rel = std::move(relation)]<
typename Target>(Target&& target)
97 requires std::equivalence_relation<
99 std::ranges::range_reference_t<Target>,
100 std::ranges::range_reference_t<Target>>
102 return std::ranges::is_sorted(
107 "is an unsorted range"};
117 [](std::ranges::range
auto&& target) {
118 return std::ranges::empty(target);
121 "is not an empty range"};
129 constexpr auto has_size(
const std::integral
auto expected)
132 [](std::ranges::range
auto&& target,
const std::integral
auto size) {
133 return std::cmp_equal(
135 std::ranges::size(target));
138 "has different size than {}",
139 std::make_tuple(expected)};
146 template <
typename Matcher>
150 using MatcherT = std::remove_cvref_t<Matcher>;
152 [](std::ranges::range
auto&& target,
const MatcherT& m) {
153 return std::ranges::all_of(
155 [&](
const auto& element) {
return m.matches(element); });
157 "each el in range: el {}",
158 "not each el in range: el {}",
160 mimicpp::detail::arg_storage<
163 decltype([](
const auto& m) {
return mimicpp::detail::describe_hook::describe(m); })>{
164 std::forward<MatcherT>(matcher)})};
171 template <
typename Matcher>
175 using MatcherT = std::remove_cvref_t<Matcher>;
177 [](std::ranges::range
auto&& target,
const MatcherT& m) {
178 return std::ranges::any_of(
180 [&](
const auto& element) {
return m.matches(element); });
182 "any el in range: el {}",
183 "none el in range: el {}",
185 mimicpp::detail::arg_storage<
188 decltype([](
const auto& m) {
return mimicpp::detail::describe_hook::describe(m); })>{
189 std::forward<MatcherT>(matcher)})};
Generic matcher and the basic building block of most of the built-in matchers.
Definition GeneralMatchers.hpp:68
constexpr auto eq(Range &&expected, Comparator comparator=Comparator{})
Tests, whether the target range compares equal to the expected range, by comparing them element-wise.
Definition RangeMatchers.hpp:39
constexpr auto each_element(Matcher &&matcher)
Tests, whether each element of the target range matches the specified matcher.
Definition RangeMatchers.hpp:148
constexpr auto unordered_eq(Range &&expected, Comparator comparator=Comparator{})
Tests, whether the target range is a permutation of the expected range, by comparing them element-wis...
Definition RangeMatchers.hpp:67
constexpr auto any_element(Matcher &&matcher)
Tests, whether any element of the target range matches the specified matcher.
Definition RangeMatchers.hpp:173
constexpr auto has_size(const std::integral auto expected)
Tests, whether the target range has the expected size.
Definition RangeMatchers.hpp:129
constexpr auto is_sorted(Relation relation=Relation{})
Tests, whether the target range is sorted, by applying the relation on each adjacent elements.
Definition RangeMatchers.hpp:93
constexpr auto is_empty()
Tests, whether the target range is empty.
Definition RangeMatchers.hpp:114
Definition RangeMatchers.hpp:21