Added new kind of test: check for specific properties of AST

This commit is contained in:
Matheus Aguiar
2023-08-21 12:37:40 -03:00
parent ee21b03e6c
commit 969aea6d33
13 changed files with 371 additions and 1 deletions
+15
View File
@@ -144,4 +144,19 @@ bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string*
return parse(readerBuilder, _input, _json, _errs);
}
std::optional<Json::Value> jsonValueByPath(Json::Value const& _node, std::string_view _jsonPath)
{
if (!_node.isObject() || _jsonPath.empty())
return {};
std::string memberName = std::string(_jsonPath.substr(0, _jsonPath.find_first_of('.')));
if (!_node.isMember(memberName))
return {};
if (memberName == _jsonPath)
return _node[memberName];
return jsonValueByPath(_node[memberName], _jsonPath.substr(memberName.size() + 1));
}
} // namespace solidity::util
+9
View File
@@ -26,6 +26,8 @@
#include <json/json.h>
#include <string>
#include <string_view>
#include <optional>
namespace solidity::util
{
@@ -67,6 +69,13 @@ std::string jsonPrint(Json::Value const& _input, JsonFormat const& _format);
/// \return \c true if the document was successfully parsed, \c false if an error occurred.
bool jsonParseStrict(std::string const& _input, Json::Value& _json, std::string* _errs = nullptr);
/// Retrieves the value specified by @p _jsonPath by from a series of nested JSON dictionaries.
/// @param _jsonPath A dot-separated series of dictionary keys.
/// @param _node The node representing the start of the path.
/// @returns The value of the last key on the path. @a nullptr if any node on the path descends
/// into something that is not a dictionary or the key is not present.
std::optional<Json::Value> jsonValueByPath(Json::Value const& _node, std::string_view _jsonPath);
namespace detail
{