From e14060bffb522517aeda9d600f751625b2cbfb37 Mon Sep 17 00:00:00 2001 From: Mike Pennisi Date: Tue, 14 Apr 2015 13:35:10 -0400 Subject: [PATCH] Add asertions for Generator Statement syntax tests Ensure that these forms result in objects that meet basic expectations about generator functions. --- test/language/statements/generators/return.js | 12 +- .../generators/yield-as-binding-identifier.js | 5 + .../yield-as-expression-with-rhs.js | 111 +++++++++++++++- .../yield-as-expression-without-rhs.js | 121 +++++++++++++++++- ...-function-expression-binding-identifier.js | 6 + ...enerator-declaration-binding-identifier.js | 15 +++ .../yield-as-identifier-in-nested-function.js | 5 + .../yield-as-literal-property-name.js | 5 + .../generators/yield-as-property-name.js | 5 + .../generators/yield-as-statement.js | 37 +++++- .../generators/yield-as-yield-operand.js | 15 +++ .../statements/generators/yield-newline.js | 11 +- .../generators/yield-star-before-newline.js | 8 +- 13 files changed, 340 insertions(+), 16 deletions(-) diff --git a/test/language/statements/generators/return.js b/test/language/statements/generators/return.js index 8ffb3e17f9..de7e4b50fb 100644 --- a/test/language/statements/generators/return.js +++ b/test/language/statements/generators/return.js @@ -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); diff --git a/test/language/statements/generators/yield-as-binding-identifier.js b/test/language/statements/generators/yield-as-binding-identifier.js index e8b2c2ef55..fa7cc86cd0 100644 --- a/test/language/statements/generators/yield-as-binding-identifier.js +++ b/test/language/statements/generators/yield-as-binding-identifier.js @@ -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); diff --git a/test/language/statements/generators/yield-as-expression-with-rhs.js b/test/language/statements/generators/yield-as-expression-with-rhs.js index 5022f67951..3c2d56643b 100644 --- a/test/language/statements/generators/yield-as-expression-with-rhs.js +++ b/test/language/statements/generators/yield-as-expression-with-rhs.js @@ -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' +); diff --git a/test/language/statements/generators/yield-as-expression-without-rhs.js b/test/language/statements/generators/yield-as-expression-without-rhs.js index 63b9b22948..c06dd7766a 100644 --- a/test/language/statements/generators/yield-as-expression-without-rhs.js +++ b/test/language/statements/generators/yield-as-expression-without-rhs.js @@ -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' +); diff --git a/test/language/statements/generators/yield-as-function-expression-binding-identifier.js b/test/language/statements/generators/yield-as-function-expression-binding-identifier.js index 08b06d5a1a..56c5d072a9 100644 --- a/test/language/statements/generators/yield-as-function-expression-binding-identifier.js +++ b/test/language/statements/generators/yield-as-function-expression-binding-identifier.js @@ -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); diff --git a/test/language/statements/generators/yield-as-generator-declaration-binding-identifier.js b/test/language/statements/generators/yield-as-generator-declaration-binding-identifier.js index eea595ea0c..89afbf4ef4 100644 --- a/test/language/statements/generators/yield-as-generator-declaration-binding-identifier.js +++ b/test/language/statements/generators/yield-as-generator-declaration-binding-identifier.js @@ -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'); diff --git a/test/language/statements/generators/yield-as-identifier-in-nested-function.js b/test/language/statements/generators/yield-as-identifier-in-nested-function.js index 438fe55e23..326554dba3 100644 --- a/test/language/statements/generators/yield-as-identifier-in-nested-function.js +++ b/test/language/statements/generators/yield-as-identifier-in-nested-function.js @@ -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); diff --git a/test/language/statements/generators/yield-as-literal-property-name.js b/test/language/statements/generators/yield-as-literal-property-name.js index 3b2555e387..e6faf1f109 100644 --- a/test/language/statements/generators/yield-as-literal-property-name.js +++ b/test/language/statements/generators/yield-as-literal-property-name.js @@ -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); diff --git a/test/language/statements/generators/yield-as-property-name.js b/test/language/statements/generators/yield-as-property-name.js index d3a584a674..be770038d1 100644 --- a/test/language/statements/generators/yield-as-property-name.js +++ b/test/language/statements/generators/yield-as-property-name.js @@ -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); diff --git a/test/language/statements/generators/yield-as-statement.js b/test/language/statements/generators/yield-as-statement.js index d76b027941..1c9aa142c3 100644 --- a/test/language/statements/generators/yield-as-statement.js +++ b/test/language/statements/generators/yield-as-statement.js @@ -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' +); diff --git a/test/language/statements/generators/yield-as-yield-operand.js b/test/language/statements/generators/yield-as-yield-operand.js index 00815fc27f..6737b1dae5 100644 --- a/test/language/statements/generators/yield-as-yield-operand.js +++ b/test/language/statements/generators/yield-as-yield-operand.js @@ -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'); diff --git a/test/language/statements/generators/yield-newline.js b/test/language/statements/generators/yield-newline.js index b4153832cb..349019dbef 100644 --- a/test/language/statements/generators/yield-newline.js +++ b/test/language/statements/generators/yield-newline.js @@ -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'); diff --git a/test/language/statements/generators/yield-star-before-newline.js b/test/language/statements/generators/yield-star-before-newline.js index 3f3ab2f40d..13f39ed0ae 100644 --- a/test/language/statements/generators/yield-star-before-newline.js +++ b/test/language/statements/generators/yield-star-before-newline.js @@ -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);