10#include "prettyprint.hpp"
16template <
typename A,
typename E>
29 [[nodiscard]] std::string name(
const std::string& name)
const;
30 [[nodiscard]] std::string name_to_sentence(
const std::string& name)
const;
31 static std::string split_words(
const std::string& sym);
32 static std::string underscore(
const std::string& camel_cased_word);
33 static std::string last(
const std::string& s,
char delim);
34 static std::string improve_hash_formatting(
const std::string& inspect_string);
36 template <Util::is_streamable T>
37 static std::string
to_word(
const T& item);
40 static std::string
to_word(
const T& item);
43 static std::string to_word_type(
const T& item);
45 template <
typename A,
typename E>
52 static std::string
to_sentence(
const std::vector<T>& words);
55 static std::string inspect_object(
const T&
object);
68 std::vector<std::string> words;
69 for (
const auto&
object : objects) {
70 words.push_back(
to_word(
object));
74 switch (words.size()) {
78 ss <<
" " << words[0];
81 ss <<
" " << words[0] <<
" and " << words[1];
85 for (
size_t i = 0; i < words.size() - 1; ++i) {
91 ss <<
", and " << words.back();
121template <Util::is_streamable T>
123 std::ostringstream oss;
130 return item ?
"true" :
"false";
134inline std::string Pretty::to_word<std::true_type>(
const std::true_type& ) {
152 std::stringstream ss;
154 ss <<
"#<" << Util::demangle(
typeid(item).name()) <<
":" << &item <<
">";
169template <
typename A,
typename E>
172 if (description.empty()) {
173 return "[No description]";
179inline std::string Pretty::to_word_type(
const T& item) {
180 std::string word =
to_word(item);
187inline std::string Pretty::name_to_sentence(
const std::string& n)
const {
188 return split_words(name(n));
191inline std::string Pretty::name(
const std::string& name)
const {
193 return last(name,
':');
198inline std::string Pretty::split_words(
const std::string& sym) {
199 return std::regex_replace(sym, std::regex(
"_"),
" ");
202inline std::string Pretty::underscore(
const std::string& word) {
203 std::string str = std::regex_replace(word, std::regex(
"([A-Z]+)([A-Z][a-z])"),
"$1_$2");
204 str = std::regex_replace(str, std::regex(
"([a-z\\d])([A-Z])"),
"$1_$2");
205 str = std::regex_replace(str, std::regex(
"-"),
"_");
206 std::ranges::transform(str, str.begin(), ::tolower);
210inline std::string Pretty::last(
const std::string& s,
const char delim) {
211 std::vector<std::string> elems;
212 std::stringstream ss(s);
214 while (getline(ss, item, delim)) {
216 elems.push_back(item);
222inline std::string Pretty::improve_hash_formatting(
const std::string& inspect_string) {
223 return std::regex_replace(inspect_string, std::regex(
"(\\S)=>(\\S)"),
"$1 => $2");
234inline std::string Pretty::inspect_object(
const O& o) {
246inline std::string Pretty::inspect_object<const char*>(
const char*
const& o) {
247 return std::format(
"(const char *) => \"{}\"", o);
258inline std::string Pretty::inspect_object<std::string>(
const std::string& o) {
259 return std::format(
"(std::string) => \"{}\"", o);
263inline std::string Pretty::inspect_object<std::string_view>(
const std::string_view& o) {
264 return std::format(
"(std::string_view) => \"{}\"", o);
the base class for all Matcher classes and objects
Definition matcher_base.hpp:37
virtual std::string description()
Get the description of the Matcher.
Definition matcher_base.hpp:138
Checks whether T can be streamed.
Definition util.hpp:81
A helper base class that assists in pretty-printing various objects.
Definition pretty_matchers.hpp:27
static std::string to_word(const T &item)
Formats an object as a string when operator<< is available.
Definition pretty_matchers.hpp:122
static std::string to_sentence(const T &item)
Take a single object and format it as a sentance.
Definition pretty_matchers.hpp:106
Utility functions and classes.
std::string demangle(const char *name)
Definition util.hpp:38