UNPKG

modernirc

Version:

IRC library for creating modern IRC bots

62 lines (56 loc) 1.3 kB
import test from 'node:test' import { cutStringLength, mergeDeep, oGet, } from '../lib/util.js' test('split string by length', (t) => { const result = cutStringLength('1234567890', 3) t.assert.deepEqual(result, ['123', '456', '789', '0']) }) test('mergeDeep objects', (t) => { const target = { a: 1, b: 2, c: [3, 4], d: false, e: { ea: 1, eb: 2 } } const toMerge = { b: 8, c: [2], d: true, e: { eb: 9, ec: 3 } } const result = mergeDeep(target, toMerge) t.assert.deepEqual(result, { a: 1, b: 8, c: [2], // Arrays are not merged d: true, e: { ea: 1, eb: 9, ec: 3, }, }) }) test('oGet', (t) => { const fixture = { a: 1, b: 2, c: '3', d: { e: true, f: 4.3, }, g: null, h: { i: { j: { k: { l: 'foo', }, }, }, m: 'bar', n: ['baz', 'pure'], }, } t.assert.deepEqual(oGet(fixture, 'a'), 1) t.assert.deepEqual(oGet(fixture, 'd.e'), true) t.assert.deepEqual(typeof oGet(fixture, 'z'), 'undefined') t.assert.deepEqual(oGet(fixture, 'h.i.j.k.l'), 'foo') t.assert.deepEqual(oGet(fixture, 'h.n.0'), 'baz') t.assert.deepEqual(oGet(fixture, 'h.n.1'), 'pure') t.assert.deepEqual(typeof oGet(fixture, 2), 'undefined') })