aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorDaniel Kirchner <daniel@ekpyron.org>2018-04-12 00:01:01 +0800
committerDaniel Kirchner <daniel@ekpyron.org>2018-04-12 00:01:24 +0800
commitfdcbf1337a018087fe82a2fbef938d0acd6769f9 (patch)
tree4a598510c2f7514717ad16c066fe1cd5d62c097d /test/libsolidity
parentd50d1f0ac1841a1d287a216451e93573fc07474e (diff)
downloaddexon-solidity-fdcbf1337a018087fe82a2fbef938d0acd6769f9.tar.gz
dexon-solidity-fdcbf1337a018087fe82a2fbef938d0acd6769f9.tar.zst
dexon-solidity-fdcbf1337a018087fe82a2fbef938d0acd6769f9.zip
Syntax Tests: extract array_length_* tests.
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp165
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol7
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol8
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol7
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol7
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol10
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/constant_var.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol8
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol5
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/pure_functions.sol6
-rw-r--r--test/libsolidity/syntaxTests/arrayLength/too_large.sol5
20 files changed, 117 insertions, 165 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index fcee0df3..293f5f44 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -7720,171 +7720,6 @@ BOOST_AUTO_TEST_CASE(address_overload_resolution)
CHECK_SUCCESS(text);
}
-BOOST_AUTO_TEST_CASE(array_length_too_large)
-{
- char const* text = R"(
- contract C {
- uint[8**90] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_not_convertible_to_integer)
-{
- char const* text = R"(
- contract C {
- uint[true] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_constant_var)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = 10;
- uint[LEN] ids;
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_non_integer_constant_var)
-{
- char const* text = R"(
- contract C {
- bool constant LEN = true;
- uint[LEN] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_cannot_be_function)
-{
- char const* text = R"(
- contract C {
- function f() {}
- uint[f] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_can_be_recursive_constant)
-{
- char const* text = R"(
- contract C {
- uint constant L = 5;
- uint constant LEN = L + 4 * L;
- uint[LEN] ids;
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_cannot_be_function_call)
-{
- char const* text = R"(
- contract C {
- function f(uint x) {}
- uint constant LEN = f();
- uint[LEN] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_const_cannot_be_fractional)
-{
- char const* text = R"(
- contract C {
- fixed constant L = 10.5;
- uint[L] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Array with fractional length specified");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_can_be_constant_in_struct)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = 10;
- struct Test {
- uint[LEN] ids;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_can_be_constant_in_function)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = 10;
- function f() {
- uint[LEN] a;
- }
- }
- )";
- CHECK_SUCCESS(text);
-}
-
-BOOST_AUTO_TEST_CASE(array_length_cannot_be_constant_function_parameter)
-{
- char const* text = R"(
- contract C {
- function f(uint constant LEN) {
- uint[LEN] a;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_with_cyclic_constant)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = LEN;
- function f() {
- uint[LEN] a;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Cyclic constant definition (or maximum recursion depth exhausted).");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_with_complex_cyclic_constant)
-{
- char const* text = R"(
- contract C {
- uint constant L2 = LEN - 10;
- uint constant L1 = L2 / 10;
- uint constant LEN = 10 + L1 * 5;
- function f() {
- uint[LEN] a;
- }
- }
- )";
- CHECK_ERROR(text, TypeError, "Cyclic constant definition (or maximum recursion depth exhausted).");
-}
-
-BOOST_AUTO_TEST_CASE(array_length_with_pure_functions)
-{
- char const* text = R"(
- contract C {
- uint constant LEN = keccak256(ripemd160(33));
- uint[LEN] ids;
- }
- )";
- CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal or constant expression.");
-}
-
BOOST_AUTO_TEST_CASE(array_length_invalid_expression)
{
char const* text = R"(
diff --git a/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol b/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol
new file mode 100644
index 00000000..11d40f26
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/array_length_cannot_be_constant_function_parameter.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f(uint constant LEN) {
+ uint[LEN] a;
+ }
+}
+// ----
+// TypeError: (62-65): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol
new file mode 100644
index 00000000..92536dd5
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_function.sol
@@ -0,0 +1,8 @@
+contract C {
+ uint constant LEN = 10;
+ function f() public pure {
+ uint[LEN] memory a;
+ a;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol
new file mode 100644
index 00000000..89e174f2
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/can_be_constant_in_struct.sol
@@ -0,0 +1,7 @@
+contract C {
+ uint constant LEN = 10;
+ struct Test {
+ uint[LEN] ids;
+ }
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol b/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol
new file mode 100644
index 00000000..6810a9d6
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/can_be_recursive_constant.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint constant L = 5;
+ uint constant LEN = L + 4 * L;
+ uint[LEN] ids;
+}
+// ----
diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol
new file mode 100644
index 00000000..ac3abc4c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function.sol
@@ -0,0 +1,6 @@
+contract C {
+ function f() {}
+ uint[f] ids;
+}
+// ----
+// TypeError: (42-43): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol
new file mode 100644
index 00000000..a6863955
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/cannot_be_function_call.sol
@@ -0,0 +1,7 @@
+contract C {
+ function f(uint x) {}
+ uint constant LEN = f();
+ uint[LEN] ids;
+}
+// ----
+// TypeError: (77-80): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol b/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol
new file mode 100644
index 00000000..254f9f02
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/complex_cyclic_constant.sol
@@ -0,0 +1,10 @@
+contract C {
+ uint constant L2 = LEN - 10;
+ uint constant L1 = L2 / 10;
+ uint constant LEN = 10 + L1 * 5;
+ function f() {
+ uint[LEN] a;
+ }
+}
+// ----
+// TypeError: (36-39): Cyclic constant definition (or maximum recursion depth exhausted).
diff --git a/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol b/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol
new file mode 100644
index 00000000..397bbbcd
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/const_cannot_be_fractional.sol
@@ -0,0 +1,6 @@
+contract C {
+ fixed constant L = 10.5;
+ uint[L] ids;
+}
+// ----
+// TypeError: (51-52): Array with fractional length specified.
diff --git a/test/libsolidity/syntaxTests/arrayLength/constant_var.sol b/test/libsolidity/syntaxTests/arrayLength/constant_var.sol
new file mode 100644
index 00000000..41750250
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/constant_var.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint constant LEN = 10;
+ uint[LEN] ids;
+}
+// ---- \ No newline at end of file
diff --git a/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol b/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol
new file mode 100644
index 00000000..91ba9045
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/cyclic_constant.sol
@@ -0,0 +1,8 @@
+contract C {
+ uint constant LEN = LEN;
+ function f() {
+ uint[LEN] a;
+ }
+}
+// ----
+// TypeError: (37-40): Cyclic constant definition (or maximum recursion depth exhausted).
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol
new file mode 100644
index 00000000..c92861eb
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_1.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[-true] ids;
+}
+// ----
+// TypeError: (22-27): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol
new file mode 100644
index 00000000..92e3c3cf
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_2.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[true/1] ids;
+}
+// ----
+// TypeError: (22-28): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol
new file mode 100644
index 00000000..26add45c
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_3.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[1/true] ids;
+}
+// ----
+// TypeError: (22-28): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol
new file mode 100644
index 00000000..a0d58f4a
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_4.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[1.111111E1111111111111] ids;
+}
+// ----
+// TypeError: (22-44): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol
new file mode 100644
index 00000000..38a80867
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/invalid_expression_5.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[3/0] ids;
+}
+// ----
+// TypeError: (22-25): Operator / not compatible with types int_const 3 and int_const 0
diff --git a/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol b/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol
new file mode 100644
index 00000000..7a853a34
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/non_integer_constant_var.sol
@@ -0,0 +1,6 @@
+contract C {
+ bool constant LEN = true;
+ uint[LEN] ids;
+}
+// ----
+// TypeError: (52-55): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol b/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol
new file mode 100644
index 00000000..b44ccfe9
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/not_convertible_to_integer.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[true] ids;
+}
+// ----
+// TypeError: (22-26): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol b/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol
new file mode 100644
index 00000000..b620db76
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/pure_functions.sol
@@ -0,0 +1,6 @@
+contract C {
+ uint constant LEN = keccak256(ripemd160(33));
+ uint[LEN] ids;
+}
+// ----
+// TypeError: (72-75): Invalid array length, expected integer literal or constant expression.
diff --git a/test/libsolidity/syntaxTests/arrayLength/too_large.sol b/test/libsolidity/syntaxTests/arrayLength/too_large.sol
new file mode 100644
index 00000000..c90a7494
--- /dev/null
+++ b/test/libsolidity/syntaxTests/arrayLength/too_large.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint[8**90] ids;
+}
+// ----
+// TypeError: (22-27): Invalid array length, expected integer literal or constant expression.