expression_formatter Class
Formats values and expressions into an owned string buffer. More...
Declaration
Included Headers
Classes Index
| struct | colour_code |
|
An ANSI colour escape sequence, to be written as it is. More... | |
Friends Index
| class | check_result |
|
The check result, which formats its expression and its message. More... | |
| struct | plain_text |
|
The plain text writer, for the names of the test cases and the operands of the application types. More... | |
Public Constructors Index
| expression_formatter (const colours &colours) noexcept | |
|
Constructor with colour configuration. More... | |
| expression_formatter (const expression_formatter &)=delete | |
|
Deleted copy constructor to prevent copying. More... | |
| expression_formatter (expression_formatter &&)=delete | |
|
Deleted move constructor to prevent moving. More... | |
| expression_formatter (void) noexcept | |
|
Constructs a formatter without colours. More... | |
Private Constructors Index
| expression_formatter (std::string &&buffer) noexcept | |
|
Constructs a formatter in the plain mode, for a message. More... | |
Public Destructor Index
| ~expression_formatter ()=default | |
|
Default destructor. More... | |
Public Operators Index
| expression_formatter & | operator<< (bool v) |
|
Appends the string representation of a boolean value. More... | |
| expression_formatter & | operator<< (char c) |
|
Appends a character, as a quoted literal, to the buffer. More... | |
| expression_formatter & | operator<< (char16_t c) |
|
Appends a UTF-16 code unit, as a quoted u literal, to the buffer. More... | |
| expression_formatter & | operator<< (char32_t c) |
|
Appends a UTF-32 character, as a quoted U literal, to the buffer. More... | |
template <character Char_T> | |
| expression_formatter & | operator<< (const basic_c_string< Char_T > &s) |
|
Appends a C string operand of a comparator. More... | |
template <typename Char_T, std::size_t N> | |
| expression_formatter & | operator<< (const Char_T(&s)[N]) |
|
Appends the text held by an array of characters. More... | |
template <class Lhs_T, class Rhs_T> | |
| expression_formatter & | operator<< (const detail::and_op< Lhs_T, Rhs_T > &op) |
|
Formats a logical AND as (lhs and rhs). More... | |
template <class Lhs_T, class Rhs_T, class Epsilon_T> | |
| expression_formatter & | operator<< (const detail::approx_op< Lhs_T, Rhs_T, Epsilon_T > &op) |
|
Formats an approximate comparison as lhs ~ (rhs +/- epsilon). More... | |
template <class Lhs_T, class Rhs_T, class Compare_T> | |
| expression_formatter & | operator<< (const detail::compare_op< Lhs_T, Rhs_T, Compare_T > &op) |
template <class T> | |
| expression_formatter & | operator<< (const detail::not_op< T > &op) |
|
Formats a logical NOT as not operand. More... | |
| expression_formatter & | operator<< (const detail::nothrow_op &op) |
template <class Lhs_T, class Rhs_T> | |
| expression_formatter & | operator<< (const detail::or_op< Lhs_T, Rhs_T > &op) |
|
Formats a logical OR as (lhs or rhs). More... | |
template <class T, class Predicate_T> | |
| expression_formatter & | operator<< (const detail::predicate_op< T, Predicate_T > &op) |
|
Formats a unary predicate as symbol operand. More... | |
template <class Exception_T> | |
| expression_formatter & | operator<< (const detail::throws_op< Exception_T > &op) |
|
Formats a throws expression as throws<TypeName>, or as throws when any exception is expected. More... | |
| expression_formatter & | operator<< (const named_bool &b) |
|
Appends the name of a named boolean constant. More... | |
template <class Rep, class Period> | |
| expression_formatter & | operator<< (const std::chrono::duration< Rep, Period > &d) |
|
Appends a duration, as the count followed by the unit. More... | |
template <class T> | |
| expression_formatter & | operator<< (const std::optional< T > &o) |
|
Appends the value of an optional, or nullopt. More... | |
template <class T1, class T2> | |
| expression_formatter & | operator<< (const std::pair< T1, T2 > &p) |
|
Appends the members of a pair, as (first, second). More... | |
template <class... Ts> | |
| expression_formatter & | operator<< (const std::tuple< Ts... > &t) |
|
Appends the elements of a tuple, as (e1, e2, …). More... | |
template <class T> | |
| expression_formatter & | operator<< (const T &t) |
|
Appends a container's elements enclosed in braces. More... | |
template <class T> | |
| expression_formatter & | operator<< (const T &t) |
|
Appends the value of a framework value wrapper via detail::unwrap(). More... | |
| expression_formatter & | operator<< (double v) |
|
Appends a double value (no suffix). More... | |
| expression_formatter & | operator<< (float v) |
|
Appends a float value with type suffix "f". More... | |
| expression_formatter & | operator<< (long double v) |
|
Appends a long double value with type suffix "L". More... | |
template <typename Pointer_T> | |
| expression_formatter & | operator<< (Pointer_T s) |
|
Appends the text of a null-terminated C string of any character type. More... | |
| expression_formatter & | operator<< (signed char c) |
|
Appends a signed char value, as a cast. More... | |
| expression_formatter & | operator<< (signed int v) |
|
Appends a signed int value (no suffix). More... | |
| expression_formatter & | operator<< (signed long long v) |
|
Appends a signed long long value with type suffix "ll". More... | |
| expression_formatter & | operator<< (signed long v) |
|
Appends a signed long value with type suffix "l". More... | |
| expression_formatter & | operator<< (signed short v) |
|
Appends a signed short value, as a cast. More... | |
| expression_formatter & | operator<< (std::nullopt_t) |
|
Appends the string "nullopt". More... | |
| expression_formatter & | operator<< (std::nullptr_t) |
|
Appends the string "nullptr". More... | |
| expression_formatter & | operator<< (std::string_view sv) |
|
Appends a string view to the buffer. More... | |
| expression_formatter & | operator<< (std::u16string_view sv) |
|
Appends a UTF-16 string view to the buffer, as UTF-8. More... | |
| expression_formatter & | operator<< (std::u32string_view sv) |
|
Appends a UTF-32 string view to the buffer, as UTF-8. More... | |
| expression_formatter & | operator<< (std::wstring_view sv) |
|
Appends a wide string view to the buffer, as UTF-8. More... | |
template <typename T> | |
| expression_formatter & | operator<< (T *v) |
|
Appends the hexadecimal address of a pointer. More... | |
template <class T> | |
| expression_formatter & | operator<< (T v) |
|
Appends the underlying value of a scoped enumeration. More... | |
| expression_formatter & | operator<< (unsigned char c) |
|
Appends an unsigned char value, as a cast. More... | |
| expression_formatter & | operator<< (unsigned int v) |
|
Appends an unsigned int value with type suffix "u". More... | |
| expression_formatter & | operator<< (unsigned long long v) |
|
Appends an unsigned long long value with type suffix "ull". More... | |
| expression_formatter & | operator<< (unsigned long v) |
|
Appends an unsigned long value with type suffix "ul". More... | |
| expression_formatter & | operator<< (unsigned short v) |
|
Appends an unsigned short value, as a cast. More... | |
| expression_formatter & | operator<< (wchar_t c) |
|
Appends a wide character, as a quoted L literal, to the buffer. More... | |
| expression_formatter & | operator= (const expression_formatter &)=delete |
|
Deleted copy assignment operator to prevent copying. More... | |
| expression_formatter & | operator= (expression_formatter &&)=delete |
|
Deleted move assignment operator to prevent moving. More... | |
Private Operators Index
| expression_formatter & | operator<< (colour_code code) |
|
Appends a colour code, as it is. More... | |
Public Member Functions Index
| const std::string & | str (void) const noexcept |
|
Returns the text written to the formatter. More... | |
Private Member Functions Index
template <class Lhs_T, class Rhs_T> | |
| void | append_and_operand (const detail::and_op< Lhs_T, Rhs_T > &op) |
|
Appends the operands of a logical AND, separated by and. More... | |
template <class T> | |
| void | append_and_operand (const T &t) |
|
Appends an operand of a chain of logical ANDs. More... | |
| void | append_c_string (const char *s, std::size_t capacity) |
|
Appends the text of a C string held in a buffer of a known capacity. More... | |
| void | append_c_string (const char16_t *s, std::size_t capacity) |
|
Appends the text of a UTF-16 C string held in a buffer of a known capacity. More... | |
| void | append_c_string (const char32_t *s, std::size_t capacity) |
|
Appends the text of a UTF-32 C string held in a buffer of a known capacity. More... | |
| void | append_c_string (const wchar_t *s, std::size_t capacity) |
|
Appends the text of a wide C string held in a buffer of a known capacity. More... | |
| void | append_character (std::string_view prefix, char32_t code, std::size_t size) |
|
Appends a character, or a code unit, as a quoted literal. More... | |
| void | append_decimal_point (std::size_t start) |
|
Adds a decimal point to a floating-point value formatted as an integer. More... | |
template <class Tuple_T, std::size_t... Is> | |
| void | append_elements (const Tuple_T &t, std::index_sequence< Is... >) |
|
Appends the elements of a tuple-like object, separated by commas. More... | |
template <class Lhs_T, class Rhs_T> | |
| void | append_first_difference (const Lhs_T &lhs, const Rhs_T &rhs) |
|
Appends the index of the first difference of two ranges, if it is not among the elements written. More... | |
template <class Lhs_T, class Rhs_T, class Epsilon_T> | |
| void | append_not_operand (const detail::approx_op< Lhs_T, Rhs_T, Epsilon_T > &op, colour_code outer_colour) |
|
Appends an approximate comparison that is the operand of a negation, between parentheses. More... | |
template <class Lhs_T, class Rhs_T, class Compare_T> | |
| void | append_not_operand (const detail::compare_op< Lhs_T, Rhs_T, Compare_T > &op, colour_code outer_colour) |
|
Appends a comparison that is the operand of a negation, between parentheses. More... | |
template <class T> | |
| void | append_not_operand (const T &t, colour_code outer_colour) |
|
Appends the operand of a negation. More... | |
template <class T> | |
| void | append_operand (const T &value) |
|
Appends an operand of an expression. More... | |
template <class Lhs_T, class Rhs_T> | |
| void | append_or_operand (const detail::or_op< Lhs_T, Rhs_T > &op) |
|
Appends the operands of a logical OR, separated by or. More... | |
template <class T> | |
| void | append_or_operand (const T &t) |
|
Appends an operand of a chain of logical ORs. More... | |
| void | append_suffix (const char *suffix) |
|
Appends the type suffix of a number. More... | |
| void | append_throw_reason (const detail::callable_op &op) |
|
Appends the reason why a check of the exceptions failed. More... | |
template <class T> | |
| void | append_value (const T &value) |
|
Appends an element of a range, pair, tuple, or optional. More... | |
| void | begin_check (const void *owner) |
|
Prepares the buffer for the expression of a new check. More... | |
| const std::string & | check_text (const void *owner) const noexcept |
|
Returns the expression text of a check. More... | |
| colour_code | colour (const bool cond) const |
|
Selects the appropriate colour code based on a condition. More... | |
| colour_code | colour_none (void) const |
|
Returns the colour code that resets the colour. More... | |
| void | end_check (const void *owner) noexcept |
|
Releases the expression text of a check, after it was reported. More... | |
| void | prepend_cast (std::size_t start, const char *type) |
|
Prefixes a number with its type, written as a cast. More... | |
Private Member Attributes Index
| std::string | buffer_ {} |
|
The internal output buffer. More... | |
| const colours & | colours_ |
|
ANSI colour codes for output formatting. More... | |
| const void * | owner_ { nullptr } |
|
The check whose expression is in the buffer. More... | |
| std::vector< std::pair< const void *, std::string > > | pending_ {} |
|
The expression texts of the pending checks whose buffer was reused. More... | |
| const bool | plain_ { false } |
|
Whether the formatter writes a message. More... | |
Private Static Attributes Index
| static constexpr size_t | max_range_elements_ = 16 |
|
The maximum number of elements of a range written. More... | |
Deprecated Functions Index
| const char * | c_str (void) const noexcept |
|
Deprecated access to the text as a C string. More... | |
| bool | empty (void) const noexcept |
|
Deprecated test for an empty text. More... | |
Description
Formats values and expressions into an owned string buffer.
expression_formatter owns a std::string buffer and provides operator<< overloads for all standard arithmetic types, character types, strings, pointers, containers, scoped enumerations (including std::byte), pairs, tuples, optionals, and framework expression types (see extension::is_op).
The numeric overloads append a type suffix (e.g., 42u, 3l, 1.5f, 1.5L) and write the types that have no standard literal suffix as a cast ((unsigned short)3); int and double have no suffix, and the floating-point values always have a decimal point or an exponent (42.0), so that they can be distinguished from the integers.
The same overloads also write the messages appended to the checks (expect (...) << value), so that a message accepts the same values as an expression, including the application types with an operator<< for this formatter. For the messages, check_result uses a formatter in the plain mode, which writes the numbers without the type suffixes and without the added decimal point (42, 1.5), and the strings and the char values without quotes, as text, with only the control characters other than the tab and the line feed, and DEL, escaped; the other values are written as in the expressions.
The class is non-copyable and non-movable to avoid accidental copying of the internal buffer.
Apart from the constructors, the public members are the operator<< overloads and the read-only str(), so that the application operator<< functions for user-defined types can only append text. The functions that assign the buffer to a check, and return and release its text, are private, and called only by check_result, a friend; an application function calling them would corrupt the texts of the pending checks.
Definition at line 229 of file expression-formatter.h.
Friends
check_result
|
The check result, which formats its expression and its message.
It assigns the buffer to the checks, retrieves and releases their texts, and uses the plain mode for the messages.
Definition at line 239 of file expression-formatter.h.
Reference check_result.
Referenced by check_result.
plain_text
|
The plain text writer, for the names of the test cases and the operands of the application types.
It uses the plain mode, which is private, to write the values in the names generated by test_each(), and, for append_operand(), the operands written by an application operator<<.
Definition at line 251 of file expression-formatter.h.
Reference plain_text.
Referenced by plain_text.
Public Constructors
expression_formatter()
| inline noexcept |
Constructor with colour configuration.
- Parameters
-
colours Reference to a colours instance for output formatting; it must outlive the formatter.
Initialises the colours_ reference with the provided colours instance. The internal buffer is default-initialised to an empty string.
Declaration at line 275 of file expression-formatter.h, definition at line 90 of file expression-formatter-inlines.h.
Reference colours_.
expression_formatter()
| delete |
Deleted copy constructor to prevent copying.
The formatter is owned by a reporter and refers to its colours.
Definition at line 283 of file expression-formatter.h.
Reference expression_formatter.
expression_formatter()
| delete |
Deleted move constructor to prevent moving.
The formatter is owned by a reporter and refers to its colours.
Definition at line 291 of file expression-formatter.h.
Reference expression_formatter.
expression_formatter()
| inline noexcept |
Constructs a formatter without colours.
Writes the values as in the expressions of the reports, with the type suffixes, but without colours. Intended for the applications that test their own operator<< functions without a runner: construct a formatter, write a value, and compare str() with the expected text.
- Parameters
None.
Refers to the colours_none set, so that nothing is coloured; the internal buffer is empty and the mode is not plain.
Declaration at line 267 of file expression-formatter.h, definition at line 80 of file expression-formatter-inlines.h.
References colours_ and micro_os_plus::micro_test_plus::detail::colours_none.
Referenced by expression_formatter, expression_formatter, ~expression_formatter, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator= and operator=.
Private Constructors
expression_formatter()
| inline explicit noexcept |
Constructs a formatter in the plain mode, for a message.
Used only by check_result and plain_text, which move their text into the buffer, append a value, and move the text back, so that no other buffer is allocated. The plain mode writes the numbers without the type suffixes and without the added decimal point, and the strings and the char values without quotes, with only some control characters escaped; the messages are never coloured.
- Parameters
-
buffer The text to which the values are appended.
Takes over the text of buffer, without copying it, refers to the colours_none set, and sets the plain mode.
Declaration at line 1253 of file expression-formatter.h, definition at line 101 of file expression-formatter-inlines.h.
References buffer_, colours_, micro_os_plus::micro_test_plus::detail::colours_none and plain_.
Public Destructor
~expression_formatter()
| default |
Default destructor.
Releases the internal buffer; the referenced colours are not owned.
Definition at line 319 of file expression-formatter.h.
Reference expression_formatter.
Public Operators
operator<<()
|
Appends the string representation of a boolean value.
- Parameters
-
v The boolean value.
- Returns
Reference to this instance.
Appends the string "true" or "false" to the internal buffer based on the value of v.
Declaration at line 600 of file expression-formatter.h, definition at line 711 of file expression-formatter.cpp.
References expression_formatter and buffer_.
operator<<()
|
Appends a character, as a quoted literal, to the buffer.
The character is written between single quotes, with the non-printable characters escaped ('a', ' ', '\\0', '\\x1b'), so that it can be identified in the reports. To write a separator without quotes, use a string (" "). In the plain mode, used for the messages, the character is appended without quotes, and escaped only if it is a control character other than the tab and the line feed, or DEL.
- Parameters
-
c The character to append.
- Returns
Reference to this instance.
The character is written as a C++ character literal, between single quotes, by append_character(), so that the spaces and the control characters are visible, and a zero does not end the text when it is printed as a C string. The values above 0x7F (for example the bytes of the UTF-8 sequences) are written as two hexadecimal digits ('\\xc3').
In the plain mode, used for the messages, the character is appended as text, without quotes, and escaped only if it is a control character other than the tab and the line feed, or DEL, as append_plain() does for the strings.
Declaration at line 414 of file expression-formatter.h, definition at line 529 of file expression-formatter.cpp.
References expression_formatter, append_character, micro_os_plus::micro_test_plus::detail::append_control_escape, buffer_ and plain_.
operator<<()
|
Appends a UTF-16 code unit, as a quoted u literal, to the buffer.
The value is written with the u prefix and the escapes of char (u'a', u'\\n'); the other values outside ASCII are written as universal character names (u'\\u00e9'), and the surrogates, which are halves of the pairs, not characters, as four hexadecimal digits (u'\\xd83d'). Without the overload, the value would be promoted to int and written as a number. The plain mode, used for the messages, writes it in the same way, since it cannot be appended unchanged.
- Parameters
-
c The code unit to append.
- Returns
Reference to this instance.
Written by append_character() with the u prefix, also in the plain mode.
Declaration at line 455 of file expression-formatter.h, definition at line 568 of file expression-formatter.cpp.
References expression_formatter and append_character.
operator<<()
|
Appends a UTF-32 character, as a quoted U literal, to the buffer.
The value is written with the U prefix and the escapes of char (U'a', U'\\n'); the other values outside ASCII are written as universal character names (U'\\u00e9', U'\\U0001f600'), and the values that are not Unicode characters (the surrogates and the values above 0x10FFFF) as eight hexadecimal digits (U'\\x0000d83d'). Without the overload, the value would be promoted to unsigned int and written as a number. The plain mode, used for the messages, writes it in the same way, since it cannot be appended unchanged.
- Parameters
-
c The character to append.
- Returns
Reference to this instance.
Written by append_character() with the U prefix, also in the plain mode.
Declaration at line 476 of file expression-formatter.h, definition at line 580 of file expression-formatter.cpp.
References expression_formatter and append_character.
operator<<()
|
Appends a C string operand of a comparator.
Quoted and escaped as a string view of the character type (with the prefix of the wide and Unicode strings); a null pointer is written as nullptr.
- Template Parameters
-
Char_T The character type of the operand.
- Parameters
-
s The operand.
- Returns
Reference to this instance.
Appends the characters of the string, quoted and escaped as the overload for the string view of the character type does (without quotes in the plain mode, with only the control characters escaped), or "nullptr" for a null pointer, as the other operator overloads do for these values.
Declaration at line 576 of file expression-formatter.h, definition at line 436 of file expression-formatter-inlines.h.
References expression_formatter, buffer_, micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::is_null and micro_os_plus::micro_test_plus::detail::basic_c_string< Char_T >::view.
operator<<()
|
Appends the text held by an array of characters.
Selected for the arrays of the character types, including the string literals, but not for the volatile characters, whose arrays are written as the pointers they decay to are. The text ends at the first null character or at the end of the array, whichever comes first, so that an array that is full, without a terminator, such as a fixed-size name field, is not read beyond its end. Otherwise it is written as the overload for the character pointers writes the text of a pointer.
- Template Parameters
-
Char_T The character type; it satisfies detail::character, and is not volatile.
N The number of elements of the array.
- Parameters
-
s The array.
- Returns
Reference to this instance.
The size of the array limits the characters read, so that an array that is full, without a terminator, is not read beyond its end.
Declaration at line 560 of file expression-formatter.h, definition at line 203 of file expression-formatter-inlines.h.
References expression_formatter and append_c_string.
operator<<()
|
Formats a logical AND as (lhs and rhs).
A chain of ANDs, as built by all_of() for more than two operands, is written as a single group, (a and b and c).
- Template Parameters
-
Lhs_T Left-hand operand type.
Rhs_T Right-hand operand type.
- Parameters
-
op The logical AND expression.
- Returns
Reference to this instance.
The operands, written by append_and_operand(), are separated by the word and, in the colour of the result of each conjunction; a chain of conjunctions is enclosed in a single pair of parentheses, which are not coloured.
Declaration at line 975 of file expression-formatter.h, definition at line 605 of file expression-formatter-inlines.h.
References expression_formatter and append_and_operand.
operator<<()
|
Formats an approximate comparison as lhs ~ (rhs +/- epsilon).
The notation is the one used by Boost UT, in ASCII, so that it is also valid in the TAP output.
- Template Parameters
-
Lhs_T Left-hand operand type.
Rhs_T Right-hand operand type.
Epsilon_T Tolerance type.
- Parameters
-
op The comparison expression.
- Returns
Reference to this instance.
Formats the operands of an approximate comparison as lhs ~ (rhs +/- epsilon), in the colour of the result, as the relational comparisons are.
Declaration at line 959 of file expression-formatter.h, definition at line 589 of file expression-formatter-inlines.h.
References expression_formatter, colour and colour_none.
operator<<()
|
Formats a relational comparison as lhs op rhs.
The operator symbol is taken from the tag (for example == for detail::equal_to).
- Template Parameters
-
Lhs_T Left-hand operand type.
Rhs_T Right-hand operand type.
Compare_T The tag that defines the comparison.
- Parameters
-
op The comparison expression.
- Returns
Reference to this instance.
The left-hand side and right-hand side values are formatted and separated by the operator symbol of the tag (==, !=, >, >=, <, or <= for the built-in tags, or the symbol of an application tag), in the colour of the result (green for passed, red for failed, when colours are enabled).
If an equality compares two ranges that are written truncated, the index of the first difference is appended, if the elements written do not show it (see append_first_difference()).
Declaration at line 941 of file expression-formatter.h, definition at line 518 of file expression-formatter-inlines.h.
References expression_formatter, append_first_difference, append_operand, colour and colour_none.
operator<<()
|
Formats a logical NOT as not operand.
A negated comparison is written between parentheses (not (a == b)), so that the negation is not read as applying to the left operand only.
- Template Parameters
-
T The operand type.
- Parameters
-
op The logical NOT expression.
- Returns
Reference to this instance.
Writes the word not, followed by the operand, in the colour of the result of the negation. A comparison is written between parentheses (see append_not_operand()).
Declaration at line 1007 of file expression-formatter.h, definition at line 690 of file expression-formatter-inlines.h.
References expression_formatter, append_not_operand, colour and colour_none.
operator<<()
| inline |
Formats a nothrow expression as nothrow.
If the check failed, the reason is appended (see append_throw_reason()).
- Parameters
-
op The nothrow expression.
- Returns
Reference to this instance.
Writes nothrow, in the colour of the result.
It is defined inline, not in the library sources, so that it is available to the applications built with exceptions even when the library is built without them.
Declaration at line 1055 of file expression-formatter.h, definition at line 796 of file expression-formatter-inlines.h.
References expression_formatter, append_throw_reason, colour and colour_none.
operator<<()
|
Formats a logical OR as (lhs or rhs).
A chain of ORs, as built by any_of() for more than two operands, is written as a single group, (a or b or c).
- Template Parameters
-
Lhs_T Left-hand operand type.
Rhs_T Right-hand operand type.
- Parameters
-
op The logical OR expression.
- Returns
Reference to this instance.
The operands, written by append_or_operand(), are separated by the word or, in the colour of the result of each disjunction; a chain of disjunctions is enclosed in a single pair of parentheses, which are not coloured.
Declaration at line 991 of file expression-formatter.h, definition at line 648 of file expression-formatter-inlines.h.
References expression_formatter and append_or_operand.
operator<<()
|
Formats a unary predicate as symbol operand.
The symbol is the one of the tag, written as defined by the application, so it includes the separating space.
- Template Parameters
-
T The operand type.
Predicate_T The tag that defines the predicate.
- Parameters
-
op The predicate expression.
- Returns
Reference to this instance.
Writes the symbol of the tag, followed by the operand, with the same colour highlighting as the logical negation, so that the predicates of the application are reported as the built-in expressions are.
Declaration at line 1023 of file expression-formatter.h, definition at line 749 of file expression-formatter-inlines.h.
References expression_formatter, append_operand, colour and colour_none.
operator<<()
|
Formats a throws expression as throws<TypeName>, or as throws when any exception is expected.
If the check failed, the reason is appended (see append_throw_reason()).
- Template Parameters
-
Exception_T The expected exception type, or void for any exception.
- Parameters
-
op The throws expression.
- Returns
Reference to this instance.
Writes throws, followed, when a specific exception type is expected, by its name between angle brackets, as returned by reflection::type_name(), in the colour of the result.
Declaration at line 1042 of file expression-formatter.h, definition at line 770 of file expression-formatter-inlines.h.
References expression_formatter, append_throw_reason, buffer_, colour, colour_none and micro_os_plus::micro_test_plus::reflection::type_name.
operator<<()
|
Appends the name of a named boolean constant.
The constant, created by the _b literal, is reported by its name, not by its value, which is always true.
- Parameters
-
b The named boolean constant.
- Returns
Reference to this instance.
Appends the name as it is, without quotes, so that the comparison is reported with the name instead of true.
Declaration at line 590 of file expression-formatter.h, definition at line 698 of file expression-formatter.cpp.
References expression_formatter, buffer_ and micro_os_plus::micro_test_plus::detail::named_bool::name.
operator<<()
|
Appends a duration, as the count followed by the unit.
The count is written without a type suffix, followed by the unit: ns, us, ms, s, min, or h for the standard periods, or the ratio, as [N/D]s, for the other ones. The overload takes part in the overload resolution only if the count is an arithmetic type.
- Template Parameters
-
Rep The type of the count.
Period The period of the duration.
- Parameters
-
d The duration.
- Returns
Reference to this instance.
Writes the count with append_number(), without a type suffix, then the unit selected from the period; the periods without a standard unit are written as the ratio, [N/D]s, with the numerator and the denominator also written with append_number(), without type suffixes.
Declaration at line 921 of file expression-formatter.h, definition at line 371 of file expression-formatter-inlines.h.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number and buffer_.
operator<<()
|
Appends the value of an optional, or nullopt.
A value is formatted through operator<<, as the contained type, so an optional with a value is written as the value alone; an optional without a value is written as nullopt. The overload takes part in the overload resolution only if the contained type is printable.
- Template Parameters
-
T The type of the contained value.
- Parameters
-
o The optional.
- Returns
Reference to this instance.
Streams the contained value through operator<< if there is one, otherwise streams std::nullopt.
Declaration at line 901 of file expression-formatter.h, definition at line 350 of file expression-formatter-inlines.h.
References expression_formatter and append_value.
operator<<()
|
Appends the members of a pair, as (first, second).
Each member is formatted through operator<<, so the pairs stored in the maps are also formatted, as {(1, 2), (3, 4)}. The overload takes part in the overload resolution only if both members are printable, so that extension::printable is false for a pair that cannot be written.
- Template Parameters
-
T1 The type of the first member.
T2 The type of the second member.
- Parameters
-
p The pair.
- Returns
Reference to this instance.
Writes the opening parenthesis, the two members through append_elements(), and the closing parenthesis.
Declaration at line 865 of file expression-formatter.h, definition at line 318 of file expression-formatter-inlines.h.
References expression_formatter and append_elements.
operator<<()
|
Appends the elements of a tuple, as (e1, e2, …).
Each element is formatted through operator<<; an empty tuple is written as (). The overload takes part in the overload resolution only if all the elements are printable.
- Template Parameters
-
Ts The types of the elements.
- Parameters
-
t The tuple.
- Returns
Reference to this instance.
Writes the opening parenthesis, the elements through append_elements(), and the closing parenthesis.
Declaration at line 882 of file expression-formatter.h, definition at line 334 of file expression-formatter-inlines.h.
References expression_formatter and append_elements.
operator<<()
|
Appends a container's elements enclosed in braces.
Elements are formatted as { e1, e2, … } by iterating the container and recursing through operator<< for each element. Only the first 16 elements are written, followed by ", ... (<count> elements)" if there are more; the elements of the types signed char and unsigned char are written as plain numbers, without the type suffix.
- Template Parameters
-
T A range type satisfying detail::formattable_range: with begin() and end() members or functions, not an array, not a string, without elements of its own type, and with printable elements.
- Parameters
-
t The container.
- Returns
Reference to this instance.
Definition at line 819 of file expression-formatter.h.
References expression_formatter, c_str, empty and str.
operator<<()
|
Appends the value of a framework value wrapper via detail::unwrap().
Only the wrappers with a get() accessor (the to_* wrappers and the literals) are accepted. Any other type satisfying extension::is_op must have its own overload, as the built-in expressions and extension::compare_op and extension::predicate_op have; without it, detail::unwrap() would return the expression itself, and this overload would call itself without end, so such a type is rejected at compile time.
- Template Parameters
-
T A value wrapper type satisfying extension::is_op<T>, with a get() accessor.
- Parameters
-
t The value wrapper.
- Returns
Reference to this instance.
Delegates to detail::unwrap(t) to obtain the displayable value of a value wrapper, then streams it through operator<< to format it into the buffer. The get() constraint guarantees that detail::unwrap(t) returns the wrapped value, not the wrapper itself, which would select this overload again.
Iterates the container and formats each element separated by ", ", surrounded by { and }. Each element is streamed through operator<<, which recurses as needed for nested types.
Only the first max_range_elements_ elements are written; if there are more, the elements are still counted, and the text ", ... (<count> elements)" is written after the last one, so that a check on a large buffer neither exhausts the memory nor buries the report. The elements of the types signed char and unsigned char (such as std::uint8_t) are bytes, not numbers with a type, so they are written without the type suffix.
The range-based for statement uses the begin() and end() members, or, if there are none, the functions found by argument-dependent lookup, as detail::formattable_range does.
Declaration at line 795 of file expression-formatter.h, definition at line 235 of file expression-formatter-inlines.h.
References expression_formatter and micro_os_plus::micro_test_plus::detail::unwrap.
operator<<()
|
Appends a double value (no suffix).
An integral value is written with a decimal point (42.0), to distinguish it from an int.
- Parameters
-
v The double value.
- Returns
Reference to this instance.
Converts v to its string representation via append_number() and adds the decimal point if needed (via append_decimal_point()), without a type suffix.
Declaration at line 734 of file expression-formatter.h, definition at line 907 of file expression-formatter.cpp.
References expression_formatter, append_decimal_point, micro_os_plus::micro_test_plus::detail::append_number and buffer_.
operator<<()
|
Appends a float value with type suffix "f".
An integral value is written with a decimal point (42.0f); the infinities and the NaNs are written without the suffix.
- Parameters
-
v The float value.
- Returns
Reference to this instance.
Converts v to its string representation via append_number(), adds the decimal point if needed (via append_decimal_point()), and appends the type suffix "f", unless the text is an infinity or a NaN, which would read as a misspelling (inff).
Declaration at line 721 of file expression-formatter.h, definition at line 888 of file expression-formatter.cpp.
References expression_formatter, append_decimal_point, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends a long double value with type suffix "L".
An integral value is written with a decimal point (42.0L); the infinities and the NaNs are written without the suffix.
- Parameters
-
v The long double value.
- Returns
Reference to this instance.
Converts v to its string representation via append_number(), adds the decimal point if needed (via append_decimal_point()), and appends the type suffix "L", the C++ suffix of the long double literals (there is no suffix "ld"), written in upper case, since "l" would suggest long. The suffix is not appended to an infinity or a NaN, which would read as a misspelling (infL).
Declaration at line 747 of file expression-formatter.h, definition at line 926 of file expression-formatter.cpp.
References expression_formatter, append_decimal_point, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends the text of a null-terminated C string of any character type.
Selected for the pointers to the character types (char, wchar_t, char8_t, char16_t, and char32_t, possibly const), including the string literals when they are passed through a pointer; the arrays are written by the overload for arrays, which does not read beyond the array. A null pointer is rendered as "nullptr". The text must be null-terminated.
The char text is appended without quotes, with only the control characters other than the tab and the line feed, and DEL, escaped, in both modes, since this is how the string literals are written by the operator<< functions of the applications, for example for separators. The char pointers that are values to be reported, such as the operands of the comparators and the elements of the ranges, pairs, tuples, and optionals, are written quoted, like the std::string values, by the overload for basic_c_string; an application writes a quoted value with a std::string_view.
The text of the pointers and of the arrays of the wide character types is converted to UTF-8 and written as the char text is, in both modes, without quotes, so that the string literals of these types can be used by the applications, for example as separators. As operands of the comparators, these pointers and arrays are reported quoted, like the std::wstring values, by the overload for basic_c_string.
- Template Parameters
-
Pointer_T The pointer type; it satisfies detail::character_pointer.
- Parameters
-
s The C string, or a null pointer.
- Returns
Reference to this instance.
The text is not bounded, so it must be null-terminated; the overload for the arrays is more specialised, so it is selected for the arrays, which cannot be read beyond their end.
Declaration at line 536 of file expression-formatter.h, definition at line 189 of file expression-formatter-inlines.h.
References expression_formatter and append_c_string.
operator<<()
|
Appends a signed char value, as a cast.
- Parameters
-
c The signed char value.
- Returns
Reference to this instance.
Converts c to its decimal string representation via append_number() and prefixes it with the cast (signed char), since the type has no standard literal suffix, and the suffix "c" would suggest char, which is written as a character.
Declaration at line 627 of file expression-formatter.h, definition at line 748 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, buffer_ and prepend_cast.
operator<<()
|
Appends a signed int value (no suffix).
- Parameters
-
v The signed int value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() without a type suffix.
Declaration at line 663 of file expression-formatter.h, definition at line 809 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number and buffer_.
operator<<()
|
Appends a signed long long value with type suffix "ll".
- Parameters
-
v The signed long long value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and appends the type suffix "ll".
Declaration at line 699 of file expression-formatter.h, definition at line 860 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends a signed long value with type suffix "l".
- Parameters
-
v The signed long value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and appends the type suffix "l".
Declaration at line 681 of file expression-formatter.h, definition at line 834 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends a signed short value, as a cast.
- Parameters
-
v The signed short value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and prefixes it with the cast (short), since the type has no standard literal suffix, and the suffix "s" would be that of the std::chrono::seconds durations.
Declaration at line 645 of file expression-formatter.h, definition at line 779 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, buffer_ and prepend_cast.
operator<<()
|
Appends the string "nullopt".
Selected for std::nullopt, so that an optional value can be compared with it (eq (opt, std::nullopt)).
- Returns
Reference to this instance.
Appends the string "nullopt" to the internal buffer; also used by the std::optional template for the optionals without a value.
Declaration at line 619 of file expression-formatter.h, definition at line 734 of file expression-formatter.cpp.
References expression_formatter and buffer_.
operator<<()
|
Appends the string "nullptr".
- Returns
Reference to this instance.
Appends the string "nullptr" to the internal buffer.
Declaration at line 608 of file expression-formatter.h, definition at line 722 of file expression-formatter.cpp.
References expression_formatter and buffer_.
operator<<()
|
Appends a string view to the buffer.
The string is written between double quotes, with the control characters, the double quote, and the backslash escaped. In the plain mode, used for the messages, it is appended without quotes, with only the control characters other than the tab and the line feed, and DEL, escaped, since they can change the state of a terminal, or truncate a text.
- Parameters
-
sv The string view to append.
- Returns
Reference to this instance.
The string is written as a C++ string literal, between double quotes, by append_quoted(), so that the empty and blank strings are visible, and the control characters are escaped. In the plain mode, used for the messages, the contents are appended without quotes, by append_plain(), with only the control characters that can change the state of a terminal, or truncate a text, escaped (all except the tab and the line feed, and DEL).
Declaration at line 338 of file expression-formatter.h, definition at line 448 of file expression-formatter.cpp.
References expression_formatter, buffer_ and plain_.
operator<<()
|
Appends a UTF-16 string view to the buffer, as UTF-8.
Written as the overload for std::wstring_view writes the text.
- Parameters
-
sv The string view to append.
- Returns
Reference to this instance.
Converted to UTF-8, and written as a std::string_view is.
Declaration at line 384 of file expression-formatter.h, definition at line 499 of file expression-formatter.cpp.
Reference expression_formatter.
operator<<()
|
Appends a UTF-32 string view to the buffer, as UTF-8.
Written as the overload for std::wstring_view writes the text.
- Parameters
-
sv The string view to append.
- Returns
Reference to this instance.
Converted to UTF-8, and written as a std::string_view is.
Declaration at line 396 of file expression-formatter.h, definition at line 509 of file expression-formatter.cpp.
Reference expression_formatter.
operator<<()
|
Appends a wide string view to the buffer, as UTF-8.
The text is converted to UTF-8 and written as a std::string_view is: between double quotes, with the control characters, the double quote, and the backslash escaped, or, in the plain mode, used for the messages, without quotes, with only some control characters escaped. The code units that are not valid, such as an unpaired surrogate, are written as the replacement character U+FFFD. The wchar_t units are taken as UTF-16 where wchar_t has 16 bits, and as UTF-32 otherwise.
- Parameters
-
sv The string view to append.
- Returns
Reference to this instance.
Converted to UTF-8, as UTF-16 where wchar_t has 16 bits, and as UTF-32 otherwise, and written as a std::string_view is.
Declaration at line 357 of file expression-formatter.h, definition at line 467 of file expression-formatter.cpp.
Reference expression_formatter.
operator<<()
|
Appends the hexadecimal address of a pointer.
Null pointers are rendered as "0x0". Non-null pointers are formatted with snprintf using the p specifier.
The pointers to the character types are excluded, so that they are written as strings by the overload for the character pointers; the signed char and unsigned char pointers, usually byte buffers, are written as addresses.
- Template Parameters
-
T The type pointed to, other than a character type.
- Parameters
-
v The pointer value.
- Returns
Reference to this instance.
The address is formatted by the detail::append_pointer() helper, shared with the detail::reporter.
Declaration at line 771 of file expression-formatter.h, definition at line 217 of file expression-formatter-inlines.h.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_pointer and buffer_.
operator<<()
|
Appends the underlying value of a scoped enumeration.
The value is converted to the underlying type and formatted as that type, with its suffix (for example 1 for an int and (unsigned char)1 for std::byte, whose underlying type is unsigned char).
The unscoped enumerations are not selected, since they convert implicitly to an integer, and are formatted as one.
An operator<< defined by the application for an enumeration, for example to write the names of the enumerators, is preferred to this template.
- Template Parameters
-
T A scoped enumeration type.
- Parameters
-
v The enumeration value.
- Returns
Reference to this instance.
Converts the value with static_cast to the underlying type, and streams the result through operator<<, which selects the overload of that type.
Declaration at line 845 of file expression-formatter.h, definition at line 305 of file expression-formatter-inlines.h.
Reference expression_formatter.
operator<<()
|
Appends an unsigned char value, as a cast.
- Parameters
-
c The unsigned char value.
- Returns
Reference to this instance.
Converts c to its decimal string representation via append_number() and prefixes it with the cast (unsigned char), since the type has no standard literal suffix.
Declaration at line 636 of file expression-formatter.h, definition at line 763 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, buffer_ and prepend_cast.
operator<<()
|
Appends an unsigned int value with type suffix "u".
- Parameters
-
v The unsigned int value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and appends the type suffix "u".
Declaration at line 672 of file expression-formatter.h, definition at line 821 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends an unsigned long long value with type suffix "ull".
- Parameters
-
v The unsigned long long value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and appends the type suffix "ull".
Declaration at line 708 of file expression-formatter.h, definition at line 873 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends an unsigned long value with type suffix "ul".
- Parameters
-
v The unsigned long value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and appends the type suffix "ul".
Declaration at line 690 of file expression-formatter.h, definition at line 847 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, append_suffix and buffer_.
operator<<()
|
Appends an unsigned short value, as a cast.
- Parameters
-
v The unsigned short value.
- Returns
Reference to this instance.
Converts v to its decimal string representation via append_number() and prefixes it with the cast (unsigned short), since the type has no standard literal suffix, and the suffix "us" would be that of the std::chrono::microseconds durations.
Declaration at line 654 of file expression-formatter.h, definition at line 795 of file expression-formatter.cpp.
References expression_formatter, micro_os_plus::micro_test_plus::detail::append_number, buffer_ and prepend_cast.
operator<<()
|
Appends a wide character, as a quoted L literal, to the buffer.
The value is written with the L prefix, as a char16_t value where wchar_t has 16 bits (Windows), and as a char32_t value elsewhere (L'a', L'\\u00e9'); a negative value is written by its bits. Without the overload, the value would be promoted to an integer type and written as a number. The plain mode, used for the messages, writes it in the same way, since it cannot be appended unchanged.
- Parameters
-
c The character to append.
- Returns
Reference to this instance.
Written by append_character() with the L prefix, also in the plain mode. The value is first converted to the unsigned type of the same size, so that a negative value is not sign-extended to 32 bits.
Declaration at line 495 of file expression-formatter.h, definition at line 594 of file expression-formatter.cpp.
References expression_formatter and append_character.
operator=()
| delete |
Deleted copy assignment operator to prevent copying.
The formatter is owned by a reporter and refers to its colours.
Definition at line 300 of file expression-formatter.h.
Reference expression_formatter.
operator=()
| delete |
Deleted move assignment operator to prevent moving.
The formatter is owned by a reporter and refers to its colours.
Definition at line 310 of file expression-formatter.h.
Reference expression_formatter.
Private Operators
operator<<()
| inline |
Appends a colour code, as it is.
The escape sequence is not escaped, unlike the text of the strings; the sequences are empty when the colours are not used.
- Parameters
-
code The colour code to append.
- Returns
Reference to this instance.
Appends the escape sequence to the buffer as it is, without the escaping of the control characters that the string overloads apply.
Declaration at line 1328 of file expression-formatter.h, definition at line 136 of file expression-formatter-inlines.h.
References expression_formatter, buffer_ and micro_os_plus::micro_test_plus::detail::expression_formatter::colour_code::sequence.
Public Member Functions
str()
| inline nodiscard noexcept |
Returns the text written to the formatter.
Intended for testing the application operator<< functions with a formatter constructed for this purpose; since the formatter only appends, the text of each value starts where the previous one ended. The text cannot be modified through this reference.
- Parameters
None.
- Returns
Const reference to the accumulated string.
Returns a const reference to the internal buffer_ string.
Declaration at line 1076 of file expression-formatter.h, definition at line 149 of file expression-formatter-inlines.h.
Reference buffer_.
Referenced by operator<<.
Private Member Functions
append_and_operand()
|
Appends the operands of a logical AND, separated by and.
- Template Parameters
-
Lhs_T Left-hand operand type.
Rhs_T Right-hand operand type.
- Parameters
-
op The logical AND expression.
- Returns
Nothing.
The left operand is written first, as the operands of a chain if it is a logical AND too, then the word and, coloured by the result of this operation, and the right operand.
Declaration at line 1540 of file expression-formatter.h, definition at line 631 of file expression-formatter-inlines.h.
References append_and_operand, append_operand, colour and colour_none.
append_and_operand()
|
Appends an operand of a chain of logical ANDs.
An operand that is itself a logical AND is written as the operands of a chain, without its own parentheses; any other operand is written as usual.
- Template Parameters
-
T The type of the operand.
- Parameters
-
t The operand.
- Returns
Nothing.
The generic operand is written through the usual overloads.
Declaration at line 1527 of file expression-formatter.h, definition at line 618 of file expression-formatter-inlines.h.
Reference append_operand.
Referenced by append_and_operand and operator<<.
append_c_string()
|
Appends the text of a C string held in a buffer of a known capacity.
The text ends at the first null character or after capacity characters, whichever comes first. A null pointer is written as "nullptr". The text is written without quotes, with the control characters escaped, in both modes; the text of the other character types is first converted to UTF-8. Shared by the overloads for the character pointers (unbounded capacity) and for the arrays.
- Parameters
-
s The text, or a null pointer.
capacity The number of characters that may be read, or std::string_view::npos if the text is null-terminated.
- Returns
Nothing.
The text ends at the first null character or after capacity characters. It is appended as append_plain() does, with the control characters other than the tab and the line feed, and DEL, escaped, or as "nullptr" for a null pointer, as the basic_c_string overload does; the null pointer must therefore be checked before the text is read, and no more than capacity characters are read, so that an array that is full, without a terminator, is not overread.
Declaration at line 1168 of file expression-formatter.h, definition at line 612 of file expression-formatter.cpp.
Reference buffer_.
Referenced by operator<< and operator<<.
append_c_string()
|
Appends the text of a UTF-16 C string held in a buffer of a known capacity.
As the overload for char, with the text converted to UTF-8 first.
- Parameters
-
s The text, or a null pointer.
capacity The number of characters that may be read, or std::string_view::npos if the text is null-terminated.
- Returns
Nothing.
Written as the overload for const wchar_t* writes the text.
Declaration at line 1221 of file expression-formatter.h, definition at line 664 of file expression-formatter.cpp.
Reference buffer_.
append_c_string()
|
Appends the text of a UTF-32 C string held in a buffer of a known capacity.
As the overload for char, with the text converted to UTF-8 first.
- Parameters
-
s The text, or a null pointer.
capacity The number of characters that may be read, or std::string_view::npos if the text is null-terminated.
- Returns
Nothing.
Written as the overload for const wchar_t* writes the text.
Declaration at line 1238 of file expression-formatter.h, definition at line 680 of file expression-formatter.cpp.
Reference buffer_.
append_c_string()
|
Appends the text of a wide C string held in a buffer of a known capacity.
As the overload for char, with the text converted to UTF-8 first.
- Parameters
-
s The text, or a null pointer.
capacity The number of characters that may be read, or std::string_view::npos if the text is null-terminated.
- Returns
Nothing.
The text, bounded by capacity as for the char text, is converted to UTF-8 and written as the char text is, without quotes, with the control characters escaped, whatever the mode.
Declaration at line 1185 of file expression-formatter.h, definition at line 630 of file expression-formatter.cpp.
Reference buffer_.
append_character()
|
Appends a character, or a code unit, as a quoted literal.
Shared by the overloads of all the character types, so that they escape the values in the same way. The usual escape sequences are used for '\\0', '\\a', '\\b', '\\t', '\\n', '\\v', '\\f', '\\r', '\\'', and '\\\\', and the other control characters and DEL are written as two hexadecimal digits ('\\x1b'). The values that are not characters by themselves (the values above 0x7F of the 8-bit types, the surrogates, and the values above 0x10FFFF) are written with \\x and all the hexadecimal digits of their type, and the other values outside ASCII as universal character names, \\u with four digits, or \\U with eight. The printable ASCII characters are written unchanged. The hexadecimal digits are lowercase.
- Parameters
-
prefix The prefix of the literal ("", "u8", "u", "U", or "L").
code The value, converted without the sign extension.
size The size of the character type, in bytes.
- Returns
Nothing.
A value of an 8-bit type above 0x7F is a part of a multi-byte sequence; for the wider types, the surrogates (0xD800 to 0xDFFF) and the values above 0x10FFFF are not Unicode characters, and cannot be written as universal character names. They are written with \\x and twice as many hexadecimal digits as the bytes of the type, so that the width of the type is visible. The control characters keep the two digits of char, since they are the same in all the encodings.
Declaration at line 1405 of file expression-formatter.h, definition at line 1015 of file expression-formatter.cpp.
Reference buffer_.
Referenced by operator<<, operator<<, operator<< and operator<<.
append_decimal_point()
|
Adds a decimal point to a floating-point value formatted as an integer.
Called after a floating-point value was appended to the buffer; ".0" is appended only if the value was written with digits only, and not in the plain mode.
- Parameters
-
start The position in the buffer where the value begins.
- Returns
Nothing.
The shortest representation of a floating-point value with an integral value has no decimal point (42.0 is formatted as 42), so it cannot be distinguished from an integer. If the text appended since start contains only digits, after an optional sign, ".0" is appended. The text with a decimal point or an exponent, and the infinities and NaNs, are left unchanged, as is all text in the plain mode, used for the messages.
Declaration at line 1345 of file expression-formatter.h, definition at line 949 of file expression-formatter.cpp.
References buffer_ and plain_.
Referenced by operator<<, operator<< and operator<<.
append_elements()
|
Appends the elements of a tuple-like object, separated by commas.
Shared by the pair and tuple overloads; the elements are obtained with std::get<Is>() and formatted through operator<<, without the enclosing parentheses.
- Template Parameters
-
Tuple_T A type accepted by std::get (a pair or a tuple).
Is The indices of the elements.
- Parameters
-
t The tuple-like object.
- Returns
Nothing.
Expands the indices in a fold expression over the comma operator, so the elements are written in order; the separator is omitted before the first element. For an empty tuple, nothing is written.
Declaration at line 1468 of file expression-formatter.h, definition at line 418 of file expression-formatter-inlines.h.
Reference append_value.
Referenced by operator<< and operator<<.
append_first_difference()
|
Appends the index of the first difference of two ranges, if it is not among the elements written.
A range is written with at most max_range_elements_ elements, so a difference after them is not visible in the report. The elements are compared in step, and, if the first difference is at an index not written, the text " (first difference at index <index>)" is appended. A range that is a prefix of the other differs at its size. Nothing is appended if the ranges do not differ, or if the difference is among the elements written.
- Template Parameters
-
Lhs_T Left-hand range type.
Rhs_T Right-hand range type.
- Parameters
-
lhs The left-hand range.
rhs The right-hand range.
- Returns
Nothing.
Walks both ranges in step up to the first pair of elements that differ, or up to the end of the shorter one. The elements are compared as the comparator does, with equal_to::apply(), so that integers of different signedness are compared by value.
Declaration at line 1492 of file expression-formatter.h, definition at line 555 of file expression-formatter-inlines.h.
References micro_os_plus::micro_test_plus::detail::append_number, micro_os_plus::micro_test_plus::detail::equal_to::apply, buffer_ and max_range_elements_.
Referenced by operator<<.
append_not_operand()
|
Appends an approximate comparison that is the operand of a negation, between parentheses.
- Template Parameters
-
Lhs_T The type of the left hand side operand.
Rhs_T The type of the right hand side operand.
Epsilon_T The type of the tolerance.
- Parameters
-
op The approximate comparison.
outer_colour The colour of the negation, in which the parentheses are written.
- Returns
Nothing.
As for the relational comparisons, the colour of the negation is written again before the closing parenthesis, since the comparison resets it.
Declaration at line 1629 of file expression-formatter.h, definition at line 734 of file expression-formatter-inlines.h.
append_not_operand()
|
Appends a comparison that is the operand of a negation, between parentheses.
- Template Parameters
-
Lhs_T The type of the left hand side operand.
Rhs_T The type of the right hand side operand.
Compare_T The tag of the comparison.
- Parameters
-
op The comparison.
outer_colour The colour of the negation, in which the parentheses are written.
- Returns
Nothing.
The comparison writes its own colours; the opening parenthesis is written in the colour of the negation, which is still active, and, since the comparison resets the colour at its end, the colour is written again before the closing parenthesis.
Declaration at line 1609 of file expression-formatter.h, definition at line 719 of file expression-formatter-inlines.h.
append_not_operand()
|
Appends the operand of a negation.
Written as append_operand() writes it. A comparison, which has its operator between the operands, is written between parentheses, so that not (a == b) is not read as (not a) == b. The logical combinations write their own parentheses, and the predicates, written as a prefix, and the plain Boolean values do not need them.
- Template Parameters
-
T The type of the operand.
- Parameters
-
t The operand.
outer_colour The colour of the negation, used by the overloads that write parentheses; ignored here.
- Returns
Nothing.
Written as append_operand() writes it.
Declaration at line 1591 of file expression-formatter.h, definition at line 704 of file expression-formatter-inlines.h.
Reference append_operand.
Referenced by operator<<.
append_operand()
|
Appends an operand of an expression.
An operand that the formatter has a member operator<< for is written by it, unless the application defines a free operator<< for the type. An operand of an application type, found by argument-dependent lookup, is written in the plain mode, as the messages are, so that the values that its operator<< writes are shown as it writes them, without the type suffixes and the quotes; this includes the scoped enumerations and the types with begin() and end() for which the application defines an operator<<.
- Template Parameters
-
T The type of the operand.
- Parameters
-
value The operand.
- Returns
Nothing.
The operands of the types that the formatter writes itself are passed to its operator<<; the other ones, the application types, are written by plain_text::append(), which hands to their operator<< a formatter in the plain mode. A type with a free operator<< is an application type, even if a template of the formatter accepts it too (a scoped enumeration, or a type with begin() and end()), since a call on this formatter would select the function of the application, which would write on the formatter of the report with its decorations.
Declaration at line 1449 of file expression-formatter.h, definition at line 488 of file expression-formatter-inlines.h.
References micro_os_plus::micro_test_plus::detail::plain_text::append and buffer_.
Referenced by append_and_operand, append_and_operand, append_not_operand, append_or_operand, append_or_operand, append_value, operator<< and operator<<.
append_or_operand()
|
Appends the operands of a logical OR, separated by or.
- Template Parameters
-
Lhs_T Left-hand operand type.
Rhs_T Right-hand operand type.
- Parameters
-
op The logical OR expression.
- Returns
Nothing.
The left operand is written first, as the operands of a chain if it is a logical OR too, then the word or, coloured by the result of this operation, and the right operand.
Declaration at line 1568 of file expression-formatter.h, definition at line 674 of file expression-formatter-inlines.h.
References append_operand, append_or_operand, colour and colour_none.
append_or_operand()
|
Appends an operand of a chain of logical ORs.
Like append_and_operand(), for the logical OR.
- Template Parameters
-
T The type of the operand.
- Parameters
-
t The operand.
- Returns
Nothing.
The generic operand is written through the usual overloads.
Declaration at line 1555 of file expression-formatter.h, definition at line 661 of file expression-formatter-inlines.h.
Reference append_operand.
Referenced by append_or_operand and operator<<.
append_suffix()
|
Appends the type suffix of a number.
Called after a number was appended to the buffer; in the plain mode, used for the messages, nothing is appended.
- Parameters
-
suffix The suffix of the type (e.g. "u", "ll", "f").
- Returns
Nothing.
Appends suffix, unless the formatter is in the plain mode, used for the messages, which writes the numbers without suffixes.
Declaration at line 1359 of file expression-formatter.h, definition at line 980 of file expression-formatter.cpp.
References buffer_ and plain_.
Referenced by operator<<, operator<<, operator<<, operator<<, operator<<, operator<< and operator<<.
append_throw_reason()
| inline |
Appends the reason why a check of the exceptions failed.
Nothing if the check passed. Otherwise , but nothing was thrown, , but a std::exception was thrown: "what", or , but an exception of unknown type was thrown. Defined inline, like the operator<< overloads that call it.
- Parameters
-
op The expression of the check.
- Returns
Nothing.
The what() of the exception is written as a string operand, quoted and escaped. Defined inline, not in the library sources, for the same reason as the operator<< overloads that call it.
Declaration at line 1509 of file expression-formatter.h, definition at line 810 of file expression-formatter-inlines.h.
References buffer_, micro_os_plus::micro_test_plus::detail::std_exception and micro_os_plus::micro_test_plus::detail::unknown_exception.
Referenced by operator<< and operator<<.
append_value()
|
Appends an element of a range, pair, tuple, or optional.
Writes the char pointers as quoted C strings, so that an element is reported like a std::string one, and passes all the other values to their operator<<. The strings written by the operator<< of the application types are not affected.
- Template Parameters
-
T The type of the element.
- Parameters
-
value The element.
- Returns
Nothing.
The pointers to the character types are written as C strings, quoted and escaped as the std::string values are, with a null pointer written as nullptr; all the other values are written by append_operand(). In the plain mode, used for the messages, the strings are not quoted.
Declaration at line 1425 of file expression-formatter.h, definition at line 461 of file expression-formatter-inlines.h.
Reference append_operand.
Referenced by append_elements and operator<<.
begin_check()
|
Prepares the buffer for the expression of a new check.
If the text in the buffer belongs to a check that was not reported yet (it was created by a function called in the arguments of this check, and is reported at the end of the statement), the text is first moved aside, so that this check can still report it. The buffer is then cleared and assigned to owner.
- Parameters
-
owner The check that will format its expression next.
- Returns
Nothing.
In the usual case, the previous check was already reported (its end_check() reset owner_), and the buffer is only cleared, keeping its capacity. Otherwise the text of the previous, still pending, check is moved into pending_.
Declaration at line 1273 of file expression-formatter.h, definition at line 1089 of file expression-formatter.cpp.
References buffer_, owner_ and pending_.
Referenced by micro_os_plus::micro_test_plus::detail::check_result::init.
check_text()
| nodiscard noexcept |
Returns the expression text of a check.
- Parameters
-
owner The check that formatted the expression.
- Returns
The text in the buffer, if it still belongs to owner, otherwise the text moved aside for it; it remains valid until end_check().
Searches pending_ only when the buffer belongs to another check. If the check is not found (which does not happen when the calls are paired), an empty string is returned.
Declaration at line 1284 of file expression-formatter.h, definition at line 1107 of file expression-formatter.cpp.
References buffer_, empty, owner_ and pending_.
Referenced by micro_os_plus::micro_test_plus::detail::check_result::~check_result.
colour()
| inline nodiscard |
Selects the appropriate colour code based on a condition.
- Parameters
-
cond Boolean value indicating pass (true) or fail (false).
- Returns
The corresponding ANSI colour code.
Returns the ANSI colour code for pass or fail, depending on the boolean condition provided.
Declaration at line 1306 of file expression-formatter.h, definition at line 115 of file expression-formatter-inlines.h.
References colours_, micro_os_plus::micro_test_plus::detail::colours::fail and micro_os_plus::micro_test_plus::detail::colours::pass.
Referenced by append_and_operand, append_or_operand, operator<<, operator<<, operator<<, operator<<, operator<< and operator<<.
colour_none()
| inline nodiscard |
Returns the colour code that resets the colour.
- Parameters
None.
- Returns
The reset code of the colours of the formatter.
Returns the reset code of the colours of the formatter.
Declaration at line 1316 of file expression-formatter.h, definition at line 125 of file expression-formatter-inlines.h.
References colours_ and micro_os_plus::micro_test_plus::detail::colours::none.
Referenced by append_and_operand, append_or_operand, operator<<, operator<<, operator<<, operator<<, operator<< and operator<<.
end_check()
| noexcept |
Releases the expression text of a check, after it was reported.
- Parameters
-
owner The check that formatted the expression.
- Returns
Nothing.
If the buffer belongs to owner, it is released (and reused by the next check); otherwise the text moved aside for owner is removed from pending_, by moving the last entry into its place.
Declaration at line 1295 of file expression-formatter.h, definition at line 1133 of file expression-formatter.cpp.
prepend_cast()
|
Prefixes a number with its type, written as a cast.
Called after a number was appended to the buffer, for the types that have no standard literal suffix (signed char, unsigned char, short, and unsigned short); in the plain mode, used for the messages, nothing is inserted.
- Parameters
-
start The position of the first character of the number in the buffer.
type The cast, with the parentheses (e.g. "(unsigned short)").
- Returns
Nothing.
Inserts type at the position start, before the number, unless the formatter is in the plain mode, used for the messages, which writes the numbers without type marks.
Declaration at line 1378 of file expression-formatter.h, definition at line 995 of file expression-formatter.cpp.
References buffer_ and plain_.
Referenced by operator<<, operator<<, operator<< and operator<<.
Private Member Attributes
buffer_
|
The internal output buffer.
Accumulates the formatted text; cleared by begin_check().
Definition at line 1647 of file expression-formatter.h.
Referenced by expression_formatter, micro_os_plus::micro_test_plus::detail::plain_text::append, append_c_string, append_c_string, append_c_string, append_c_string, append_character, append_decimal_point, append_first_difference, append_operand, append_suffix, append_throw_reason, begin_check, c_str, check_text, empty, micro_os_plus::micro_test_plus::detail::check_result::operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, operator<<, prepend_cast and str.
colours_
|
ANSI colour codes for output formatting.
A reference to the colours of the owning reporter, so that later changes (e.g. enabling colours) are picked up automatically.
Definition at line 1639 of file expression-formatter.h.
Referenced by expression_formatter, expression_formatter, expression_formatter, colour and colour_none.
owner_
|
The check whose expression is in the buffer.
Set by begin_check() and reset by end_check(); nullptr when the text in the buffer does not belong to a pending check.
Definition at line 1656 of file expression-formatter.h.
Referenced by begin_check, check_text and end_check.
pending_
|
The expression texts of the pending checks whose buffer was reused.
Normally empty: a check is reported at the end of its statement, before the next check begins. Only when a check begins while an earlier one is not yet reported, as when the arguments of a check call a function that makes its own checks, is the text of the earlier check moved here, keyed by the check, so that the check objects themselves do not need to own a copy, which would increase the stack usage of the test functions.
Definition at line 1671 of file expression-formatter.h.
Referenced by begin_check, check_text and end_check.
plain_
|
Whether the formatter writes a message.
Set only by the private constructor, used by check_result and by plain_text; in this mode the numbers have no type suffixes and no added decimal point, and the strings and the char values are not quoted.
Definition at line 1682 of file expression-formatter.h.
Referenced by expression_formatter, append_decimal_point, append_suffix, operator<<, operator<< and prepend_cast.
Private Static Attributes
max_range_elements_
| constexpr static |
The maximum number of elements of a range written.
Limits the size of the report of a check on a large container, which is held in memory (and, in TAP, copied) until reported.
Definition at line 1146 of file expression-formatter.h.
Referenced by append_first_difference.
Deprecated Functions
c_str()
| inline nodiscard noexcept |
Deprecated access to the text as a C string.
Forwards to str().c_str(). The other buffer accessors of v5.0.1 (clear(), append(), and reserve()) were removed, since they allowed an application operator<< to alter the texts of the pending checks.
- Parameters
None.
- Returns
A pointer to the null-terminated text.
Declaration at line 1098 of file expression-formatter.h, definition at line 161 of file expression-formatter-inlines.h.
Reference buffer_.
Referenced by operator<<.
empty()
| inline nodiscard noexcept |
Deprecated test for an empty text.
- Parameters
None.
- Return Values
-
true The formatter holds no text.
false The formatter holds some text.
Declaration at line 1112 of file expression-formatter.h, definition at line 172 of file expression-formatter-inlines.h.
Reference buffer_.
Referenced by check_text and operator<<.
The documentation for this class was generated from the following files:
Generated via doxygen2docusaurus 2.2.8 by Doxygen 1.18.0.