Merge pull request #621 from Microsoft/specConformanceTests

Conformance coverage for spec change #589
This commit is contained in:
Jason Freeman
2014-09-08 14:21:37 -07:00
40 changed files with 792 additions and 4 deletions

View File

@@ -0,0 +1,6 @@
==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbient.ts (1 errors) ====
module M {
export declare module "M" { }
~~~
!!! Ambient external modules cannot be nested in other modules.
}

View File

@@ -0,0 +1,6 @@
//// [ambientExternalModuleInsideNonAmbient.ts]
module M {
export declare module "M" { }
}
//// [ambientExternalModuleInsideNonAmbient.js]

View File

@@ -0,0 +1,4 @@
==== tests/cases/conformance/ambient/ambientExternalModuleInsideNonAmbientExternalModule.ts (1 errors) ====
export declare module "M" { }
~~~
!!! Ambient external modules cannot be nested in other modules.

View File

@@ -0,0 +1,6 @@
//// [ambientExternalModuleInsideNonAmbientExternalModule.ts]
export declare module "M" { }
//// [ambientExternalModuleInsideNonAmbientExternalModule.js]
define(["require", "exports"], function (require, exports) {
});

View File

@@ -0,0 +1,25 @@
//// [tests/cases/conformance/ambient/ambientExternalModuleMerging.ts] ////
//// [ambientExternalModuleMerging_use.ts]
import M = require("M");
// Should be strings
var x = M.x;
var y = M.y;
//// [ambientExternalModuleMerging_declare.ts]
declare module "M" {
export var x: string;
}
// Merge
declare module "M" {
export var y: string;
}
//// [ambientExternalModuleMerging_use.js]
define(["require", "exports", "M"], function (require, exports, M) {
// Should be strings
var x = M.x;
var y = M.y;
});
//// [ambientExternalModuleMerging_declare.js]

View File

@@ -0,0 +1,28 @@
=== tests/cases/conformance/ambient/ambientExternalModuleMerging_use.ts ===
import M = require("M");
>M : typeof M
// Should be strings
var x = M.x;
>x : string
>M.x : string
>M : typeof M
>x : string
var y = M.y;
>y : string
>M.y : string
>M : typeof M
>y : string
=== tests/cases/conformance/ambient/ambientExternalModuleMerging_declare.ts ===
declare module "M" {
export var x: string;
>x : string
}
// Merge
declare module "M" {
export var y: string;
>y : string
}

View File

@@ -0,0 +1,24 @@
//// [ambientInsideNonAmbient.ts]
module M {
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
}
module M2 {
declare var x;
declare function f();
declare class C { }
declare enum E { }
declare module M { }
}
//// [ambientInsideNonAmbient.js]
var M;
(function (M) {
})(M || (M = {}));
var M2;
(function (M2) {
})(M2 || (M2 = {}));

View File

@@ -0,0 +1,38 @@
=== tests/cases/conformance/ambient/ambientInsideNonAmbient.ts ===
module M {
>M : typeof M
export declare var x;
>x : any
export declare function f();
>f : () => any
export declare class C { }
>C : C
export declare enum E { }
>E : E
export declare module M { }
>M : unknown
}
module M2 {
>M2 : typeof M2
declare var x;
>x : any
declare function f();
>f : () => any
declare class C { }
>C : C
declare enum E { }
>E : E
declare module M { }
>M : unknown
}

View File

@@ -0,0 +1,10 @@
//// [ambientInsideNonAmbientExternalModule.ts]
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
//// [ambientInsideNonAmbientExternalModule.js]
define(["require", "exports"], function (require, exports) {
});

View File

@@ -0,0 +1,16 @@
=== tests/cases/conformance/ambient/ambientInsideNonAmbientExternalModule.ts ===
export declare var x;
>x : any
export declare function f();
>f : () => any
export declare class C { }
>C : C
export declare enum E { }
>E : E
export declare module M { }
>M : unknown

