Skip to content

Commit e1f2fbf

Browse files
committed
Add tests for array destructuring of iterables
1 parent a477b63 commit e1f2fbf

90 files changed

Lines changed: 2140 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [iterableArrayPattern1.ts]
2+
var [a, b] = new SymbolIterator;
3+
class SymbolIterator {
4+
next() {
5+
return {
6+
value: Symbol(),
7+
done: false
8+
};
9+
}
10+
11+
[Symbol.iterator]() {
12+
return this;
13+
}
14+
}
15+
16+
//// [iterableArrayPattern1.js]
17+
var [a, b] = new SymbolIterator;
18+
class SymbolIterator {
19+
next() {
20+
return {
21+
value: Symbol(),
22+
done: false
23+
};
24+
}
25+
[Symbol.iterator]() {
26+
return this;
27+
}
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern1.ts ===
2+
var [a, b] = new SymbolIterator;
3+
>a : symbol
4+
>b : symbol
5+
>new SymbolIterator : SymbolIterator
6+
>SymbolIterator : typeof SymbolIterator
7+
8+
class SymbolIterator {
9+
>SymbolIterator : SymbolIterator
10+
11+
next() {
12+
>next : () => { value: symbol; done: boolean; }
13+
14+
return {
15+
>{ value: Symbol(), done: false } : { value: symbol; done: boolean; }
16+
17+
value: Symbol(),
18+
>value : symbol
19+
>Symbol() : symbol
20+
>Symbol : SymbolConstructor
21+
22+
done: false
23+
>done : boolean
24+
25+
};
26+
}
27+
28+
[Symbol.iterator]() {
29+
>Symbol.iterator : symbol
30+
>Symbol : SymbolConstructor
31+
>iterator : symbol
32+
33+
return this;
34+
>this : SymbolIterator
35+
}
36+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
tests/cases/conformance/es6/destructuring/iterableArrayPattern10.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[any, any]'.
2+
Property '0' is missing in type 'FooIterator'.
3+
4+
5+
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern10.ts (1 errors) ====
6+
function fun([a, b]) { }
7+
fun(new FooIterator);
8+
~~~~~~~~~~~~~~~
9+
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[any, any]'.
10+
!!! error TS2345: Property '0' is missing in type 'FooIterator'.
11+
class Bar { x }
12+
class Foo extends Bar { y }
13+
class FooIterator {
14+
next() {
15+
return {
16+
value: new Foo,
17+
done: false
18+
};
19+
}
20+
21+
[Symbol.iterator]() {
22+
return this;
23+
}
24+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [iterableArrayPattern10.ts]
2+
function fun([a, b]) { }
3+
fun(new FooIterator);
4+
class Bar { x }
5+
class Foo extends Bar { y }
6+
class FooIterator {
7+
next() {
8+
return {
9+
value: new Foo,
10+
done: false
11+
};
12+
}
13+
14+
[Symbol.iterator]() {
15+
return this;
16+
}
17+
}
18+
19+
//// [iterableArrayPattern10.js]
20+
function fun([a, b]) {
21+
}
22+
fun(new FooIterator);
23+
class Bar {
24+
}
25+
class Foo extends Bar {
26+
}
27+
class FooIterator {
28+
next() {
29+
return {
30+
value: new Foo,
31+
done: false
32+
};
33+
}
34+
[Symbol.iterator]() {
35+
return this;
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [iterableArrayPattern11.ts]
2+
function fun([a, b] = new FooIterator) { }
3+
fun(new FooIterator);
4+
class Bar { x }
5+
class Foo extends Bar { y }
6+
class FooIterator {
7+
next() {
8+
return {
9+
value: new Foo,
10+
done: false
11+
};
12+
}
13+
14+
[Symbol.iterator]() {
15+
return this;
16+
}
17+
}
18+
19+
//// [iterableArrayPattern11.js]
20+
function fun([a, b] = new FooIterator) {
21+
}
22+
fun(new FooIterator);
23+
class Bar {
24+
}
25+
class Foo extends Bar {
26+
}
27+
class FooIterator {
28+
next() {
29+
return {
30+
value: new Foo,
31+
done: false
32+
};
33+
}
34+
[Symbol.iterator]() {
35+
return this;
36+
}
37+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern11.ts ===
2+
function fun([a, b] = new FooIterator) { }
3+
>fun : ([a, b]?: FooIterator) => void
4+
>a : Foo
5+
>b : Foo
6+
>new FooIterator : FooIterator
7+
>FooIterator : typeof FooIterator
8+
9+
fun(new FooIterator);
10+
>fun(new FooIterator) : void
11+
>fun : ([a, b]?: FooIterator) => void
12+
>new FooIterator : FooIterator
13+
>FooIterator : typeof FooIterator
14+
15+
class Bar { x }
16+
>Bar : Bar
17+
>x : any
18+
19+
class Foo extends Bar { y }
20+
>Foo : Foo
21+
>Bar : Bar
22+
>y : any
23+
24+
class FooIterator {
25+
>FooIterator : FooIterator
26+
27+
next() {
28+
>next : () => { value: Foo; done: boolean; }
29+
30+
return {
31+
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
32+
33+
value: new Foo,
34+
>value : Foo
35+
>new Foo : Foo
36+
>Foo : typeof Foo
37+
38+
done: false
39+
>done : boolean
40+
41+
};
42+
}
43+
44+
[Symbol.iterator]() {
45+
>Symbol.iterator : symbol
46+
>Symbol : SymbolConstructor
47+
>iterator : symbol
48+
49+
return this;
50+
>this : FooIterator
51+
}
52+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [iterableArrayPattern12.ts]
2+
function fun([a, ...b] = new FooIterator) { }
3+
fun(new FooIterator);
4+
class Bar { x }
5+
class Foo extends Bar { y }
6+
class FooIterator {
7+
next() {
8+
return {
9+
value: new Foo,
10+
done: false
11+
};
12+
}
13+
14+
[Symbol.iterator]() {
15+
return this;
16+
}
17+
}
18+
19+
//// [iterableArrayPattern12.js]
20+
function fun([a, ...b] = new FooIterator) {
21+
}
22+
fun(new FooIterator);
23+
class Bar {
24+
}
25+
class Foo extends Bar {
26+
}
27+
class FooIterator {
28+
next() {
29+
return {
30+
value: new Foo,
31+
done: false
32+
};
33+
}
34+
[Symbol.iterator]() {
35+
return this;
36+
}
37+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
=== tests/cases/conformance/es6/destructuring/iterableArrayPattern12.ts ===
2+
function fun([a, ...b] = new FooIterator) { }
3+
>fun : ([a, ...b]?: FooIterator) => void
4+
>a : Foo
5+
>b : Foo[]
6+
>new FooIterator : FooIterator
7+
>FooIterator : typeof FooIterator
8+
9+
fun(new FooIterator);
10+
>fun(new FooIterator) : void
11+
>fun : ([a, ...b]?: FooIterator) => void
12+
>new FooIterator : FooIterator
13+
>FooIterator : typeof FooIterator
14+
15+
class Bar { x }
16+
>Bar : Bar
17+
>x : any
18+
19+
class Foo extends Bar { y }
20+
>Foo : Foo
21+
>Bar : Bar
22+
>y : any
23+
24+
class FooIterator {
25+
>FooIterator : FooIterator
26+
27+
next() {
28+
>next : () => { value: Foo; done: boolean; }
29+
30+
return {
31+
>{ value: new Foo, done: false } : { value: Foo; done: boolean; }
32+
33+
value: new Foo,
34+
>value : Foo
35+
>new Foo : Foo
36+
>Foo : typeof Foo
37+
38+
done: false
39+
>done : boolean
40+
41+
};
42+
}
43+
44+
[Symbol.iterator]() {
45+
>Symbol.iterator : symbol
46+
>Symbol : SymbolConstructor
47+
>iterator : symbol
48+
49+
return this;
50+
>this : FooIterator
51+
}
52+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//// [iterableArrayPattern13.ts]
2+
function fun([a, ...b]) { }
3+
fun(new FooIterator);
4+
class Bar { x }
5+
class Foo extends Bar { y }
6+
class FooIterator {
7+
next() {
8+
return {
9+
value: new Foo,
10+
done: false
11+
};
12+
}
13+
14+
[Symbol.iterator]() {
15+
return this;
16+
}
17+
}
18+
19+
//// [iterableArrayPattern13.js]
20+
function fun([a, ...b]) {
21+
}
22+
fun(new FooIterator);
23+
class Bar {
24+
}
25+
class Foo extends Bar {
26+
}
27+
class FooIterator {
28+
next() {
29+
return {
30+
value: new Foo,
31+
done: false
32+
};
33+
}
34+
[Symbol.iterator]() {
35+
return this;
36+
}
37+
}

0 commit comments

Comments
 (0)