Adding tests

This commit is contained in:
Anders Hejlsberg 2015-09-24 13:52:19 -07:00
parent 1a26789615
commit eb73565429
5 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,30 @@
//// [destructuringWithGenericParameter.ts]
class GenericClass<T> {
payload: T;
}
var genericObject = new GenericClass<{ greeting: string }>();
function genericFunction<T>(object: GenericClass<T>, callback: (payload: T) => void) {
callback(object.payload);
}
genericFunction(genericObject, ({greeting}) => {
var s = greeting.toLocaleLowerCase(); // Greeting should be of type string
});
//// [destructuringWithGenericParameter.js]
var GenericClass = (function () {
function GenericClass() {
}
return GenericClass;
})();
var genericObject = new GenericClass();
function genericFunction(object, callback) {
callback(object.payload);
}
genericFunction(genericObject, function (_a) {
var greeting = _a.greeting;
var s = greeting.toLocaleLowerCase(); // Greeting should be of type string
});

View File

@ -0,0 +1,45 @@
=== tests/cases/compiler/destructuringWithGenericParameter.ts ===
class GenericClass<T> {
>GenericClass : Symbol(GenericClass, Decl(destructuringWithGenericParameter.ts, 0, 0))
>T : Symbol(T, Decl(destructuringWithGenericParameter.ts, 0, 19))
payload: T;
>payload : Symbol(payload, Decl(destructuringWithGenericParameter.ts, 0, 23))
>T : Symbol(T, Decl(destructuringWithGenericParameter.ts, 0, 19))
}
var genericObject = new GenericClass<{ greeting: string }>();
>genericObject : Symbol(genericObject, Decl(destructuringWithGenericParameter.ts, 4, 3))
>GenericClass : Symbol(GenericClass, Decl(destructuringWithGenericParameter.ts, 0, 0))
>greeting : Symbol(greeting, Decl(destructuringWithGenericParameter.ts, 4, 38))
function genericFunction<T>(object: GenericClass<T>, callback: (payload: T) => void) {
>genericFunction : Symbol(genericFunction, Decl(destructuringWithGenericParameter.ts, 4, 61))
>T : Symbol(T, Decl(destructuringWithGenericParameter.ts, 6, 25))
>object : Symbol(object, Decl(destructuringWithGenericParameter.ts, 6, 28))
>GenericClass : Symbol(GenericClass, Decl(destructuringWithGenericParameter.ts, 0, 0))
>T : Symbol(T, Decl(destructuringWithGenericParameter.ts, 6, 25))
>callback : Symbol(callback, Decl(destructuringWithGenericParameter.ts, 6, 52))
>payload : Symbol(payload, Decl(destructuringWithGenericParameter.ts, 6, 64))
>T : Symbol(T, Decl(destructuringWithGenericParameter.ts, 6, 25))
callback(object.payload);
>callback : Symbol(callback, Decl(destructuringWithGenericParameter.ts, 6, 52))
>object.payload : Symbol(GenericClass.payload, Decl(destructuringWithGenericParameter.ts, 0, 23))
>object : Symbol(object, Decl(destructuringWithGenericParameter.ts, 6, 28))
>payload : Symbol(GenericClass.payload, Decl(destructuringWithGenericParameter.ts, 0, 23))
}
genericFunction(genericObject, ({greeting}) => {
>genericFunction : Symbol(genericFunction, Decl(destructuringWithGenericParameter.ts, 4, 61))
>genericObject : Symbol(genericObject, Decl(destructuringWithGenericParameter.ts, 4, 3))
>greeting : Symbol(greeting, Decl(destructuringWithGenericParameter.ts, 10, 33))
var s = greeting.toLocaleLowerCase(); // Greeting should be of type string
>s : Symbol(s, Decl(destructuringWithGenericParameter.ts, 11, 7))
>greeting.toLocaleLowerCase : Symbol(String.toLocaleLowerCase, Decl(lib.d.ts, 402, 26))
>greeting : Symbol(greeting, Decl(destructuringWithGenericParameter.ts, 10, 33))
>toLocaleLowerCase : Symbol(String.toLocaleLowerCase, Decl(lib.d.ts, 402, 26))
});

View File

@ -0,0 +1,50 @@
=== tests/cases/compiler/destructuringWithGenericParameter.ts ===
class GenericClass<T> {
>GenericClass : GenericClass<T>
>T : T
payload: T;
>payload : T
>T : T
}
var genericObject = new GenericClass<{ greeting: string }>();
>genericObject : GenericClass<{ greeting: string; }>
>new GenericClass<{ greeting: string }>() : GenericClass<{ greeting: string; }>
>GenericClass : typeof GenericClass
>greeting : string
function genericFunction<T>(object: GenericClass<T>, callback: (payload: T) => void) {
>genericFunction : <T>(object: GenericClass<T>, callback: (payload: T) => void) => void
>T : T
>object : GenericClass<T>
>GenericClass : GenericClass<T>
>T : T
>callback : (payload: T) => void
>payload : T
>T : T
callback(object.payload);
>callback(object.payload) : void
>callback : (payload: T) => void
>object.payload : T
>object : GenericClass<T>
>payload : T
}
genericFunction(genericObject, ({greeting}) => {
>genericFunction(genericObject, ({greeting}) => { var s = greeting.toLocaleLowerCase(); // Greeting should be of type string}) : void
>genericFunction : <T>(object: GenericClass<T>, callback: (payload: T) => void) => void
>genericObject : GenericClass<{ greeting: string; }>
>({greeting}) => { var s = greeting.toLocaleLowerCase(); // Greeting should be of type string} : ({greeting}: { greeting: string; }) => void
>greeting : string
var s = greeting.toLocaleLowerCase(); // Greeting should be of type string
>s : string
>greeting.toLocaleLowerCase() : string
>greeting.toLocaleLowerCase : () => string
>greeting : string
>toLocaleLowerCase : () => string
});

View File

@ -0,0 +1,13 @@
class GenericClass<T> {
payload: T;
}
var genericObject = new GenericClass<{ greeting: string }>();
function genericFunction<T>(object: GenericClass<T>, callback: (payload: T) => void) {
callback(object.payload);
}
genericFunction(genericObject, ({greeting}) => {
var s = greeting.toLocaleLowerCase(); // Greeting should be of type string
});

View File

@ -0,0 +1,11 @@
/// <reference path='fourslash.ts'/>
////const result = [{ foo: 'hello' }]
//// .map(({ /*1*/foo }) => /*2*/foo)
//// .map(foo => foo);
goTo.marker('1');
verify.quickInfoIs('var foo: string');
goTo.marker('2');
verify.quickInfoIs('var foo: string');