Skip to content

Commit

Permalink
Add <= and >= matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Aug 4, 2024
1 parent 23838cf commit 5e5159f
Showing 1 changed file with 64 additions and 10 deletions.
74 changes: 64 additions & 10 deletions Source/UEST/Public/UEST.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ namespace UEST
template<typename T>
struct EqualTo final : IMatcher<T>
{
T Expected;
const T& Expected;

EqualTo(T Expected)
EqualTo(const T& Expected)
: Expected(Expected)
{
}
Expand All @@ -113,9 +113,9 @@ namespace UEST
template<typename T>
struct LessThan final : IMatcher<T>
{
T Expected;
const T& Expected;

LessThan(T Expected)
LessThan(const T& Expected)
: Expected(Expected)
{
}
Expand All @@ -131,12 +131,33 @@ namespace UEST
}
};

template<typename T>
struct LessThanOrEqual final : IMatcher<T>
{
const T& Expected;

LessThanOrEqual(const T& Expected)
: Expected(Expected)
{
}

virtual bool Matches(const T& Value) const override
{
return Value <= Expected;
}

virtual FString Describe() const override
{
return FString::Printf(TEXT("be less than or equal to %s"), *CQTestConvert::ToString(Expected));
}
};

template<typename T>
struct GreaterThan final : IMatcher<T>
{
T Expected;
const T& Expected;

GreaterThan(T Expected)
GreaterThan(const T& Expected)
: Expected(Expected)
{
}
Expand All @@ -152,6 +173,27 @@ namespace UEST
}
};

template<typename T>
struct GreaterThanOrEqual final : IMatcher<T>
{
const T& Expected;

GreaterThanOrEqual(const T& Expected)
: Expected(Expected)
{
}

virtual bool Matches(const T& Value) const override
{
return Value >= Expected;
}

virtual FString Describe() const override
{
return FString::Printf(TEXT("be greater than or equal to %s"), *CQTestConvert::ToString(Expected));
}
};

template<typename T, typename M>
struct Not : IMatcher<T>
{
Expand Down Expand Up @@ -181,8 +223,8 @@ namespace UEST
{
M Matcher;

explicit Passthrough(P... Args)
: Matcher{Forward<P>(Args)...}
explicit Passthrough(const P&... Args)
: Matcher{Args...}
{}

template<typename U>
Expand All @@ -205,9 +247,15 @@ namespace Is
template<typename T>
using LessThan = UEST::Passthrough<UEST::Matchers::LessThan<T>, T>;

template<typename T>
using LessThanOrEqual = UEST::Passthrough<UEST::Matchers::LessThanOrEqual<T>, T>;

template<typename T>
using GreaterThan = UEST::Passthrough<UEST::Matchers::GreaterThan<T>, T>;

template<typename T>
using GreaterThanOrEqual = UEST::Passthrough<UEST::Matchers::GreaterThanOrEqual<T>, T>;

namespace Not
{
static struct
Expand Down Expand Up @@ -241,10 +289,16 @@ namespace Is
using EqualTo = UEST::Passthrough<UEST::Matchers::Not<T, UEST::Matchers::EqualTo<T>>, T>;

template<typename T>
using LessThan = UEST::Passthrough<UEST::Matchers::Not<T, UEST::Matchers::LessThan<T>>, T>;
using LessThan = UEST::Passthrough<UEST::Matchers::GreaterThanOrEqual<T>, T>;

template<typename T>
using LessThanOrEqual = UEST::Passthrough<UEST::Matchers::GreaterThan<T>, T>;

template<typename T>
using GreaterThan = UEST::Passthrough<UEST::Matchers::LessThanOrEqual<T>, T>;

template<typename T>
using GreaterThan = UEST::Passthrough<UEST::Matchers::Not<T, UEST::Matchers::GreaterThan<T>>, T>;
using GreaterThanOrEqual = UEST::Passthrough<UEST::Matchers::LessThan<T>, T>;
}
}

Expand Down

0 comments on commit 5e5159f

Please sign in to comment.