1616*/
1717// SPDX-License-Identifier: GPL-3.0
1818
19+ #pragma once
20+
21+ #include < test/libsolidity/util/SoltestErrors.h>
22+
23+ #include < libsolutil/StringUtils.h>
24+
25+ #include < range/v3/view/map.hpp>
26+
1927#include < boost/filesystem.hpp>
28+ #include < boost/throw_exception.hpp>
29+
2030#include < fstream>
2131#include < map>
2232#include < string>
2333
24- #pragma once
25-
2634namespace solidity ::frontend::test
2735{
2836
@@ -58,6 +66,9 @@ class TestCaseReader
5866 size_t sizetSetting (std::string const & _name, size_t _defaultValue);
5967 std::string stringSetting (std::string const & _name, std::string const & _defaultValue);
6068
69+ template <typename E>
70+ E enumSetting (std::string const & _name, std::map<std::string, E> const & _choices, std::string const & _defaultChoice);
71+
6172 void ensureAllSettingsRead () const ;
6273
6374private:
@@ -71,4 +82,20 @@ class TestCaseReader
7182 std::map<std::string, std::string> m_settings;
7283 std::map<std::string, std::string> m_unreadSettings; // /< tracks which settings are left unread
7384};
85+
86+ template <typename E>
87+ E TestCaseReader::enumSetting (std::string const & _name, std::map<std::string, E> const & _choices, std::string const & _defaultChoice)
88+ {
89+ soltestAssert (_choices.count (_defaultChoice) > 0 , " " );
90+
91+ std::string value = stringSetting (_name, _defaultChoice);
92+
93+ if (_choices.count (value) == 0 )
94+ BOOST_THROW_EXCEPTION (std::runtime_error (
95+ " Invalid Enum value: " + value + " . Available choices: " + util::joinHumanReadable (_choices | ranges::views::keys) + " ."
96+ ));
97+
98+ return _choices.at (value);
99+ }
100+
74101}
0 commit comments