From 4cd258bcb6d65e18c782cf21d4257338a616360b Mon Sep 17 00:00:00 2001 From: light7734 Date: Sun, 10 Aug 2025 23:26:06 +0330 Subject: [PATCH] refactor(test): printable concept to accept enums --- modules/test/public/expects.hpp | 26 +++++++++++++++++++++++--- modules/test/public/test.hpp | 17 ----------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/test/public/expects.hpp b/modules/test/public/expects.hpp index 825de25..8878092 100644 --- a/modules/test/public/expects.hpp +++ b/modules/test/public/expects.hpp @@ -7,8 +7,10 @@ namespace lt::test { template -concept Printable = requires(std::ostream &os, T t) { - { os << t } -> std::same_as; +concept Printable = requires(std::ostream &stream, T value) { + { stream << value } -> std::same_as; +} || requires(std::ostream &stream, T value) { + { stream << std::to_underlying(value) } -> std::same_as; }; template @@ -58,7 +60,25 @@ constexpr void expect_eq( std::source_location source_location = std::source_location::current() ) { - if (lhs != rhs) + if constexpr (std::is_enum_v) + { + if (lhs != rhs) + { + throw std::runtime_error { + std::format( + "Failed equality expectation:\n" + "\tactual: {}\n" + "\texpected: {}\n" + "\tlocation: {}:{}", + std::to_underlying(lhs), + std::to_underlying(rhs), + source_location.file_name(), + source_location.line() + ), + }; + } + } + else if (lhs != rhs) { throw std::runtime_error { std::format( diff --git a/modules/test/public/test.hpp b/modules/test/public/test.hpp index b6c2172..8c15205 100644 --- a/modules/test/public/test.hpp +++ b/modules/test/public/test.hpp @@ -5,23 +5,6 @@ namespace lt::test { -namespace concepts { - -template -concept printable = requires(std::ostream &os, T t) { - { os << t } -> std::same_as; -}; - -// clang-format off -template -concept test = requires(T test) { - { test.name } -> printable; - { test = expr } -> std::same_as; -}; -// clang-format on - -} // namespace concepts - namespace details { class Registry