diff --git a/opm/simulators/flow/KeywordValidation.cpp b/opm/simulators/flow/KeywordValidation.cpp index 5eacd78cd..8683308c1 100644 --- a/opm/simulators/flow/KeywordValidation.cpp +++ b/opm/simulators/flow/KeywordValidation.cpp @@ -129,14 +129,16 @@ namespace KeywordValidation // Find the index number, which starts counting at one, so item_index + 1 const auto& item_properties = keyword_properties->second.find(item_index + 1); if (item_properties != keyword_properties->second.end()) { - // Validate the item, if it is partially supported. - validateKeywordItem(keyword, - item_properties->second, - keyword.size() > 1, - record_index, - item_index, - item.get(0), - errors); + if (item.hasValue(0)) { + // Validate the item, if it is partially supported. + validateKeywordItem(keyword, + item_properties->second, + keyword.size() > 1, + record_index, + item_index, + item.get(0), + errors); + } } } } diff --git a/tests/test_keyword_validator.cpp b/tests/test_keyword_validator.cpp index 153b8d18d..0d1c44194 100644 --- a/tests/test_keyword_validator.cpp +++ b/tests/test_keyword_validator.cpp @@ -40,8 +40,15 @@ const PartiallySupportedKeywords test_string_items = { { "PINCH", { - {2, {false, allow_values{"GAP", "BAR"}, std::nullopt}}, // GAP - {4, {true, allow_values{"TOPBOT"}, "This is a critical error"}}, // PINCHOUT_OPTION + {2, {false, allow_values {"GAP", "BAR"}, std::nullopt}}, // GAP + {4, {true, allow_values {"TOPBOT"}, "This is a critical error"}}, // PINCHOUT_OPTION + }, + }, + { + "EQLOPTS", + { + {1, {false, allow_values {}, std::nullopt}}, + {3, {false, allow_values {"THPRESS"}, std::nullopt}}, }, }, }; @@ -51,15 +58,15 @@ const PartiallySupportedKeywords test_int_items = { { "ENDSCALE", { - {3, {false, allow_values{1}, std::nullopt}}, // NTENDP - {4, {true, allow_values{20, 30, 40}, std::nullopt}}, // NSENDP + {3, {false, allow_values {1}, std::nullopt}}, // NTENDP + {4, {true, allow_values {20, 30, 40}, std::nullopt}}, // NSENDP }, }, { "COMPDAT", { - {2, {false, allow_values{1}, std::nullopt}}, // I - {3, {false, allow_values{1}, std::nullopt}}, // J + {2, {false, allow_values {1}, std::nullopt}}, // I + {3, {false, allow_values {1}, std::nullopt}}, // J }, }, }; @@ -70,12 +77,13 @@ const PartiallySupportedKeywords test_double_items = { "EHYSTR", { {1, {false, [](double x) { return x > 0; }, std::nullopt}}, - {3, {false, allow_values{1.0, 2.0}, std::nullopt}}, + {3, {false, allow_values {1.0, 2.0}, std::nullopt}}, }, }, }; + BOOST_AUTO_TEST_CASE(non_critical_keyword) { const auto keywords_string = std::string {R"( @@ -513,3 +521,53 @@ ENDSCALE " In file: , line 4\n" " This is a critical error"); } + + +BOOST_AUTO_TEST_CASE(keyword_without_default) +{ + const auto keywords_string = std::string {R"( +EQLOPTS + 1* / +)"}; + const auto deck = Parser {}.parseString(keywords_string); + const auto& test_keyword = deck.getKeyword("EQLOPTS"); + KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items); + std::vector errors; + validator.validateDeckKeyword(test_keyword, errors); + BOOST_CHECK(errors.size() == 0); +} + + + +BOOST_AUTO_TEST_CASE(keyword_without_default_with_wrong_value) +{ + const auto keywords_string = std::string {R"( +EQLOPTS + FOO / +)"}; + const auto deck = Parser {}.parseString(keywords_string); + const auto& test_keyword = deck.getKeyword("EQLOPTS"); + KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items); + std::vector errors; + validator.validateDeckKeyword(test_keyword, errors); + BOOST_CHECK(errors.size() == 1); + BOOST_CHECK(errors[0].item_number == 1); + BOOST_CHECK(errors[0].item_value == "FOO"); + BOOST_CHECK(!errors[0].user_message); +} + + + +BOOST_AUTO_TEST_CASE(keyword_without_default_with_correct_value) +{ + const auto keywords_string = std::string {R"( +EQLOPTS + 1* 1* THPRESS / +)"}; + const auto deck = Parser {}.parseString(keywords_string); + const auto& test_keyword = deck.getKeyword("EQLOPTS"); + KeywordValidator validator(test_unsupported_keywords, test_string_items, test_int_items, test_double_items); + std::vector errors; + validator.validateDeckKeyword(test_keyword, errors); + BOOST_CHECK(errors.size() == 0); +}