Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Feb 3, 2020
1 parent bdc9366 commit 43679d2
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 1 deletion.
29 changes: 29 additions & 0 deletions tests/baselines/reference/arrayConcat2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,24 @@ a.concat('Hello');

var b = new Array<string>();
b.concat('hello');

const expected1: undefined = undefined as Flatten<undefined>;

// #19535

let [actual2] = (undefined as unknown as string[][]).concat([""]);
const expected2: string | string[] = actual2;
actual2 = undefined as unknown as string | string[];

// #26378

let [actual3] = [""].concat([1]);
const expected3: string | number = actual3;
actual3 = undefined as unknown as string | number;

// #26976

[].concat([""]);


//// [arrayConcat2.js]
Expand All @@ -14,3 +32,14 @@ a.concat("hello", 'world');
a.concat('Hello');
var b = new Array();
b.concat('hello');
var expected1 = undefined;
// #19535
var actual2 = undefined.concat([""])[0];
var expected2 = actual2;
actual2 = undefined;
// #26378
var actual3 = [""].concat([1])[0];
var expected3 = actual3;
actual3 = undefined;
// #26976
[].concat([""]);
42 changes: 42 additions & 0 deletions tests/baselines/reference/arrayConcat2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,45 @@ b.concat('hello');
>b : Symbol(b, Decl(arrayConcat2.ts, 5, 3))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

const expected1: undefined = undefined as Flatten<undefined>;
>expected1 : Symbol(expected1, Decl(arrayConcat2.ts, 8, 5))
>undefined : Symbol(undefined)
>Flatten : Symbol(Flatten, Decl(lib.es5.d.ts, --, --))

// #19535

let [actual2] = (undefined as unknown as string[][]).concat([""]);
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
>(undefined as unknown as string[][]).concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>undefined : Symbol(undefined)
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

const expected2: string | string[] = actual2;
>expected2 : Symbol(expected2, Decl(arrayConcat2.ts, 13, 5))
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))

actual2 = undefined as unknown as string | string[];
>actual2 : Symbol(actual2, Decl(arrayConcat2.ts, 12, 5))
>undefined : Symbol(undefined)

// #26378

let [actual3] = [""].concat([1]);
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
>[""].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

const expected3: string | number = actual3;
>expected3 : Symbol(expected3, Decl(arrayConcat2.ts, 19, 5))
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))

actual3 = undefined as unknown as string | number;
>actual3 : Symbol(actual3, Decl(arrayConcat2.ts, 18, 5))
>undefined : Symbol(undefined)

// #26976

[].concat([""]);
>[].concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))
>concat : Symbol(Array.concat, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --))

65 changes: 64 additions & 1 deletion tests/baselines/reference/arrayConcat2.types
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
=== tests/cases/compiler/arrayConcat2.ts ===
var a: string[] = [];
>a : string[]
>[] : undefined[]
>[] : never[]

a.concat("hello", 'world');
>a.concat("hello", 'world') : string[]
Expand Down Expand Up @@ -30,3 +30,66 @@ b.concat('hello');
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
>'hello' : "hello"

const expected1: undefined = undefined as Flatten<undefined>;
>expected1 : undefined
>undefined as Flatten<undefined> : undefined
>undefined : undefined

// #19535

let [actual2] = (undefined as unknown as string[][]).concat([""]);
>actual2 : string | string[]
>(undefined as unknown as string[][]).concat([""]) : (string | string[])[]
>(undefined as unknown as string[][]).concat : { (...items: ConcatArray<string[]>[]): string[][]; <U extends any[]>(...items: U): (string[] | Flatten<U[number]>)[]; }
>(undefined as unknown as string[][]) : string[][]
>undefined as unknown as string[][] : string[][]
>undefined as unknown : unknown
>undefined : undefined
>concat : { (...items: ConcatArray<string[]>[]): string[][]; <U extends any[]>(...items: U): (string[] | Flatten<U[number]>)[]; }
>[""] : string[]
>"" : ""

const expected2: string | string[] = actual2;
>expected2 : string | string[]
>actual2 : string | string[]

actual2 = undefined as unknown as string | string[];
>actual2 = undefined as unknown as string | string[] : string | string[]
>actual2 : string | string[]
>undefined as unknown as string | string[] : string | string[]
>undefined as unknown : unknown
>undefined : undefined

// #26378

let [actual3] = [""].concat([1]);
>actual3 : string | number
>[""].concat([1]) : (string | number)[]
>[""].concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
>[""] : string[]
>"" : ""
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
>[1] : number[]
>1 : 1

const expected3: string | number = actual3;
>expected3 : string | number
>actual3 : string | number

actual3 = undefined as unknown as string | number;
>actual3 = undefined as unknown as string | number : string | number
>actual3 : string | number
>undefined as unknown as string | number : string | number
>undefined as unknown : unknown
>undefined : undefined

// #26976

[].concat([""]);
>[].concat([""]) : string[]
>[].concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): Flatten<U[number]>[]; }
>[] : never[]
>concat : { (...items: ConcatArray<never>[]): never[]; <U extends any[]>(...items: U): Flatten<U[number]>[]; }
>[""] : string[]
>"" : ""

15 changes: 15 additions & 0 deletions tests/baselines/reference/arrayFlat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//// [arrayFlat.ts]
// #24579 and #29604

let [actual] = [[""], [1]].flat();
const expected: string | number = actual;
actual = undefined as string | number;
const f: any extends typeof actual ? true : false = false;


