Implements easier assertions for iterators
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
43e612122c
commit
195043d4c5
|
@ -12,12 +12,12 @@
|
||||||
ss << #expr << "\""; \
|
ss << #expr << "\""; \
|
||||||
throw std::logic_error(ss.str()); \
|
throw std::logic_error(ss.str()); \
|
||||||
}
|
}
|
||||||
|
#define AssertForEach(iterator, assertion) { for (auto item: iterator) Assert(assertion)}
|
||||||
#else
|
#else
|
||||||
// Assert is empty if NO_ASSERT is defined.
|
// Assert is empty if NO_ASSERT is defined.
|
||||||
#define Assert(expr) ;
|
#define Assert(expr) ;
|
||||||
|
#define AssertForEach(iterator, assertion) ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define AssertNotNull(value) Assert(value != nullptr)
|
#define AssertNotNull(value) Assert(value != nullptr)
|
||||||
#define UnpackWeakPtr(weakPtr, sharedPtr) \
|
#define AssertAllNotNull(iterator) AssertForEach(iterator, item != nullptr)
|
||||||
Assert(!weakPtr.expired()); \
|
|
||||||
auto sharedPtr = weakPtr.lock();
|
|
||||||
|
|
|
@ -19,3 +19,8 @@ TEST_CASE("Multiple asserts", "[Utilities]") {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
|
TEST_CASE("AssertNotNull throws if nullptr", "[Utilities]") { REQUIRE_THROWS(TestWrapperNotNull(nullptr)); }
|
||||||
|
|
||||||
|
TEST_CASE("Assert for each", "[Utilities]") {
|
||||||
|
auto i = {10, 500, 2300, 454};
|
||||||
|
AssertForEach(i, item > 0)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue