Add scanner test for specially handled keywords in Yul

This commit is contained in:
Alex Beregszaszi 2020-07-27 18:34:24 +01:00
parent 64c73baee9
commit bd7283ad22

View File

@ -819,6 +819,71 @@ BOOST_AUTO_TEST_CASE(irregular_line_breaks_in_strings)
} }
} }
BOOST_AUTO_TEST_CASE(solidity_keywords)
{
// These are tokens which have a different meaning in Yul.
string keywords = "return byte bool address var in true false leave switch case default";
Scanner scanner(CharStream(keywords, ""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Return);
BOOST_CHECK_EQUAL(scanner.next(), Token::Byte);
BOOST_CHECK_EQUAL(scanner.next(), Token::Bool);
BOOST_CHECK_EQUAL(scanner.next(), Token::Address);
BOOST_CHECK_EQUAL(scanner.next(), Token::Var);
BOOST_CHECK_EQUAL(scanner.next(), Token::In);
BOOST_CHECK_EQUAL(scanner.next(), Token::TrueLiteral);
BOOST_CHECK_EQUAL(scanner.next(), Token::FalseLiteral);
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::Switch);
BOOST_CHECK_EQUAL(scanner.next(), Token::Case);
BOOST_CHECK_EQUAL(scanner.next(), Token::Default);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
scanner.reset(CharStream(keywords, ""));
scanner.setScannerMode(ScannerKind::Yul);
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Return);
BOOST_CHECK_EQUAL(scanner.next(), Token::Byte);
BOOST_CHECK_EQUAL(scanner.next(), Token::Bool);
BOOST_CHECK_EQUAL(scanner.next(), Token::Address);
BOOST_CHECK_EQUAL(scanner.next(), Token::Var);
BOOST_CHECK_EQUAL(scanner.next(), Token::In);
BOOST_CHECK_EQUAL(scanner.next(), Token::TrueLiteral);
BOOST_CHECK_EQUAL(scanner.next(), Token::FalseLiteral);
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::Switch);
BOOST_CHECK_EQUAL(scanner.next(), Token::Case);
BOOST_CHECK_EQUAL(scanner.next(), Token::Default);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
}
BOOST_AUTO_TEST_CASE(yul_keyword_like)
{
Scanner scanner(CharStream("leave.function", ""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::Period);
BOOST_CHECK_EQUAL(scanner.next(), Token::Function);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
scanner.reset(CharStream("leave.function", ""));
scanner.setScannerMode(ScannerKind::Yul);
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
}
BOOST_AUTO_TEST_CASE(yul_identifier_with_dots)
{
Scanner scanner(CharStream("mystorage.slot := 1", ""));
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::Period);
BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssemblyAssign);
BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
scanner.reset(CharStream("mystorage.slot := 1", ""));
scanner.setScannerMode(ScannerKind::Yul);
BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Identifier);
BOOST_CHECK_EQUAL(scanner.next(), Token::AssemblyAssign);
BOOST_CHECK_EQUAL(scanner.next(), Token::Number);
BOOST_CHECK_EQUAL(scanner.next(), Token::EOS);
}
BOOST_AUTO_TEST_CASE(yul_function) BOOST_AUTO_TEST_CASE(yul_function)
{ {
string sig = "function f(a, b) -> x, y"; string sig = "function f(a, b) -> x, y";