1167d2ebdfb8d431cafad633974633814abb32d2
[platform/framework/web/crosswalk-tizen.git] /
1 'use strict';
2
3 var aFrom       = require('es5-ext/array/from')
4   , getIterator = require('es6-iterator/get')
5   , toArray     = require('es5-ext/array/to-array');
6
7 module.exports = function (T, a) {
8         var arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']]
9           , map = new T(arr), x = 'other', y = 'other2'
10           , i = 0, result = [];
11
12         a(map instanceof T, true, "Map");
13         a(map.size, 3, "Size");
14         a(map.get('raz'), 'one', "Get: contained");
15         a(map.get(x), undefined, "Get: not contained");
16         a(map.has('raz'), true, "Has: true");
17         a(map.has(x), false, "Has: false");
18         a(map.set(x, y), map, "Add: return");
19         a(map.has(x), true, "Add");
20         a(map.size, 4, "Add: Size");
21         map.set('dwa', x);
22         a(map.get('dwa'), x, "Overwrite: get");
23         a(map.size, 4, "Overwrite: size");
24
25         a(map.delete('else'), false, "Delete: false");
26
27         arr.push([x, y]);
28         arr[1][1] = x;
29         map.forEach(function () {
30                 result.push(aFrom(arguments));
31                 a(this, y, "ForEach: Context: #" + i);
32         }, y);
33
34         a.deep(result.sort(function (a, b) {
35                 return String([a[1], a[0]]).localeCompare([b[1], b[0]]);
36         }), arr.sort().map(function (val) { return [val[1], val[0], map]; }),
37                 "ForEach: Arguments");
38
39         a.deep(toArray(map.entries()).sort(), [['dwa', x], ['trzy', 'three'],
40                 [x, y], ['raz', 'one']].sort(), "Entries");
41         a.deep(toArray(map.keys()).sort(), ['dwa', 'trzy', x, 'raz'].sort(),
42                 "Keys");
43         a.deep(toArray(map.values()).sort(), [x, 'three', y, 'one'].sort(),
44                 "Values");
45         a.deep(toArray(getIterator(map)).sort(), [['dwa', x], ['trzy', 'three'],
46                 [x, y], ['raz', 'one']].sort(),
47                 "Iterator");
48
49         map.clear();
50         a(map.size, 0, "Clear: size");
51         a(map.has('trzy'), false, "Clear: has");
52         a.deep(toArray(map.values()), [], "Clear: Values");
53 };