Skip to content

Commit

Permalink
add more test samples
Browse files Browse the repository at this point in the history
Signed-off-by: Su Yihan <[email protected]>
  • Loading branch information
yviansu committed Feb 2, 2024
1 parent 6bc23f9 commit 98e2c96
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 1 deletion.
82 changes: 81 additions & 1 deletion tests/samples/tuple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,84 @@ export function tuple_as_ret() {
const obj = tuple[0];
console.log(obj.a);
console.log(tuple[1]);
}
}

export function tuple_as_array_elem() {
const tuple1: [i32, string] = [1, 'hi_1'];
const tuple2: [i32, string] = [2, 'hi_2'];
const tuple3: [i32, string] = [3, 'hi_3'];
const array: [i32, string][] = [tuple1, tuple2, tuple3];
console.log(array[0][1]);
console.log(array[1][1]);
console.log(array[2][1]);
}

export function tuple_as_obj_field() {
const tuple1: [i32, string] = [1, 'hi_1'];
const tuple2: [i32, string] = [2, 'hi_2'];
const tuple3: [i32, string] = [3, 'hi_3'];
const obj = {
a: tuple1 as [i32, string],
b: tuple2 as [i32, string],
c: tuple3 as [i32, string],
}

console.log(obj.a[1]);
console.log(obj.b[1]);
console.log(obj.c[1]);
}

interface T {
x: [i32, string],
y: [number, string],
}

export function tuple_as_infc_field() {
const tuple1: [i32, string] = [1, 'hi_1'];
const tuple2: [number, string] = [2, 'hi_2'];
const obj: T = {
x: tuple1 as [i32, string],
y: tuple2,
}
/* TODO: tuple box to any & unbox from any is not ready */
// console.log(obj.x[1]);
// console.log(obj.y[1]);
}

export function tuple_with_array() {
const array1: i32[] = [1, 2, 3];
const array2: string[] = ['hi_1', 'hi_2', 'hi_3'];
const tuple: [i32[], string[]] = [array1, array2];
console.log(tuple[0][1]);
console.log(tuple[1][1]);
}

class A {
a: i64 = 1;
b: string = 'hi_1';
}

class B {
a: i64 = 2;
b: string = 'hi_2';
}

export function tuple_with_class() {
const a_instance = new A();
const b_instance = new B();
const tuple: [A, B] = [a_instance, b_instance];
console.log(tuple[0].a);
console.log(tuple[1].b);
}

export function tuple_with_infc() {
const tuple1: [i32, string] = [1, 'hi_1'];
const tuple2: [number, string] = [2, 'hi_2'];
const obj: T = {
x: tuple1 as [i32, string],
y: tuple2,
}
const tuple: [T] = [obj];
/* TODO: tuple box to any & unbox from any is not ready */
// console.log(tuple[0].x[0]);
}
20 changes: 20 additions & 0 deletions tools/validate/wamr/validation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4205,6 +4205,26 @@
"name": "tuple_as_ret",
"args": [],
"result": "10\n100"
},
{
"name": "tuple_as_array_elem",
"args": [],
"result": "hi_1\nhi_2\nhi_3"
},
{
"name": "tuple_as_obj_field",
"args": [],
"result": "hi_1\nhi_2\nhi_3"
},
{
"name": "tuple_with_array",
"args": [],
"result": "2\nhi_2"
},
{
"name": "tuple_with_class",
"args": [],
"result": "1\nhi_2"
}
]
},
Expand Down

0 comments on commit 98e2c96

Please sign in to comment.