Skip to main content

The String Operators Reference

Overloaded operators for string comparison. More...

Functions Index

constexpr autooperator!= (std::string_view lhs, std::string_view rhs)

Non-equality operator for string_view objects. More...

constexpr autooperator== (std::string_view lhs, std::string_view rhs)

Equality operator for string_view objects. More...

Description

Overloaded operators for string comparison.

The µTest++ framework provides overloaded operators specifically for comparing string types, such as std::string_view. These operators enable clear and expressive assertions when verifying string values within test cases, supporting both equality and inequality checks.

By using these dedicated string operators, developers can write concise and readable tests that accurately reflect the intended logic. The framework ensures that string comparisons are performed correctly and that any failed checks are reported with both the actual and expected values for straightforward diagnostics.

Examples
 #include <string_view>
 using namespace std::literals; // For the "sv" literal.
 // ...
 
 mt::test_case ("Operators", [] {
  using namespace micro_test_plus::operators;
 
  mt::expect (std::string_view{ compute_ultimate_answer () } == "forty-two"sv)
  << "ultimate answer == 'forty-two'";
 });

Functions

operator!=()

auto micro_os_plus::micro_test_plus::operators::operator!= (std::string_view lhs, std::string_view rhs)
nodiscardconstexpr

Non-equality operator for string_view objects.

Parameters
[in] lhsThe left hand side std::string_view operand.
[in] rhsThe right hand side std::string_view operand.
Returns

A comparator object that evaluates to true if the string views are not equal.

This overload of the non-equality operator enables direct comparison of two std::string_view objects within the µTest++ framework. It constructs a comparator object that can be used in test expectations and assertions to verify that two string views are not equal.

Definition at line 149 of file operators.h.

operator==()

auto micro_os_plus::micro_test_plus::operators::operator== (std::string_view lhs, std::string_view rhs)
nodiscardconstexpr

Equality operator for string_view objects.

Parameters
[in] lhsThe left hand side std::string_view operand.
[in] rhsThe right hand side std::string_view operand.
Returns

A comparator object that evaluates to true if the string views are equal.

This overload of the equality operator enables direct comparison of two std::string_view objects within the µTest++ framework. It constructs a comparator object that can be used in test expectations and assertions to verify that two string views are equal.

Definition at line 128 of file operators.h.


Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.