Skip to content

Commit

Permalink
test: left-to-right function/tuple/struct arguments evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
anton-trunov committed Nov 13, 2022
1 parent e9e7578 commit 332a240
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = 'core'
source = 'path+from-root-88DBE1D69186ED7B'

[[package]]
name = 'left_to_right_arg_evaluation'
source = 'member'
dependencies = ['core']
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
license = "Apache-2.0"
name = "left_to_right_arg_evaluation"
entry = "main.sw"

[dependencies]
core = { path = "../../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"functions": [
{
"inputs": [],
"name": "main",
"output": {
"name": "",
"type": 0,
"typeArguments": null
}
}
],
"loggedTypes": [],
"types": [
{
"components": null,
"type": "bool",
"typeId": 0,
"typeParameters": null
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
script;
// This tests function, tuple, struct arguments are evaluated from left to right

fn func(a: u64, b: u64, c: u64, d: u64) -> u64 {
d
}

struct MyStruct {
a: u64,
b: u64,
c: u64,
d: u64,
}

fn main() -> bool {
let mut x: u64 = 0;

// function arguments evaluation
let func_res =
func(
{
x = 1;
0
},
{
x = 2;
0
},
{
x = 3;
0
},
x
);

// tuple evaluation
x = 0;
let tuple_res =
(
{
x = 1;
0
},
{
x = 2;
1
},
{
x = 3;
2
},
x
);

// struct evaluation
x = 0;
let struct_res =
MyStruct {
a: {
x = 1;
0
},
b: {
x = 2;
1
},
c: {
x = 3;
2
},
d: x
};

return (func_res == 3) && (tuple_res.3 == 3) && (struct_res.d == 3);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
category = "run"
expected_result = { action = "return", value = 1 }
validate_abi = true

0 comments on commit 332a240

Please sign in to comment.