forked from Alepha/Alepha
Add IStreamable helper.
This commit is contained in:
52
IOStreams/IStreamable.test/0.cc
Normal file
52
IOStreams/IStreamable.test/0.cc
Normal file
@ -0,0 +1,52 @@
|
||||
static_assert( __cplusplus > 2020'00 );
|
||||
|
||||
#include "../IStreamable.h"
|
||||
|
||||
#include <Alepha/Testing/TableTest.h>
|
||||
#include <Alepha/Testing/test.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
namespace
|
||||
{
|
||||
template< typename= Alepha::Capabilities< Alepha::IOStreams::IStreamable > >
|
||||
struct Agg_core
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
friend bool operator == ( const Agg_core &lhs, const Agg_core &rhs )= default;
|
||||
friend std::ostream &
|
||||
operator << ( std::ostream &os, const Agg_core &agg )
|
||||
{
|
||||
return os << "{ " << agg.x << ", " << agg.y << ", " << agg.z << " }";
|
||||
}
|
||||
};
|
||||
|
||||
using Agg= Agg_core<>;
|
||||
static_assert( Alepha::Aggregate< Agg > );
|
||||
static_assert( Alepha::Capability< Agg, Alepha::IOStreams::IStreamable > );
|
||||
}
|
||||
|
||||
|
||||
auto
|
||||
buildFromString( const std::string text )
|
||||
{
|
||||
Agg rv;
|
||||
std::istringstream iss{ text };
|
||||
iss >> rv;
|
||||
return rv;
|
||||
}
|
||||
|
||||
static auto init= Alepha::Utility::enroll <=[]
|
||||
{
|
||||
using namespace Alepha::Testing::exports;
|
||||
using namespace Alepha::Testing::literals::test_literals;
|
||||
|
||||
"Simple IStream"_test <=TableTest< buildFromString >
|
||||
::Cases
|
||||
{
|
||||
{ "smoke test", { "1\t2\t3" }, { 1, 2, 3 } },
|
||||
};
|
||||
};
|
||||
2
IOStreams/IStreamable.test/CMakeLists.txt
Normal file
2
IOStreams/IStreamable.test/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
||||
link_libraries( unit-test )
|
||||
unit_test( 0 )
|
||||
Reference in New Issue
Block a user