From 9fb3eb0419551dfedce6f8a18c9e0d36ddda51a1 Mon Sep 17 00:00:00 2001 From: Patrick Date: Mon, 29 Jul 2024 16:30:37 +0200 Subject: [PATCH] added assert_nothrow and added ranges_equal --- test/common_helper/test.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/test/common_helper/test.hpp b/test/common_helper/test.hpp index 1a8dfc6..7feee06 100644 --- a/test/common_helper/test.hpp +++ b/test/common_helper/test.hpp @@ -33,6 +33,7 @@ constexpr auto make_copy(auto& value) -> std::remove_cvref_t { #define ASSERT(condition, ...) ASSERT_MSG((condition), "Condition (" #condition ") evaluated to false" _LOCATION, __VA_ARGS__) #define ASSERT_MSG(condition, msg, ...) { if (!(condition)) return _ret_val_from_ctx<__VA_ARGS__>(ReturnCode::FAILED, msg); } static_assert(true, "") #define ASSERT_THROWS(operation, exception_type, ...) if not consteval { try { operation; ASSERT_MSG(false, #operation " did not throw " #exception_type _LOCATION, __VA_ARGS__); } catch (exception_type &e) {} } static_assert(true, "") +#define ASSERT_NOTHROW(operation, exception_type, ...) if not consteval { try { operation; } catch (exception_type &e) { ASSERT_MSG(false, #operation " threw " #exception_type _LOCATION, __VA_ARGS__); } } static_assert(true, "") template concept StringLike = std::is_convertible_v; @@ -66,6 +67,19 @@ constexpr bool all_equal_to(I first, S last, T t) { return std::ranges::equal(r1, r2); } +template + requires StringLike> && StringLike> +constexpr bool ranges_equal(R1 r1, R2 r2) { + auto r1t = r1 | std::ranges::views::transform([](auto&& e) constexpr { return std::string_view(e); }); + auto r2t = r2 | std::ranges::views::transform([](auto&& e) constexpr { return std::string_view(e); }); + return std::ranges::equal(r1t, r2t); +} + +template +constexpr bool ranges_equal(R1 r1, R2 r2) { + return std::ranges::equal(r1, r2); +} + template S, std::ranges::range R> requires StringLike> constexpr bool equal_to(I first, S last, R r) {