View File

@@ -1,4 +1,4 @@
==== tests/cases/compiler/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ====
==== tests/cases/conformance/types/members/augmentedTypeAssignmentCompatIndexSignature.ts (2 errors) ====
interface Foo { a }
interface Bar { b }

View File

@@ -1,4 +1,4 @@
=== tests/cases/compiler/augmentedTypeBracketAccessIndexSignature.ts ===
=== tests/cases/conformance/types/members/augmentedTypeBracketAccessIndexSignature.ts ===
interface Foo { a }
>Foo : Foo
>a : any

View File

@@ -0,0 +1,26 @@
//// [classDoesNotDependOnPrivateMember.ts]
module M {
interface I { }
export class C {
private x: I;
}
}
//// [classDoesNotDependOnPrivateMember.js]
var M;
(function (M) {
var C = (function () {
function C() {
}
return C;
})();
M.C = C;
})(M || (M = {}));
//// [classDoesNotDependOnPrivateMember.d.ts]
declare module M {
class C {
private x;
}
}

View File

@@ -0,0 +1,15 @@
=== tests/cases/conformance/declarationEmit/classDoesNotDependOnPrivateMember.ts ===
module M {
>M : typeof M
interface I { }
>I : I
export class C {
>C : C
private x: I;
>x : I
>I : I
}
}

View File

@@ -0,0 +1,28 @@
//// [contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts]
declare function foo(x: (y: string) => (y2: number) => void);
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
var z = y.charAt(0); // Should be string
return null;
});
foo((y: string) => {
return y2 => {
var z = y2.toFixed(); // Should be string
return 0;
};
});
//// [contextuallyTypedFunctionExpressionsAndReturnAnnotations.js]
// Contextually type the parameter even if there is a return annotation
foo(function (y) {
var z = y.charAt(0); // Should be string
return null;
});
foo(function (y) {
return function (y2) {
var z = y2.toFixed(); // Should be string
return 0;
};
});

View File

@@ -0,0 +1,45 @@
=== tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts ===
declare function foo(x: (y: string) => (y2: number) => void);
>foo : (x: (y: string) => (y2: number) => void) => any
>x : (y: string) => (y2: number) => void
>y : string
>y2 : number
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
>foo((y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;}) : any
>foo : (x: (y: string) => (y2: number) => void) => any
>(y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;} : (y: string) => (y2: number) => void
>y : string
>y2 : number
var z = y.charAt(0); // Should be string
>z : string
>y.charAt(0) : string
>y.charAt : (pos: number) => string
>y : string
>charAt : (pos: number) => string
return null;
});
foo((y: string) => {
>foo((y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };}) : any
>foo : (x: (y: string) => (y2: number) => void) => any
>(y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };} : (y: string) => (y2: number) => number
>y : string
return y2 => {
>y2 => { var z = y2.toFixed(); // Should be string return 0; } : (y2: number) => number
>y2 : number
var z = y2.toFixed(); // Should be string
>z : string
>y2.toFixed() : string
>y2.toFixed : (fractionDigits?: number) => string
>y2 : number
>toFixed : (fractionDigits?: number) => string
return 0;
};
});

View File

@@ -0,0 +1,13 @@
//// [derivedInterfaceDoesNotHideBaseSignatures.ts]
// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible.
interface Base {
(): string;
new (x: string): number;
}
interface Derived extends Base {
(): number;
new (x: string): string;
}
//// [derivedInterfaceDoesNotHideBaseSignatures.js]

View File

@@ -0,0 +1,18 @@
=== tests/cases/conformance/interfaces/interfaceDeclarations/derivedInterfaceDoesNotHideBaseSignatures.ts ===
// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible.
interface Base {
>Base : Base
(): string;
new (x: string): number;
>x : string
}
interface Derived extends Base {
>Derived : Derived
>Base : Base
(): number;
new (x: string): string;
>x : string
}

