Skip to content

Commit 6c869a5

Browse files
committed
tests: organize a bit better and cover more cases
1 parent 8c480bb commit 6c869a5

8 files changed

Lines changed: 65 additions & 9 deletions

File tree

tests/compiler/tuple-circular.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"asc_flags": [
3+
"--enable", "multi-value"
4+
],
25
"stderr": [
36
"TS2456: Type alias 'Loop' circularly references itself.",
47
"1 parse error(s)"

tests/compiler/tuple-errors.json

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: Tuple types",
7+
"18 compile error(s)"
8+
]
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,26 @@ export function TupleReturnUnimplemented6(): [i32[], [i32]] {
3535
export function TupleReturnUnimplemented7(): [i32, i32] {
3636
return [0, 1];
3737
}
38+
39+
type Box<T> = [T, i32];
40+
41+
export function TupleGeneric1(x: Box<i32>): Box<i32> {
42+
return x;
43+
}
44+
export function TupleGeneric2<T>(x: [i32, T]): [i32, T] {
45+
return x;
46+
}
47+
48+
export function TupleNullable1(x: [i32, i32] | null): [i32, i32] | null {
49+
return x;
50+
}
51+
export function TupleNullable2(x: [] | null): [] | null {
52+
return x;
53+
}
54+
55+
export function TupleTypeMismatch1(x: [i32, f32]): [f32, i32] {
56+
return x;
57+
}
58+
export function TupleTypeMismatch2(x: [f64, f32]): [f32, f64] {
59+
return x;
60+
}

tests/compiler/tuple-type-errors.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

tests/compiler/tuple-type.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"asc_flags": [
3+
"--enable", "multi-value"
34
],
45
"stderr": [
56
]

tests/parser.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { globSync } from "glob";
66
import { diff } from "../util/text.js";
77
import { stdoutColors } from "../util/terminal.js";
88
import * as optionsUtil from "../util/options.js";
9-
import { Program, Options, ASTBuilder } from "../dist/assemblyscript.js";
9+
import { Program, Options, ASTBuilder, Feature } from "../dist/assemblyscript.js";
1010

1111
const dirname = path.dirname(fileURLToPath(import.meta.url));
1212

@@ -54,16 +54,28 @@ if (argv.length) {
5454
}
5555

5656
let failures = 0;
57+
const parserTestFeatures = new Map([
58+
["tuple.ts", [Feature.MultiValue]],
59+
["tuple-more.ts", [Feature.MultiValue]],
60+
["tuple-errors.ts", [Feature.MultiValue]]
61+
]);
5762

5863
for (const filename of tests) {
5964
if (filename.charAt(0) == "_" || filename.endsWith(".fixture.ts")) continue;
6065

6166
console.log(stdoutColors.white("Testing parser/" + filename));
6267

6368
let failed = false;
64-
const program = new Program(new Options());
65-
const parser = program.parser;
69+
const options = new Options();
6670
const sourceText = fs.readFileSync(basedir + "/" + filename, { encoding: "utf8" }).replace(/\r?\n/g, "\n");
71+
const features = parserTestFeatures.get(filename);
72+
if (features) {
73+
for (const feature of features) {
74+
options.setFeature(feature);
75+
}
76+
}
77+
const program = new Program(options);
78+
const parser = program.parser;
6779
parser.parseFile(sourceText, filename, true);
6880
const serializedSourceText = ASTBuilder.build(program.sources[0]);
6981
const actual = serializedSourceText + parser.diagnostics.map(diagnostic => "// " + diagnostic +"\n").join("");

tests/parser/tuple.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ function func2(x: [i32, i32]): [i32, i32] { return x; }
1010
function func3(x: [i32, [i32, i32]], y: i32): [i32, [i32, i32]] { return x; }
1111
function func4(x: readonly [i32, string]): [void] { return [void(0)]; }
1212
function func5(x: readonly [Array<i32>, i32[]]): readonly [i32] { return [x[1].length]; }
13+
function func6(x: [i32, i32] | null): [i32, i32] | null { return x; }
14+
function func7(x: readonly [[i32[]], [string]]): readonly [[i32[]], [string]] { return x; }
1315

1416
type type1 = [i32, i32];
1517
type type2 = [i32, [i32, i32]];
1618
type type3 = readonly [i32, string];
19+
type type4 = [i32, i32] | null;
20+
type type5 = [[i32, i32], [i32, i32]];
21+
type type6<T> = [Array<T>, T[], T];

tests/parser/tuple.ts.fixture.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ function func4(x: Readonly<[i32, string]>): [void] {
3131
function func5(x: Readonly<[Array<i32>, Array<i32>]>): Readonly<[i32]> {
3232
return [x[1].length];
3333
}
34+
function func6(x: [i32, i32] | null): [i32, i32] | null {
35+
return x;
36+
}
37+
function func7(x: Readonly<[[Array<i32>], [string]]>): Readonly<[[Array<i32>], [string]]> {
38+
return x;
39+
}
3440
type type1 = [i32, i32];
3541
type type2 = [i32, [i32, i32]];
3642
type type3 = Readonly<[i32, string]>;
43+
type type4 = [i32, i32] | null;
44+
type type5 = [[i32, i32], [i32, i32]];
45+
type type6<T> = [Array<T>, Array<T>, T];

0 commit comments

Comments
 (0)