Sha256: b32fc638746aff09c486d71fc8c0d0b8fca0f86fe3387ad9111e411aa2f2190c

Contents?: true

Size: 1.64 KB

Versions: 76

Compression:

Stored size: 1.64 KB

Contents

var map = require('../');
var test = require('tape');

test('numbers -> letters', function (t) {
    t.plan(2);
    var a = map([97,98,99], function (c) {
        return String.fromCharCode(c);
    });
    t.equal(a.join(''), 'abc');
    
    var b = map(cripple([97,98,99]), function (c) {
        return String.fromCharCode(c);
    });
    t.equal(b.join(''), 'abc');
});

test('elements and indexes', function (t) {
    t.plan(8);
    var x = { q: 5 }, y = 3, z = null;
    
    t.deepEqual(
        map([x,y,z], function (c, i) { return i }),
        [ 0, 1, 2 ],
        'index check'
    );
    t.deepEqual(
        map([x,y,z], function (c, i) { return i }),
        [ 0, 1, 2 ],
        'crippled index check'
    );
    
    var xs0 = [ x, y, z ];
    map(xs0, function (c, i, xs) {
        t.strictEqual(xs, xs0, 'argument[2]');
    });
    var xs1 = [ x, y, z ];
    map(xs1, function (c, i, xs) {
        t.strictEqual(xs, xs1, 'crippled argument[2]');
    });
});

test('ignore holes', function (t) {
    t.plan(2);
    t.deepEqual(
        map(new Array(5), function (x) { return x }),
        []
    );
    t.deepEqual(
        map(cripple(new Array(5)), function (x) { return x }),
        []
    );
});

test('sparse map', function (t) {
    t.plan(2);
    var xs = new Array(5);
    xs[2] = 'a';
    xs[4] = 'b';
    t.equal(
        map(xs, function (x, i) { return x + i }).join(''),
        'a2b4'
    );
    
    var ys = new Array(5);
    ys[2] = 'a';
    ys[4] = 'b';
    t.equal(
        map(cripple(xs), function (x, i) { return x + i }).join(''),
        'a2b4'
    );
    t.end();
});

function cripple (xs) {
    xs.map = undefined;
    return xs;
}

Version data entries

76 entries across 76 versions & 4 rubygems

Version Path
trusty-festivity-extension-2.6.3 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.6.2 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.6.1 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.6 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.19 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.18 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.17 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.16 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.15 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.14 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.13 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.12 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.11 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.10 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.9 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.8 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
trusty-festivity-extension-2.5.7 node_modules/bower/node_modules/shell-quote/node_modules/array-map/test/map.js
minimum_viable_product-0.0.11 test/dummy/node_modules/array-map/test/map.js
brwy_rails-0.0.6 test/dummy/node_modules/array-map/test/map.js
brwy_rails-0.0.5 test/dummy/node_modules/array-map/test/map.js