From 705a9dc168d925c8b838ff679c18922abc82511a Mon Sep 17 00:00:00 2001 From: Liu Ming Date: Wed, 16 Mar 2016 16:34:58 +0800 Subject: [PATCH] rename ParseMode as ParseContex in Parser folder. --- opm/parser/eclipse/Parser/Parser.cpp | 42 ++--- opm/parser/eclipse/Parser/Parser.hpp | 12 +- opm/parser/eclipse/Parser/ParserKeyword.cpp | 4 +- opm/parser/eclipse/Parser/ParserKeyword.hpp | 4 +- opm/parser/eclipse/Parser/ParserRecord.cpp | 6 +- opm/parser/eclipse/Parser/ParserRecord.hpp | 4 +- .../eclipse/Parser/tests/CMakeLists.txt | 2 +- .../eclipse/Parser/tests/ParseModeTests.cpp | 168 +++++++++--------- .../Parser/tests/ParserIncludeTests.cpp | 24 +-- .../Parser/tests/ParserKeywordTests.cpp | 6 +- .../Parser/tests/ParserRecordTests.cpp | 28 +-- .../eclipse/Parser/tests/ParserTests.cpp | 6 +- 12 files changed, 153 insertions(+), 153 deletions(-) diff --git a/opm/parser/eclipse/Parser/Parser.cpp b/opm/parser/eclipse/Parser/Parser.cpp index 5620fe36e..a17086665 100644 --- a/opm/parser/eclipse/Parser/Parser.cpp +++ b/opm/parser/eclipse/Parser/Parser.cpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ namespace Opm { struct ParserState { - const ParseMode& parseMode; + const ParseContext& parseContext; Deck * deck; boost::filesystem::path dataFile; boost::filesystem::path rootPath; @@ -63,15 +63,15 @@ namespace Opm { ParserState(const ParserState& parent) - : parseMode( parent.parseMode ) + : parseContext( parent.parseContext ) { deck = parent.deck; pathMap = parent.pathMap; rootPath = parent.rootPath; } - ParserState(const ParseMode& __parseMode) - : parseMode( __parseMode ), + ParserState(const ParseContext& __parseContext) + : parseContext( __parseContext ), deck( new Deck() ), pathMap( std::make_shared< std::map< std::string, std::string > >() ), lineNR( 0 ) @@ -131,14 +131,14 @@ namespace Opm { std::string trimmedCopy = boost::algorithm::trim_copy( keywordString ); if (trimmedCopy == "/") { - errorKey = ParseMode::PARSE_RANDOM_SLASH; + errorKey = ParseContext::PARSE_RANDOM_SLASH; msg << "Extra '/' detected at: " << dataFile << ":" << lineNR; } else { - errorKey = ParseMode::PARSE_RANDOM_TEXT; + errorKey = ParseContext::PARSE_RANDOM_TEXT; msg << "String \'" << keywordString << "\' not formatted/recognized as valid keyword at: " << dataFile << ":" << lineNR; } - parseMode.handleError( errorKey , msg.str() ); + parseContext.handleError( errorKey , msg.str() ); } }; @@ -222,8 +222,8 @@ namespace Opm { is retained in the current implementation. */ - Deck * Parser::newDeckFromFile(const std::string &dataFileName, const ParseMode& parseMode) const { - std::shared_ptr parserState = std::make_shared(parseMode); + Deck * Parser::newDeckFromFile(const std::string &dataFileName, const ParseContext& parseContext) const { + std::shared_ptr parserState = std::make_shared(parseContext); parserState->openRootFile( dataFileName ); parseState(parserState); applyUnitsToDeck(*parserState->deck); @@ -231,8 +231,8 @@ namespace Opm { return parserState->deck; } - Deck * Parser::newDeckFromString(const std::string &data, const ParseMode& parseMode) const { - std::shared_ptr parserState = std::make_shared(parseMode); + Deck * Parser::newDeckFromString(const std::string &data, const ParseContext& parseContext) const { + std::shared_ptr parserState = std::make_shared(parseContext); parserState->openString( data ); parseState(parserState); @@ -242,16 +242,16 @@ namespace Opm { } - DeckPtr Parser::parseFile(const std::string &dataFileName, const ParseMode& parseMode) const { - return std::shared_ptr( newDeckFromFile( dataFileName , parseMode)); + DeckPtr Parser::parseFile(const std::string &dataFileName, const ParseContext& parseContext) const { + return std::shared_ptr( newDeckFromFile( dataFileName , parseContext)); } - DeckPtr Parser::parseString(const std::string &data, const ParseMode& parseMode) const { - return std::shared_ptr( newDeckFromString( data , parseMode)); + DeckPtr Parser::parseString(const std::string &data, const ParseContext& parseContext) const { + return std::shared_ptr( newDeckFromString( data , parseContext)); } - DeckPtr Parser::parseStream(std::shared_ptr inputStream, const ParseMode& parseMode) const { - std::shared_ptr parserState = std::make_shared(parseMode); + DeckPtr Parser::parseStream(std::shared_ptr inputStream, const ParseContext& parseContext) const { + std::shared_ptr parserState = std::make_shared(parseContext); parserState->openStream( inputStream ); parseState(parserState); @@ -407,7 +407,7 @@ bool Parser::parseState(std::shared_ptr parserState) const { if (isRecognizedKeyword(parserState->rawKeyword->getKeywordName())) { const auto* parserKeyword = getParserKeywordFromDeckName(parserState->rawKeyword->getKeywordName()); - parserState->deck->addKeyword( parserKeyword->parse(parserState->parseMode , parserState->rawKeyword ) ); + parserState->deck->addKeyword( parserKeyword->parse(parserState->parseContext , parserState->rawKeyword ) ); } else { DeckKeyword deckKeyword(parserState->rawKeyword->getKeywordName(), false); const std::string msg = "The keyword " + parserState->rawKeyword->getKeywordName() + " is not recognized"; @@ -466,7 +466,7 @@ bool Parser::parseState(std::shared_ptr parserState) const { targetSize = record.getItem( sizeKeyword.second ).get< int >( 0 ); } else { std::string msg = "Expected the kewyord: " + sizeKeyword.first + " to infer the number of records in: " + keywordString; - parserState->parseMode.handleError(ParseMode::PARSE_MISSING_DIMS_KEYWORD , msg ); + parserState->parseContext.handleError(ParseContext::PARSE_MISSING_DIMS_KEYWORD , msg ); auto keyword = getKeyword( sizeKeyword.first ); auto record = keyword->getRecord(0); @@ -480,7 +480,7 @@ bool Parser::parseState(std::shared_ptr parserState) const { } else { if (ParserKeyword::validDeckName(keywordString)) { std::string msg = "Keyword " + keywordString + " not recognized "; - parserState->parseMode.handleError( ParseMode::PARSE_UNKNOWN_KEYWORD , msg ); + parserState->parseContext.handleError( ParseContext::PARSE_UNKNOWN_KEYWORD , msg ); return std::shared_ptr( ); } else { parserState->handleRandomText( keywordString ); diff --git a/opm/parser/eclipse/Parser/Parser.hpp b/opm/parser/eclipse/Parser/Parser.hpp index 7ca24a181..1a15d0d6f 100644 --- a/opm/parser/eclipse/Parser/Parser.hpp +++ b/opm/parser/eclipse/Parser/Parser.hpp @@ -41,7 +41,7 @@ namespace Json { namespace Opm { class Deck; - class ParseMode; + class ParseContext; class RawKeyword; struct ParserState; @@ -56,12 +56,12 @@ namespace Opm { static std::string stripComments(const std::string& inputString); /// The starting point of the parsing process. The supplied file is parsed, and the resulting Deck is returned. - std::shared_ptr< Deck > parseFile(const std::string &dataFile, const ParseMode& parseMode) const; - std::shared_ptr< Deck > parseString(const std::string &data, const ParseMode& parseMode) const; - std::shared_ptr< Deck > parseStream(std::shared_ptr inputStream , const ParseMode& parseMode) const; + std::shared_ptr< Deck > parseFile(const std::string &dataFile, const ParseContext& parseContext) const; + std::shared_ptr< Deck > parseString(const std::string &data, const ParseContext& parseContext) const; + std::shared_ptr< Deck > parseStream(std::shared_ptr inputStream , const ParseContext& parseContext) const; - Deck * newDeckFromFile(const std::string &dataFileName, const ParseMode& parseMode) const; - Deck * newDeckFromString(const std::string &dataFileName, const ParseMode& parseMode) const; + Deck * newDeckFromFile(const std::string &dataFileName, const ParseContext& parseContext) const; + Deck * newDeckFromString(const std::string &dataFileName, const ParseContext& parseContext) const; std::shared_ptr< Deck > parseFile(const std::string &dataFile, bool strict = true) const; std::shared_ptr< Deck > parseString(const std::string &data, bool strict = true) const; diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index 0f760ea2e..1743c9164 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -506,7 +506,7 @@ namespace Opm { return m_deckNames.end(); } - DeckKeyword ParserKeyword::parse(const ParseMode& parseMode , RawKeywordConstPtr rawKeyword) const { + DeckKeyword ParserKeyword::parse(const ParseContext& parseContext , RawKeywordConstPtr rawKeyword) const { if (rawKeyword->isFinished()) { DeckKeyword keyword( rawKeyword->getKeywordName() ); keyword.setLocation(rawKeyword->getFilename(), rawKeyword->getLineNR()); @@ -515,7 +515,7 @@ namespace Opm { for (size_t i = 0; i < rawKeyword->size(); i++) { auto rawRecord = rawKeyword->getRecord(i); if(m_records.size() > 0) { - keyword.addRecord( getRecord( i )->parse( parseMode, rawRecord ) ); + keyword.addRecord( getRecord( i )->parse( parseContext, rawRecord ) ); } else { if(rawRecord->size() > 0) { diff --git a/opm/parser/eclipse/Parser/ParserKeyword.hpp b/opm/parser/eclipse/Parser/ParserKeyword.hpp index ff106c6a7..e36fcd74f 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.hpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.hpp @@ -39,7 +39,7 @@ namespace Json { namespace Opm { class Deck; class DeckKeyword; - class ParseMode; + class ParseContext; class ParserDoubleItem; class ParserRecord; class RawKeyword; @@ -95,7 +95,7 @@ namespace Opm { SectionNameSet::const_iterator validSectionNamesBegin() const; SectionNameSet::const_iterator validSectionNamesEnd() const; - DeckKeyword parse(const ParseMode& parseMode , std::shared_ptr< const RawKeyword > rawKeyword) const; + DeckKeyword parse(const ParseContext& parseContext , std::shared_ptr< const RawKeyword > rawKeyword) const; enum ParserKeywordSizeEnum getSizeType() const; const std::pair& getSizeDefinitionPair() const; bool isDataKeyword() const; diff --git a/opm/parser/eclipse/Parser/ParserRecord.cpp b/opm/parser/eclipse/Parser/ParserRecord.cpp index 1384df1d5..0622f9b18 100644 --- a/opm/parser/eclipse/Parser/ParserRecord.cpp +++ b/opm/parser/eclipse/Parser/ParserRecord.cpp @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include #include @@ -116,7 +116,7 @@ namespace Opm { } } - DeckRecord ParserRecord::parse(const ParseMode& parseMode , RawRecordPtr rawRecord) const { + DeckRecord ParserRecord::parse(const ParseContext& parseContext , RawRecordPtr rawRecord) const { std::string recordBeforeParsing = rawRecord->getRecordString(); DeckRecord deckRecord( size() ); for (size_t i = 0; i < size(); i++) { @@ -128,7 +128,7 @@ namespace Opm { std::string msg = "The RawRecord for keyword \"" + rawRecord->getKeywordName() + "\" in file\"" + rawRecord->getFileName() + "\" contained " + std::to_string(rawRecord->size()) + " too many items according to the spec. RawRecord was: " + recordBeforeParsing; - parseMode.handleError(ParseMode::PARSE_EXTRA_DATA , msg); + parseContext.handleError(ParseContext::PARSE_EXTRA_DATA , msg); } return deckRecord; diff --git a/opm/parser/eclipse/Parser/ParserRecord.hpp b/opm/parser/eclipse/Parser/ParserRecord.hpp index ea63f2427..ed631763c 100644 --- a/opm/parser/eclipse/Parser/ParserRecord.hpp +++ b/opm/parser/eclipse/Parser/ParserRecord.hpp @@ -28,7 +28,7 @@ namespace Opm { class Deck; class DeckRecord; - class ParseMode; + class ParseContext; class ParserItem; class RawRecord; @@ -40,7 +40,7 @@ namespace Opm { void addDataItem(std::shared_ptr< const ParserItem > item); std::shared_ptr< const ParserItem > get(size_t index) const; std::shared_ptr< const ParserItem > get(const std::string& itemName) const; - DeckRecord parse(const ParseMode& parseMode , std::shared_ptr< RawRecord > rawRecord) const; + DeckRecord parse(const ParseContext& parseContext , std::shared_ptr< RawRecord > rawRecord) const; bool isDataRecord() const; bool equal(const ParserRecord& other) const; bool hasDimension() const; diff --git a/opm/parser/eclipse/Parser/tests/CMakeLists.txt b/opm/parser/eclipse/Parser/tests/CMakeLists.txt index 0fd5afb62..21a860306 100644 --- a/opm/parser/eclipse/Parser/tests/CMakeLists.txt +++ b/opm/parser/eclipse/Parser/tests/CMakeLists.txt @@ -1,5 +1,5 @@ foreach(tapp ParserTests ParserKeywordTests ParserRecordTests - ParserItemTests ParserEnumTests ParserIncludeTests ParseModeTests) + ParserItemTests ParserEnumTests ParserIncludeTests ParseContextTests) opm_add_test(run${tapp} SOURCES ${tapp}.cpp LIBRARIES opmparser ${Boost_LIBRARIES}) endforeach() diff --git a/opm/parser/eclipse/Parser/tests/ParseModeTests.cpp b/opm/parser/eclipse/Parser/tests/ParseModeTests.cpp index 60389a90a..b75144661 100644 --- a/opm/parser/eclipse/Parser/tests/ParseModeTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParseModeTests.cpp @@ -54,32 +54,32 @@ BOOST_AUTO_TEST_CASE(TestUnkownKeyword) { "\n"; - ParseMode parseMode; + ParseContext parseContext; Parser parser(false); parser.addKeyword(); - parseMode.update(ParseMode::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck1 , parseMode ) , std::invalid_argument); + parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); + BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext ) , std::invalid_argument); - parseMode.update(ParseMode::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); - BOOST_CHECK_NO_THROW( parser.parseString( deck1 , parseMode ) ); + parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); + BOOST_CHECK_NO_THROW( parser.parseString( deck1 , parseContext ) ); - parseMode.update(ParseMode::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); - parseMode.update(ParseMode::PARSE_RANDOM_TEXT , InputError::IGNORE ); - BOOST_CHECK_THROW( parser.parseString( deck2 , parseMode ) , std::invalid_argument); + parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::THROW_EXCEPTION ); + parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE ); + BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext ) , std::invalid_argument); - parseMode.update(ParseMode::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); - parseMode.update(ParseMode::PARSE_RANDOM_TEXT , InputError::IGNORE ); - BOOST_CHECK_NO_THROW( parser.parseString( deck2 , parseMode ) ); + parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); + parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE ); + BOOST_CHECK_NO_THROW( parser.parseString( deck2 , parseContext ) ); - parseMode.update(ParseMode::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); - parseMode.update(ParseMode::PARSE_RANDOM_TEXT , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck2 , parseMode ) , std::invalid_argument); + parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); + parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::THROW_EXCEPTION ); + BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext ) , std::invalid_argument); - parseMode.update(ParseMode::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); - parseMode.update(ParseMode::PARSE_RANDOM_TEXT , InputError::IGNORE ); - BOOST_CHECK_NO_THROW( parser.parseString( deck2 , parseMode ) ); + parseContext.update(ParseContext::PARSE_UNKNOWN_KEYWORD , InputError::IGNORE ); + parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE ); + BOOST_CHECK_NO_THROW( parser.parseString( deck2 , parseContext ) ); } @@ -91,18 +91,18 @@ BOOST_AUTO_TEST_CASE( CheckMissingSizeKeyword) { "\n"; - ParseMode parseMode; + ParseContext parseContext; Parser parser(false); parser.addKeyword(); parser.addKeyword(); parser.addKeyword(); - parseMode.update( ParseMode::PARSE_MISSING_DIMS_KEYWORD , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deck , parseMode ) , std::invalid_argument); + parseContext.update( ParseContext::PARSE_MISSING_DIMS_KEYWORD , InputError::THROW_EXCEPTION ); + BOOST_CHECK_THROW( parser.parseString( deck , parseContext ) , std::invalid_argument); - parseMode.update( ParseMode::PARSE_MISSING_DIMS_KEYWORD , InputError::IGNORE ); - BOOST_CHECK_NO_THROW( parser.parseString( deck , parseMode ) ); + parseContext.update( ParseContext::PARSE_MISSING_DIMS_KEYWORD , InputError::IGNORE ); + BOOST_CHECK_NO_THROW( parser.parseString( deck , parseContext ) ); } @@ -131,21 +131,21 @@ BOOST_AUTO_TEST_CASE( CheckUnsupportedInSCHEDULE ) { "\n"; - ParseMode parseMode; + ParseContext parseContext; Parser parser(true); - auto deckSupported = parser.parseString( deckStringSupported , parseMode ); - auto deckUnSupported = parser.parseString( deckStringUnSupported , parseMode ); + auto deckSupported = parser.parseString( deckStringSupported , parseContext ); + auto deckUnSupported = parser.parseString( deckStringUnSupported , parseContext ); std::shared_ptr grid = std::make_shared( deckSupported ); std::shared_ptr ioconfig = std::make_shared( "path" ); - parseMode.update( ParseMode::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , InputError::IGNORE ); - BOOST_CHECK_NO_THROW( Schedule( parseMode , grid , deckSupported , ioconfig )); - BOOST_CHECK_NO_THROW( Schedule( parseMode , grid , deckUnSupported , ioconfig )); + parseContext.update( ParseContext::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , InputError::IGNORE ); + BOOST_CHECK_NO_THROW( Schedule( parseContext , grid , deckSupported , ioconfig )); + BOOST_CHECK_NO_THROW( Schedule( parseContext , grid , deckUnSupported , ioconfig )); - parseMode.update( ParseMode::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( Schedule( parseMode , grid , deckUnSupported , ioconfig ), std::invalid_argument ); - BOOST_CHECK_NO_THROW( Schedule( parseMode , grid , deckSupported , ioconfig )); + parseContext.update( ParseContext::UNSUPPORTED_SCHEDULE_GEO_MODIFIER , InputError::THROW_EXCEPTION ); + BOOST_CHECK_THROW( Schedule( parseContext , grid , deckUnSupported , ioconfig ), std::invalid_argument ); + BOOST_CHECK_NO_THROW( Schedule( parseContext , grid , deckSupported , ioconfig )); } @@ -165,23 +165,23 @@ BOOST_AUTO_TEST_CASE(TestRandomSlash) { - ParseMode parseMode; + ParseContext parseContext; Parser parser(false); parser.addKeyword(); parser.addKeyword(); - parseMode.update(ParseMode::PARSE_RANDOM_SLASH , InputError::THROW_EXCEPTION); - parseMode.update(ParseMode::PARSE_RANDOM_TEXT , InputError::IGNORE); - BOOST_CHECK_THROW( parser.parseString( deck1 , parseMode ) , std::invalid_argument); - BOOST_CHECK_THROW( parser.parseString( deck2 , parseMode ) , std::invalid_argument); + parseContext.update(ParseContext::PARSE_RANDOM_SLASH , InputError::THROW_EXCEPTION); + parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::IGNORE); + BOOST_CHECK_THROW( parser.parseString( deck1 , parseContext ) , std::invalid_argument); + BOOST_CHECK_THROW( parser.parseString( deck2 , parseContext ) , std::invalid_argument); - parseMode.update(ParseMode::PARSE_RANDOM_SLASH , InputError::IGNORE); - parseMode.update(ParseMode::PARSE_RANDOM_TEXT , InputError::THROW_EXCEPTION); - BOOST_CHECK_NO_THROW( parser.parseString( deck1 , parseMode ) ); - BOOST_CHECK_NO_THROW( parser.parseString( deck2 , parseMode ) ); + parseContext.update(ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE); + parseContext.update(ParseContext::PARSE_RANDOM_TEXT , InputError::THROW_EXCEPTION); + BOOST_CHECK_NO_THROW( parser.parseString( deck1 , parseContext ) ); + BOOST_CHECK_NO_THROW( parser.parseString( deck2 , parseContext ) ); } @@ -198,74 +198,74 @@ BOOST_AUTO_TEST_CASE(TestCOMPORD) { " '*' 'DEPTH' /\n" "/\n"; - ParseMode parseMode; + ParseContext parseContext; Parser parser(true); - auto deck = parser.parseString( deckString , parseMode ); + auto deck = parser.parseString( deckString , parseContext ); std::shared_ptr grid = std::make_shared( deck ); std::shared_ptr ioconfig = std::make_shared( "path" ); - parseMode.update( ParseMode::UNSUPPORTED_COMPORD_TYPE , InputError::IGNORE); - BOOST_CHECK_NO_THROW( Schedule( parseMode , grid , deck , ioconfig )); + parseContext.update( ParseContext::UNSUPPORTED_COMPORD_TYPE , InputError::IGNORE); + BOOST_CHECK_NO_THROW( Schedule( parseContext , grid , deck , ioconfig )); - parseMode.update( ParseMode::UNSUPPORTED_COMPORD_TYPE , InputError::THROW_EXCEPTION); - BOOST_CHECK_THROW( Schedule( parseMode , grid , deck , ioconfig ), std::invalid_argument ); + parseContext.update( ParseContext::UNSUPPORTED_COMPORD_TYPE , InputError::THROW_EXCEPTION); + BOOST_CHECK_THROW( Schedule( parseContext , grid , deck , ioconfig ), std::invalid_argument ); } BOOST_AUTO_TEST_CASE(TestInvalidKey) { - ParseMode parseMode; - BOOST_CHECK_THROW( parseMode.addKey("KEY*") , std::invalid_argument ); - BOOST_CHECK_THROW( parseMode.addKey("KEY:") , std::invalid_argument ); + ParseContext parseContext; + BOOST_CHECK_THROW( parseContext.addKey("KEY*") , std::invalid_argument ); + BOOST_CHECK_THROW( parseContext.addKey("KEY:") , std::invalid_argument ); } BOOST_AUTO_TEST_CASE(TestNew) { - ParseMode parseMode; + ParseContext parseContext; - BOOST_CHECK_EQUAL( false , parseMode.hasKey("NO")); - parseMode.addKey("NEW_KEY"); - BOOST_CHECK_EQUAL( true , parseMode.hasKey("NEW_KEY")); - BOOST_CHECK_THROW( parseMode.get("NO") , std::invalid_argument ); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY") , InputError::THROW_EXCEPTION ); - parseMode.addKey("KEY2"); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY") , InputError::THROW_EXCEPTION ); + BOOST_CHECK_EQUAL( false , parseContext.hasKey("NO")); + parseContext.addKey("NEW_KEY"); + BOOST_CHECK_EQUAL( true , parseContext.hasKey("NEW_KEY")); + BOOST_CHECK_THROW( parseContext.get("NO") , std::invalid_argument ); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::THROW_EXCEPTION ); + parseContext.addKey("KEY2"); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parseMode.updateKey("NO" , InputError::IGNORE) , std::invalid_argument); + BOOST_CHECK_THROW( parseContext.updateKey("NO" , InputError::IGNORE) , std::invalid_argument); - parseMode.updateKey("NEW_KEY" , InputError::WARN); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY") , InputError::WARN ); + parseContext.updateKey("NEW_KEY" , InputError::WARN); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::WARN ); - BOOST_CHECK_NO_THROW( parseMode.update("KEY2:NEW_KEY" , InputError::IGNORE)); - BOOST_CHECK_NO_THROW( parseMode.update("UnknownKey" , InputError::IGNORE)); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY") , InputError::IGNORE ); - BOOST_CHECK_EQUAL( parseMode.get("KEY2") , InputError::IGNORE ); + BOOST_CHECK_NO_THROW( parseContext.update("KEY2:NEW_KEY" , InputError::IGNORE)); + BOOST_CHECK_NO_THROW( parseContext.update("UnknownKey" , InputError::IGNORE)); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::IGNORE ); + BOOST_CHECK_EQUAL( parseContext.get("KEY2") , InputError::IGNORE ); - parseMode.addKey("SECRET_KEY"); - parseMode.addKey("NEW_KEY2"); - parseMode.addKey("NEW_KEY3"); - parseMode.update("NEW_KEY*" , InputError::WARN); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY") , InputError::WARN ); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY2") , InputError::WARN ); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY3") , InputError::WARN ); + parseContext.addKey("SECRET_KEY"); + parseContext.addKey("NEW_KEY2"); + parseContext.addKey("NEW_KEY3"); + parseContext.update("NEW_KEY*" , InputError::WARN); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY") , InputError::WARN ); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY2") , InputError::WARN ); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY3") , InputError::WARN ); - parseMode.update( InputError::IGNORE ); - BOOST_CHECK_EQUAL( parseMode.get("NEW_KEY3") , InputError::IGNORE ); - BOOST_CHECK_EQUAL( parseMode.get("SECRET_KEY") , InputError::IGNORE ); + parseContext.update( InputError::IGNORE ); + BOOST_CHECK_EQUAL( parseContext.get("NEW_KEY3") , InputError::IGNORE ); + BOOST_CHECK_EQUAL( parseContext.get("SECRET_KEY") , InputError::IGNORE ); } BOOST_AUTO_TEST_CASE( test_constructor_with_values) { - ParseMode parseMode( {{ParseMode::PARSE_RANDOM_SLASH , InputError::IGNORE}, + ParseContext parseContext( {{ParseContext::PARSE_RANDOM_SLASH , InputError::IGNORE}, {"UNSUPPORTED_*" , InputError::WARN}, {"UNKNWON-IGNORED" , InputError::WARN}}); - BOOST_CHECK_EQUAL( parseMode.get(ParseMode::PARSE_RANDOM_SLASH) , InputError::IGNORE ); - BOOST_CHECK_EQUAL( parseMode.get(ParseMode::PARSE_RANDOM_TEXT) , InputError::THROW_EXCEPTION ); - BOOST_CHECK_EQUAL( parseMode.get(ParseMode::UNSUPPORTED_INITIAL_THPRES) , InputError::WARN ); - BOOST_CHECK_EQUAL( parseMode.get(ParseMode::UNSUPPORTED_COMPORD_TYPE) , InputError::WARN ); + BOOST_CHECK_EQUAL( parseContext.get(ParseContext::PARSE_RANDOM_SLASH) , InputError::IGNORE ); + BOOST_CHECK_EQUAL( parseContext.get(ParseContext::PARSE_RANDOM_TEXT) , InputError::THROW_EXCEPTION ); + BOOST_CHECK_EQUAL( parseContext.get(ParseContext::UNSUPPORTED_INITIAL_THPRES) , InputError::WARN ); + BOOST_CHECK_EQUAL( parseContext.get(ParseContext::UNSUPPORTED_COMPORD_TYPE) , InputError::WARN ); } @@ -277,13 +277,13 @@ BOOST_AUTO_TEST_CASE( test_too_much_data ) { " 10 10 10 10 /n" "\n"; - ParseMode parseMode; + ParseContext parseContext; Parser parser; - parseMode.update(ParseMode::PARSE_EXTRA_DATA , InputError::THROW_EXCEPTION ); - BOOST_CHECK_THROW( parser.parseString( deckString , parseMode ) , std::invalid_argument); + parseContext.update(ParseContext::PARSE_EXTRA_DATA , InputError::THROW_EXCEPTION ); + BOOST_CHECK_THROW( parser.parseString( deckString , parseContext ) , std::invalid_argument); - parseMode.update(ParseMode::PARSE_EXTRA_DATA , InputError::IGNORE ); - auto deck = parser.parseString( deckString , parseMode ); + parseContext.update(ParseContext::PARSE_EXTRA_DATA , InputError::IGNORE ); + auto deck = parser.parseString( deckString , parseContext ); } diff --git a/opm/parser/eclipse/Parser/tests/ParserIncludeTests.cpp b/opm/parser/eclipse/Parser/tests/ParserIncludeTests.cpp index 56701471a..796d1b3a9 100644 --- a/opm/parser/eclipse/Parser/tests/ParserIncludeTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserIncludeTests.cpp @@ -25,13 +25,13 @@ #include #include #include -#include +#include BOOST_AUTO_TEST_CASE(ParserKeyword_includeValid) { boost::filesystem::path inputFilePath("testdata/parser/includeValid.data"); Opm::ParserPtr parser(new Opm::Parser()); - Opm::DeckConstPtr deck = parser->parseFile(inputFilePath.string() , Opm::ParseMode()); + Opm::DeckConstPtr deck = parser->parseFile(inputFilePath.string() , Opm::ParseContext()); BOOST_CHECK_EQUAL(true , deck->hasKeyword("OIL")); BOOST_CHECK_EQUAL(false , deck->hasKeyword("WATER")); @@ -41,7 +41,7 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_includeInvalid) { boost::filesystem::path inputFilePath("testdata/parser/includeInvalid.data"); Opm::ParserPtr parser(new Opm::Parser()); - BOOST_CHECK_THROW(parser->parseFile(inputFilePath.string() , Opm::ParseMode()), std::runtime_error); + BOOST_CHECK_THROW(parser->parseFile(inputFilePath.string() , Opm::ParseContext()), std::runtime_error); } BOOST_AUTO_TEST_CASE(ParserKeyword_includeWrongCase) { @@ -56,19 +56,19 @@ BOOST_AUTO_TEST_CASE(ParserKeyword_includeWrongCase) { // exactly the same spelling as their names on disk. Eclipse seems // to be a bit more relaxed when it comes to this, so we might // have to change the current behavior one not-so-fine day... - BOOST_CHECK_THROW(parser->parseFile(inputFile1Path.string(), Opm::ParseMode()), std::runtime_error); - BOOST_CHECK_THROW(parser->parseFile(inputFile2Path.string(), Opm::ParseMode()), std::runtime_error); - BOOST_CHECK_THROW(parser->parseFile(inputFile3Path.string(), Opm::ParseMode()), std::runtime_error); + BOOST_CHECK_THROW(parser->parseFile(inputFile1Path.string(), Opm::ParseContext()), std::runtime_error); + BOOST_CHECK_THROW(parser->parseFile(inputFile2Path.string(), Opm::ParseContext()), std::runtime_error); + BOOST_CHECK_THROW(parser->parseFile(inputFile3Path.string(), Opm::ParseContext()), std::runtime_error); #else // for case-insensitive filesystems, the include statement will // always work regardless of how the capitalization of the // included files is wrong... - BOOST_CHECK_EQUAL(true, parser->parseFile(inputFile1Path.string(), Opm::ParseMode())->hasKeyword("OIL")); - BOOST_CHECK_EQUAL(false, parser->parseFile(inputFile1Path.string(), Opm::ParseMode())->hasKeyword("WATER")); - BOOST_CHECK_EQUAL(true, parser->parseFile(inputFile2Path.string(), Opm::ParseMode())->hasKeyword("OIL")); - BOOST_CHECK_EQUAL(false, parser->parseFile(inputFile2Path.string(), Opm::ParseMode())->hasKeyword("WATER")); - BOOST_CHECK_EQUAL(true, parser->parseFile(inputFile3Path.string(), Opm::ParseMode())->hasKeyword("OIL")); - BOOST_CHECK_EQUAL(false, parser->parseFile(inputFile3Path.string(), Opm::ParseMode())->hasKeyword("WATER")); + BOOST_CHECK_EQUAL(true, parser->parseFile(inputFile1Path.string(), Opm::ParseContext())->hasKeyword("OIL")); + BOOST_CHECK_EQUAL(false, parser->parseFile(inputFile1Path.string(), Opm::ParseContext())->hasKeyword("WATER")); + BOOST_CHECK_EQUAL(true, parser->parseFile(inputFile2Path.string(), Opm::ParseContext())->hasKeyword("OIL")); + BOOST_CHECK_EQUAL(false, parser->parseFile(inputFile2Path.string(), Opm::ParseContext())->hasKeyword("WATER")); + BOOST_CHECK_EQUAL(true, parser->parseFile(inputFile3Path.string(), Opm::ParseContext())->hasKeyword("OIL")); + BOOST_CHECK_EQUAL(false, parser->parseFile(inputFile3Path.string(), Opm::ParseContext())->hasKeyword("WATER")); #endif } diff --git a/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp b/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp index 81c393a84..ffdf6b720 100644 --- a/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include #include #include @@ -398,14 +398,14 @@ BOOST_AUTO_TEST_CASE(ParseEmptyRecord) { std::shared_ptr record = std::make_shared(); ParserIntItemConstPtr item(new ParserIntItem(std::string("ITEM") , ALL)); RawKeywordPtr rawkeyword(new RawKeyword( tabdimsKeyword->getName() , "FILE" , 10U , 1)); - ParseMode parseMode; + ParseContext parseContext; BOOST_CHECK_EQUAL( Raw::FIXED , rawkeyword->getSizeType()); rawkeyword->addRawRecordString("/"); record->addItem(item); tabdimsKeyword->addRecord( record ); - const auto deckKeyword = tabdimsKeyword->parse( parseMode , rawkeyword ); + const auto deckKeyword = tabdimsKeyword->parse( parseContext , rawkeyword ); BOOST_REQUIRE_EQUAL( 1U , deckKeyword.size()); const auto& deckRecord = deckKeyword.getRecord(0); diff --git a/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp b/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp index c1090cafd..47ab35838 100644 --- a/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserRecordTests.cpp @@ -22,7 +22,7 @@ #include #include -#include +#include #include #include #include @@ -128,16 +128,16 @@ static ParserRecordPtr createSimpleParserRecord() { BOOST_AUTO_TEST_CASE(parse_validRecord_noThrow) { ParserRecordPtr record = createSimpleParserRecord(); RawRecordPtr rawRecord(new RawRecord("100 443 /")); - ParseMode parseMode; + ParseContext parseContext; rawRecord->dump(); - BOOST_CHECK_NO_THROW(record->parse(parseMode , rawRecord)); + BOOST_CHECK_NO_THROW(record->parse(parseContext , rawRecord)); } BOOST_AUTO_TEST_CASE(parse_validRecord_deckRecordCreated) { ParserRecordPtr record = createSimpleParserRecord(); RawRecordPtr rawRecord(new RawRecord("100 443 /")); - ParseMode parseMode; - const auto deckRecord = record->parse(parseMode , rawRecord); + ParseContext parseContext; + const auto deckRecord = record->parse(parseContext , rawRecord); BOOST_CHECK_EQUAL(2U, deckRecord.size()); } @@ -169,8 +169,8 @@ static ParserRecordPtr createMixedParserRecord() { BOOST_AUTO_TEST_CASE(parse_validMixedRecord_noThrow) { ParserRecordPtr record = createMixedParserRecord(); RawRecordPtr rawRecord(new RawRecord("1 2 10.0 20.0 4 90.0 /")); - ParseMode parseMode; - BOOST_CHECK_NO_THROW(record->parse(parseMode , rawRecord)); + ParseContext parseContext; + BOOST_CHECK_NO_THROW(record->parse(parseContext , rawRecord)); } BOOST_AUTO_TEST_CASE(Equal_Equal_ReturnsTrue) { @@ -302,7 +302,7 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { ParserIntItemConstPtr itemI(new ParserIntItem("I", SINGLE)); ParserIntItemConstPtr itemJ(new ParserIntItem("J", SINGLE)); ParserIntItemConstPtr itemK(new ParserIntItem("K", SINGLE)); - ParseMode parseMode; + ParseContext parseContext; parserRecord->addItem(itemI); parserRecord->addItem(itemJ); @@ -310,13 +310,13 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooManyItems_Throws) { RawRecordPtr rawRecord(new RawRecord("3 3 3 /")); - BOOST_CHECK_NO_THROW(parserRecord->parse(parseMode , rawRecord)); + BOOST_CHECK_NO_THROW(parserRecord->parse(parseContext , rawRecord)); RawRecordPtr rawRecordOneExtra(new RawRecord("3 3 3 4 /")); - BOOST_CHECK_THROW(parserRecord->parse(parseMode , rawRecordOneExtra), std::invalid_argument); + BOOST_CHECK_THROW(parserRecord->parse(parseContext , rawRecordOneExtra), std::invalid_argument); RawRecordPtr rawRecordForgotRecordTerminator(new RawRecord("3 3 3 \n 4 4 4 /")); - BOOST_CHECK_THROW(parserRecord->parse(parseMode , rawRecordForgotRecordTerminator), std::invalid_argument); + BOOST_CHECK_THROW(parserRecord->parse(parseContext , rawRecordForgotRecordTerminator), std::invalid_argument); } @@ -331,12 +331,12 @@ BOOST_AUTO_TEST_CASE(Parse_RawRecordTooFewItems) { parserRecord->addItem(itemJ); parserRecord->addItem(itemK); - ParseMode parseMode; + ParseContext parseContext; RawRecordPtr rawRecord(new RawRecord("3 3 /")); // no default specified for the third item, record can be parsed just fine but trying // to access the data will raise an exception... - BOOST_CHECK_NO_THROW(parserRecord->parse(parseMode , rawRecord)); - auto record = parserRecord->parse(parseMode , rawRecord); + BOOST_CHECK_NO_THROW(parserRecord->parse(parseContext , rawRecord)); + auto record = parserRecord->parse(parseContext , rawRecord); BOOST_CHECK_NO_THROW(record.getItem(2)); BOOST_CHECK_THROW(record.getItem(2).get< int >(0), std::out_of_range); } diff --git a/opm/parser/eclipse/Parser/tests/ParserTests.cpp b/opm/parser/eclipse/Parser/tests/ParserTests.cpp index 3be4e77d9..2a585d828 100644 --- a/opm/parser/eclipse/Parser/tests/ParserTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserTests.cpp @@ -25,7 +25,7 @@ #include -#include +#include #include #include #include @@ -305,6 +305,6 @@ BOOST_AUTO_TEST_CASE( quoted_comments ) { BOOST_AUTO_TEST_CASE( PATHS_has_global_scope ) { Parser parser; - parser.newDeckFromFile( "testdata/parser/PATHSInInclude.data", ParseMode() ); - BOOST_CHECK_THROW( parser.newDeckFromFile( "testdata/parser/PATHSInIncludeInvalid.data", ParseMode() ), std::runtime_error ); + parser.newDeckFromFile( "testdata/parser/PATHSInInclude.data", ParseContext() ); + BOOST_CHECK_THROW( parser.newDeckFromFile( "testdata/parser/PATHSInIncludeInvalid.data", ParseContext() ), std::runtime_error ); }