mirror of https://github.com/tc39/test262.git
Add asertions for Generator Statement syntax tests
Ensure that these forms result in objects that meet basic expectations about generator functions.
This commit is contained in:
parent
93d994df0f
commit
e14060bffb
|
@ -7,5 +7,13 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
function* g() { return; }
|
||||
function* g() { return 1; }
|
||||
function* g1() { return; }
|
||||
function* g2() { return 1; }
|
||||
|
||||
var result = g1().next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
||||
result = g2().next();
|
||||
assert.sameValue(result.value, 1);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
negative: SyntaxError
|
||||
---*/
|
||||
|
||||
var result;
|
||||
function* g() {
|
||||
yield = 1;
|
||||
}
|
||||
|
||||
result = g().next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
|
@ -7,8 +7,109 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
function* g() { (yield 1) }
|
||||
function* g() { [yield 1] }
|
||||
function* g() { {yield 1} }
|
||||
function* g() { yield 1, yield 1; }
|
||||
function* g() { (yield 1) ? yield 1 : yield 1 }
|
||||
var result, iter;
|
||||
function* g1() { (yield 1) }
|
||||
function* g2() { [yield 1] }
|
||||
function* g3() { {yield 1} }
|
||||
function* g4() { yield 1, yield 2; }
|
||||
function* g5() { (yield 1) ? yield 2 : yield 3; }
|
||||
|
||||
iter = g1();
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, 1, 'Within grouping operator: result `value`');
|
||||
assert.sameValue(
|
||||
result.done, false, 'Within grouping operator: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following grouping operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following grouping operator: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g2();
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, 1, 'Within array literal: result `value`');
|
||||
assert.sameValue(
|
||||
result.done, false, 'Within array literal: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following array literal: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following array literal: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g3();
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, 1, 'Within object literal: result `value`');
|
||||
assert.sameValue(
|
||||
result.done, false, 'Within object literal: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following object literal: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following object literal: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g4();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, 1, 'First expression in comma expression: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'First expression in comma expression: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, 2, 'Second expression in comma expression: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'Second expression in comma expression: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following comma expression: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following comma expression: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g5();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value,
|
||||
1,
|
||||
'Conditional expression in conditional operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'Conditional expression in conditional operator: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value,
|
||||
3,
|
||||
'Branch in conditional operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'Branch in conditional operator: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following conditional operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following conditional operator: result `done` flag'
|
||||
);
|
||||
|
|
|
@ -7,8 +7,119 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
function* g() { (yield) }
|
||||
function* g() { [yield] }
|
||||
function* g() { {yield} }
|
||||
function* g() { yield, yield; }
|
||||
function* g() { (yield) ? yield : yield }
|
||||
var iter, result;
|
||||
function* g1() { (yield) }
|
||||
function* g2() { [yield] }
|
||||
function* g3() { {yield} }
|
||||
function* g4() { yield, yield; }
|
||||
function* g5() { (yield) ? yield : yield; }
|
||||
|
||||
iter = g1();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Within grouping operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, false, 'Within grouping operator: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following grouping operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following grouping operator: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g2();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Within array literal: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, false, 'Within array literal: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following array literal: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following array literal: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g3();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Within object literal: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, false, 'Within object literal: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following object literal: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following object literal: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g4();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value,
|
||||
undefined,
|
||||
'First expression in comma expression: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'First expression in comma expression: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value,
|
||||
undefined,
|
||||
'Second expression in comma expression: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'Second expression in comma expression: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following comma expression: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following comma expression: result `done` flag'
|
||||
);
|
||||
|
||||
iter = g5();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value,
|
||||
undefined,
|
||||
'Conditional expression in conditional operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'Conditional expression in conditional operator: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value,
|
||||
undefined,
|
||||
'Branch in conditional operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done,
|
||||
false,
|
||||
'Branch in conditional operator: result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Following conditional operator: result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Following conditional operator: result `done` flag'
|
||||
);
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var result;
|
||||
function* g() {
|
||||
(function yield() {})
|
||||
}
|
||||
|
||||
result = g().next();
|
||||
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
|
@ -9,4 +9,19 @@
|
|||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var iter, result;
|
||||
function* yield() { (yield 3) + (yield 4); }
|
||||
|
||||
iter = yield();
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, 3, 'First result `value`');
|
||||
assert.sameValue(result.done, false, 'First result `done` flag');
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, 4, 'Second result `value`');
|
||||
assert.sameValue(result.done, false, 'Second result `done` flag');
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, undefined, 'Third result `value`');
|
||||
assert.sameValue(result.done, true, 'Third result `done` flag');
|
||||
|
|
|
@ -9,8 +9,13 @@
|
|||
flags: [noStrict]
|
||||
---*/
|
||||
|
||||
var result;
|
||||
function* g() {
|
||||
function h() {
|
||||
yield = 1;
|
||||
}
|
||||
}
|
||||
|
||||
result = g().next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
es6id: 12.1.1
|
||||
---*/
|
||||
|
||||
var result;
|
||||
function* g() {
|
||||
({ get yield() { return 1 } });
|
||||
}
|
||||
|
||||
result = g().next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
|
@ -8,6 +8,11 @@
|
|||
es6id: 12.1.1
|
||||
---*/
|
||||
|
||||
var result;
|
||||
function* g() {
|
||||
({ yield: 1 });
|
||||
}
|
||||
|
||||
result = g().next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
|
@ -7,5 +7,38 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
function* g() { yield; }
|
||||
function* g() { yield 1; }
|
||||
var iter, result;
|
||||
function* g1() { yield; }
|
||||
function* g2() { yield 1; }
|
||||
|
||||
iter = g1();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Without right-hand-side: first result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, false, 'Without right-hand-side: first result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'Without right-hand-side: second result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'Without right-hand-eside: second result `done` flag'
|
||||
);
|
||||
|
||||
iter = g2();
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, 1, 'With right-hand-side: first result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, false, 'With right-hand-side: first result `done` flag'
|
||||
);
|
||||
result = iter.next();
|
||||
assert.sameValue(
|
||||
result.value, undefined, 'With right-hand-side: second result `value`'
|
||||
);
|
||||
assert.sameValue(
|
||||
result.done, true, 'With right-hand-eside: second result `done` flag'
|
||||
);
|
||||
|
|
|
@ -8,6 +8,21 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
var iter, result;
|
||||
function* g() {
|
||||
yield yield 1;
|
||||
}
|
||||
|
||||
iter = g();
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, 1, 'First result `value`');
|
||||
assert.sameValue(result.done, false, 'First result `done` flag');
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, undefined, 'Second result `value`');
|
||||
assert.sameValue(result.done, false, 'Second result `done` flag');
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, undefined, 'Third result `value`');
|
||||
assert.sameValue(result.done, true, 'Thid result `done` flag');
|
||||
|
|
|
@ -7,9 +7,18 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
var iter, result;
|
||||
function* g() {
|
||||
yield
|
||||
1
|
||||
}
|
||||
|
||||
assert.sameValue(g().next().value, undefined);
|
||||
iter = g();
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, undefined, 'First result `value`');
|
||||
assert.sameValue(result.done, false, 'First result `done` flag');
|
||||
|
||||
result = iter.next();
|
||||
assert.sameValue(result.value, undefined, 'Second result `value`');
|
||||
assert.sameValue(result.done, true, 'Second result `done` flag');
|
||||
|
|
|
@ -7,7 +7,13 @@
|
|||
es6id: 14.4
|
||||
---*/
|
||||
|
||||
var result;
|
||||
function* g() {
|
||||
yield *
|
||||
1
|
||||
g2();
|
||||
}
|
||||
function* g2() {}
|
||||
|
||||
result = g().next();
|
||||
assert.sameValue(result.value, undefined);
|
||||
assert.sameValue(result.done, true);
|
||||
|
|
Loading…
Reference in New Issue