Code View

// SPDX-License-Identifier: MIT
#include "features.hh"

#include <iomanip>
#include <iostream>
#include <locale>
#include <sstream>

using namespace test::features;

int main( )
{
  // The $ERROR function writes to std::cerr: keep the output in one stream.
  std::cerr.rdbuf( std::cout.rdbuf( ) );

  std::locale const utf8( "C.utf8" );

  std::cout << PickStr( ) << '\n'
            << PickStr( std::locale::classic( ) ) << '\n'
            << PickStr( utf8 ) << '\n';

  std::cout << EscapesStr( ) << '\n';

  std::ostringstream formatted;
  formatted << FormattedStr( 3.14159, 7 ) << ' ' << 1.5 << ' ' << std::setw( 3 ) << 1;
  std::cout << formatted.str( ) << '\n';

  PointStreamable const point( 3, 4 );
  test::Printable const &printable = point;
  (void) printable;
  std::cout << point << ' ' << point.text( ) << ' ' << point.x( ) << '\n';

  Pair pair( 1, 2 );
  std::cout << pair << '\n';

  try
  {
    pair.fail( );
  }
  catch ( int code )
  {
    std::cout << " -> fail threw " << code << '\n';
  }

  try
  {
    pair.raise( std::locale::classic( ) );
  }
  catch ( PairException const &e )
  {
    std::cout << "raise: " << e.what( ) << ' ' << e.first( ) << '\n';
  }

  std::cout << "nothing: [" << Nothing( 0 ) << "]\n";

  Reporter reporter;
  std::cout << reporter.sayReport( "ok" ) << '\n';

  try
  {
    reporter.ReportError( "fatal" );
  }
  catch ( int code )
  {
    std::cout << "\nexit statement threw " << code << '\n';
  }

  try
  {
    ThrowFailure( 7, utf8 );
  }
  catch ( std::exception const &e )
  {
    std::cout << e.what( ) << '\n';
  }

  try
  {
    ThrowFailure( 8 );
  }
  catch ( FailureException const &e )
  {
    std::cout << e.What( ) << " code=" << e.code( ) << '\n';
  }

  try
  {
    ThrowPlain( );
  }
  catch ( PlainException const &e )
  {
    std::cout << e.what( ) << '\n';
  }

  std::cout << JustStr( ) << '\n';
}