mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1404972 - To Result add operator==. r=glandium
This is needed for using Result with gtest matchers. Differential Revision: https://phabricator.services.mozilla.com/D205958
This commit is contained in:
parent
4783bbe42c
commit
5ec78bee07
@ -834,6 +834,15 @@ class [[nodiscard]] Result final {
|
||||
constexpr auto andThen(F f) -> std::invoke_result_t<F, V&&> {
|
||||
return MOZ_LIKELY(isOk()) ? f(unwrap()) : propagateErr();
|
||||
}
|
||||
|
||||
bool operator==(const Result<V, E>& aOther) const {
|
||||
return (isOk() && aOther.isOk() && inspect() == aOther.inspect()) ||
|
||||
(isErr() && aOther.isErr() && inspectErr() == aOther.inspectErr());
|
||||
}
|
||||
|
||||
bool operator!=(const Result<V, E>& aOther) const {
|
||||
return !(*this == aOther);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -852,6 +852,50 @@ void UpcastTest() {
|
||||
}
|
||||
}
|
||||
|
||||
void EqualityTest() {
|
||||
{
|
||||
Result<int, bool> result(1);
|
||||
Result<int, bool> other(1);
|
||||
|
||||
MOZ_RELEASE_ASSERT(result == other);
|
||||
}
|
||||
|
||||
{
|
||||
Result<int, bool> result(true);
|
||||
Result<int, bool> other(true);
|
||||
|
||||
MOZ_RELEASE_ASSERT(result == other);
|
||||
}
|
||||
|
||||
{
|
||||
Result<int, bool> result(1);
|
||||
Result<int, bool> other(2);
|
||||
|
||||
MOZ_RELEASE_ASSERT(result != other);
|
||||
}
|
||||
|
||||
{
|
||||
Result<int, bool> result(true);
|
||||
Result<int, bool> other(false);
|
||||
|
||||
MOZ_RELEASE_ASSERT(result != other);
|
||||
}
|
||||
|
||||
{
|
||||
Result<int, bool> result(0);
|
||||
Result<int, bool> other(false);
|
||||
|
||||
MOZ_RELEASE_ASSERT(result != other);
|
||||
}
|
||||
|
||||
{
|
||||
Result<int, unsigned int> result(1);
|
||||
Result<int, unsigned int> other(1u);
|
||||
|
||||
MOZ_RELEASE_ASSERT(result != other);
|
||||
}
|
||||
}
|
||||
|
||||
/* * */
|
||||
|
||||
int main() {
|
||||
@ -866,5 +910,6 @@ int main() {
|
||||
UniquePtrTest();
|
||||
ZeroIsEmptyErrorTest();
|
||||
UpcastTest();
|
||||
EqualityTest();
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user