From 6014c3fe16e2d4c42c1bd710661885a5f787a715 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 14 Feb 2017 14:58:04 +0000 Subject: Add tests for scientific notation --- test/libsolidity/SolidityEndToEndTest.cpp | 17 +++++++++++++++ test/libsolidity/SolidityNameAndTypeResolution.cpp | 24 ---------------------- test/libsolidity/SolidityParser.cpp | 14 +++++++++++++ test/libsolidity/SolidityScanner.cpp | 17 ++++++++++++++- 4 files changed, 47 insertions(+), 25 deletions(-) diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index baed3f1e..21d9074d 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -9176,6 +9176,23 @@ BOOST_AUTO_TEST_CASE(revert) BOOST_CHECK(callContractFunction("a()") == encodeArgs(u256(42))); } +BOOST_AUTO_TEST_CASE(scientific_notation) +{ + char const* sourceCode = R"( + contract C { + function f() returns (uint) { + return 2e10 wei; + } + function g() returns (uint) { + return 200e-2 wei; + } + } + )"; + compileAndRun(sourceCode, 0, "C"); + BOOST_CHECK(callContractFunction("f()") == encodeArgs(u256(20000000000))); + BOOST_CHECK(callContractFunction("g()") == encodeArgs(u256(2))); +} + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index dda7105c..fc5966af 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2682,18 +2682,6 @@ BOOST_AUTO_TEST_CASE(literal_strings) CHECK_SUCCESS(text); } -BOOST_AUTO_TEST_CASE(invalid_integer_literal_exp) -{ - char const* text = R"( - contract Foo { - function f() { - var x = 1e2; - } - } - )"; - CHECK_ERROR(text, TypeError, ""); -} - BOOST_AUTO_TEST_CASE(memory_structs_with_mappings) { char const* text = R"( @@ -4843,18 +4831,6 @@ BOOST_AUTO_TEST_CASE(external_function_type_to_uint) CHECK_ERROR(text, TypeError, "Explicit type conversion not allowed"); } -BOOST_AUTO_TEST_CASE(invalid_fixed_point_literal) -{ - char const* text = R"( - contract A { - function a() { - .8E0; - } - } - )"; - CHECK_ERROR(text, TypeError, ""); -} - BOOST_AUTO_TEST_CASE(shift_constant_left_negative_rvalue) { char const* text = R"( diff --git a/test/libsolidity/SolidityParser.cpp b/test/libsolidity/SolidityParser.cpp index e5362e78..cfc76ae0 100644 --- a/test/libsolidity/SolidityParser.cpp +++ b/test/libsolidity/SolidityParser.cpp @@ -1479,6 +1479,20 @@ BOOST_AUTO_TEST_CASE(function_type_state_variable) BOOST_CHECK(successParse(text)); } +BOOST_AUTO_TEST_CASE(scientific_notation) +{ + char const* text = R"( + contract test { + uint256 a = 2e10; + uint256 b = 2E10; + uint256 c = 200e-2; + uint256 d = 2E10 wei; + } + )"; + BOOST_CHECK(successParse(text)); +} + + BOOST_AUTO_TEST_SUITE_END() } diff --git a/test/libsolidity/SolidityScanner.cpp b/test/libsolidity/SolidityScanner.cpp index 3a5c6f24..020bce7f 100644 --- a/test/libsolidity/SolidityScanner.cpp +++ b/test/libsolidity/SolidityScanner.cpp @@ -115,9 +115,21 @@ BOOST_AUTO_TEST_CASE(octal_numbers) BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Number); } +BOOST_AUTO_TEST_CASE(scientific_notation) +{ + Scanner scanner(CharStream("var x = 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(), "2e10"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); + BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); +} + BOOST_AUTO_TEST_CASE(negative_numbers) { - Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9;")); + Scanner scanner(CharStream("var x = -.2 + -0x78 + -7.3 + 8.9 + 2e-2;")); BOOST_CHECK_EQUAL(scanner.currentToken(), Token::Var); BOOST_CHECK_EQUAL(scanner.next(), Token::Identifier); BOOST_CHECK_EQUAL(scanner.next(), Token::Assign); @@ -135,6 +147,9 @@ BOOST_AUTO_TEST_CASE(negative_numbers) BOOST_CHECK_EQUAL(scanner.next(), Token::Add); BOOST_CHECK_EQUAL(scanner.next(), Token::Number); BOOST_CHECK_EQUAL(scanner.currentLiteral(), "8.9"); + BOOST_CHECK_EQUAL(scanner.next(), Token::Add); + BOOST_CHECK_EQUAL(scanner.next(), Token::Number); + BOOST_CHECK_EQUAL(scanner.currentLiteral(), "2e-2"); BOOST_CHECK_EQUAL(scanner.next(), Token::Semicolon); BOOST_CHECK_EQUAL(scanner.next(), Token::EOS); } -- cgit