16
16
*/
17
17
// SPDX-License-Identifier: GPL-3.0
18
18
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
+
19
27
#include < boost/filesystem.hpp>
28
+ #include < boost/throw_exception.hpp>
29
+
20
30
#include < fstream>
21
31
#include < map>
22
32
#include < string>
23
33
24
- #pragma once
25
-
26
34
namespace solidity ::frontend::test
27
35
{
28
36
@@ -58,6 +66,9 @@ class TestCaseReader
58
66
size_t sizetSetting (std::string const & _name, size_t _defaultValue);
59
67
std::string stringSetting (std::string const & _name, std::string const & _defaultValue);
60
68
69
+ template <typename E>
70
+ E enumSetting (std::string const & _name, std::map<std::string, E> const & _choices, std::string const & _defaultChoice);
71
+
61
72
void ensureAllSettingsRead () const ;
62
73
63
74
private:
@@ -71,4 +82,20 @@ class TestCaseReader
71
82
std::map<std::string, std::string> m_settings;
72
83
std::map<std::string, std::string> m_unreadSettings; // /< tracks which settings are left unread
73
84
};
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
+
74
101
}
0 commit comments