diff --git a/opm/parser/eclipse/Parser/ParserKeyword.cpp b/opm/parser/eclipse/Parser/ParserKeyword.cpp index f090a671b..bef96f37b 100644 --- a/opm/parser/eclipse/Parser/ParserKeyword.cpp +++ b/opm/parser/eclipse/Parser/ParserKeyword.cpp @@ -114,8 +114,13 @@ namespace Opm { ParserKeyword::ParserKeyword(const Json::JsonObject& jsonConfig) { + ParserKeywordActionEnum action = INTERNALIZE; + + if (jsonConfig.has_item("action")) + action = ParserKeywordActionEnumFromString( jsonConfig.get_string("action") ); + if (jsonConfig.has_item("name")) { - commonInit(jsonConfig.get_string("name") , INTERNALIZE); + commonInit(jsonConfig.get_string("name") , action); } else throw std::invalid_argument("Json object is missing name: property"); @@ -130,7 +135,7 @@ namespace Opm { if (isTableCollection()) addTableItems(); - if (m_fixedSize == 0 && m_keywordSizeType == FIXED) + if ((m_fixedSize == 0 && m_keywordSizeType == FIXED) || (m_action != INTERNALIZE)) return; else { if (numItems() == 0) @@ -345,7 +350,8 @@ namespace Opm { (m_record->equal( *(other.m_record) )) && (m_keywordSizeType == other.m_keywordSizeType) && (m_isDataKeyword == other.m_isDataKeyword) && - (m_isTableCollection == other.m_isTableCollection)) + (m_isTableCollection == other.m_isTableCollection) && + (m_action == other.m_action)) { bool equal = false; switch(m_keywordSizeType) { diff --git a/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp b/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp index 44f05e3c6..de58744ca 100644 --- a/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp +++ b/opm/parser/eclipse/Parser/tests/ParserKeywordTests.cpp @@ -130,8 +130,18 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject) { } +BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectWithActionInvalidThrows) { + Json::JsonObject jsonObject("{\"name\": \"XXX\" , \"size\" : 0, \"action\" : \"WhatEver?\"}"); + BOOST_CHECK_THROW(ParserKeyword parserKeyword(jsonObject) , std::invalid_argument); +} +BOOST_AUTO_TEST_CASE(ConstructFromJsonObjectWithAction) { + Json::JsonObject jsonObject("{\"name\": \"XXX\" , \"size\" : 0, \"action\" : \"IGNORE\"}"); + ParserKeyword parserKeyword(jsonObject); + BOOST_CHECK_EQUAL( IGNORE , parserKeyword.getAction() ); +} + BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_withSize) { Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : 100 , \"items\" :[{\"name\":\"ItemX\" , \"size_type\":\"SINGLE\" , \"value_type\" : \"FLOAT\"}]}"); @@ -150,6 +160,12 @@ BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingItemThrows) { BOOST_CHECK_THROW( ParserKeyword parserKeyword(jsonObject) , std::invalid_argument); } +BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_missingItemActionIgnoreOK) { + Json::JsonObject jsonObject("{\"name\": \"BPR\", \"size\" : 100, \"action\" : \"IGNORE\"}"); + BOOST_CHECK_NO_THROW( ParserKeyword parserKeyword(jsonObject)); +} + + BOOST_AUTO_TEST_CASE(ConstructFromJsonObject_nosize_notItems_OK) { Json::JsonObject jsonObject("{\"name\": \"BPR\"}"); ParserKeyword parserKeyword(jsonObject);