View File

@@ -0,0 +1,24 @@
==== tests/cases/conformance/enums/enumConstantMembers.ts (2 errors) ====
// Constant members allow negatives, but not decimals. Also hex literals are allowed
enum E1 {
a = 1,
b
}
enum E2 {
a = - 1,
b
}
enum E3 {
a = 0.1,
b // Error because 0.1 is not a constant
~
!!! Enum member must have initializer.
}
declare enum E4 {
a = 1,
b = -1,
c = 0.1 // Not a constant
~
!!! Ambient enum elements can only have integer literal initializers.
}

View File

@@ -1,4 +1,4 @@
==== tests/cases/compiler/forgottenNew.ts (1 errors) ====
==== tests/cases/conformance/expressions/functionCalls/forgottenNew.ts (1 errors) ====
module Tools {
export class NullLogger { }
}

View File

@@ -1,4 +1,4 @@
==== tests/cases/compiler/indexSignatureTypeInference.ts (1 errors) ====
==== tests/cases/conformance/types/typeRelationships/typeInference/indexSignatureTypeInference.ts (1 errors) ====
interface NumberMap<T> {
[index: number]: T;
}

View File

@@ -0,0 +1,99 @@
//// [recursiveTypesWithTypeof.ts]
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c: typeof c;
var c: any;
var d: typeof e;
var d: any;
var e: typeof d;
var e: any;
// In type arguments, these should be any
interface Foo<T> { }
var f: Array<typeof f>;
var f: any;
var f2: Foo<typeof f2>;
var f2: any;
var f3: Foo<typeof f3>[];
var f3: any;
// Truly recursive types
var g: { x: typeof g; };
var g: typeof g.x;
var h: () => typeof h;
var h = h();
var i: (x: typeof i) => typeof x;
var i = i(i);
var j: <T extends typeof j>(x: T) => T;
var j = j(j);
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
var h2 = new h2();
var i2: new (x: typeof i2) => typeof x;
var i2 = new i2(i2);
var j2: new <T extends typeof j2>(x: T) => T;
var j2 = new j2(j2);
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
var hy1 = hy1[0].x;
var hy2: { x: Array<typeof hy2> };
var hy2 = hy2.x[0];
interface Foo2<T, U> { }
// This one should be any because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
var hy3: any;
//// [recursiveTypesWithTypeof.js]
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c;
var c;
var d;
var d;
var e;
var e;
var f;
var f;
var f2;
var f2;
var f3;
var f3;
// Truly recursive types
var g;
var g;
var h;
var h = h();
var i;
var i = i(i);
var j;
var j = j(j);
// Same as h, i, j with construct signatures
var h2;
var h2 = new h2();
var i2;
var i2 = new i2(i2);
var j2;
var j2 = new j2(j2);
// Indexers
var k;
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1;
var hy1 = hy1[0].x;
var hy2;
var hy2 = hy2.x[0];
// This one should be any because the first type argument is not contained inside a type literal
var hy3;
var hy3;

View File

