From bbe51cfafe00e371bbb3e102d9ab50726f098b66 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 4 Feb 2015 15:39:57 -0800 Subject: [PATCH] Adding tests --- .../reference/callWithSpread.errors.txt | 59 ++++++ tests/baselines/reference/callWithSpread.js | 117 +++++++++++ .../baselines/reference/callWithSpreadES6.js | 105 ++++++++++ .../reference/callWithSpreadES6.types | 196 ++++++++++++++++++ .../functionCalls/callWithSpread.ts | 52 +++++ .../functionCalls/callWithSpreadES6.ts | 54 +++++ 6 files changed, 583 insertions(+) create mode 100644 tests/baselines/reference/callWithSpread.errors.txt create mode 100644 tests/baselines/reference/callWithSpread.js create mode 100644 tests/baselines/reference/callWithSpreadES6.js create mode 100644 tests/baselines/reference/callWithSpreadES6.types create mode 100644 tests/cases/conformance/expressions/functionCalls/callWithSpread.ts create mode 100644 tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts diff --git a/tests/baselines/reference/callWithSpread.errors.txt b/tests/baselines/reference/callWithSpread.errors.txt new file mode 100644 index 00000000000..7ea026f4346 --- /dev/null +++ b/tests/baselines/reference/callWithSpread.errors.txt @@ -0,0 +1,59 @@ +tests/cases/conformance/expressions/functionCalls/callWithSpread.ts(52,21): error TS2468: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher. + + +==== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts (1 errors) ==== + interface X { + foo(x: number, y: number, ...z: string[]); + } + + function foo(x: number, y: number, ...z: string[]) { + } + + var a: string[]; + var z: number[]; + var obj: X; + var xa: X[]; + + foo(1, 2, "abc"); + foo(1, 2, ...a); + foo(1, 2, ...a, "abc"); + + obj.foo(1, 2, "abc"); + obj.foo(1, 2, ...a); + obj.foo(1, 2, ...a, "abc"); + + (obj.foo)(1, 2, "abc"); + (obj.foo)(1, 2, ...a); + (obj.foo)(1, 2, ...a, "abc"); + + xa[1].foo(1, 2, "abc"); + xa[1].foo(1, 2, ...a); + xa[1].foo(1, 2, ...a, "abc"); + + (xa[1].foo)(...[1, 2, "abc"]); + + class C { + constructor(x: number, y: number, ...z: string[]) { + this.foo(x, y); + this.foo(x, y, ...z); + } + foo(x: number, y: number, ...z: string[]) { + } + } + + class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } + } + + // Only supported in when target is ES6 + var c = new C(1, 2, ...a); + ~~~~ +!!! error TS2468: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher. + \ No newline at end of file diff --git a/tests/baselines/reference/callWithSpread.js b/tests/baselines/reference/callWithSpread.js new file mode 100644 index 00000000000..d676c0f2a33 --- /dev/null +++ b/tests/baselines/reference/callWithSpread.js @@ -0,0 +1,117 @@ +//// [callWithSpread.ts] +interface X { + foo(x: number, y: number, ...z: string[]); +} + +function foo(x: number, y: number, ...z: string[]) { +} + +var a: string[]; +var z: number[]; +var obj: X; +var xa: X[]; + +foo(1, 2, "abc"); +foo(1, 2, ...a); +foo(1, 2, ...a, "abc"); + +obj.foo(1, 2, "abc"); +obj.foo(1, 2, ...a); +obj.foo(1, 2, ...a, "abc"); + +(obj.foo)(1, 2, "abc"); +(obj.foo)(1, 2, ...a); +(obj.foo)(1, 2, ...a, "abc"); + +xa[1].foo(1, 2, "abc"); +xa[1].foo(1, 2, ...a); +xa[1].foo(1, 2, ...a, "abc"); + +(xa[1].foo)(...[1, 2, "abc"]); + +class C { + constructor(x: number, y: number, ...z: string[]) { + this.foo(x, y); + this.foo(x, y, ...z); + } + foo(x: number, y: number, ...z: string[]) { + } +} + +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} + +// Only supported in when target is ES6 +var c = new C(1, 2, ...a); + + +//// [callWithSpread.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +function foo(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } +} +var a; +var z; +var obj; +var xa; +foo(1, 2, "abc"); +foo.apply(void 0, [1, 2].concat(a)); +foo.apply(void 0, [1, 2].concat(a, ["abc"])); +obj.foo(1, 2, "abc"); +obj.foo.apply(obj, [1, 2].concat(a)); +obj.foo.apply(obj, [1, 2].concat(a, ["abc"])); +(obj.foo)(1, 2, "abc"); +obj.foo.apply(obj, [1, 2].concat(a)); +obj.foo.apply(obj, [1, 2].concat(a, ["abc"])); +xa[1].foo(1, 2, "abc"); +(_a = xa[1]).foo.apply(_a, [1, 2].concat(a)); +(_b = xa[1]).foo.apply(_b, [1, 2].concat(a, ["abc"])); +(_c = xa[1]).foo.apply(_c, [1, 2, "abc"]); +var C = (function () { + function C(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } + this.foo(x, y); + this.foo.apply(this, [x, y].concat(z)); + } + C.prototype.foo = function (x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } + }; + return C; +})(); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.call(this, 1, 2); + _super.apply(this, [1, 2].concat(a)); + } + D.prototype.foo = function () { + _super.prototype.foo.call(this, 1, 2); + _super.prototype.foo.apply(this, [1, 2].concat(a)); + }; + return D; +})(C); +// Only supported in when target is ES6 +var c = new C(1, 2, ...a); +var _a, _b, _c; diff --git a/tests/baselines/reference/callWithSpreadES6.js b/tests/baselines/reference/callWithSpreadES6.js new file mode 100644 index 00000000000..bdb5aab33ec --- /dev/null +++ b/tests/baselines/reference/callWithSpreadES6.js @@ -0,0 +1,105 @@ +//// [callWithSpreadES6.ts] + +interface X { + foo(x: number, y: number, ...z: string[]); +} + +function foo(x: number, y: number, ...z: string[]) { +} + +var a: string[]; +var z: number[]; +var obj: X; +var xa: X[]; + +foo(1, 2, "abc"); +foo(1, 2, ...a); +foo(1, 2, ...a, "abc"); + +obj.foo(1, 2, "abc"); +obj.foo(1, 2, ...a); +obj.foo(1, 2, ...a, "abc"); + +(obj.foo)(1, 2, "abc"); +(obj.foo)(1, 2, ...a); +(obj.foo)(1, 2, ...a, "abc"); + +xa[1].foo(1, 2, "abc"); +xa[1].foo(1, 2, ...a); +xa[1].foo(1, 2, ...a, "abc"); + +(xa[1].foo)(...[1, 2, "abc"]); + +class C { + constructor(x: number, y: number, ...z: string[]) { + this.foo(x, y); + this.foo(x, y, ...z); + } + foo(x: number, y: number, ...z: string[]) { + } +} + +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} + +// Only supported in when target is ES6 +var c = new C(1, 2, ...a); + + +//// [callWithSpreadES6.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +function foo(x, y, ...z) { +} +var a; +var z; +var obj; +var xa; +foo(1, 2, "abc"); +foo(1, 2, ...a); +foo(1, 2, ...a, "abc"); +obj.foo(1, 2, "abc"); +obj.foo(1, 2, ...a); +obj.foo(1, 2, ...a, "abc"); +(obj.foo)(1, 2, "abc"); +(obj.foo)(1, 2, ...a); +(obj.foo)(1, 2, ...a, "abc"); +xa[1].foo(1, 2, "abc"); +xa[1].foo(1, 2, ...a); +xa[1].foo(1, 2, ...a, "abc"); +xa[1].foo(...[1, 2, "abc"]); +var C = (function () { + function C(x, y, ...z) { + this.foo(x, y); + this.foo(x, y, ...z); + } + C.prototype.foo = function (x, y, ...z) { + }; + return C; +})(); +var D = (function (_super) { + __extends(D, _super); + function D() { + _super.call(this, 1, 2); + _super.call(this, 1, 2, ...a); + } + D.prototype.foo = function () { + _super.prototype.foo.call(this, 1, 2); + _super.prototype.foo.call(this, 1, 2, ...a); + }; + return D; +})(C); +// Only supported in when target is ES6 +var c = new C(1, 2, ...a); diff --git a/tests/baselines/reference/callWithSpreadES6.types b/tests/baselines/reference/callWithSpreadES6.types new file mode 100644 index 00000000000..8a75d21e4ef --- /dev/null +++ b/tests/baselines/reference/callWithSpreadES6.types @@ -0,0 +1,196 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts === + +interface X { +>X : X + + foo(x: number, y: number, ...z: string[]); +>foo : (x: number, y: number, ...z: string[]) => any +>x : number +>y : number +>z : string[] +} + +function foo(x: number, y: number, ...z: string[]) { +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +var a: string[]; +>a : string[] + +var z: number[]; +>z : number[] + +var obj: X; +>obj : X +>X : X + +var xa: X[]; +>xa : X[] +>X : X + +foo(1, 2, "abc"); +>foo(1, 2, "abc") : void +>foo : (x: number, y: number, ...z: string[]) => void + +foo(1, 2, ...a); +>foo(1, 2, ...a) : void +>foo : (x: number, y: number, ...z: string[]) => void +>a : string[] + +foo(1, 2, ...a, "abc"); +>foo(1, 2, ...a, "abc") : void +>foo : (x: number, y: number, ...z: string[]) => void +>a : string[] + +obj.foo(1, 2, "abc"); +>obj.foo(1, 2, "abc") : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any + +obj.foo(1, 2, ...a); +>obj.foo(1, 2, ...a) : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>a : string[] + +obj.foo(1, 2, ...a, "abc"); +>obj.foo(1, 2, ...a, "abc") : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>a : string[] + +(obj.foo)(1, 2, "abc"); +>(obj.foo)(1, 2, "abc") : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any + +(obj.foo)(1, 2, ...a); +>(obj.foo)(1, 2, ...a) : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>a : string[] + +(obj.foo)(1, 2, ...a, "abc"); +>(obj.foo)(1, 2, ...a, "abc") : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>a : string[] + +xa[1].foo(1, 2, "abc"); +>xa[1].foo(1, 2, "abc") : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>foo : (x: number, y: number, ...z: string[]) => any + +xa[1].foo(1, 2, ...a); +>xa[1].foo(1, 2, ...a) : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>foo : (x: number, y: number, ...z: string[]) => any +>a : string[] + +xa[1].foo(1, 2, ...a, "abc"); +>xa[1].foo(1, 2, ...a, "abc") : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>foo : (x: number, y: number, ...z: string[]) => any +>a : string[] + +(xa[1].foo)(...[1, 2, "abc"]); +>(xa[1].foo)(...[1, 2, "abc"]) : any +>(xa[1].foo) : Function +>xa[1].foo : Function +>Function : Function +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>foo : (x: number, y: number, ...z: string[]) => any +>[1, 2, "abc"] : (string | number)[] + +class C { +>C : C + + constructor(x: number, y: number, ...z: string[]) { +>x : number +>y : number +>z : string[] + + this.foo(x, y); +>this.foo(x, y) : void +>this.foo : (x: number, y: number, ...z: string[]) => void +>this : C +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number + + this.foo(x, y, ...z); +>this.foo(x, y, ...z) : void +>this.foo : (x: number, y: number, ...z: string[]) => void +>this : C +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] + } + foo(x: number, y: number, ...z: string[]) { +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] + } +} + +class D extends C { +>D : D +>C : C + + constructor() { + super(1, 2); +>super(1, 2) : void +>super : typeof C + + super(1, 2, ...a); +>super(1, 2, ...a) : void +>super : typeof C +>a : string[] + } + foo() { +>foo : () => void + + super.foo(1, 2); +>super.foo(1, 2) : void +>super.foo : (x: number, y: number, ...z: string[]) => void +>super : C +>foo : (x: number, y: number, ...z: string[]) => void + + super.foo(1, 2, ...a); +>super.foo(1, 2, ...a) : void +>super.foo : (x: number, y: number, ...z: string[]) => void +>super : C +>foo : (x: number, y: number, ...z: string[]) => void +>a : string[] + } +} + +// Only supported in when target is ES6 +var c = new C(1, 2, ...a); +>c : C +>new C(1, 2, ...a) : C +>C : typeof C +>a : string[] + diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts new file mode 100644 index 00000000000..9acba00697a --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts @@ -0,0 +1,52 @@ +interface X { + foo(x: number, y: number, ...z: string[]); +} + +function foo(x: number, y: number, ...z: string[]) { +} + +var a: string[]; +var z: number[]; +var obj: X; +var xa: X[]; + +foo(1, 2, "abc"); +foo(1, 2, ...a); +foo(1, 2, ...a, "abc"); + +obj.foo(1, 2, "abc"); +obj.foo(1, 2, ...a); +obj.foo(1, 2, ...a, "abc"); + +(obj.foo)(1, 2, "abc"); +(obj.foo)(1, 2, ...a); +(obj.foo)(1, 2, ...a, "abc"); + +xa[1].foo(1, 2, "abc"); +xa[1].foo(1, 2, ...a); +xa[1].foo(1, 2, ...a, "abc"); + +(xa[1].foo)(...[1, 2, "abc"]); + +class C { + constructor(x: number, y: number, ...z: string[]) { + this.foo(x, y); + this.foo(x, y, ...z); + } + foo(x: number, y: number, ...z: string[]) { + } +} + +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} + +// Only supported in when target is ES6 +var c = new C(1, 2, ...a); diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts new file mode 100644 index 00000000000..2f7d16ba368 --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts @@ -0,0 +1,54 @@ +// @target: ES6 + +interface X { + foo(x: number, y: number, ...z: string[]); +} + +function foo(x: number, y: number, ...z: string[]) { +} + +var a: string[]; +var z: number[]; +var obj: X; +var xa: X[]; + +foo(1, 2, "abc"); +foo(1, 2, ...a); +foo(1, 2, ...a, "abc"); + +obj.foo(1, 2, "abc"); +obj.foo(1, 2, ...a); +obj.foo(1, 2, ...a, "abc"); + +(obj.foo)(1, 2, "abc"); +(obj.foo)(1, 2, ...a); +(obj.foo)(1, 2, ...a, "abc"); + +xa[1].foo(1, 2, "abc"); +xa[1].foo(1, 2, ...a); +xa[1].foo(1, 2, ...a, "abc"); + +(xa[1].foo)(...[1, 2, "abc"]); + +class C { + constructor(x: number, y: number, ...z: string[]) { + this.foo(x, y); + this.foo(x, y, ...z); + } + foo(x: number, y: number, ...z: string[]) { + } +} + +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} + +// Only supported in when target is ES6 +var c = new C(1, 2, ...a);