//// [arrayFlat.js]
// #24579 and #29604
var actual = [[""], [1]].flat()[0];
var expected = actual;
actual = undefined;
var f = false;
20 changes: 20 additions & 0 deletions tests/baselines/reference/arrayFlat.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
=== tests/cases/compiler/arrayFlat.ts ===
// #24579 and #29604

let [actual] = [[""], [1]].flat();
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))
>[[""], [1]].flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)
>flat : Symbol(Array.flat, Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --) ... and 1 more)

const expected: string | number = actual;
>expected : Symbol(expected, Decl(arrayFlat.ts, 3, 5))
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))

actual = undefined as string | number;
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))
>undefined : Symbol(undefined)

const f: any extends typeof actual ? true : false = false;
>f : Symbol(f, Decl(arrayFlat.ts, 5, 5))
>actual : Symbol(actual, Decl(arrayFlat.ts, 2, 5))

31 changes: 31 additions & 0 deletions tests/baselines/reference/arrayFlat.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
=== tests/cases/compiler/arrayFlat.ts ===
// #24579 and #29604

let [actual] = [[""], [1]].flat();
>actual : string | number
>[[""], [1]].flat() : (string | number)[]
>[[""], [1]].flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string[] | number[])[] | (string | number)[]; }
>[[""], [1]] : (string[] | number[])[]
>[""] : string[]
>"" : ""
>[1] : number[]
>1 : 1
>flat : { (depth: 4): (string | number)[]; (depth: 3): (string | number)[]; (depth: 2): (string | number)[]; (depth?: 1): (string | number)[]; (depth: 0): (string[] | number[])[]; (depth: number): (string[] | number[])[] | (string | number)[]; }

const expected: string | number = actual;
>expected : string | number
>actual : string | number

actual = undefined as string | number;
>actual = undefined as string | number : string | number
>actual : string | number
>undefined as string | number : string | number
>undefined : undefined

const f: any extends typeof actual ? true : false = false;
>f : boolean
>actual : string | number
>true : true
>false : false
>false : false

10 changes: 10 additions & 0 deletions tests/baselines/reference/arrayFlatMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,20 @@ const array: number[] = [];
const readonlyArray: ReadonlyArray<number> = [];
array.flatMap((): ReadonlyArray<number> => []); // ok
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok

// #19535

let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
const expected: string | string[] = actual;
actual = undefined as string | string[];


//// [arrayFlatMap.js]
var array = [];
var readonlyArray = [];
array.flatMap(function () { return []; }); // ok
readonlyArray.flatMap(function () { return []; }); // ok
// #19535
var actual = [""].flatMap(undefined)[0];
var expected = actual;
actual = undefined;
16 changes: 16 additions & 0 deletions tests/baselines/reference/arrayFlatMap.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,19 @@ readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
>flatMap : Symbol(ReadonlyArray.flatMap, Decl(lib.es2019.array.d.ts, --, --))
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --))

// #19535

let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5))
>[""].flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
>flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
>undefined : Symbol(undefined)

const expected: string | string[] = actual;
>expected : Symbol(expected, Decl(arrayFlatMap.ts, 8, 5))
>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5))

actual = undefined as string | string[];
>actual : Symbol(actual, Decl(arrayFlatMap.ts, 7, 5))
>undefined : Symbol(undefined)

22 changes: 22 additions & 0 deletions tests/baselines/reference/arrayFlatMap.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,25 @@ readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
>(): ReadonlyArray<number> => [] : () => readonly number[]
>[] : undefined[]

// #19535

let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
>actual : string | string[]
>[""].flatMap(undefined as () => string[] | string[][]) : (string | string[])[]
>[""].flatMap : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => Flatten<U>[]
>[""] : string[]
>"" : ""
>flatMap : <U>(callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => Flatten<U>[]
>undefined as () => string[] | string[][] : () => string[] | string[][]
>undefined : undefined

const expected: string | string[] = actual;
>expected : string | string[]
>actual : string | string[]

actual = undefined as string | string[];
>actual = undefined as string | string[] : string | string[]
>actual : string | string[]
>undefined as string | string[] : string | string[]
>undefined : undefined

19 changes: 19 additions & 0 deletions tests/cases/compiler/arrayConcat2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,22 @@ a.concat('Hello');

var b = new Array<string>();
b.concat('hello');

const expected1: undefined = undefined as Flatten<undefined>;

// #19535

let [actual2] = (undefined as unknown as string[][]).concat([""]);
const expected2: string | string[] = actual2;
actual2 = undefined as unknown as string | string[];

// #26378

let [actual3] = [""].concat([1]);
const expected3: string | number = actual3;
actual3 = undefined as unknown as string | number;

// #26976

// @strictNullChecks: true
[].concat([""]);
8 changes: 8 additions & 0 deletions tests/cases/compiler/arrayFlat.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @lib: es2019

// #24579 and #29604

let [actual] = [[""], [1]].flat();
const expected: string | number = actual;
actual = undefined as string | number;
const f: any extends typeof actual ? true : false = false;
6 changes: 6 additions & 0 deletions tests/cases/compiler/arrayFlatMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ const array: number[] = [];
const readonlyArray: ReadonlyArray<number> = [];
array.flatMap((): ReadonlyArray<number> => []); // ok
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok

// #19535

let [actual] = [""].flatMap(undefined as () => string[] | string[][]);
const expected: string | string[] = actual;
actual = undefined as string | string[];

0 comments on commit 43679d2

Please sign in to comment.