@@ -0,0 +1,196 @@
=== tests/cases/conformance/types/specifyingTypes/typeQueries/recursiveTypesWithTypeof.ts ===
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c: typeof c;
>c : any
>c : any
var c: any;
>c : any
var d: typeof e;
>d : any
>e : any
var d: any;
>d : any
var e: typeof d;
>e : any
>d : any
var e: any;
>e : any
// In type arguments, these should be any
interface Foo<T> { }
>Foo : Foo<T>
>T : T
var f: Array<typeof f>;
>f : any
>Array : T[]
>f : any
var f: any;
>f : any
var f2: Foo<typeof f2>;
>f2 : any
>Foo : Foo<T>
>f2 : any
var f2: any;
>f2 : any
var f3: Foo<typeof f3>[];
>f3 : any
>Foo : Foo<T>
>f3 : any
var f3: any;
>f3 : any
// Truly recursive types
var g: { x: typeof g; };
>g : { x: any; }
>x : { x: any; }
>g : { x: any; }
var g: typeof g.x;
>g : { x: any; }
>g : { x: any; }
>x : { x: any; }
var h: () => typeof h;
>h : () => any
>h : () => any
var h = h();
>h : () => any
>h() : () => any
>h : () => any
var i: (x: typeof i) => typeof x;
>i : (x: any) => any
>x : (x: any) => any
>i : (x: any) => any
>x : (x: any) => any
var i = i(i);
>i : (x: any) => any
>i(i) : (x: any) => any
>i : (x: any) => any
>i : (x: any) => any
var j: <T extends typeof j>(x: T) => T;
>j : <T extends any>(x: T) => T
>T : T
>j : <T extends any>(x: T) => T
>x : T
>T : T
>T : T
var j = j(j);
>j : <T extends any>(x: T) => T
>j(j) : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
>j : <T extends any>(x: T) => T
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
>h2 : new () => any
>h2 : new () => any
var h2 = new h2();
>h2 : new () => any
>new h2() : new () => any
>h2 : new () => any
var i2: new (x: typeof i2) => typeof x;
>i2 : new (x: any) => any
>x : new (x: any) => any
>i2 : new (x: any) => any
>x : new (x: any) => any
var i2 = new i2(i2);
>i2 : new (x: any) => any
>new i2(i2) : new (x: any) => any
>i2 : new (x: any) => any
>i2 : new (x: any) => any
var j2: new <T extends typeof j2>(x: T) => T;
>j2 : new <T extends any>(x: T) => T
>T : T
>j2 : new <T extends any>(x: T) => T
>x : T
>T : T
>T : T
var j2 = new j2(j2);
>j2 : new <T extends any>(x: T) => T
>new j2(j2) : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
>j2 : new <T extends any>(x: T) => T
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
>k : { [x: string]: any; [x: number]: any; }
>n : number
>k : { [x: string]: any; [x: number]: any; }
>s : string
>k : { [x: string]: any; [x: number]: any; }
var k = k[0];
>k : { [x: string]: any; [x: number]: any; }
>k[0] : { [x: string]: any; [x: number]: any; }
>k : { [x: string]: any; [x: number]: any; }
var k = k[''];
>k : { [x: string]: any; [x: number]: any; }
>k[''] : { [x: string]: any; [x: number]: any; }
>k : { [x: string]: any; [x: number]: any; }
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
>hy1 : { x: any[]; }[]
>x : { x: any[]; }[]
>hy1 : { x: any[]; }[]
var hy1 = hy1[0].x;
>hy1 : { x: any[]; }[]
>hy1[0].x : { x: any[]; }[]
>hy1[0] : { x: any[]; }
>hy1 : { x: any[]; }[]
>x : { x: any[]; }[]
var hy2: { x: Array<typeof hy2> };
>hy2 : { x: any[]; }
>x : { x: any[]; }[]
>Array : T[]
>hy2 : { x: any[]; }
var hy2 = hy2.x[0];
>hy2 : { x: any[]; }
>hy2.x[0] : { x: any[]; }
>hy2.x : { x: any[]; }[]
>hy2 : { x: any[]; }
>x : { x: any[]; }[]
interface Foo2<T, U> { }
>Foo2 : Foo2<T, U>
>T : T
>U : U
// This one should be any because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
>hy3 : any
>Foo2 : Foo2<T, U>
>hy3 : any
>x : any
>hy3 : any
var hy3: any;
>hy3 : any

View File

@@ -0,0 +1,5 @@
//// [specializedSignatureWithOptional.ts]
declare function f(x?: "hi"): void;
declare function f(x?: string): void;
//// [specializedSignatureWithOptional.js]

View File

