Skip to content

Commit 98fe27f

Browse files
committed
tests: add tests for named tuple types
1 parent b7dfb8f commit 98fe27f

4 files changed

Lines changed: 20 additions & 1 deletion

File tree

tests/compiler/tuple-errors.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
],
55
"stderr": [
66
"AS100: Not implemented: Tuple types",
7-
"18 compile error(s)"
7+
"20 compile error(s)"
88
]
99
}

tests/compiler/tuple-errors.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type TupleTypeUnimplemented4 = [i32, TupleTypeUnimplemented1];
55
export type TupleTypeUnimplemented5 = [string, i32];
66
export type TupleTypeUnimplemented6 = [i32[], [i32]];
77
export type TupleTypeUnimplemented7 = [i32, i32];
8+
export type TupleTypeUnimplemented8 = [x: i32, y: i32];
89

910
export function TupleParamUnimplemented1(x: []): void { }
1011
export function TupleParamUnimplemented2(x: [i32]): void { }
@@ -13,6 +14,7 @@ export function TupleParamUnimplemented4(x: [i32, TupleTypeUnimplemented1]): voi
1314
export function TupleParamUnimplemented5(x: [string, i32]): void { }
1415
export function TupleParamUnimplemented6(x: [i32[], [i32]]): void { }
1516
export function TupleParamUnimplemented7(x: [i32, i32]): void { }
17+
export function TupleParamUnimplemented8(x: [left: i32, right: i32]): void { }
1618

1719
export function TupleReturnUnimplemented1(): [] {
1820
return [];
@@ -35,6 +37,9 @@ export function TupleReturnUnimplemented6(): [i32[], [i32]] {
3537
export function TupleReturnUnimplemented7(): [i32, i32] {
3638
return [0, 1];
3739
}
40+
export function TupleReturnUnimplemented8(): [first: i32, second: i32] {
41+
return [0, 1];
42+
}
3843

3944
type Box<T> = [T, i32];
4045

tests/parser/tuple.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ function tuple3(): [i32, string] { return [1, "a"]; }
44
function tuple4(): [Array<i32>, i32[]] { return [new Array<i32>(), [1, 2]]; }
55
function tuple5(): [i32] { return [1]; }
66
function tuple6(): [[i32[]]] { return [[[1, 2]]]; }
7+
function tuple7(): [x: i32, y: i32] { return [1, 2]; }
8+
function tuple8(): [head: i32, tail: [lo: i32, hi: i32]] { return [1, [2, 3]]; }
79

810
function func1(a: i32, b: i32): [i32, i32] { return [a, b]; }
911
function func2(x: [i32, i32]): [i32, i32] { return x; }
@@ -12,10 +14,12 @@ function func4(x: readonly [i32, string]): [void] { return [void(0)]; }
1214
function func5(x: readonly [Array<i32>, i32[]]): readonly [i32] { return [x[1].length]; }
1315
function func6(x: [i32, i32] | null): [i32, i32] | null { return x; }
1416
function func7(x: readonly [[i32[]], [string]]): readonly [[i32[]], [string]] { return x; }
17+
function func8(x: [left: i32, right: i32]): [first: i32, second: i32] { return x; }
1518

1619
type type1 = [i32, i32];
1720
type type2 = [i32, [i32, i32]];
1821
type type3 = readonly [i32, string];
1922
type type4 = [i32, i32] | null;
2023
type type5 = [[i32, i32], [i32, i32]];
2124
type type6<T> = [Array<T>, T[], T];
25+
type type7 = [start: i32, end: [lo: i32, hi: i32]];

tests/parser/tuple.ts.fixture.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ function tuple5(): [i32] {
1616
function tuple6(): [[Array<i32>]] {
1717
return [[[1, 2]]];
1818
}
19+
function tuple7(): [x: i32, y: i32] {
20+
return [1, 2];
21+
}
22+
function tuple8(): [head: i32, tail: [lo: i32, hi: i32]] {
23+
return [1, [2, 3]];
24+
}
1925
function func1(a: i32, b: i32): [i32, i32] {
2026
return [a, b];
2127
}
@@ -37,9 +43,13 @@ function func6(x: [i32, i32] | null): [i32, i32] | null {
3743
function func7(x: Readonly<[[Array<i32>], [string]]>): Readonly<[[Array<i32>], [string]]> {
3844
return x;
3945
}
46+
function func8(x: [left: i32, right: i32]): [first: i32, second: i32] {
47+
return x;
48+
}
4049
type type1 = [i32, i32];
4150
type type2 = [i32, [i32, i32]];
4251
type type3 = Readonly<[i32, string]>;
4352
type type4 = [i32, i32] | null;
4453
type type5 = [[i32, i32], [i32, i32]];
4554
type type6<T> = [Array<T>, Array<T>, T];
55+
type type7 = [start: i32, end: [lo: i32, hi: i32]];

0 commit comments

Comments
 (0)