Sha256: 36310e4357c95bc4dff1b081217e0afdad2a2d6a7bfa84f99363218db1c7724d

Contents?: true

Size: 1.77 KB

Versions: 51

Compression:

Stored size: 1.77 KB

Contents

'use strict';

var aFrom       = require('es5-ext/array/from')
  , getIterator = require('es6-iterator/get')
  , toArray     = require('es5-ext/array/to-array');

module.exports = function (T, a) {
	var arr = [['raz', 'one'], ['dwa', 'two'], ['trzy', 'three']]
	  , map = new T(arr), x = 'other', y = 'other2'
	  , i = 0, result = [];

	a(map instanceof T, true, "Map");
	a(map.size, 3, "Size");
	a(map.get('raz'), 'one', "Get: contained");
	a(map.get(x), undefined, "Get: not contained");
	a(map.has('raz'), true, "Has: true");
	a(map.has(x), false, "Has: false");
	a(map.set(x, y), map, "Add: return");
	a(map.has(x), true, "Add");
	a(map.size, 4, "Add: Size");
	map.set('dwa', x);
	a(map.get('dwa'), x, "Overwrite: get");
	a(map.size, 4, "Overwrite: size");

	a(map.delete('else'), false, "Delete: false");

	arr.push([x, y]);
	arr[1][1] = x;
	map.forEach(function () {
		result.push(aFrom(arguments));
		a(this, y, "ForEach: Context: #" + i);
	}, y);

	a.deep(result.sort(function (a, b) {
		return String([a[1], a[0]]).localeCompare([b[1], b[0]]);
	}), arr.sort().map(function (val) { return [val[1], val[0], map]; }),
		"ForEach: Arguments");

	a.deep(toArray(map.entries()).sort(), [['dwa', x], ['trzy', 'three'],
		[x, y], ['raz', 'one']].sort(), "Entries");
	a.deep(toArray(map.keys()).sort(), ['dwa', 'trzy', x, 'raz'].sort(),
		"Keys");
	a.deep(toArray(map.values()).sort(), [x, 'three', y, 'one'].sort(),
		"Values");
	a.deep(toArray(getIterator(map)).sort(), [['dwa', x], ['trzy', 'three'],
		[x, y], ['raz', 'one']].sort(),
		"Iterator");

	map.clear();
	a(map.size, 0, "Clear: size");
	a(map.has('trzy'), false, "Clear: has");
	a.deep(toArray(map.values()), [], "Clear: Values");

	a.h1("Empty initialization");
	map = new T();
	map.set('foo', 'bar');
	a(map.size, 1);
	a(map.get('foo'), 'bar');
};

Version data entries

51 entries across 51 versions & 6 rubygems

Version Path
govuk_publishing_components-16.19.0 node_modules/es6-map/test/primitive/index.js
govuk_publishing_components-16.18.0 node_modules/es6-map/test/primitive/index.js
govuk_publishing_components-16.17.0 node_modules/es6-map/test/primitive/index.js
optimacms-0.4.3 spec/dummy/node_modules/es6-map/test/primitive/index.js
optimacms-0.4.2 spec/dummy/node_modules/es6-map/test/primitive/index.js
cortex-0.1.3 spec/dummy/node_modules/es6-map/test/primitive/index.js
guard-sass-lint-0.1.2 node_modules/es6-map/test/primitive/index.js
guard-sass-lint-0.1.1 node_modules/es6-map/test/primitive/index.js
lanes-0.8.0 node_modules/es6-map/test/primitive/index.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/es6-map/test/primitive/index.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/es6-map/test/primitive/index.js