mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Merge pull request #3387 from verveerpj/fix_keyword_validation
Small fix for the keyword validation
This commit is contained in:
commit
7d2984e3a3
@ -129,6 +129,7 @@ namespace KeywordValidation
|
|||||||
// Find the index number, which starts counting at one, so item_index + 1
|
// Find the index number, which starts counting at one, so item_index + 1
|
||||||
const auto& item_properties = keyword_properties->second.find(item_index + 1);
|
const auto& item_properties = keyword_properties->second.find(item_index + 1);
|
||||||
if (item_properties != keyword_properties->second.end()) {
|
if (item_properties != keyword_properties->second.end()) {
|
||||||
|
if (item.hasValue(0)) {
|
||||||
// Validate the item, if it is partially supported.
|
// Validate the item, if it is partially supported.
|
||||||
validateKeywordItem<T>(keyword,
|
validateKeywordItem<T>(keyword,
|
||||||
item_properties->second,
|
item_properties->second,
|
||||||
@ -142,6 +143,7 @@ namespace KeywordValidation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -44,6 +44,13 @@ const PartiallySupportedKeywords<std::string> test_string_items = {
|
|||||||
{4, {true, allow_values<std::string> {"TOPBOT"}, "This is a critical error"}}, // PINCHOUT_OPTION
|
{4, {true, allow_values<std::string> {"TOPBOT"}, "This is a critical error"}}, // PINCHOUT_OPTION
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"EQLOPTS",
|
||||||
|
{
|
||||||
|
{1, {false, allow_values<std::string> {}, std::nullopt}},
|
||||||
|
{3, {false, allow_values<std::string> {"THPRESS"}, std::nullopt}},
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -76,6 +83,7 @@ const PartiallySupportedKeywords<double> test_double_items = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(non_critical_keyword)
|
BOOST_AUTO_TEST_CASE(non_critical_keyword)
|
||||||
{
|
{
|
||||||
const auto keywords_string = std::string {R"(
|
const auto keywords_string = std::string {R"(
|
||||||
@ -513,3 +521,53 @@ ENDSCALE
|
|||||||
" In file: <memory string>, line 4\n"
|
" In file: <memory string>, line 4\n"
|
||||||
" This is a critical error");
|
" 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<ValidationError> 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<ValidationError> 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<ValidationError> errors;
|
||||||
|
validator.validateDeckKeyword(test_keyword, errors);
|
||||||
|
BOOST_CHECK(errors.size() == 0);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user