Add tests

This commit is contained in:
Jason Freeman
2015-07-24 14:59:01 -07:00
parent f44bcbda3c
commit 628d63cf75
10 changed files with 210 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
tests/cases/compiler/requiredInitializedParameter1.ts(11,1): error TS2346: Supplied parameters do not match any signature of call target.
tests/cases/compiler/requiredInitializedParameter1.ts(16,1): error TS2346: Supplied parameters do not match any signature of call target.
==== tests/cases/compiler/requiredInitializedParameter1.ts (2 errors) ====
function f1(a, b = 0, c) { }
function f2(a, b = 0, c = 0) { }
function f3(a, b = 0, c?) { }
function f4(a, b = 0, ...c) { }
f1(0, 1, 2);
f2(0, 1, 2);
f3(0, 1, 2);
f4(0, 1, 2);
f1(0, 1);
~~~~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
f2(0, 1);
f3(0, 1);
f4(0, 1);
f1(0);
~~~~~
!!! error TS2346: Supplied parameters do not match any signature of call target.
f2(0);
f3(0);
f4(0);

View File

@@ -0,0 +1,51 @@
//// [requiredInitializedParameter1.ts]
function f1(a, b = 0, c) { }
function f2(a, b = 0, c = 0) { }
function f3(a, b = 0, c?) { }
function f4(a, b = 0, ...c) { }
f1(0, 1, 2);
f2(0, 1, 2);
f3(0, 1, 2);
f4(0, 1, 2);
f1(0, 1);
f2(0, 1);
f3(0, 1);
f4(0, 1);
f1(0);
f2(0);
f3(0);
f4(0);
//// [requiredInitializedParameter1.js]
function f1(a, b, c) {
if (b === void 0) { b = 0; }
}
function f2(a, b, c) {
if (b === void 0) { b = 0; }
if (c === void 0) { c = 0; }
}
function f3(a, b, c) {
if (b === void 0) { b = 0; }
}
function f4(a, b) {
if (b === void 0) { b = 0; }
var c = [];
for (var _i = 2; _i < arguments.length; _i++) {
c[_i - 2] = arguments[_i];
}
}
f1(0, 1, 2);
f2(0, 1, 2);
f3(0, 1, 2);
f4(0, 1, 2);
f1(0, 1);
f2(0, 1);
f3(0, 1);
f4(0, 1);
f1(0);
f2(0);
f3(0);
f4(0);

View File

@@ -0,0 +1,17 @@
tests/cases/compiler/requiredInitializedParameter2.ts(5,7): error TS2420: Class 'C1' incorrectly implements interface 'I1'.
Types of property 'method' are incompatible.
Type '(a: number, b: any) => void' is not assignable to type '() => any'.
==== tests/cases/compiler/requiredInitializedParameter2.ts (1 errors) ====
interface I1 {
method();
}
class C1 implements I1 {
~~
!!! error TS2420: Class 'C1' incorrectly implements interface 'I1'.
!!! error TS2420: Types of property 'method' are incompatible.
!!! error TS2420: Type '(a: number, b: any) => void' is not assignable to type '() => any'.
method(a = 0, b) { }
}

View File

@@ -0,0 +1,18 @@
//// [requiredInitializedParameter2.ts]
interface I1 {
method();
}
class C1 implements I1 {
method(a = 0, b) { }
}
//// [requiredInitializedParameter2.js]
var C1 = (function () {
function C1() {
}
C1.prototype.method = function (a, b) {
if (a === void 0) { a = 0; }
};
return C1;
})();

View File

@@ -0,0 +1,27 @@
//// [requiredInitializedParameter3.ts]
interface I1 {
method();
}
class C1 implements I1 {
method(a = 0, b?) { }
}
//// [requiredInitializedParameter3.js]
var C1 = (function () {
function C1() {
}
C1.prototype.method = function (a, b) {
if (a === void 0) { a = 0; }
};
return C1;
})();
//// [requiredInitializedParameter3.d.ts]
interface I1 {
method(): any;
}
declare class C1 implements I1 {
method(a?: number, b?: any): void;
}

View File

@@ -0,0 +1,17 @@
=== tests/cases/compiler/requiredInitializedParameter3.ts ===
interface I1 {
>I1 : Symbol(I1, Decl(requiredInitializedParameter3.ts, 0, 0))
method();
>method : Symbol(method, Decl(requiredInitializedParameter3.ts, 0, 14))
}
class C1 implements I1 {
>C1 : Symbol(C1, Decl(requiredInitializedParameter3.ts, 2, 1))
>I1 : Symbol(I1, Decl(requiredInitializedParameter3.ts, 0, 0))
method(a = 0, b?) { }
>method : Symbol(method, Decl(requiredInitializedParameter3.ts, 4, 24))
>a : Symbol(a, Decl(requiredInitializedParameter3.ts, 5, 11))
>b : Symbol(b, Decl(requiredInitializedParameter3.ts, 5, 17))
}

View File

@@ -0,0 +1,18 @@
=== tests/cases/compiler/requiredInitializedParameter3.ts ===
interface I1 {
>I1 : I1
method();
>method : () => any
}
class C1 implements I1 {
>C1 : C1
>I1 : I1
method(a = 0, b?) { }
>method : (a?: number, b?: any) => void
>a : number
>0 : number
>b : any
}

View File

@@ -0,0 +1,19 @@
function f1(a, b = 0, c) { }
function f2(a, b = 0, c = 0) { }
function f3(a, b = 0, c?) { }
function f4(a, b = 0, ...c) { }
f1(0, 1, 2);
f2(0, 1, 2);
f3(0, 1, 2);
f4(0, 1, 2);
f1(0, 1);
f2(0, 1);
f3(0, 1);
f4(0, 1);
f1(0);
f2(0);
f3(0);
f4(0);

View File

@@ -0,0 +1,7 @@
interface I1 {
method();
}
class C1 implements I1 {
method(a = 0, b) { }
}

View File

@@ -0,0 +1,8 @@
//@declaration: true
interface I1 {
method();
}
class C1 implements I1 {
method(a = 0, b?) { }
}