|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Relational comparator struct template. More...
#include "micro-os-plus/micro-test-plus.h"
Public Types | |
| using | op_type = op |
| Marker identifying the framework expression types. | |
Public Member Functions | |
| template<class L, class R> requires extension::compare_tag<Compare_T, unwrapped_t<L>, unwrapped_t<R>> | |
| constexpr | compare_op (L &&lhs, R &&rhs, Compare_T) |
| Constructs a comparator for the given operands. | |
| constexpr decltype(auto) | lhs (void) const |
| Retrieves the left-hand operand. | |
| constexpr | operator bool () const |
| Conversion operator to boolean. | |
| constexpr decltype(auto) | rhs (void) const |
| Retrieves the right-hand operand. | |
Private Attributes | |
| Lhs_T | lhs_ |
| Stores the left-hand operand. | |
| Rhs_T | rhs_ |
| Stores the right-hand operand. | |
| const bool | value_ {} |
| Stores the result of the comparison. | |
Derived from binary_op, this struct compares the left-hand operand with the right-hand operand, using the operator defined by the tag Compare_T (equal_to, not_equal_to, greater, greater_equal, less, or less_equal). It is used within test expressions to provide human-readable relational checks, with the actual and expected values, and the symbol of the tag, reported upon failure.
The tag is passed as an empty constructor argument, so that all three template arguments are deduced, for example compare_op{ lhs, rhs, equal_to{} }. A factory function would do the same, but at -O0 it adds one function per instantiation.
It is also public, as extension::compare_op, so that the applications can define their own comparisons with their own tags. A tag is an empty struct with:
The operands are reported as the built-in comparators report them: the stored operands are prepared by as_operand(), so the C strings are written quoted, and the arrays as ranges; the tag still receives the operands as they were passed, without this conversion.
The temporaries are moved into the comparator, and the named operands are copied (see stored_operand_t), so a comparator built in a function from its const& parameters can be returned from it.
| Lhs_T | The type of the stored left-hand operand, either the operand type, or a const reference to it. |
| Rhs_T | The type of the stored right-hand operand, either the operand type, or a const reference to it. |
| Compare_T | The tag that defines the comparison. It is stateless, with a static symbol and a static apply(), so a parameter, such as a tolerance, is passed as an operand, usually the right one, and reported with the operands. |
|
inherited |
Detected by the extension::is_op concept, and inherited by all types derived from op.
Definition at line 128 of file extension.h.
|
constexpr |
The result is computed from the arguments, before they are forwarded to the base. The tag argument is used only to deduce Compare_T.
| L | The type of the left-hand operand argument. |
| R | The type of the right-hand operand argument. |
| lhs | The left-hand operand. |
| rhs | The right-hand operand. |
Evaluates the comparison inside an immediately invoked lambda, which converts the result of Compare_T::apply() to bool, and passes it to the binary_op base class constructor:
Definition at line 855 of file detail-inlines.h.
|
nodiscardconstexprinherited |
The operand is unwrapped with detail::unwrap() and returned by reference, so that formatting it does not copy it.
Returns the value of the left-hand operand, unwrapped by detail::unwrap() if it is a framework wrapper type; the stored operand is not copied.
Definition at line 181 of file detail-inlines.h.
References lhs(), lhs_, and micro_os_plus::micro_test_plus::detail::unwrap().
Referenced by micro_os_plus::micro_test_plus::detail::and_op< Lhs_T, Rhs_T >::and_op(), micro_os_plus::micro_test_plus::detail::approx_op< Lhs_T, Rhs_T, Epsilon_T >::approx_op(), binary_op(), micro_os_plus::micro_test_plus::detail::compare_op< Lhs_T, Rhs_T, Compare_T >::compare_op(), micro_os_plus::micro_test_plus::detail::or_op< Lhs_T, Rhs_T >::or_op(), and lhs().
|
nodiscardconstexprinherited |
Returns the pre-computed boolean result stored by the derived comparator's constructor.
Definition at line 167 of file detail-inlines.h.
References binary_op(), and value_.
|
nodiscardconstexprinherited |
The operand is unwrapped with detail::unwrap() and returned by reference, so that formatting it does not copy it.
Returns the value of the right-hand operand, unwrapped by detail::unwrap() if it is a framework wrapper type; the stored operand is not copied.
Definition at line 194 of file detail-inlines.h.
References rhs(), rhs_, and micro_os_plus::micro_test_plus::detail::unwrap().
Referenced by micro_os_plus::micro_test_plus::detail::and_op< Lhs_T, Rhs_T >::and_op(), micro_os_plus::micro_test_plus::detail::approx_op< Lhs_T, Rhs_T, Epsilon_T >::approx_op(), binary_op(), micro_os_plus::micro_test_plus::detail::compare_op< Lhs_T, Rhs_T, Compare_T >::compare_op(), micro_os_plus::micro_test_plus::detail::or_op< Lhs_T, Rhs_T >::or_op(), and rhs().
|
privateinherited |
A value, moved from a temporary or copied from a named operand, or, for a named operand that cannot be copied, a const reference to it (see stored_operand_t). It is not const, so that a temporary expression can be moved into an enclosing one.
Definition at line 410 of file detail.h.
Referenced by binary_op(), and lhs().
|
privateinherited |
Stored as the left-hand operand is.
Definition at line 418 of file detail.h.
Referenced by binary_op(), and rhs().
|
privateinherited |
Computed once, by the derived comparator constructor.
Definition at line 426 of file detail.h.
Referenced by binary_op(), and operator bool().