mirror of https://github.com/tc39/test262.git
Merge pull request #167 from smikes/generator-tests
initial set of generator tests
This commit is contained in:
commit
4c510bf078
|
@ -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);
|
|
@ -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) {
|
||||
}
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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);
|
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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;
|
||||
}
|
||||
};
|
|
@ -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);
|
|
@ -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);
|
|
@ -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);
|
Loading…
Reference in New Issue