aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-02-14 22:58:04 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-03-15 21:06:26 +0800
commit6014c3fe16e2d4c42c1bd710661885a5f787a715 (patch)
tree361d3f39859bda1c1c469402bd7bf3ce7ee0e1f0
parent924a8fff6bc517519eb91ca73adf06505b3f5a87 (diff)
downloaddexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.tar
dexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.tar.gz
dexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.tar.bz2
dexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.tar.lz
dexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.tar.xz
dexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.tar.zst
dexon-solidity-6014c3fe16e2d4c42c1bd710661885a5f787a715.zip
Add tests for scientific notation
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp17
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp24
-rw-r--r--test/libsolidity/SolidityParser.cpp14
-rw-r--r--test/libsolidity/SolidityScanner.cpp17
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);
}