Skip to content

Commit 83eb987

Browse files
committed
Cleans up test file parser and its tests.
1 parent 3ee2efe commit 83eb987

File tree

3 files changed

+229
-161
lines changed

3 files changed

+229
-161
lines changed

test/libsolidity/util/TestFileParser.cpp

+24-23
Original file line numberDiff line numberDiff line change
@@ -65,25 +65,32 @@ vector<dev::solidity::test::FunctionCall> TestFileParser::parseFunctionCalls()
6565
{
6666
FunctionCall call;
6767

68-
expect(SoltToken::Newline);
69-
call.signature = parseFunctionSignature();
68+
/// If this is not the first call in the test,
69+
/// the last call to parseParameter could have eaten the
70+
/// new line already. This could only be fixed with a one
71+
/// token lookahead that checks parseParameter
72+
/// if the next token is an identifier.
73+
if (calls.empty())
74+
expect(SoltToken::Newline);
75+
else
76+
accept(SoltToken::Newline, true);
7077

78+
call.signature = parseFunctionSignature();
7179
if (accept(SoltToken::Comma, true))
7280
call.value = parseFunctionCallValue();
7381
if (accept(SoltToken::Colon, true))
7482
call.arguments = parseFunctionCallArguments();
7583

76-
call.displayMode = parseNewline();
84+
if (accept(SoltToken::Newline, true))
85+
call.displayMode = FunctionCall::DisplayMode::MultiLine;
86+
7787
call.arguments.comment = parseComment();
7888

7989
if (accept(SoltToken::Newline, true))
8090
call.displayMode = FunctionCall::DisplayMode::MultiLine;
81-
expect(SoltToken::Arrow);
8291

92+
expect(SoltToken::Arrow);
8393
call.expectations = parseFunctionCallExpectations();
84-
85-
if (accept(SoltToken::Newline, false))
86-
call.displayMode = parseNewline();
8794
call.expectations.comment = parseComment();
8895

8996
calls.emplace_back(std::move(call));
@@ -121,12 +128,12 @@ bool TestFileParser::accept(SoltToken _token, bool const _expect)
121128
bool TestFileParser::expect(SoltToken _token, bool const _advance)
122129
{
123130
if (m_scanner.currentToken() != _token)
124-
throw Error
125-
(Error::Type::ParserError,
126-
"Unexpected " + formatToken(m_scanner.currentToken()) + ": \"" +
127-
m_scanner.currentLiteral() + "\". " +
128-
"Expected \"" + formatToken(_token) + "\"."
129-
);
131+
throw Error(
132+
Error::Type::ParserError,
133+
"Unexpected " + formatToken(m_scanner.currentToken()) + ": \"" +
134+
m_scanner.currentLiteral() + "\". " +
135+
"Expected \"" + formatToken(_token) + "\"."
136+
);
130137
if (_advance)
131138
m_scanner.scanNextToken();
132139
return true;
@@ -184,7 +191,10 @@ FunctionCallExpectations TestFileParser::parseFunctionCallExpectations()
184191

185192
auto param = parseParameter();
186193
if (param.abiType.type == ABIType::None)
194+
{
195+
expectations.failure = false;
187196
return expectations;
197+
}
188198
expectations.parameters.emplace_back(param);
189199

190200
while (accept(SoltToken::Comma, true))
@@ -227,7 +237,7 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
227237
abiType = ABIType{ABIType::UnsignedDec, 32};
228238
number = convertNumber(parseNumber());
229239
}
230-
if (accept(SoltToken::Failure, true))
240+
else if (accept(SoltToken::Failure, true))
231241
{
232242
abiType = ABIType{ABIType::Failure, 0};
233243
return make_pair(bytes{}, abiType);
@@ -241,13 +251,6 @@ pair<bytes, ABIType> TestFileParser::parseABITypeLiteral()
241251
}
242252
}
243253

244-
solidity::test::FunctionCall::DisplayMode TestFileParser::parseNewline()
245-
{
246-
if (accept(SoltToken::Newline, true))
247-
return FunctionCall::DisplayMode::MultiLine;
248-
return FunctionCall::DisplayMode::SingleLine;
249-
}
250-
251254
string TestFileParser::parseComment()
252255
{
253256
string comment = m_scanner.currentLiteral();
@@ -348,8 +351,6 @@ void TestFileParser::Scanner::scanNextToken()
348351
}
349352
}
350353
while (token.first == SoltToken::Whitespace);
351-
352-
m_nextToken = token;
353354
m_currentToken = token;
354355
}
355356

test/libsolidity/util/TestFileParser.h

-7
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,6 @@ class TestFileParser
257257
void scanNextToken();
258258

259259
SoltToken currentToken() { return m_currentToken.first; }
260-
SoltToken peekToken() { return m_nextToken.first; }
261-
262260
std::string currentLiteral() { return m_currentToken.second; }
263261

264262
std::string scanComment();
@@ -283,7 +281,6 @@ class TestFileParser
283281
std::string m_currentLiteral;
284282

285283
TokenDesc m_currentToken;
286-
TokenDesc m_nextToken;
287284
};
288285

289286
bool accept(SoltToken _token, bool const _expect = false);
@@ -321,10 +318,6 @@ class TestFileParser
321318
/// if data type is not supported.
322319
std::pair<bytes, ABIType> parseABITypeLiteral();
323320

324-
/// Accepts a newline `//` and returns DisplayMode::MultiLine
325-
/// if found, DisplayMode::SingleLine otherwise.
326-
FunctionCall::DisplayMode parseNewline();
327-
328321
/// Parses a comment
329322
std::string parseComment();
330323

0 commit comments

Comments
 (0)