Add tests for downlevel for-of type checking

This commit is contained in:
Jason Freeman 2015-03-11 16:33:38 -07:00
parent 29cbe9d4ba
commit 03176d33ef
45 changed files with 350 additions and 0 deletions

View File

@ -0,0 +1,7 @@
tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck1.ts(1,15): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck1.ts (1 errors) ====
for (var v of "") { }
~~
!!! error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.

View File

@ -0,0 +1,7 @@
//// [ES3For-ofTypeCheck1.ts]
for (var v of "") { }
//// [ES3For-ofTypeCheck1.js]
for (var _i = 0, _a = ""; _i < _a.length; _i++) {
var v = _a[_i];
}

View File

@ -0,0 +1,9 @@
//// [ES3For-ofTypeCheck2.ts]
for (var v of [true]) { }
//// [ES3For-ofTypeCheck2.js]
for (var _i = 0, _a = [
true
]; _i < _a.length; _i++) {
var v = _a[_i];
}

View File

@ -0,0 +1,5 @@
=== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck2.ts ===
for (var v of [true]) { }
>v : boolean
>[true] : boolean[]

View File

@ -0,0 +1,8 @@
tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck4.ts(2,17): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck4.ts (1 errors) ====
var union: string | string[];
for (const v of union) { }
~~~~~
!!! error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.

View File

@ -0,0 +1,9 @@
//// [ES3For-ofTypeCheck4.ts]
var union: string | string[];
for (const v of union) { }
//// [ES3For-ofTypeCheck4.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,9 @@
//// [ES3For-ofTypeCheck6.ts]
var union: string[] | number[];
for (var v of union) { }
//// [ES3For-ofTypeCheck6.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,8 @@
=== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck6.ts ===
var union: string[] | number[];
>union : string[] | number[]
for (var v of union) { }
>v : string | number
>union : string[] | number[]

View File

@ -0,0 +1,7 @@
//// [ES5For-ofTypeCheck1.ts]
for (var v of "") { }
//// [ES5For-ofTypeCheck1.js]
for (var _i = 0, _a = ""; _i < _a.length; _i++) {
var v = _a[_i];
}

View File

@ -0,0 +1,4 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck1.ts ===
for (var v of "") { }
>v : string

View File

@ -0,0 +1,23 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(1,15): error TS2461: Type 'StringIterator' is not an array type.
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts(11,6): error TS2304: Cannot find name 'Symbol'.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck10.ts (2 errors) ====
for (var v of new StringIterator) { }
~~~~~~~~~~~~~~~~~~
!!! error TS2461: Type 'StringIterator' is not an array type.
// In ES3/5, you cannot for...of over an arbitrary iterable.
class StringIterator {
next() {
return {
done: true,
value: ""
};
}
[Symbol.iterator]() {
~~~~~~
!!! error TS2304: Cannot find name 'Symbol'.
return this;
}
}

View File

@ -0,0 +1,35 @@
//// [ES5For-ofTypeCheck10.ts]
for (var v of new StringIterator) { }
// In ES3/5, you cannot for...of over an arbitrary iterable.
class StringIterator {
next() {
return {
done: true,
value: ""
};
}
[Symbol.iterator]() {
return this;
}
}
//// [ES5For-ofTypeCheck10.js]
for (var _i = 0, _a = new StringIterator; _i < _a.length; _i++) {
var v = _a[_i];
}
// In ES3/5, you cannot for...of over an arbitrary iterable.
var StringIterator = (function () {
function StringIterator() {
}
StringIterator.prototype.next = function () {
return {
done: true,
value: ""
};
};
StringIterator.prototype[Symbol.iterator] = function () {
return this;
};
return StringIterator;
})();

View File

@ -0,0 +1,11 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts(3,6): error TS2322: Type 'string | number' is not assignable to type 'string'.
Type 'number' is not assignable to type 'string'.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck11.ts (1 errors) ====
var union: string | number[];
var v: string;
for (v of union) { }
~
!!! error TS2322: Type 'string | number' is not assignable to type 'string'.
!!! error TS2322: Type 'number' is not assignable to type 'string'.

View File

@ -0,0 +1,11 @@
//// [ES5For-ofTypeCheck11.ts]
var union: string | number[];
var v: string;
for (v of union) { }
//// [ES5For-ofTypeCheck11.js]
var union;
var v;
for (var _i = 0; _i < union.length; _i++) {
v = union[_i];
}

View File

@ -0,0 +1,9 @@
//// [ES5For-ofTypeCheck2.ts]
for (var v of [true]) { }
//// [ES5For-ofTypeCheck2.js]
for (var _i = 0, _a = [
true
]; _i < _a.length; _i++) {
var v = _a[_i];
}

View File

@ -0,0 +1,5 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck2.ts ===
for (var v of [true]) { }
>v : boolean
>[true] : boolean[]

View File

@ -0,0 +1,12 @@
//// [ES5For-ofTypeCheck3.ts]
var tuple: [string, number] = ["", 0];
for (var v of tuple) { }
//// [ES5For-ofTypeCheck3.js]
var tuple = [
"",
0
];
for (var _i = 0; _i < tuple.length; _i++) {
var v = tuple[_i];
}

