ed2790de9b5cc686d34112034c6f0854962536f3
[platform/framework/web/crosswalk-tizen.git] /
1 'use strict';
2
3 var iteratorSymbol = require('es6-symbol').iterator
4   , toArray        = require('es5-ext/array/to-array')
5   , Map            = require('../../primitive')
6
7   , compare, mapToResults;
8
9 compare = function (a, b) {
10         if (!a.value) return -1;
11         if (!b.value) return 1;
12         return a.value[0].localeCompare(b.value[0]);
13 };
14
15 mapToResults = function (arr) {
16         return arr.sort().map(function (value) {
17                 return { done: false, value: value };
18         });
19 };
20
21 module.exports = function (T) {
22         return {
23                 "": function (a) {
24                         var arr, it, y, z, map, result = [];
25
26                         arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
27                                 ['cztery', 'four'], ['pięć', 'five']];
28                         map = new Map(arr);
29
30                         it = new T(map);
31                         a(it[iteratorSymbol](), it, "@@iterator");
32                         y = it.next();
33                         result.push(y);
34                         z = it.next();
35                         a.not(y, z, "Recreate result");
36                         result.push(z);
37                         result.push(it.next());
38                         result.push(it.next());
39                         result.push(it.next());
40                         a.deep(result.sort(compare), mapToResults(arr));
41                         a.deep(y = it.next(), { done: true, value: undefined }, "End");
42                         a.not(y, it.next(), "Recreate result on dead");
43                 },
44                 Emited: function (a) {
45                         var arr, it, map, result = [];
46
47                         arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
48                                 ['cztery', 'four'], ['pięć', 'five']];
49                         map = new Map(arr);
50
51                         it = new T(map);
52                         result.push(it.next());
53                         result.push(it.next());
54                         map.set('sześć', 'six');
55                         arr.push(['sześć', 'six']);
56                         result.push(it.next());
57                         map.delete('pięć');
58                         arr.splice(4, 1);
59                         result.push(it.next());
60                         result.push(it.next());
61                         a.deep(result.sort(compare), mapToResults(arr));
62                         a.deep(it.next(), { done: true, value: undefined }, "End");
63                 },
64                 "Emited #2": function (a) {
65                         var arr, it, map, result = [];
66
67                         arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
68                                 ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
69                         map = new Map(arr);
70
71                         it = new T(map);
72                         result.push(it.next());
73                         result.push(it.next());
74                         map.set('siedem', 'seven');
75                         map.delete('siedem');
76                         result.push(it.next());
77                         result.push(it.next());
78                         map.delete('pięć');
79                         arr.splice(4, 1);
80                         result.push(it.next());
81                         a.deep(result.sort(compare), mapToResults(arr));
82                         a.deep(it.next(), { done: true, value: undefined }, "End");
83                 },
84                 "Emited: Clear #1": function (a) {
85                         var arr, it, map, result = [];
86
87                         arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
88                                 ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
89                         map = new Map(arr);
90
91                         it = new T(map);
92                         result.push(it.next());
93                         result.push(it.next());
94                         arr = [['raz', 'one'], ['dwa', 'two']];
95                         map.clear();
96                         a.deep(result.sort(compare), mapToResults(arr));
97                         a.deep(it.next(), { done: true, value: undefined }, "End");
98                 },
99                 "Emited: Clear #2": function (a) {
100                         var arr, it, map, result = [];
101
102                         arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three'],
103                                 ['cztery', 'four'], ['pięć', 'five'], ['sześć', 'six']];
104                         map = new Map(arr);
105
106                         it = new T(map);
107                         result.push(it.next());
108                         result.push(it.next());
109                         map.clear();
110                         map.set('foo', 'bru');
111                         map.set('bar', 'far');
112                         arr = [['raz', 'one'], ['dwa', 'two'], ['foo', 'bru'], ['bar', 'far']];
113                         result.push(it.next());
114                         result.push(it.next());
115                         a.deep(result.sort(compare), mapToResults(arr));
116                         a.deep(it.next(), { done: true, value: undefined }, "End");
117                 },
118                 Kinds: function (a) {
119                         var arr = [['raz', 'one'], ['dwa', 'two']], map = new Map(arr);
120
121                         a.deep(toArray(new T(map)).sort(), arr.sort(), "Default");
122                         a.deep(toArray(new T(map, 'key+value')).sort(), arr.sort(),
123                                 "Key + Value");
124                         a.deep(toArray(new T(map, 'value')).sort(), ['one', 'two'].sort(),
125                                 "Value");
126                         a.deep(toArray(new T(map, 'key')).sort(), ['raz', 'dwa'].sort(),
127                                 "Key");
128                 }
129         };
130 };