mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Organizing array tests into more directories.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
contract c {
|
||||
uint256[] data;
|
||||
|
||||
function test()
|
||||
public
|
||||
returns (uint256 x, uint256 y, uint256 z, uint256 l)
|
||||
{
|
||||
data.push(5);
|
||||
x = data[0];
|
||||
data.push(4);
|
||||
y = data[1];
|
||||
data.push(3);
|
||||
l = data.length;
|
||||
z = data[2];
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 5, 4, 3, 3
|
||||
@@ -0,0 +1,17 @@
|
||||
contract C {
|
||||
uint8 b = 23;
|
||||
uint120[][] s;
|
||||
uint8 a = 17;
|
||||
function f() public {
|
||||
s.push();
|
||||
assert(s.length == 1);
|
||||
assert(s[0].length == 0);
|
||||
s[0].push();
|
||||
assert(s[0].length == 1);
|
||||
assert(s[0][0] == 0);
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// f() ->
|
||||
@@ -0,0 +1,18 @@
|
||||
contract c {
|
||||
uint80[] x;
|
||||
|
||||
function test() public returns (uint80, uint80, uint80, uint80) {
|
||||
x.push(1);
|
||||
x.push(2);
|
||||
x.push(3);
|
||||
x.push(4);
|
||||
x.push(5);
|
||||
x.pop();
|
||||
return (x[0], x[1], x[2], x[3]);
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 1, 2, 3, 4
|
||||
@@ -0,0 +1,23 @@
|
||||
contract c {
|
||||
struct S {
|
||||
uint16 a;
|
||||
uint16 b;
|
||||
uint16[3] c;
|
||||
uint16[] d;
|
||||
}
|
||||
S[] data;
|
||||
|
||||
function test() public returns (uint16, uint16, uint16, uint16) {
|
||||
S memory s;
|
||||
s.a = 2;
|
||||
s.b = 3;
|
||||
s.c[2] = 4;
|
||||
s.d = new uint16[](4);
|
||||
s.d[2] = 5;
|
||||
data.push(s);
|
||||
return (data[0].a, data[0].b, data[0].c[2], data[0].d[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// ----
|
||||
// test() -> 2, 3, 4, 5
|
||||
@@ -0,0 +1,19 @@
|
||||
contract c {
|
||||
bytes data;
|
||||
|
||||
function test() public returns (bool x) {
|
||||
data.push(0x05);
|
||||
if (data.length != 1) return true;
|
||||
if (data[0] != 0x05) return true;
|
||||
data.push(0x04);
|
||||
if (data[1] != 0x04) return true;
|
||||
data.push(0x03);
|
||||
uint256 l = data.length;
|
||||
if (data[2] != 0x03) return true;
|
||||
if (l != 0x03) return true;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> false
|
||||
@@ -0,0 +1,19 @@
|
||||
// Tests transition between short and long encoding
|
||||
contract c {
|
||||
bytes data;
|
||||
|
||||
function test() public returns (uint256) {
|
||||
for (uint8 i = 1; i < 40; i++) {
|
||||
data.push(bytes1(i));
|
||||
if (data.length != i) return 0x1000 + i;
|
||||
if (data[data.length - 1] != bytes1(i)) return i;
|
||||
}
|
||||
for (uint8 i = 1; i < 40; i++)
|
||||
if (data[i - 1] != bytes1(i)) return 0x1000000 + i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// test() -> 0
|
||||
@@ -0,0 +1,34 @@
|
||||
contract C {
|
||||
uint[] array;
|
||||
|
||||
function f() public returns (uint) {
|
||||
uint y = array.push();
|
||||
return y;
|
||||
}
|
||||
|
||||
function lv(uint value) public {
|
||||
array.push() = value;
|
||||
}
|
||||
|
||||
function a(uint index) public view returns (uint) {
|
||||
return array[index];
|
||||
}
|
||||
|
||||
function l() public view returns (uint) {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// l() -> 0
|
||||
// lv(uint256): 42 ->
|
||||
// l() -> 1
|
||||
// a(uint256): 0 -> 42
|
||||
// f() -> 0
|
||||
// l() -> 2
|
||||
// a(uint256): 1 -> 0
|
||||
// lv(uint256): 111 ->
|
||||
// l() -> 3
|
||||
// a(uint256): 2 -> 111
|
||||
@@ -0,0 +1,41 @@
|
||||
contract C {
|
||||
uint[][] array2d;
|
||||
|
||||
function l() public returns (uint) {
|
||||
return array2d.length;
|
||||
}
|
||||
|
||||
function ll(uint index) public returns (uint) {
|
||||
return array2d[index].length;
|
||||
}
|
||||
|
||||
function a(uint i, uint j) public returns (uint) {
|
||||
return array2d[i][j];
|
||||
}
|
||||
|
||||
function f(uint index, uint value) public {
|
||||
uint[] storage pointer = array2d.push();
|
||||
for (uint i = 0; i <= index; ++i)
|
||||
pointer.push();
|
||||
pointer[index] = value;
|
||||
}
|
||||
|
||||
function lv(uint value) public {
|
||||
array2d.push().push() = value;
|
||||
}
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// l() -> 0
|
||||
// f(uint256,uint256): 42, 64 ->
|
||||
// l() -> 1
|
||||
// ll(uint256): 0 -> 43
|
||||
// a(uint256,uint256): 0, 42 -> 64
|
||||
// f(uint256,uint256): 84, 128 ->
|
||||
// l() -> 2
|
||||
// ll(uint256): 1 -> 85
|
||||
// a(uint256,uint256): 0, 42 -> 64
|
||||
// a(uint256,uint256): 1, 84 -> 128
|
||||
// lv(uint256): 512 ->
|
||||
// a(uint256,uint256): 2, 0 -> 512
|
||||
@@ -0,0 +1,28 @@
|
||||
contract C {
|
||||
bytes array;
|
||||
|
||||
function f() public {
|
||||
array.push();
|
||||
}
|
||||
|
||||
function g(uint x) public {
|
||||
for (uint i = 0; i < x; ++i)
|
||||
array.push() = bytes1(uint8(i));
|
||||
}
|
||||
|
||||
function l() public returns (uint) {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
function a(uint index) public view returns (bytes1) {
|
||||
return array[index];
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// l() -> 0
|
||||
// g(uint256): 70 ->
|
||||
// l() -> 70
|
||||
// a(uint256): 69 -> left(69)
|
||||
// f() ->
|
||||
// l() -> 71
|
||||
// a(uint256): 70 -> 0
|
||||
@@ -0,0 +1,46 @@
|
||||
contract C {
|
||||
struct S {
|
||||
uint x;
|
||||
}
|
||||
|
||||
S[] array;
|
||||
|
||||
function f(uint y) public {
|
||||
S storage s = array.push();
|
||||
g(s, y);
|
||||
}
|
||||
|
||||
function g(S storage s, uint y) internal {
|
||||
s.x = y;
|
||||
}
|
||||
|
||||
function h(uint y) public {
|
||||
g(array.push(), y);
|
||||
}
|
||||
|
||||
function lv(uint y) public {
|
||||
array.push().x = y;
|
||||
}
|
||||
|
||||
function a(uint i) public returns (uint) {
|
||||
return array[i].x;
|
||||
}
|
||||
|
||||
function l() public returns (uint) {
|
||||
return array.length;
|
||||
}
|
||||
|
||||
}
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// l() -> 0
|
||||
// f(uint256): 42 ->
|
||||
// l() -> 1
|
||||
// a(uint256): 0 -> 42
|
||||
// h(uint256): 84 ->
|
||||
// l() -> 2
|
||||
// a(uint256): 1 -> 84
|
||||
// lv(uint256): 4096 ->
|
||||
// l() -> 3
|
||||
// a(uint256): 2 -> 4096
|
||||
Reference in New Issue
Block a user