Skip to content

Commit 2745e7c

Browse files
committed
tests: add some basic tests
1 parent 9a36236 commit 2745e7c

14 files changed

Lines changed: 189 additions & 0 deletions
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"asc_flags": [
3+
"--disable", "multi-value"
4+
],
5+
"stderr": [
6+
"AS103: Feature 'multi-value' is not enabled.",
7+
"[i32, i32]",
8+
"EOF"
9+
]
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
function pair(x: i32): [i32, i32] {
2+
return [x, x + 1];
3+
}
4+
5+
function empty(): [] {
6+
return [];
7+
}
8+
9+
pair(1);
10+
empty();
11+
12+
ERROR("EOF");
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
(module
2+
(type $0 (func (param i64) (result i64 i64)))
3+
(type $1 (func (param i32 i32) (result i32 i32)))
4+
(global $~lib/memory/__data_end i32 (i32.const 8))
5+
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 32776))
6+
(global $~lib/memory/__heap_base i32 (i32.const 32776))
7+
(memory $0 0)
8+
(table $0 1 1 funcref)
9+
(elem $0 (i32.const 1))
10+
(export "divmod" (func $features/multi-value/divmod))
11+
(export "pass" (func $features/multi-value/pass))
12+
(export "memory" (memory $0))
13+
(func $features/multi-value/divmod (param $a i32) (param $b i32) (result i32 i32)
14+
local.get $a
15+
local.get $b
16+
i32.div_s
17+
local.get $a
18+
local.get $b
19+
i32.rem_s
20+
tuple.make 2
21+
return
22+
)
23+
(func $features/multi-value/pair (param $x i64) (result i64 i64)
24+
local.get $x
25+
local.get $x
26+
i64.const 1
27+
i64.add
28+
tuple.make 2
29+
return
30+
)
31+
(func $features/multi-value/pass (param $x i64) (result i64 i64)
32+
local.get $x
33+
call $features/multi-value/pair
34+
return
35+
)
36+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"features": [
3+
"multi-value"
4+
],
5+
"asc_flags": [
6+
]
7+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
(module
2+
(type $0 (func (param i32 i32) (result i32 i32)))
3+
(type $1 (func (param i64) (result i64 i64)))
4+
(memory $0 0)
5+
(export "divmod" (func $features/multi-value/divmod))
6+
(export "pass" (func $features/multi-value/pass))
7+
(export "memory" (memory $0))
8+
(func $features/multi-value/divmod (param $0 i32) (param $1 i32) (result i32 i32)
9+
local.get $0
10+
local.get $1
11+
i32.div_s
12+
local.get $0
13+
local.get $1
14+
i32.rem_s
15+
tuple.make 2
16+
)
17+
(func $features/multi-value/pass (param $0 i64) (result i64 i64)
18+
local.get $0
19+
local.get $0
20+
i64.const 1
21+
i64.add
22+
tuple.make 2
23+
)
24+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function divmod(a: i32, b: i32): [i32, i32] {
2+
return [a / b, a % b];
3+
}
4+
5+
function pair(x: i64): [i64, i64] {
6+
return [x, x + 1];
7+
}
8+
9+
export function pass(x: i64): [i64, i64] {
10+
return pair(x);
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"asc_flags": [
3+
"--enable", "multi-value",
4+
"--bindings", "esm"
5+
],
6+
"stderr": [
7+
"EOF",
8+
"AS100: Not implemented: Exported multi-value functions are not yet supported with --bindings"
9+
]
10+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export function pair(a: i32): [i32, i32] {
2+
return [a, a + 1];
3+
}
4+
5+
ERROR("EOF");
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"asc_flags": [
3+
"--enable", "multi-value"
4+
],
5+
"stderr": [
6+
"AS100: Not implemented: Using multi-value call results outside of direct return forwarding",
7+
"EOF"
8+
]
9+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
function one(): [i32] {
2+
return [1];
3+
}
4+
5+
function badArity(): [i32, i32] {
6+
return [1];
7+
}
8+
9+
function badForward(): [i32, i32] {
10+
return one();
11+
}
12+
13+
function badUse(): i32 {
14+
let x = badArity();
15+
return x;
16+
}
17+
18+
function pair64(x: i64): [i64, i64] {
19+
return [x, x + 1];
20+
}
21+
22+
function add1(x: i64): i64 {
23+
return x + 1;
24+
}
25+
26+
function badNestedForward(): [i64, i64] {
27+
return pair64(add1(pair64(10)));
28+
}
29+
30+
badArity();
31+
badForward();
32+
badUse();
33+
badNestedForward();
34+
35+
ERROR("EOF");

0 commit comments

Comments
 (0)