TTS v3.0.0
The Tiny Test System
 
Loading...
Searching...
No Matches
Text Utilities

Classes

struct  tts::text
 Lightweight string-like object. More...
 

Functions

template<typename T >
text tts::as_text (T const &e)
 Value-to-string conversion.
 

Function Documentation

◆ as_text()

template<typename T >
text tts::as_text ( T const &  e)

#include <tts/tools/as_text.hpp>

Value-to-string conversion.

When displaying the data required to understand a test's failures, TTS may need to print out value of various types. as_text provides a centralized way to perform such a task by handling most common types including:

  • pointers
  • floating points
  • integers
  • sequences of such types

as_text takes care of applying any command-line options related to formatting to the value printed. For user defined types, an overload of a to_text function must be found via ADL.

Examples

#define TTS_MAIN // No need for main()
#include <tts/tts.hpp>
namespace space
{
struct some_type
{
int i;
};
tts::text to_text(some_type const& s) { return "some_type[" + tts::as_text(s.i) + "]"; }
struct some_other_type
{
int j;
friend tts::text to_text(some_other_type const& s) { return "[[" + tts::as_text(s.j) + "]]"; }
};
}
TTS_CASE("Check display of type with specific to_text")
{
TTS_EQUAL(tts::as_text(space::some_type {42}), "some_type[42]");
TTS_EQUAL(tts::as_text(space::some_other_type {63}), "[[63]]");
};
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition relation.hpp:134
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition case.hpp:139
text as_text(T const &e)
Value-to-string conversion.
Definition as_text.hpp:49
Lightweight string-like object.
Definition text.hpp:39
Parameters
eValue to convert to tts::text
Returns
An instance of tts::text containing a representation of the value of e
See also
tts::text