1
0
forked from Alepha/Alepha

Started work towards stream based output for debug printing.

This will let me fix the double-case printing in the universal
test case handler.
This commit is contained in:
2023-11-06 22:58:31 -05:00
parent 3942d98684
commit ab13e7b58d

View File

@ -41,10 +41,9 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
using namespace std::literals::string_literals; using namespace std::literals::string_literals;
template< OutputMode outputMode, typename T > template< OutputMode outputMode, typename T >
std::string void
stringifyValue( const T &v ) streamValue( const T &v, std::ostream &oss )
{ {
std::ostringstream oss;
if constexpr( false ) ; // To keep the rest of the clauses regular if constexpr( false ) ; // To keep the rest of the clauses regular
else if constexpr( std::is_same_v< std::uint8_t, std::decay_t< T > > ) else if constexpr( std::is_same_v< std::uint8_t, std::decay_t< T > > )
{ {
@ -68,11 +67,12 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
} }
else if constexpr( Meta::is_ostreamable_v< T > ) else if constexpr( Meta::is_ostreamable_v< T > )
{ {
return IOStreams::stringify( v ); oss << v;
} }
else if constexpr( Meta::is_optional_v< T > ) else if constexpr( Meta::is_optional_v< T > )
{ {
return v.has_value() ? stringifyValue< outputMode >( v.value() ) : "<noopt>"s; if( not v.has_value() ) oss << "<noopt>";
else streamValue< outputMode >( v.value(), oss );
} }
else if constexpr( Meta::is_sequence_v< T > ) else if constexpr( Meta::is_sequence_v< T > )
{ {
@ -85,14 +85,19 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
oss << Meta::sequence_kind_v< T > << "(" << v.size() << " elements):\n{" << std::endl; oss << Meta::sequence_kind_v< T > << "(" << v.size() << " elements):\n{" << std::endl;
int index= 0; int index= 0;
for( const auto &elem: v ) oss << "\t" << index++ << ": " << stringifyValue< outputMode >( elem ) << "," << std::endl; for( const auto &elem: v )
{
oss << "\t" << index++ << ": ";
streamValue< outputMode >( elem, oss );
oss << "," << std::endl;
}
oss << "}" << std::endl; oss << "}" << std::endl;
} }
} }
else if constexpr( Meta::is_pair_v< T > ) else if constexpr( Meta::is_pair_v< T > )
{ {
const auto &[ first, second ]= v; const auto &[ first, second ]= v;
return stringifyValue< outputMode >( std::tie( first, second ) ); streamValue< outputMode >( std::tie( first, second ), oss );
} }
else if constexpr( Meta::is_tuple_v< T > ) else if constexpr( Meta::is_tuple_v< T > )
{ {
@ -101,7 +106,8 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
{ {
if( not first ) oss << ", "; if( not first ) oss << ", ";
first= false; first= false;
oss << std::endl << stringifyValue< outputMode >( elem ); oss << std::endl;
streamValue< outputMode >( elem, oss );
}; };
oss << std::endl << ']' << std::endl; oss << std::endl << ']' << std::endl;
} }
@ -109,7 +115,7 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
{ {
if( false ) ; // For alignment if( false ) ; // For alignment
else if( v == TotalOrder::less ) oss << "less"; else if( v == TotalOrder::less ) oss << "less";
else if ( v == TotalOrder::equal ) oss << "equal"; else if( v == TotalOrder::equal ) oss << "equal";
else if( v == TotalOrder::greater ) oss << "greater"; else if( v == TotalOrder::greater ) oss << "greater";
else throw std::logic_error( "Impossible `TotalOrder` condition." ); else throw std::logic_error( "Impossible `TotalOrder` condition." );
} }
@ -117,6 +123,14 @@ namespace Alepha::Hydrogen::Testing ::detail:: printDebugging_m
{ {
static_assert( dependent_value< false, T >, "One of the types used in the testing table does not support stringification." ); static_assert( dependent_value< false, T >, "One of the types used in the testing table does not support stringification." );
} }
}
template< OutputMode outputMode, typename T >
std::string
stringifyValue( const T &v )
{
std::ostringstream oss;
streamValue< outputMode >( v, oss );
return std::move( oss ).str(); return std::move( oss ).str();
} }