11#include <boost/type_index.hpp>
13#include <fmt/format.h>
14#include <range/v3/range/concepts.hpp>
15#include <range/v3/view/transform.hpp>
56 constexpr fmt::formattable
auto pre(std::span<const inspection::Token> tokens, std::string_view raw_str,
69 constexpr fmt::formattable
auto pre(
const T& val)
const;
74inline std::string
str_default(
const std::convertible_to<std::string_view>
auto& val) {
75 return fmt::format(
"{:?}", std::string_view{val});
80 return fmt::format(
"{}", val);
84 return fmt::format(
"{:?}", val);
89 return fmt::format(
"{}", val);
92template <ranges::range Range>
93 requires(!std::convertible_to<Range, std::string_view>)
95 return fmt::to_string(fmt::join(
96 val | ranges::views::transform([](
const auto& elem) {
return str_fn_dispatcher(elem).original; }),
", "));
99template <
typename T,
typename E>
103 if constexpr (std::same_as<T, void>) {
111 std::string err_str = [&expected]() -> std::string {
112 if constexpr (std::same_as<E, void>) {
119 return fmt::format(
"%#`<fg:red>{}`", err_str);
123 return fmt::format(
"{}", error_kind);
128 const T& val)
const {
129 return {fmt::to_string(
pre(tokens, raw_str, val))};
133constexpr fmt::formattable
auto ReprFn::pre(std::span<const inspection::Token> tokens, std::string_view raw_str,
134 const T& val)
const {
135 if constexpr (
requires { val.repr(tokens, raw_str); }) {
136 return val.repr(tokens, raw_str);
137 }
else if constexpr (
requires {
repr(tokens, raw_str, val); }) {
138 return repr(tokens, raw_str, val);
139 }
else if constexpr (
requires { repr_default(tokens, raw_str, val); }) {
140 return repr_default(tokens, raw_str, val);
149 return {fmt::to_string(
pre(val))};
153constexpr fmt::formattable
auto StrFn::pre(
const T& val)
const {
154 if constexpr (
requires { val.str(); }) {
156 }
else if constexpr (
requires {
str(val); }) {
158 }
else if constexpr (
requires {
str_default(val); }) {
161 LOG_WARN(
"No `str` implementation for type <{}>", boost::typeindex::type_id<T>().pretty_name());
std::variant wrapper for a partial implementation of C++23's expected type
Definition expected.hpp:34
constexpr U & value()
Definition expected.hpp:78
constexpr E error() const
Definition expected.hpp:149
constexpr bool has_value() const
Definition expected.hpp:64
#define LOG_WARN(...)
Definition logging.hpp:43
constexpr StrFn str_fn_dispatcher
Definition stringize.hpp:72
constexpr ReprFn repr_fn_dispatcher
Definition stringize.hpp:60
std::string str_default(const std::convertible_to< std::string_view > auto &val)
Definition stringize.hpp:74
For everything related to test requirement stringification.
Definition stringize.hpp:35
constexpr const auto & str
str customization point object The return value of this function is guaranteed to be parsable by high...
Definition stringize.hpp:190
constexpr const auto & repr
repr customization point object The return value of this function is guaranteed to be parsable by hig...
Definition stringize.hpp:178
ErrorKind
Definition error_types.hpp:11
Result type of a call to str or repr
Definition stringize.hpp:39
std::string original
Definition stringize.hpp:43
std::string syntax_highlight() const
Definition stringize.cpp:13
std::string resolve_blocks(bool do_colorize) const
Definition stringize.cpp:9
Definition stringize.hpp:51
constexpr fmt::formattable auto pre(std::span< const inspection::Token > tokens, std::string_view raw_str, const T &val) const
Definition stringize.hpp:133
StringizeResult operator()(std::span< const inspection::Token > tokens, std::string_view raw_str, const T &val) const
Definition stringize.hpp:127
str function dispatcher
Definition stringize.hpp:64
constexpr fmt::formattable auto pre(const T &val) const
Definition stringize.hpp:153
StringizeResult operator()(const T &val) const
str function dispatcher
Definition stringize.hpp:148