diff --git a/src/njoy21.hpp b/src/njoy21.hpp index 780dc29e..a35b8f67 100644 --- a/src/njoy21.hpp +++ b/src/njoy21.hpp @@ -3,8 +3,6 @@ #include #include - - #include #include #include @@ -13,6 +11,8 @@ #include #include +#include "json.hpp" + #include "ENDFtk.hpp" #include "dimwits.hpp" #include "Log.hpp" @@ -36,6 +36,7 @@ struct CommandLine; #include "njoy21/io.hpp" #include "njoy21/interface.hpp" #include "njoy21/legacy.hpp" +#include "njoy21/modern.hpp" #include "njoy21/Version.hpp" #include "njoy21/Signature.hpp" diff --git a/src/njoy21/Driver.hpp b/src/njoy21/Driver.hpp index b194e36a..95f55779 100644 --- a/src/njoy21/Driver.hpp +++ b/src/njoy21/Driver.hpp @@ -3,10 +3,15 @@ class Driver { std::unique_ptr< io::Manager > manager; Queue queue; + nlohmann::json args; - Driver( std::unique_ptr< io::Manager >&& manager, Queue&& queue ) : + Driver( std::unique_ptr< io::Manager >&& manager, + Queue&& queue, + nlohmann::json&& args ) : manager( std::move(manager) ), - queue( std::move(queue) ){} + queue( std::move(queue) ), + args( std::move( args ) ) + {} #include "njoy21/Driver/Factory.hpp" diff --git a/src/njoy21/Driver/Factory.hpp b/src/njoy21/Driver/Factory.hpp index 017257ba..c6240d5b 100644 --- a/src/njoy21/Driver/Factory.hpp +++ b/src/njoy21/Driver/Factory.hpp @@ -7,21 +7,13 @@ class Factory { #include "njoy21/Driver/Factory/src/setupManager.hpp" #include "njoy21/Driver/Factory/src/setupLegacyDirectory.hpp" + #include "njoy21/Driver/Factory/src/setupModernDirectory.hpp" - static Directory setupModernDirectory( CommandLine& commandLine ){ - return ( commandLine.legacySwitch ) ? Directory() : Directory(); - } - - template< typename First, typename Second, typename... Args > - static void cycle( First&& first, Second&& second, Args&... args ){ - while ( first( args... ) and second( args... ) ){} - } - public: Factory( int argc, char* argv[] ) : commandLine( argc, argv ), - manager( std::make_unique< io::Manager > - ( setupManager( this->commandLine ) ) ), + manager( + std::make_unique< io::Manager > ( setupManager( this->commandLine ) ) ), legacy( setupLegacyDirectory( this->commandLine ) ), modern( setupModernDirectory( this->commandLine ) ){} diff --git a/src/njoy21/Driver/Factory/src/callOperator.hpp b/src/njoy21/Driver/Factory/src/callOperator.hpp index cac23074..76714fe6 100644 --- a/src/njoy21/Driver/Factory/src/callOperator.hpp +++ b/src/njoy21/Driver/Factory/src/callOperator.hpp @@ -1,16 +1,21 @@ Driver operator()(){ + + // For passing arbitrary arguments to modules + auto args = nlohmann::json::object(); + auto outputPair = this->manager->output( - static_cast(nullptr) ); + static_cast< modern::Sequence*>(nullptr) ); const auto& output = outputPair.first; // const auto& error = outputPair.second; (*output) << banner; output->flush(); legacy::Sequence::Factory legacyFactory( *(this->manager), this->legacy ); - legacy::Sequence::Factory modernFactory( *(this->manager), this->modern ); //placeholder + modern::Sequence::Factory modernFactory( *(this->manager) ); auto makeProcessor = []( auto& set, auto& factory ){ return [&]( auto& label, auto& queue ){ + // If the label is among the allowed modules in factory if ( set.count(label) ){ queue.push( factory( label ) ); return true; @@ -20,12 +25,16 @@ Driver operator()(){ }; auto legacyProcessor = makeProcessor( this->legacy, legacyFactory ); auto modernProcessor = makeProcessor( this->modern, modernFactory ); - Queue queue; + + Queue queue; auto label = lipservice::Label::extract( manager->input() ); + auto cycle = [&]( auto& first, auto& second ){ + while( first( label, queue ) and second( label, queue ) ){ } + }; this->legacy.count( label ) ? - cycle( legacyProcessor, modernProcessor, label, queue ) : - cycle( modernProcessor, legacyProcessor, label, queue ); + cycle( legacyProcessor, modernProcessor ) : + cycle( modernProcessor, legacyProcessor ); if ( label != "STOP" ){ Log::error( "Unrecognized routine label on line {}", @@ -35,5 +44,8 @@ Driver operator()(){ } if ( this->commandLine.verifyOnly ){ queue = Queue(); } - return Driver( std::move(this->manager), std::move(queue) ); + + return Driver( std::move( this->manager ), + std::move( queue ), + std::move( args ) ); } diff --git a/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp b/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp index 738a7128..83513b36 100644 --- a/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp +++ b/src/njoy21/Driver/Factory/src/setupLegacyDirectory.hpp @@ -6,6 +6,6 @@ static Directory setupLegacyDirectory( CommandLine& commandLine ){ "COVR", "WIMSR", "POWR", "CCCCR", "ERRORR" } ): Directory( { "MODER", "RECONR", "BROADR", "PURR", "UNRESR", "ACER", "GASPR", "HEATR", "GROUPR", "VIEWR", "MIXR", "DTFR", - "THERMR", "LEAPR", "RESXSR", "MATXSR", "GAMINR", "PLOTR", + "LEAPR", "RESXSR", "MATXSR", "GAMINR", "PLOTR", "COVR", "WIMSR", "POWR", "CCCCR", "ERRORR" } ); } diff --git a/src/njoy21/Driver/Factory/src/setupManager.hpp b/src/njoy21/Driver/Factory/src/setupManager.hpp index e67c2144..b1a7a5f5 100644 --- a/src/njoy21/Driver/Factory/src/setupManager.hpp +++ b/src/njoy21/Driver/Factory/src/setupManager.hpp @@ -5,14 +5,9 @@ static io::Manager setupManager( CommandLine& commandLine ){ std::exit( 0 ); } - if ( commandLine.inputPath ){ - builder.input( *(commandLine.inputPath) ); - } - if ( commandLine.outputPath ){ - builder.output( *(commandLine.outputPath) ); - } - if ( commandLine.errorPath ){ - builder.error( *(commandLine.errorPath) ); - } + if ( commandLine.inputPath ){ builder.input( *(commandLine.inputPath) ); } + if ( commandLine.outputPath ){ builder.output( *(commandLine.outputPath) ); } + if ( commandLine.errorPath ){ builder.error( *(commandLine.errorPath) ); } + return builder.construct(); } diff --git a/src/njoy21/Driver/Factory/src/setupModernDirectory.hpp b/src/njoy21/Driver/Factory/src/setupModernDirectory.hpp new file mode 100644 index 00000000..d12280f1 --- /dev/null +++ b/src/njoy21/Driver/Factory/src/setupModernDirectory.hpp @@ -0,0 +1,5 @@ +static Directory setupModernDirectory( CommandLine& commandLine ){ + return ( commandLine.legacySwitch ) ? + Directory() : + Directory( { "THERMR" } ); +} diff --git a/src/njoy21/Driver/src/callOperator.hpp b/src/njoy21/Driver/src/callOperator.hpp index 28988ee7..4aa51ece 100644 --- a/src/njoy21/Driver/src/callOperator.hpp +++ b/src/njoy21/Driver/src/callOperator.hpp @@ -1,7 +1,7 @@ void operator()(){ while ( this->queue.size() ){ auto& routine = *( this->queue.front() ); - routine(); + routine( this->args ); this->queue.pop(); } } diff --git a/src/njoy21/Driver/test/Driver.test.cpp b/src/njoy21/Driver/test/Driver.test.cpp index f4dfbe03..3a74cc51 100644 --- a/src/njoy21/Driver/test/Driver.test.cpp +++ b/src/njoy21/Driver/test/Driver.test.cpp @@ -13,8 +13,8 @@ using namespace njoy::njoy21; SCENARIO("run a simple njoy problem"){ { - std::vector< std::string > args = - { "./njoy21", "--input", "input.txt", "--output", "output.txt" }; + std::vector< std::string > args = { + "./njoy21", "--input", "input.njoy", "--output", "output.txt" }; Driver driver( args.size(), argv(args) ); driver(); } diff --git a/src/njoy21/Driver/test/resources/input.njoy b/src/njoy21/Driver/test/resources/input.njoy new file mode 100644 index 00000000..d165c691 --- /dev/null +++ b/src/njoy21/Driver/test/resources/input.njoy @@ -0,0 +1,11 @@ +moder + 20 -30 / +reconr + -30 -31 / + 'automated processing using ndvv.njoy.process see *log files' / + 2631 0 0 / + 0.001 0.0 0.01 5.000000000000004e-08 / + 0 / +moder + -31 21 / +stop diff --git a/src/njoy21/interface.hpp b/src/njoy21/interface.hpp index de5d421e..fc3e5c41 100644 --- a/src/njoy21/interface.hpp +++ b/src/njoy21/interface.hpp @@ -4,11 +4,21 @@ struct Routine { struct Sequence { virtual ~Sequence() = default; - virtual void operator()() = 0; + + /* + * Passing a JSON object is intended to give us the flexibility to pass + * whatever arguments we wish in the future. It is the responsibility of the + * underlying module to determine if they want to do anything with those + * arguments. + + * Perhaps this shoud be a variadic template instead of passing a genric + * JSON object + */ + virtual void operator()( const nlohmann::json& ) = 0; }; virtual ~Routine() = default; - virtual void operator()() = 0; + virtual void operator()( const nlohmann::json& ) = 0; }; } diff --git a/src/njoy21/io/Manager.hpp b/src/njoy21/io/Manager.hpp index 360a36b5..2f42cc4e 100644 --- a/src/njoy21/io/Manager.hpp +++ b/src/njoy21/io/Manager.hpp @@ -15,18 +15,19 @@ class Manager { inputStream( std::move(input) ), outputPath( std::move(outputPath) ), errorPath( std::move(errorPath) ), - legacyBuffer( utility::stream::TemporaryFileStream() ){} + legacyBuffer( utility::stream::TemporaryFileStream() ) + {} public: -#include "njoy21/io/Manager/Builder.hpp" -#include "njoy21/io/Manager/FileGuard.hpp" + #include "njoy21/io/Manager/Builder.hpp" + #include "njoy21/io/Manager/FileGuard.hpp" lipservice::iRecordStream< char >& input(){ return this->inputStream; } -#include "njoy21/io/Manager/src/output.hpp" + #include "njoy21/io/Manager/src/output.hpp" std::ostream& buffer(){ return this->legacyBuffer; } diff --git a/src/njoy21/legacy.hpp b/src/njoy21/legacy.hpp index 095f707b..fa9d7270 100644 --- a/src/njoy21/legacy.hpp +++ b/src/njoy21/legacy.hpp @@ -1,5 +1,3 @@ namespace legacy { - #include "njoy21/legacy/Sequence.hpp" - } diff --git a/src/njoy21/legacy/Sequence.hpp b/src/njoy21/legacy/Sequence.hpp index 20559642..5fd5f6b7 100644 --- a/src/njoy21/legacy/Sequence.hpp +++ b/src/njoy21/legacy/Sequence.hpp @@ -9,14 +9,16 @@ class Sequence : public interface::Routine::Sequence { List sequence; Sequence( io::Manager& manager, List&& sequence ) : - manager( manager ), sequence( std::move(sequence) ){} + manager( manager ), + sequence( std::move(sequence) ) + {} public: #include "njoy21/legacy/Sequence/Factory.hpp" - void operator()(){ + void operator()( const nlohmann::json& args ){ auto fileGaurd = manager.output( this ); - for ( auto& routine : this->sequence ){ (*routine)(); } + for ( auto& routine : this->sequence ){ (*routine)( args ); } } }; diff --git a/src/njoy21/legacy/Sequence/Factory.hpp b/src/njoy21/legacy/Sequence/Factory.hpp index ca4c9e0e..e319aa6e 100644 --- a/src/njoy21/legacy/Sequence/Factory.hpp +++ b/src/njoy21/legacy/Sequence/Factory.hpp @@ -1,32 +1,14 @@ struct Factory { protected: - using parser = - std::function - < std::unique_ptr< interface::Routine >( lipservice::iRecordStream< char >& ) >; + using parser = std::function < + std::unique_ptr< interface::Routine >( + lipservice::iRecordStream< char >& ) >; io::Manager& manager; std::unordered_set< std::string >& permittedRoutines; - #define PAIR( routine ) \ - std::make_pair< std::string, parser > \ - ( #routine, \ - []( lipservice::iRecordStream< char >& inputStream ) -> std::unique_ptr< interface::Routine > \ - { return std::make_unique< routine >( inputStream ); } ) - - std::unique_ptr< interface::Routine > - parse( std::string& label, lipservice::iRecordStream< char >& input ){ - static const std::unordered_map< std::string, parser > parserMap = - { PAIR( MODER ), PAIR( RECONR ), PAIR( BROADR ), PAIR( PURR ), - PAIR( UNRESR ), PAIR( ACER ), PAIR( GASPR ), PAIR( HEATR ), - PAIR( GROUPR ), PAIR( VIEWR ), PAIR( MIXR ), PAIR( DTFR ), - PAIR( THERMR ), PAIR( LEAPR ), PAIR( RESXSR ), PAIR( MATXSR ), - PAIR( GAMINR ), PAIR( PLOTR ), PAIR( COVR ), PAIR( WIMSR ), - PAIR( POWR ), PAIR( CCCCR ), PAIR( ERRORR ) }; - return parserMap.at( label )( input ); - } - - #undef Pair + #include "njoy21/legacy/Sequence/Factory/src/parse.hpp" public: Factory( io::Manager& manager, @@ -34,29 +16,5 @@ struct Factory { manager( manager ), permittedRoutines( permittedRoutines ){} - std::unique_ptr< interface::Routine::Sequence > - operator()( std::string& label ){ - using TeeBuffer = - utility::stream::basic_Tee_streambuf< utility::stream::InputTag, char >; - - auto& input = manager.input(); - auto readBuffer = input.rdbuf(); - try { - std::vector< std::unique_ptr< interface::Routine > > sequence; - do { - { - TeeBuffer teeBuffer( readBuffer, manager.buffer().rdbuf() ); - input.rdbuf( &teeBuffer ); - sequence.push_back( this->parse( label, input ) ); - input.rdbuf( readBuffer ); - } - label = lipservice::Label::extract( input ); - } while ( this->permittedRoutines.count( label ) ); - return std::make_unique< Sequence > - ( Sequence( manager, std::move( sequence ) ) ); - } catch ( std::exception& e ){ - input.rdbuf( readBuffer ); - throw e; - } - } + #include "njoy21/legacy/Sequence/Factory/src/callOperator.hpp" }; diff --git a/src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp b/src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp new file mode 100644 index 00000000..32121d8d --- /dev/null +++ b/src/njoy21/legacy/Sequence/Factory/src/callOperator.hpp @@ -0,0 +1,27 @@ +std::unique_ptr< interface::Routine::Sequence > +operator()( std::string& label ){ + using TeeBuffer = + utility::stream::basic_Tee_streambuf< utility::stream::InputTag, char >; + + auto& input = manager.input(); + auto readBuffer = input.rdbuf(); + try { + std::vector< std::unique_ptr< interface::Routine > > sequence; + + do { + TeeBuffer teeBuffer( readBuffer, manager.buffer().rdbuf() ); + input.rdbuf( &teeBuffer ); + sequence.push_back( this->parse( label, input ) ); + input.rdbuf( readBuffer ); + + label = lipservice::Label::extract( input ); + } while ( this->permittedRoutines.count( label ) ); + + return std::make_unique< Sequence >( + Sequence( manager, std::move( sequence ) ) ); + } catch ( std::exception& e ){ + input.rdbuf( readBuffer ); + throw e; + } +} + diff --git a/src/njoy21/legacy/Sequence/Factory/src/parse.hpp b/src/njoy21/legacy/Sequence/Factory/src/parse.hpp new file mode 100644 index 00000000..e7cefefc --- /dev/null +++ b/src/njoy21/legacy/Sequence/Factory/src/parse.hpp @@ -0,0 +1,19 @@ +#define PAIR( routine ) \ + std::make_pair< std::string, parser > \ + ( #routine, \ + []( lipservice::iRecordStream< char >& inputStream ) \ + -> std::unique_ptr< interface::Routine > \ + { return std::make_unique< routine >( inputStream ); } ) + +std::unique_ptr< interface::Routine > +parse( std::string& label, lipservice::iRecordStream< char >& input ){ + static const std::unordered_map< std::string, parser > parserMap = + { PAIR( MODER ), PAIR( RECONR ), PAIR( BROADR ), PAIR( PURR ), + PAIR( UNRESR ), PAIR( ACER ), PAIR( GASPR ), PAIR( HEATR ), + PAIR( GROUPR ), PAIR( VIEWR ), PAIR( MIXR ), PAIR( DTFR ), + PAIR( THERMR ), PAIR( LEAPR ), PAIR( RESXSR ), PAIR( MATXSR ), + PAIR( GAMINR ), PAIR( PLOTR ), PAIR( COVR ), PAIR( WIMSR ), + PAIR( POWR ), PAIR( CCCCR ), PAIR( ERRORR ) }; + return parserMap.at( label )( input ); +} +#undef PAIR diff --git a/src/njoy21/legacy/Sequence/routines.hpp b/src/njoy21/legacy/Sequence/routines.hpp index cf17bc91..993a138d 100644 --- a/src/njoy21/legacy/Sequence/routines.hpp +++ b/src/njoy21/legacy/Sequence/routines.hpp @@ -8,7 +8,7 @@ static void ignore( T&& ){} lipservice::MODULE command( stream ); \ ignore(command); \ } \ - void operator()(){ njoy_c_##MODULE(); } \ + void operator()( const nlohmann::json& ){ njoy_c_##MODULE(); } \ }; DEFINE_ROUTINE( MODER ) diff --git a/src/njoy21/legacy/Sequence/test/Sequence.test.cpp b/src/njoy21/legacy/Sequence/test/Sequence.test.cpp index 4f86d978..1e22dc18 100644 --- a/src/njoy21/legacy/Sequence/test/Sequence.test.cpp +++ b/src/njoy21/legacy/Sequence/test/Sequence.test.cpp @@ -7,7 +7,7 @@ using namespace njoy::njoy21; -SCENARIO( "Sequence can be constructed" ){ +SCENARIO( "Legacy Sequence can be constructed" ){ std::string moderInput( "1 -22 \n" @@ -40,8 +40,8 @@ SCENARIO( "Sequence can be constructed" ){ std::string label("MODER"); legacy::Sequence::Factory myFactory( manager, permittedRoutines ); auto mySequence = myFactory( label ); - REQUIRE( label == "GROUPR" ); - REQUIRE( mockBuffer.str() == moderInput + reconrInput ); + CHECK( label == "GROUPR" ); + CHECK( mockBuffer.str() == moderInput + reconrInput ); std::cin.rdbuf( cin_buffer ); manager.buffer().rdbuf( buffer_buffer ); diff --git a/src/njoy21/modern.hpp b/src/njoy21/modern.hpp new file mode 100644 index 00000000..d505fa79 --- /dev/null +++ b/src/njoy21/modern.hpp @@ -0,0 +1,3 @@ +namespace modern { +#include "njoy21/modern/Sequence.hpp" +} diff --git a/src/njoy21/modern/Sequence.hpp b/src/njoy21/modern/Sequence.hpp new file mode 100644 index 00000000..5e968f83 --- /dev/null +++ b/src/njoy21/modern/Sequence.hpp @@ -0,0 +1,26 @@ +class Sequence : public interface::Routine::Sequence { +protected: +#include "njoy21/modern/Sequence/routines.hpp" + + using List = std::vector< std::unique_ptr< interface::Routine > >; + + /* fields */ + io::Manager& manager; + List sequence; + + Sequence( io::Manager& manager, List&& sequence ) : + manager( manager ), + sequence( std::move(sequence) ) + {} + +public: + + #include "njoy21/modern/Sequence/Factory.hpp" + + void operator()( const nlohmann::json& args ){ + auto fileGaurd = manager.output( this ); + for ( auto& routine : this->sequence ){ + (*routine)( args ); + } + } +}; diff --git a/src/njoy21/modern/Sequence/Factory.hpp b/src/njoy21/modern/Sequence/Factory.hpp new file mode 100644 index 00000000..6e29fded --- /dev/null +++ b/src/njoy21/modern/Sequence/Factory.hpp @@ -0,0 +1,18 @@ +struct Factory { +protected: + + using parser = std::function < + std::unique_ptr< interface::Routine >( + lipservice::iRecordStream< char >& ) >; + + io::Manager& manager; + const std::unordered_set< std::string > permittedRoutines{ "THERMR" }; + + #include "njoy21/modern/Sequence/Factory/src/parse.hpp" + +public: + Factory( io::Manager& manager ): + manager( manager ) + { } + #include "njoy21/modern/Sequence/Factory/src/callOperator.hpp" +}; diff --git a/src/njoy21/modern/Sequence/Factory/src/callOperator.hpp b/src/njoy21/modern/Sequence/Factory/src/callOperator.hpp new file mode 100644 index 00000000..10ceb5a3 --- /dev/null +++ b/src/njoy21/modern/Sequence/Factory/src/callOperator.hpp @@ -0,0 +1,26 @@ +std::unique_ptr< interface::Routine::Sequence > +operator()( std::string& label ){ + using TeeBuffer = + utility::stream::basic_Tee_streambuf< utility::stream::InputTag, char >; + + auto& input = manager.input(); + auto readBuffer = input.rdbuf(); + try { + std::vector< std::unique_ptr< interface::Routine > > sequence; + do { + TeeBuffer teeBuffer( readBuffer, manager.buffer().rdbuf() ); + input.rdbuf( &teeBuffer ); + sequence.push_back( this->parse( label, input ) ); + input.rdbuf( readBuffer ); + + label = lipservice::Label::extract( input ); + } while ( this->permittedRoutines.count( label ) ); + + return std::make_unique< Sequence > + ( Sequence( manager, std::move( sequence ) ) ); + } catch ( std::exception& e ){ + input.rdbuf( readBuffer ); + throw e; + } +} + diff --git a/src/njoy21/modern/Sequence/Factory/src/parse.hpp b/src/njoy21/modern/Sequence/Factory/src/parse.hpp new file mode 100644 index 00000000..f89e950b --- /dev/null +++ b/src/njoy21/modern/Sequence/Factory/src/parse.hpp @@ -0,0 +1,15 @@ +#define PAIR( routine ) \ +std::make_pair< std::string, parser > \ +( #routine, \ + []( lipservice::iRecordStream< char >& inputStream ) \ + -> std::unique_ptr< interface::Routine > \ + { return std::make_unique< routine >( inputStream ); } ) + +std::unique_ptr< interface::Routine > +parse( std::string& label, lipservice::iRecordStream< char >& input ){ + static const std::unordered_map< std::string, parser > parserMap = + { PAIR( THERMR ) }; + + return parserMap.at( label )( input ); +} +#undef PAIR diff --git a/src/njoy21/modern/Sequence/routines.hpp b/src/njoy21/modern/Sequence/routines.hpp new file mode 100644 index 00000000..787e1ce1 --- /dev/null +++ b/src/njoy21/modern/Sequence/routines.hpp @@ -0,0 +1,16 @@ +#define DEFINE_ROUTINE( MODULE ) \ + struct MODULE : public interface::Routine { \ + nlohmann::json j##MODULE; \ + \ + template< typename Char > \ + MODULE( lipservice::iRecordStream< Char >& stream ){ \ + lipservice::MODULE command( stream ); \ + this->j##MODULE = command; \ + } \ + void operator()( const nlohmann::json& args ){ \ + njoy::MODULE::MODULE{}( std::move( this->j##MODULE ), args ); \ + } \ + }; + + DEFINE_ROUTINE( RECONR ) +#undef DEFINE_ROUTINE diff --git a/src/njoy21/modern/Sequence/test/CMakeLists.txt b/src/njoy21/modern/Sequence/test/CMakeLists.txt new file mode 100644 index 00000000..58d4d56e --- /dev/null +++ b/src/njoy21/modern/Sequence/test/CMakeLists.txt @@ -0,0 +1,14 @@ + +add_executable( njoy21.modern.Sequence.test Sequence.test.cpp ) +target_compile_options( njoy21.modern.Sequence.test PRIVATE ${${PREFIX}_common_flags} +$<$:${${PREFIX}_strict_flags}>$<$: +${${PREFIX}_DEBUG_flags} +$<$:${${PREFIX}_coverage_flags}>> +$<$: +${${PREFIX}_RELEASE_flags} +$<$:${${PREFIX}_link_time_optimization_flags}> +$<$:${${PREFIX}_nonportable_optimization_flags}>> + +${CXX_appended_flags} ${njoy21_appended_flags} ) +target_link_libraries( njoy21.modern.Sequence.test PUBLIC njoy21 ) +add_test( NAME njoy21.modern.Sequence COMMAND njoy21.modern.Sequence.test ) \ No newline at end of file diff --git a/src/njoy21/modern/Sequence/test/Sequence.test.cpp b/src/njoy21/modern/Sequence/test/Sequence.test.cpp new file mode 100644 index 00000000..841fb301 --- /dev/null +++ b/src/njoy21/modern/Sequence/test/Sequence.test.cpp @@ -0,0 +1,40 @@ +#define CATCH_CONFIG_MAIN + +#include + +#include "catch.hpp" +#include "njoy21.hpp" + +using namespace njoy::njoy21; + +SCENARIO( "Modern Sequence can be constructed" ){ + + std::string reconrInput( + " 21 22\n" + "'This is a sample Card2'\n" + " 1306 0 0\n" + "0.005 0 0.1 5e-07\n" + "0/\n" ); + + std::istringstream mockInput( reconrInput + "GROUPR\n" ); + + auto cin_buffer = std::cin.rdbuf(); + std::cin.rdbuf( mockInput.rdbuf() ); + + auto manager = io::Manager::Builder().construct(); + + std::ostringstream mockBuffer; + auto buffer_buffer = manager.buffer().rdbuf(); + manager.buffer().rdbuf( mockBuffer.rdbuf() ); + + std::string label("RECONR"); + + modern::Sequence::Factory myFactory( manager ); + auto mySequence = myFactory( label ); + + CHECK( label == "GROUPR" ); + CHECK( mockBuffer.str() == reconrInput ); + + std::cin.rdbuf( cin_buffer ); + manager.buffer().rdbuf( buffer_buffer ); +}