@@ -0,0 +1,9 @@
=== tests/cases/conformance/types/objectTypeLiteral/callSignatures/specializedSignatureWithOptional.ts ===
declare function f(x?: "hi"): void;
>f : { (x?: "hi"): void; (x?: string): void; }
>x : "hi"
declare function f(x?: string): void;
>f : { (x?: "hi"): void; (x?: string): void; }
>x : string

View File

@@ -0,0 +1,3 @@
module M {
export declare module "M" { }
}

View File

@@ -0,0 +1,2 @@
//@module: amd
export declare module "M" { }

View File

@@ -0,0 +1,16 @@
//@filename: ambientExternalModuleMerging_use.ts
//@module: amd
import M = require("M");
// Should be strings
var x = M.x;
var y = M.y;
//@filename: ambientExternalModuleMerging_declare.ts
declare module "M" {
export var x: string;
}
// Merge
declare module "M" {
export var y: string;
}

View File

@@ -0,0 +1,15 @@
module M {
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }
}
module M2 {
declare var x;
declare function f();
declare class C { }
declare enum E { }
declare module M { }
}

View File

@@ -0,0 +1,6 @@
// @module: amd
export declare var x;
export declare function f();
export declare class C { }
export declare enum E { }
export declare module M { }

View File

@@ -0,0 +1,7 @@
//@declaration: true
module M {
interface I { }
export class C {
private x: I;
}
}

View File

@@ -0,0 +1,19 @@
// Constant members allow negatives, but not decimals. Also hex literals are allowed
enum E1 {
a = 1,
b
}
enum E2 {
a = - 1,
b
}
enum E3 {
a = 0.1,
b // Error because 0.1 is not a constant
}
declare enum E4 {
a = 1,
b = -1,
c = 0.1 // Not a constant
}

View File

@@ -0,0 +1,14 @@
declare function foo(x: (y: string) => (y2: number) => void);
// Contextually type the parameter even if there is a return annotation
foo((y): (y2: number) => void => {
var z = y.charAt(0); // Should be string
return null;
});
foo((y: string) => {
return y2 => {
var z = y2.toFixed(); // Should be string
return 0;
};
});

View File

@@ -0,0 +1,10 @@
// Derived interfaces no longer hide signatures from base types, so these signatures are always compatible.
interface Base {
(): string;
new (x: string): number;
}
interface Derived extends Base {
(): number;
new (x: string): string;
}

View File

@@ -0,0 +1,2 @@
declare function f(x?: "hi"): void;
declare function f(x?: string): void;

View File

@@ -0,0 +1,53 @@
// None of these declarations should have any errors!
// Using typeof directly, these should be any
var c: typeof c;
var c: any;
var d: typeof e;
var d: any;
var e: typeof d;
var e: any;
// In type arguments, these should be any
interface Foo<T> { }
var f: Array<typeof f>;
var f: any;
var f2: Foo<typeof f2>;
var f2: any;
var f3: Foo<typeof f3>[];
var f3: any;
// Truly recursive types
var g: { x: typeof g; };
var g: typeof g.x;
var h: () => typeof h;
var h = h();
var i: (x: typeof i) => typeof x;
var i = i(i);
var j: <T extends typeof j>(x: T) => T;
var j = j(j);
// Same as h, i, j with construct signatures
var h2: new () => typeof h2;
var h2 = new h2();
var i2: new (x: typeof i2) => typeof x;
var i2 = new i2(i2);
var j2: new <T extends typeof j2>(x: T) => T;
var j2 = new j2(j2);
// Indexers
var k: { [n: number]: typeof k;[s: string]: typeof k };
var k = k[0];
var k = k[''];
// Hybrid - contains type literals as well as type arguments
// These two are recursive
var hy1: { x: typeof hy1 }[];
var hy1 = hy1[0].x;
var hy2: { x: Array<typeof hy2> };
var hy2 = hy2.x[0];
interface Foo2<T, U> { }
// This one should be any because the first type argument is not contained inside a type literal
var hy3: Foo2<typeof hy3, { x: typeof hy3 }>;
var hy3: any;