diff options
author | Balajiganapathi S <balajiganapathi.s@gmail.com> | 2017-10-21 03:35:08 +0800 |
---|---|---|
committer | Christian Parpart <christian@ethereum.org> | 2018-08-08 18:05:51 +0800 |
commit | 0000bfc604b985c47ab153f4172596b860c7cce8 (patch) | |
tree | 8bf5d50847fb78f89ce1cf380f86691257344b33 /test/libsolidity | |
parent | 4dc3335cda18bae7c683227a9795a7cc1de95fd2 (diff) | |
download | dexon-solidity-0000bfc604b985c47ab153f4172596b860c7cce8.tar.gz dexon-solidity-0000bfc604b985c47ab153f4172596b860c7cce8.tar.zst dexon-solidity-0000bfc604b985c47ab153f4172596b860c7cce8.zip |
Allow underscores in numbers.
Diffstat (limited to 'test/libsolidity')
-rw-r--r-- | test/libsolidity/SolidityScanner.cpp | 166 |
1 files changed, 166 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 42e1b18e..b650d918 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -155,6 +155,172 @@ BOOST_AUTO_TEST_CASE(trailing_dot) BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); } +BOOST_AUTO_TEST_CASE(underscores_in_integer) +{ + Scanner scanner(CharStream("var x = 1_23_4;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Number); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "1234"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + +BOOST_AUTO_TEST_CASE(underscores_in_scientific_notation) +{ + Scanner scanner(CharStream("var x = 1_2e10;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Number); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "12e10"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + +BOOST_AUTO_TEST_CASE(underscores_in_scientific_notation_in_exp_part) +{ + Scanner scanner(CharStream("var x = 12e1_0;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Number); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "12e10"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + + +BOOST_AUTO_TEST_CASE(underscores_in_hex) +{ + Scanner scanner(CharStream("var x = 0xab_19cf;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Number); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "0xab19cf"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_integer_is_identifier) +{ + Scanner scanner(CharStream("var x = _12;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_decimal_is_identifier) +{ + Scanner scanner(CharStream("var x = _1.2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_decimal_after_dot_illegal) +{ + Scanner scanner(CharStream("var x = 1._2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_exp_are_identifier) +{ + Scanner scanner(CharStream("var x = _1e2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_exp_after_e_illegal) +{ + Scanner scanner(CharStream("var x = 1e_2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_hex_illegal) +{ + Scanner scanner(CharStream("var x = 0x_abc;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(trailing_underscore_integer_illegal) +{ + Scanner scanner(CharStream("var x = 12_;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_after_decimal_illegal) +{ + Scanner scanner(CharStream("var x = 1.2_;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(leading_underscore_before_decimal_illegal) +{ + Scanner scanner(CharStream("var x = 1_.2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(trailing_underscore_exp_illegal) +{ + Scanner scanner(CharStream("var x = 1e2_;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(trailing_underscore_exp_before_e_illegal) +{ + Scanner scanner(CharStream("var x = 1_e2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(trailing_underscore_hex_illegal) +{ + Scanner scanner(CharStream("var x = 0xabc_;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + +BOOST_AUTO_TEST_CASE(double_underscore_illegal) +{ + Scanner scanner(CharStream("var x = 1__2;")); + BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); + BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); + BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); + BOOST_CHECK_EQUAL(scanner.next(), Token::Illegal); +} + BOOST_AUTO_TEST_CASE(negative_numbers) { Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9 + 2e-2;")); |