Debian Codegraph @

rhino/testsrc/tests/js1_7/geniter/builtin-Iterator-function.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 var gTestfile = 'builtin-Iterator-function.js';
7 //-----------------------------------------------------------------------------
8 var BUGNUMBER = "(none)";
9 var summary = "Iterator() test";
10 var actual, expect;
11
12 printBugNumber(BUGNUMBER);
13 printStatus(summary);
14
15 /**************
16 * BEGIN TEST *
17 **************/
18
19 var failed = false;
20
21 function Array_equals(a, b)
22 {
23 if (!(a instanceof Array) || !(b instanceof Array))
24 throw new Error("Arguments not both of type Array");
25 if (a.length != b.length)
26 return false;
27 for (var i = 0, sz = a.length; i < sz; i++)
28 if (a[i] !== b[i])
29 return false;
30 return true;
31 }
32
33 var meow = "meow", oink = "oink", baa = "baa";
34
35 var it = Iterator([meow, oink, baa]);
36 var it2 = Iterator([meow, oink, baa], true);
37
38 try
39 {
40 if (!Array_equals(it.next(), [0, meow]))
41 throw [0, meow];
42 if (!Array_equals(it.next(), [1, oink]))
43 throw [1, oink];
44 if (!Array_equals(it.next(), [2, baa]))
45 throw [2, baa];
46
47 var stopPassed = false;
48 try
49 {
50 it.next();
51 }
52 catch (e)
53 {
54 if (e === StopIteration)
55 stopPassed = true;
56 }
57
58 if (!stopPassed)
59 throw "it: missing or incorrect StopIteration";
60
61 if (it2.next() != 0)
62 throw "wanted key=0";
63 if (it2.next() != 1)
64 throw "wanted key=1";
65 if (it2.next() != 2)
66 throw "wanted key=2";
67
68 var stopPassed = false;
69 try
70 {
71 it2.next();
72 }
73 catch (e)
74 {
75 if (e === StopIteration)
76 stopPassed = true;
77 }
78
79 if (!stopPassed)
80 throw "it2: missing or incorrect StopIteration";
81 }
82 catch (e)
83 {
84 failed = e;
85 }
86
87 expect = false;
88 actual = failed;
89
90 reportCompare(expect, actual, summary);