Merge pull request #167 from smikes/generator-tests

initial set of generator tests
This commit is contained in:
Brian Terlson 2015-02-19 17:48:11 -08:00
commit 4c510bf078
11 changed files with 198 additions and 0 deletions

View File

@ -0,0 +1,17 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Generator can be declared with GeneratorDeclaration syntax
es6id: 14.4
author: Sam Mikes
description: can declare generator functions
---*/
function *foo(a) { yield a+1; return; }
var g = foo(3);
assert.sameValue(g.next().value, 4);
assert.sameValue(g.next().done, true);

View File

@ -0,0 +1,17 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
GeneratorMethod early SyntaxError when super is called
directly inside generator args
es6id: 14.4.1
author: Sam Mikes
description: GeneratorMethod error if HasDirectSuper in args
negative: SyntaxError
---*/
var obj = {
*foo(a = super) {
}
};

View File

@ -0,0 +1,17 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
GeneratorMethod can reference SuperProperty in arg
es6id: 14.4.1
author: Sam Mikes
description: GeneratorMethod uses SuperProperty (allowed)
feature: default-arg, generator, super
---*/
var obj = {
*foo(a = super.x) {
yield;
}
};

View File

@ -0,0 +1,18 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
GeneratorMethod early SyntaxError when super is called
directly inside generator body
es6id: 14.4.1
author: Sam Mikes
description: GeneratorMethod error if HasDirectSuper in body
negative: SyntaxError
---*/
var obj = {
*foo(a) {
super;
}
};

View File

@ -0,0 +1,16 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
GeneratorMethod can reference SuperProperty in body
es6id: 14.4.1
author: Sam Mikes
description: GeneratorMethod body uses SuperProperty (allowed)
---*/
var obj = {
*foo(a) {
yield super.x;
}
};

View File

@ -0,0 +1,19 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Generator can be declared with GeneratorMethod syntax
es6id: 14.4
author: Sam Mikes
description: can declare generator methods
---*/
var obj = {
*foo(a) { yield a+1; return; }
};
var g = obj.foo(3);
assert.sameValue(g.next().value, 4);
assert.sameValue(g.next().done, true);

View File

@ -0,0 +1,18 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
GeneratorMethod early SyntaxError when lexical declaration
inside generator shadows parameter name
es6id: 14.4.1
author: Sam Mikes
description: GeneratorMethod error with lexical shadowing
negative: SyntaxError
---*/
var obj = {
*foo(a) {
const a = 3;
}
};

View File

@ -0,0 +1,18 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
GeneratorMethod early SyntaxError when lexical declaration
inside generator shadows parameter name
es6id: 14.4.1
author: Sam Mikes
description: GeneratorMethod error with lexical shadowing
negative: SyntaxError
---*/
var obj = {
*foo(a) {
let a = 3;
}
};

View File

@ -0,0 +1,19 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Generator can be declared with GeneratorExpression syntax
es6id: 14.4
author: Sam Mikes
description: can create generator function expressions (no name)
---*/
var f = function *(a) { yield a+1; return; };
assert.sameValue(f.name, 'f');
var g = f(3);
assert.sameValue(g.next().value, 4);
assert.sameValue(g.next().done, true);

View File

@ -0,0 +1,19 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Generator can be declared with GeneratorExpression syntax
es6id: 14.4
author: Sam Mikes
description: can create generator function expressions (with name)
---*/
var f = function *foo(a) { yield a+1; return; };
assert.sameValue(f.name, 'foo');
var g = f(3);
assert.sameValue(g.next().value, 4);
assert.sameValue(g.next().done, true);

View File

@ -0,0 +1,20 @@
// Copyright 2015 Cubane Canada, Inc. All rights reserved.
// See LICENSE for details.
/*---
info: >
Generator can be declared with GeneratorExpression syntax
es6id: 14.4
author: Sam Mikes
description: can create generator function expressions (no name)
---*/
var a = [function *(a) { yield a+1; return; }];
var f = a[0];
assert.sameValue(f.name, '');
var g = f(3);
assert.sameValue(g.next().value, 4);
assert.sameValue(g.next().done, true);