UNPKG

moy-fp

Version:
145 lines (134 loc) 2.44 kB
import __ from '../../src/Function/__' /** * [k] -> v -> {k: v} -> {k: v} */ import assocPath from '../../src/Object/assocPath' test('assocPath(not using __), length 0', () => { expect( assocPath([])(2)({a: 1, b: 2, c: 3}) ).toEqual({a: 1, b: 2, c: 3}) }) test('assocPath(not using __), length 1', () => { expect( assocPath(['a'])(2)({a: 1, b: 2, c: 3}) ).toEqual({a: 2, b: 2, c: 3}) }) test('assocPath(not using __), length 2, last key is integer', () => { expect( assocPath(['a', 2])(4)({a: [1, 2, 3, 4], b: 2, c: 3}) ).toEqual({a: [1, 2, 4, 4], b: 2, c: 3}) }) test('assocPath(not using __), length 3, without integer key', () => { expect( assocPath(['a', 'x', 'y'])(3)({ a: { x: { y: 1 } }, b: 2, c: 3, }) ).toEqual({ a: { x: { y: 3, } }, b: 2, c: 3, }) }) test('assocPath(not using __), length 3, with integer key', () => { expect( assocPath(['a', 1, 'x'])(3)({ a: [{x: 1}, {x: 2}, {x: 3}], b: 2, c: 3, }) ).toEqual({ a: [{x: 1}, {x: 3}, {x: 3}], b: 2, c: 3, }) }) test('assocPath(not using __), length 3, undefined(not integer)', () => { expect( assocPath(['a', 'x', 'y'])(3)({ b: 2, c: 3, }) ).toEqual({ a: { x: { y: 3, } }, b: 2, c: 3, }) }) test('assocPath(not using __), length 3, undefined(integer)', () => { expect( assocPath(['a', 2, 'x'])(3)({ a: [{x: 1}, {x: 2}], b: 2, c: 3, }) ).toEqual({ a: [{x: 1}, {x: 2}, {x: 3}], b: 2, c: 3, }) }) test('assocPath(not using __), length 3, null(not integer)', () => { expect( assocPath(['a', 'x', 'y'])(3)({ a: null, b: 2, c: 3, }) ).toEqual({ a: { x: { y: 3, } }, b: 2, c: 3, }) }) test('assocPath(not using __), length 3, null(integer)', () => { expect( assocPath(['a', 2, 'x'])(3)({ a: [{x: 1}, {x: 2}, null], b: 2, c: 3, }) ).toEqual({ a: [{x: 1}, {x: 2}, {x: 3}], b: 2, c: 3, }) }) test('assocPath(using __), length 3, without integer key', () => { expect( assocPath(['a', 'x', 'y'], __, { a: { x: { y: 1 } }, b: 2, c: 3, })(3) ).toEqual({ a: { x: { y: 3, } }, b: 2, c: 3, }) })