|
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 //----------------------------------------------------------------------------- |
|
7 var BUGNUMBER = "(none)"; |
|
8 var summary = "Iterator() test"; |
|
9 var actual, expect; |
|
10 |
|
11 printBugNumber(BUGNUMBER); |
|
12 printStatus(summary); |
|
13 |
|
14 /************** |
|
15 * BEGIN TEST * |
|
16 **************/ |
|
17 |
|
18 var failed = false; |
|
19 |
|
20 function Array_equals(a, b) |
|
21 { |
|
22 if (!(a instanceof Array) || !(b instanceof Array)) |
|
23 throw new Error("Arguments not both of type Array"); |
|
24 if (a.length != b.length) |
|
25 return false; |
|
26 for (var i = 0, sz = a.length; i < sz; i++) |
|
27 if (a[i] !== b[i]) |
|
28 return false; |
|
29 return true; |
|
30 } |
|
31 |
|
32 var meow = "meow", oink = "oink", baa = "baa"; |
|
33 |
|
34 var it = Iterator([meow, oink, baa]); |
|
35 var it2 = Iterator([meow, oink, baa], true); |
|
36 |
|
37 try |
|
38 { |
|
39 if (!Array_equals(it.next(), [0, meow])) |
|
40 throw [0, meow]; |
|
41 if (!Array_equals(it.next(), [1, oink])) |
|
42 throw [1, oink]; |
|
43 if (!Array_equals(it.next(), [2, baa])) |
|
44 throw [2, baa]; |
|
45 |
|
46 var stopPassed = false; |
|
47 try |
|
48 { |
|
49 it.next(); |
|
50 } |
|
51 catch (e) |
|
52 { |
|
53 if (e === StopIteration) |
|
54 stopPassed = true; |
|
55 } |
|
56 |
|
57 if (!stopPassed) |
|
58 throw "it: missing or incorrect StopIteration"; |
|
59 |
|
60 if (it2.next() != 0) |
|
61 throw "wanted key=0"; |
|
62 if (it2.next() != 1) |
|
63 throw "wanted key=1"; |
|
64 if (it2.next() != 2) |
|
65 throw "wanted key=2"; |
|
66 |
|
67 var stopPassed = false; |
|
68 try |
|
69 { |
|
70 it2.next(); |
|
71 } |
|
72 catch (e) |
|
73 { |
|
74 if (e === StopIteration) |
|
75 stopPassed = true; |
|
76 } |
|
77 |
|
78 if (!stopPassed) |
|
79 throw "it2: missing or incorrect StopIteration"; |
|
80 } |
|
81 catch (e) |
|
82 { |
|
83 failed = e; |
|
84 } |
|
85 |
|
86 expect = false; |
|
87 actual = failed; |
|
88 |
|
89 reportCompare(expect, actual, summary); |