View File

@ -0,0 +1,9 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck3.ts ===
var tuple: [string, number] = ["", 0];
>tuple : [string, number]
>["", 0] : [string, number]
for (var v of tuple) { }
>v : string | number
>tuple : [string, number]

View File

@ -0,0 +1,9 @@
//// [ES5For-ofTypeCheck4.ts]
var union: string | string[];
for (const v of union) { }
//// [ES5For-ofTypeCheck4.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,8 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck4.ts ===
var union: string | string[];
>union : string | string[]
for (const v of union) { }
>v : string
>union : string | string[]

View File

@ -0,0 +1,9 @@
//// [ES5For-ofTypeCheck5.ts]
var union: string | number[];
for (var v of union) { }
//// [ES5For-ofTypeCheck5.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,8 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck5.ts ===
var union: string | number[];
>union : string | number[]
for (var v of union) { }
>v : string | number
>union : string | number[]

View File

@ -0,0 +1,9 @@
//// [ES5For-ofTypeCheck6.ts]
var union: string[] | number[];
for (var v of union) { }
//// [ES5For-ofTypeCheck6.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,8 @@
=== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck6.ts ===
var union: string[] | number[];
>union : string[] | number[]
for (var v of union) { }
>v : string | number
>union : string[] | number[]

View File

@ -0,0 +1,8 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck7.ts(2,15): error TS2461: Type 'number' is not an array type.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck7.ts (1 errors) ====
var union: string | number;
for (var v of union) { }
~~~~~
!!! error TS2461: Type 'number' is not an array type.

View File

@ -0,0 +1,9 @@
//// [ES5For-ofTypeCheck7.ts]
var union: string | number;
for (var v of union) { }
//// [ES5For-ofTypeCheck7.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,11 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck8.ts(3,6): error TS2322: Type 'string | number | symbol' is not assignable to type 'symbol'.
Type 'string' is not assignable to type 'symbol'.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck8.ts (1 errors) ====
var union: string | string[]| number[]| symbol[];
var v: symbol;
for (v of union) { }
~
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'symbol'.
!!! error TS2322: Type 'string' is not assignable to type 'symbol'.

View File

@ -0,0 +1,11 @@
//// [ES5For-ofTypeCheck8.ts]
var union: string | string[]| number[]| symbol[];
var v: symbol;
for (v of union) { }
//// [ES5For-ofTypeCheck8.js]
var union;
var v;
for (var _i = 0; _i < union.length; _i++) {
v = union[_i];
}

View File

@ -0,0 +1,8 @@
tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts(2,15): error TS2461: Type 'number | symbol | string[]' is not an array type.
==== tests/cases/conformance/statements/for-ofStatements/ES5For-ofTypeCheck9.ts (1 errors) ====
var union: string | string[] | number | symbol;
for (let v of union) { }
~~~~~
!!! error TS2461: Type 'number | symbol | string[]' is not an array type.

View File

@ -0,0 +1,9 @@
//// [ES5For-ofTypeCheck9.ts]
var union: string | string[] | number | symbol;
for (let v of union) { }
//// [ES5For-ofTypeCheck9.js]
var union;
for (var _i = 0; _i < union.length; _i++) {
var v = union[_i];
}

View File

@ -0,0 +1,2 @@
//@target: ES3
for (var v of "") { }

View File

@ -0,0 +1,2 @@
//@target: ES3
for (var v of [true]) { }

View File

@ -0,0 +1,3 @@
//@target: ES3
var union: string | string[];
for (const v of union) { }

View File

@ -0,0 +1,3 @@
//@target: ES3
var union: string[] | number[];
for (var v of union) { }

View File

@ -0,0 +1,2 @@
//@target: ES5
for (var v of "") { }

View File

@ -0,0 +1,15 @@
//@target: ES5
for (var v of new StringIterator) { }
// In ES3/5, you cannot for...of over an arbitrary iterable.
class StringIterator {
next() {
return {
done: true,
value: ""
};
}
[Symbol.iterator]() {
return this;
}
}

View File

@ -0,0 +1,4 @@
//@target: ES5
var union: string | number[];
var v: string;
for (v of union) { }

View File

@ -0,0 +1,2 @@
//@target: ES5
for (var v of [true]) { }

View File

@ -0,0 +1,3 @@
//@target: ES5
var tuple: [string, number] = ["", 0];
for (var v of tuple) { }

View File

@ -0,0 +1,3 @@
//@target: ES5
var union: string | string[];
for (const v of union) { }

View File

@ -0,0 +1,3 @@
//@target: ES5
var union: string | number[];
for (var v of union) { }

View File

@ -0,0 +1,3 @@
//@target: ES5
var union: string[] | number[];
for (var v of union) { }

View File

@ -0,0 +1,3 @@
//@target: ES5
var union: string | number;
for (var v of union) { }

View File

@ -0,0 +1,4 @@
//@target: ES5
var union: string | string[]| number[]| symbol[];
var v: symbol;
for (v of union) { }

View File

@ -0,0 +1,3 @@
//@target: ES5
var union: string | string[] | number | symbol;
for (let v of union) { }