js/src/tests/js1_7/geniter/builtin-Iterator-function.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/js1_7/geniter/builtin-Iterator-function.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +//-----------------------------------------------------------------------------
    1.10 +var BUGNUMBER     = "(none)";
    1.11 +var summary = "Iterator() test";
    1.12 +var actual, expect;
    1.13 +
    1.14 +printBugNumber(BUGNUMBER);
    1.15 +printStatus(summary);
    1.16 +
    1.17 +/**************
    1.18 + * BEGIN TEST *
    1.19 + **************/
    1.20 +
    1.21 +var failed = false;
    1.22 +
    1.23 +function Array_equals(a, b)
    1.24 +{
    1.25 +  if (!(a instanceof Array) || !(b instanceof Array))
    1.26 +    throw new Error("Arguments not both of type Array");
    1.27 +  if (a.length != b.length)
    1.28 +    return false;
    1.29 +  for (var i = 0, sz = a.length; i < sz; i++)
    1.30 +    if (a[i] !== b[i])
    1.31 +      return false;
    1.32 +  return true;
    1.33 +}
    1.34 +
    1.35 +var meow = "meow", oink = "oink", baa = "baa";
    1.36 +
    1.37 +var it = Iterator([meow, oink, baa]);
    1.38 +var it2 = Iterator([meow, oink, baa], true);
    1.39 +
    1.40 +try
    1.41 +{
    1.42 +  if (!Array_equals(it.next(), [0, meow]))
    1.43 +    throw [0, meow];
    1.44 +  if (!Array_equals(it.next(), [1, oink]))
    1.45 +    throw [1, oink];
    1.46 +  if (!Array_equals(it.next(), [2, baa]))
    1.47 +    throw [2, baa];
    1.48 +
    1.49 +  var stopPassed = false;
    1.50 +  try
    1.51 +  {
    1.52 +    it.next();
    1.53 +  }
    1.54 +  catch (e)
    1.55 +  {
    1.56 +    if (e === StopIteration)
    1.57 +      stopPassed = true;
    1.58 +  }
    1.59 +
    1.60 +  if (!stopPassed)
    1.61 +    throw "it: missing or incorrect StopIteration";
    1.62 +
    1.63 +  if (it2.next() != 0)
    1.64 +    throw "wanted key=0";
    1.65 +  if (it2.next() != 1)
    1.66 +    throw "wanted key=1";
    1.67 +  if (it2.next() != 2)
    1.68 +    throw "wanted key=2";
    1.69 +
    1.70 +  var stopPassed = false;
    1.71 +  try
    1.72 +  {
    1.73 +    it2.next();
    1.74 +  }
    1.75 +  catch (e)
    1.76 +  {
    1.77 +    if (e === StopIteration)
    1.78 +      stopPassed = true;
    1.79 +  }
    1.80 +
    1.81 +  if (!stopPassed)
    1.82 +    throw "it2: missing or incorrect StopIteration";
    1.83 +}
    1.84 +catch (e)
    1.85 +{
    1.86 +  failed = e;
    1.87 +}
    1.88 +
    1.89 +expect = false;
    1.90 +actual = failed;
    1.91 +
    1.92 +reportCompare(expect, actual, summary);

mercurial