]>
Commit | Line | Data |
---|---|---|
ed1e77d3 A |
1 | // This test checks the behavior of the iterator.next methods on Map objects |
2 | ||
3 | var testArray = [1,2,3,4,5,6] | |
4 | var testMap = new Map(); | |
5 | for (var [key, value] of testArray.entries()) { | |
6 | testMap.set(key, value); | |
7 | } | |
8 | var keys = testMap.keys(); | |
9 | var i = 0; | |
10 | while (true) { | |
11 | var {done, value: key} = keys.next(); | |
12 | if (done) | |
13 | break; | |
14 | if (key >= testArray.length) | |
15 | throw "Error: bad value: " + key; | |
16 | i++; | |
17 | } | |
18 | ||
19 | if (testMap.size !== i) | |
20 | throw "Error: bad value: " + i; | |
21 | ||
22 | var value = keys.next().value; | |
23 | if (value !== undefined) | |
24 | throw "Error: bad value: " + value; | |
25 | ||
26 | var values = testMap.values(); | |
27 | var i = 0; | |
28 | while (true) { | |
29 | var {done, value} = values.next(); | |
30 | if (done) | |
31 | break; | |
32 | i++; | |
33 | if (testArray.indexOf(value) === -1) | |
34 | throw "Error: bad value: " + value; | |
35 | } | |
36 | ||
37 | if (testMap.size !== i) | |
38 | throw "Error: bad value: " + i; | |
39 | ||
40 | var value = values.next().value; | |
41 | if (value !== undefined) | |
42 | throw "Error: bad value: " + value; | |
43 | ||
44 | var entries = testMap.entries(); | |
45 | var i = 0; | |
46 | do { | |
47 | var {done, value: entry} = entries.next(); | |
48 | if (done) | |
49 | break; | |
50 | var [key, value] = entry; | |
51 | if (value !== testMap.get(key)) | |
52 | throw "Error: bad value: " + value + " " + testMap.get(key); | |
53 | if (key >= testArray.length) | |
54 | throw "Error: bad value: " + key; | |
55 | i++; | |
56 | if (testArray.indexOf(value) === -1) | |
57 | throw "Error: bad value: " + value + " " + i; | |
58 | } while (!done); | |
59 | ||
60 | if (testMap.size !== i) | |
61 | throw "Error: bad value: " + i; | |
62 | ||
63 | var value = entries.next().value; | |
64 | if (value !== undefined) | |
65 | throw "Error: bad value: " + value; | |
66 | ||
67 | var entries = testMap.entries(); | |
68 | var i = 0; | |
69 | do { | |
70 | var {done, value: entry} = entries.next(); | |
71 | if (done) | |
72 | break; | |
73 | var [key, value] = entry; | |
74 | if (value !== testMap.get(key)) | |
75 | throw "Error: bad value: " + value + " " + testMap.get(key); | |
76 | i++; | |
77 | if (i % 4 === 0) | |
78 | testMap.set(100000 + i, i); | |
79 | } while (!done); | |
80 | ||
81 | if (testMap.size !== i) | |
82 | throw "Error: bad value: " + i; | |
83 | ||
84 | var value = entries.next().value; | |
85 | if (value !== undefined) | |
86 | throw "Error: bad value: " + value; | |
87 | ||
88 | function otherKey(key) { | |
89 | return (key + 1) % testArray.length; | |
90 | } | |
91 | ||
92 | var entries = testMap.entries(); | |
93 | var i = 0; | |
94 | do { | |
95 | var {done, value: entry} = entries.next(); | |
96 | if (done) | |
97 | break; | |
98 | var [key, value] = entry; | |
99 | if (value !== testMap.get(key)) | |
100 | throw "Error: bad value: " + value + " " + testMap.get(key); | |
101 | i++; | |
102 | if (i % 4 === 0) | |
103 | testMap.delete(otherKey(key)); | |
104 | } while (!done); | |
105 | ||
106 | if (testMap.size !== i) | |
107 | throw "Error: bad value: " + i; | |
108 | ||
109 | var value = entries.next().value; | |
110 | if (value !== undefined) | |
111 | throw "Error: bad value: " + value; |