summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/generators/326466-01.js
blob: a5123ecf71063f9d5d46e650c354511355dbaabc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

//-----------------------------------------------------------------------------
var BUGNUMBER = 326466;
var summary = 'Implement Pythonic generators and iteration protocol support';
var actual;
var expect;

printBugNumber(BUGNUMBER);
printStatus (summary);
 
function* fib()
{
  var a = 0, b = 1;

  while (true)
  {
    yield a;
    var t = a;
    a = b;
    b += t;
  }
}

var g = fib();

expect = '[object Generator]';
actual = g.toString();
reportCompare(expect, actual, summary);

var actual = [];
var expect = [0, 1, 1, 2, 3, 5, 8, 13];
actual.push(g.next().value);
actual.push(g.next().value);
actual.push(g.next().value);
actual.push(g.next().value);
actual.push(g.next().value);
actual.push(g.next().value);
actual.push(g.next().value);
actual.push(g.next().value);
reportCompare(expect.join(), actual.join(), summary);