MCPcopy Create free account
hub / github.com/argotorg/solidity / extractTestsFromAST

Method extractTestsFromAST

test/libsolidity/ASTPropertyTest.cpp:111–184  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109}
110
111void ASTPropertyTest::extractTestsFromAST(Json const& _astJson)
112{
113 std::queue<Json> nodesToVisit;
114 nodesToVisit.push(_astJson);
115
116 while (!nodesToVisit.empty())
117 {
118 Json& node = nodesToVisit.front();
119
120 if (node.is_array())
121 for (auto&& member: node)
122 nodesToVisit.push(member);
123 else if (node.is_object())
124 for (auto const& [memberName, value]: node.items())
125 {
126 if (memberName != "documentation")
127 {
128 nodesToVisit.push(node[memberName]);
129 continue;
130 }
131
132 std::string nodeDocstring = value.is_object() ?
133 value["text"].get<std::string>() : value.get<std::string>();
134 soltestAssert(!nodeDocstring.empty());
135
136 std::vector<StringPair> pairs = readKeyValuePairs(nodeDocstring);
137 if (pairs.empty())
138 continue;
139
140 for (auto const& [testId, testedProperty]: pairs)
141 {
142 soltestAssert(
143 m_tests.count(testId) > 0,
144 "Test \"" + testId + "\" does not have a corresponding expected value."
145 );
146 soltestAssert(
147 m_tests[testId].property.empty(),
148 "Test \"" + testId + "\" was already defined before."
149 );
150 m_tests[testId].property = testedProperty;
151
152 soltestAssert(node.contains("nodeType"));
153 std::optional<Json> propertyNode = jsonValueByPath(node, testedProperty);
154 soltestAssert(
155 propertyNode.has_value(),
156 node["nodeType"].get<std::string>() + " node does not have a property named \""s + testedProperty + "\""
157 );
158 soltestAssert(
159 !propertyNode->is_object() && !propertyNode->is_array(),
160 "Property \"" + testedProperty + "\" is an object or an array."
161 );
162 if (propertyNode->is_string())
163 m_tests[testId].obtainedValue = propertyNode->get<std::string>();
164 else if (propertyNode->is_boolean())
165 m_tests[testId].obtainedValue = fmt::format("{}", propertyNode->get<bool>());
166 else
167 soltestAssert(false);
168 }

Callers

nothing calls this directly

Calls 6

jsonValueByPathFunction · 0.85
pushMethod · 0.45
emptyMethod · 0.45
countMethod · 0.45
containsMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected