Skip to content

Commit

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

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

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

// #19535

const [x] = (undefined as unknown as string[][]).concat([""]);
x == "";

// #26378

[""].concat([1]);

// #26976

[].concat([""]);


//// [arrayConcat2.js]
Expand All @@ -14,3 +29,11 @@ a.concat("hello", 'world');
a.concat('Hello');
var b = new Array();
b.concat('hello');
var expected = undefined;
// #19535
var x = undefined.concat([""])[0];
x == "";
// #26378
[""].concat([1]);
// #26976
[].concat([""]);
28 changes: 28 additions & 0 deletions tests/baselines/reference/arrayConcat2.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,31 @@ 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 expected: undefined = undefined as Flatten<undefined>;
>expected : Symbol(expected, Decl(arrayConcat2.ts, 8, 5))
>undefined : Symbol(undefined)
>Flatten : Symbol(Flatten, Decl(lib.es5.d.ts, --, --))

// #19535

const [x] = (undefined as unknown as string[][]).concat([""]);
>x : Symbol(x, Decl(arrayConcat2.ts, 12, 7))
>(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, --, --))

x == "";
>x : Symbol(x, Decl(arrayConcat2.ts, 12, 7))

// #26378

[""].concat([1]);
>[""].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, --, --))

// #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, --, --))

47 changes: 46 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,48 @@ b.concat('hello');
>concat : { (...items: ConcatArray<string>[]): string[]; <U extends any[]>(...items: U): (string | Flatten<U[number]>)[]; }
>'hello' : "hello"

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

// #19535

const [x] = (undefined as unknown as string[][]).concat([""]);
>x : 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[]
>"" : ""

x == "";
>x == "" : boolean
>x : string | string[]
>"" : ""

// #26378

[""].concat([1]);
>[""].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

// #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[]
>"" : ""

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

const [x] = [[""], [1]].flat();
const f: any extends typeof x ? true : false = false;


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

const [x] = [[""], [1]].flat();
>x : Symbol(x, Decl(arrayFlat.ts, 2, 7))
>[[""], [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 f: any extends typeof x ? true : false = false;
>f : Symbol(f, Decl(arrayFlat.ts, 3, 5))
>x : Symbol(x, Decl(arrayFlat.ts, 2, 7))

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

const [x] = [[""], [1]].flat();
>x : 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 f: any extends typeof x ? true : false = false;
>f : boolean
>x : string | number
>true : true
>false : false
>false : false

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

// #19535

const [x] = [""].flatMap(undefined as () => string[] | string[][]);
x == "";


//// [arrayFlatMap.js]
var array = [];
var readonlyArray = [];
array.flatMap(function () { return []; }); // ok
readonlyArray.flatMap(function () { return []; }); // ok
// #19535
var x = [""].flatMap(undefined)[0];
x == "";
11 changes: 11 additions & 0 deletions tests/baselines/reference/arrayFlatMap.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ 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

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

x == "";
>x : Symbol(x, Decl(arrayFlatMap.ts, 7, 7))

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

// #19535

const [x] = [""].flatMap(undefined as () => string[] | string[][]);
>x : 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

x == "";
>x == "" : boolean
>x : string | string[]
>"" : ""

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

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

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

// #19535

const [x] = (undefined as unknown as string[][]).concat([""]);
x == "";

// #26378

[""].concat([1]);

// #26976

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

// #24579 and #29604

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

// #19535

const [x] = [""].flatMap(undefined as () => string[] | string[][]);
x == "";

0 comments on commit 77844cc

Please sign in to comment.