Iterator tests
This commit is contained in:
parent
2858771a54
commit
3d5c113bee
16 changed files with 247 additions and 27 deletions
14
tests/baselines/reference/for-of14.errors.txt
Normal file
14
tests/baselines/reference/for-of14.errors.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
tests/cases/conformance/es6/for-ofStatements/for-of14.ts(2,11): error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of14.ts (1 errors) ====
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail because the iterator is not iterable
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2488: The right-hand side of a 'for...of' statement must have a '[Symbol.iterator]()' method that returns an iterator.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
}
|
21
tests/baselines/reference/for-of14.js
Normal file
21
tests/baselines/reference/for-of14.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
//// [for-of14.ts]
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail because the iterator is not iterable
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of14.js]
|
||||
var v;
|
||||
for (v of new StringIterator) { } // Should fail because the iterator is not iterable
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype.next = function () {
|
||||
return "";
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
17
tests/baselines/reference/for-of15.errors.txt
Normal file
17
tests/baselines/reference/for-of15.errors.txt
Normal file
|
@ -0,0 +1,17 @@
|
|||
tests/cases/conformance/es6/for-ofStatements/for-of15.ts(2,11): error TS2490: The object returned by the next method of the iterator must have a 'value' property.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of15.ts (1 errors) ====
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2490: The object returned by the next method of the iterator must have a 'value' property.
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
27
tests/baselines/reference/for-of15.js
Normal file
27
tests/baselines/reference/for-of15.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
//// [for-of15.ts]
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of15.js]
|
||||
var v;
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype.next = function () {
|
||||
return "";
|
||||
};
|
||||
StringIterator.prototype[Symbol.iterator] = function () {
|
||||
return this;
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
14
tests/baselines/reference/for-of16.errors.txt
Normal file
14
tests/baselines/reference/for-of16.errors.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
tests/cases/conformance/es6/for-ofStatements/for-of16.ts(2,11): error TS2489: The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of16.ts (1 errors) ====
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2489: The iterator returned by the right-hand side of a 'for...of' statement must have a 'next()' method.
|
||||
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
21
tests/baselines/reference/for-of16.js
Normal file
21
tests/baselines/reference/for-of16.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
//// [for-of16.ts]
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of16.js]
|
||||
var v;
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype[Symbol.iterator] = function () {
|
||||
return this;
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
20
tests/baselines/reference/for-of17.errors.txt
Normal file
20
tests/baselines/reference/for-of17.errors.txt
Normal file
|
@ -0,0 +1,20 @@
|
|||
tests/cases/conformance/es6/for-ofStatements/for-of17.ts(2,6): error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/for-ofStatements/for-of17.ts (1 errors) ====
|
||||
var v: string;
|
||||
for (v of new NumberIterator) { } // Should succeed
|
||||
~
|
||||
!!! error TS2322: Type 'number' is not assignable to type 'string'.
|
||||
|
||||
class NumberIterator {
|
||||
next() {
|
||||
return {
|
||||
value: 0,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
33
tests/baselines/reference/for-of17.js
Normal file
33
tests/baselines/reference/for-of17.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
//// [for-of17.ts]
|
||||
var v: string;
|
||||
for (v of new NumberIterator) { } // Should succeed
|
||||
|
||||
class NumberIterator {
|
||||
next() {
|
||||
return {
|
||||
value: 0,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of17.js]
|
||||
var v;
|
||||
for (v of new NumberIterator) { } // Should succeed
|
||||
var NumberIterator = (function () {
|
||||
function NumberIterator() {
|
||||
}
|
||||
NumberIterator.prototype.next = function () {
|
||||
return {
|
||||
value: 0,
|
||||
done: false
|
||||
};
|
||||
};
|
||||
NumberIterator.prototype[Symbol.iterator] = function () {
|
||||
return this;
|
||||
};
|
||||
return NumberIterator;
|
||||
})();
|
33
tests/baselines/reference/for-of18.js
Normal file
33
tests/baselines/reference/for-of18.js
Normal file
|
@ -0,0 +1,33 @@
|
|||
//// [for-of18.ts]
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should succeed
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
value: "",
|
||||
done: false
|
||||
};
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
//// [for-of18.js]
|
||||
var v;
|
||||
for (v of new StringIterator) { } // Should succeed
|
||||
var StringIterator = (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype.next = function () {
|
||||
return {
|
||||
value: "",
|
||||
done: false
|
||||
};
|
||||
};
|
||||
StringIterator.prototype[Symbol.iterator] = function () {
|
||||
return this;
|
||||
};
|
||||
return StringIterator;
|
||||
})();
|
35
tests/baselines/reference/for-of18.types
Normal file
35
tests/baselines/reference/for-of18.types
Normal file
|
@ -0,0 +1,35 @@
|
|||
=== tests/cases/conformance/es6/for-ofStatements/for-of18.ts ===
|
||||
var v: string;
|
||||
>v : string
|
||||
|
||||
for (v of new StringIterator) { } // Should succeed
|
||||
>v : string
|
||||
>new StringIterator : StringIterator
|
||||
>StringIterator : typeof StringIterator
|
||||
|
||||
class StringIterator {
|
||||
>StringIterator : StringIterator
|
||||
|
||||
next() {
|
||||
>next : () => { value: string; done: boolean; }
|
||||
|
||||
return {
|
||||
>{ value: "", done: false } : { value: string; done: boolean; }
|
||||
|
||||
value: "",
|
||||
>value : string
|
||||
|
||||
done: false
|
||||
>done : boolean
|
||||
|
||||
};
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
>Symbol.iterator : symbol
|
||||
>Symbol : SymbolConstructor
|
||||
>iterator : symbol
|
||||
|
||||
return this;
|
||||
>this : StringIterator
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
var v: string;
|
||||
for (v of new StringIterator) { } // Should fail because the iterator is not iterable
|
||||
|
||||
class StringIterator implements Iterator<string> {
|
||||
class StringIterator {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
//@target: ES6
|
||||
var v: string;
|
||||
for (v of new StringIterator) { } // Should succeed
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
|
||||
class StringIterator implements Iterator<string> {
|
||||
class StringIterator {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
//@target: ES6
|
||||
var v: string;
|
||||
for (v of (new StringIterator)[Symbol.iterator]()) { } // Should succeed
|
||||
for (v of new StringIterator) { } // Should fail
|
||||
|
||||
class StringIterator implements Iterator<string> {
|
||||
next() {
|
||||
return "";
|
||||
}
|
||||
class StringIterator {
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
//@target: ES6
|
||||
var v: number;
|
||||
for (v of (new NumberIterator)[Symbol.iterator]().next()) { } // Should fail
|
||||
var v: string;
|
||||
for (v of new NumberIterator) { } // Should succeed
|
||||
|
||||
class NumberIterator {
|
||||
next() {
|
||||
return 0;
|
||||
return {
|
||||
value: 0,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
//@target: ES6
|
||||
var v: string;
|
||||
for (v of (new StringIterator)[Symbol.iterator]().next()) { } // Should succeed
|
||||
for (v of new StringIterator) { } // Should succeed
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
|
|
|
@ -1,15 +0,0 @@
|
|||
//@target: ES6
|
||||
var v: string;
|
||||
for (v of (new StringIterator)[Symbol.iterator]().next()) { } // Should fail
|
||||
|
||||
class StringIterator {
|
||||
next() {
|
||||
return {
|
||||
value: 0,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue