Skip to content

Commit

Permalink
fix: use std::equal_to and similar instead of std::ranges::equal_to i…
Browse files Browse the repository at this point in the history
…n ordering matches
  • Loading branch information
DNKpp committed Sep 26, 2024
1 parent 3c3d143 commit 9caff9d
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
12 changes: 6 additions & 6 deletions include/mimic++/Matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ namespace mimicpp::matches
constexpr auto eq(T&& value)
{
return PredicateMatcher{
std::ranges::equal_to{},
std::equal_to{},
"== {}",
"!= {}",
std::tuple{std::forward<T>(value)}
Expand All @@ -229,7 +229,7 @@ namespace mimicpp::matches
constexpr auto ne(T&& value)
{
return PredicateMatcher{
std::ranges::not_equal_to{},
std::not_equal_to{},
"!= {}",
"== {}",
std::tuple{std::forward<T>(value)}
Expand All @@ -246,7 +246,7 @@ namespace mimicpp::matches
constexpr auto lt(T&& value)
{
return PredicateMatcher{
std::ranges::less{},
std::less{},
"< {}",
">= {}",
std::tuple{std::forward<T>(value)}
Expand All @@ -263,7 +263,7 @@ namespace mimicpp::matches
constexpr auto le(T&& value)
{
return PredicateMatcher{
std::ranges::less_equal{},
std::less_equal{},
"<= {}",
"> {}",
std::tuple{std::forward<T>(value)}
Expand All @@ -280,7 +280,7 @@ namespace mimicpp::matches
constexpr auto gt(T&& value)
{
return PredicateMatcher{
std::ranges::greater{},
std::greater{},
"> {}",
"<= {}",
std::tuple{std::forward<T>(value)}
Expand All @@ -297,7 +297,7 @@ namespace mimicpp::matches
constexpr auto ge(T&& value)
{
return PredicateMatcher{
std::ranges::greater_equal{},
std::greater_equal{},
">= {}",
"< {}",
std::tuple{std::forward<T>(value)}
Expand Down
72 changes: 72 additions & 0 deletions test/unit-tests/Matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,78 @@ TEST_CASE(
}
}

TEST_CASE(
"Ordering matches support different, but comparable types, on both sides.",
"[matcher]"
)
{
SECTION("matches::eq")
{
const auto matcher = matches::eq(std::nullopt);

std::optional<int> opt{};
REQUIRE(matcher.matches(opt));

opt = 42;
REQUIRE_FALSE(matcher.matches(opt));
}

SECTION("matches::ne")
{
const auto matcher = matches::ne(std::nullopt);

std::optional opt{42};
REQUIRE(matcher.matches(opt));

opt.reset();
REQUIRE_FALSE(matcher.matches(opt));
}

SECTION("matches::lt")
{
const auto matcher = matches::lt(std::nullopt);

std::optional opt{42};
REQUIRE_FALSE(matcher.matches(opt));

opt.reset();
REQUIRE_FALSE(matcher.matches(opt));
}

SECTION("matches::le")
{
const auto matcher = matches::le(std::nullopt);

std::optional opt{42};
REQUIRE_FALSE(matcher.matches(opt));

opt.reset();
REQUIRE(matcher.matches(opt));
}

SECTION("matches::gt")
{
const auto matcher = matches::gt(std::nullopt);

std::optional opt{42};
REQUIRE(matcher.matches(opt));

opt.reset();
REQUIRE_FALSE(matcher.matches(opt));
}

SECTION("matches::ge")
{
const auto matcher = matches::ge(std::nullopt);

std::optional opt{42};
REQUIRE(matcher.matches(opt));

opt.reset();
REQUIRE(matcher.matches(opt));
}
}

TEST_CASE(
"matches::predicate matches when the given predicate is satisfied.",
"[matcher]"
Expand Down

0 comments on commit 9caff9d

Please sign in to comment.