11cb0ef41Sopenharmony_ciconst { inspect } = require('util') 21cb0ef41Sopenharmony_ciconst t = require('tap') 31cb0ef41Sopenharmony_ciconst Queryable = require('../../../lib/utils/queryable.js') 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cit.test('retrieve single nested property', async t => { 61cb0ef41Sopenharmony_ci const fixture = { 71cb0ef41Sopenharmony_ci foo: { 81cb0ef41Sopenharmony_ci bar: 'bar', 91cb0ef41Sopenharmony_ci baz: 'baz', 101cb0ef41Sopenharmony_ci }, 111cb0ef41Sopenharmony_ci lorem: { 121cb0ef41Sopenharmony_ci ipsum: 'ipsum', 131cb0ef41Sopenharmony_ci }, 141cb0ef41Sopenharmony_ci } 151cb0ef41Sopenharmony_ci const q = new Queryable(fixture) 161cb0ef41Sopenharmony_ci const query = 'foo.bar' 171cb0ef41Sopenharmony_ci t.strictSame(q.query(query), { [query]: 'bar' }, 181cb0ef41Sopenharmony_ci 'should retrieve property value when querying for dot-sep name') 191cb0ef41Sopenharmony_ci}) 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_cit.test('query', async t => { 221cb0ef41Sopenharmony_ci const fixture = { 231cb0ef41Sopenharmony_ci o: 'o', 241cb0ef41Sopenharmony_ci single: [ 251cb0ef41Sopenharmony_ci 'item', 261cb0ef41Sopenharmony_ci ], 271cb0ef41Sopenharmony_ci w: [ 281cb0ef41Sopenharmony_ci 'a', 291cb0ef41Sopenharmony_ci 'b', 301cb0ef41Sopenharmony_ci 'c', 311cb0ef41Sopenharmony_ci ], 321cb0ef41Sopenharmony_ci list: [ 331cb0ef41Sopenharmony_ci { 341cb0ef41Sopenharmony_ci name: 'first', 351cb0ef41Sopenharmony_ci }, 361cb0ef41Sopenharmony_ci { 371cb0ef41Sopenharmony_ci name: 'second', 381cb0ef41Sopenharmony_ci }, 391cb0ef41Sopenharmony_ci ], 401cb0ef41Sopenharmony_ci foo: { 411cb0ef41Sopenharmony_ci bar: 'bar', 421cb0ef41Sopenharmony_ci baz: 'baz', 431cb0ef41Sopenharmony_ci }, 441cb0ef41Sopenharmony_ci lorem: { 451cb0ef41Sopenharmony_ci ipsum: 'ipsum', 461cb0ef41Sopenharmony_ci dolor: [ 471cb0ef41Sopenharmony_ci 'a', 481cb0ef41Sopenharmony_ci 'b', 491cb0ef41Sopenharmony_ci 'c', 501cb0ef41Sopenharmony_ci { 511cb0ef41Sopenharmony_ci sit: [ 521cb0ef41Sopenharmony_ci 'amet', 531cb0ef41Sopenharmony_ci ], 541cb0ef41Sopenharmony_ci }, 551cb0ef41Sopenharmony_ci ], 561cb0ef41Sopenharmony_ci }, 571cb0ef41Sopenharmony_ci a: [ 581cb0ef41Sopenharmony_ci [ 591cb0ef41Sopenharmony_ci [ 601cb0ef41Sopenharmony_ci { 611cb0ef41Sopenharmony_ci b: [ 621cb0ef41Sopenharmony_ci [ 631cb0ef41Sopenharmony_ci { 641cb0ef41Sopenharmony_ci c: 'd', 651cb0ef41Sopenharmony_ci }, 661cb0ef41Sopenharmony_ci ], 671cb0ef41Sopenharmony_ci ], 681cb0ef41Sopenharmony_ci }, 691cb0ef41Sopenharmony_ci ], 701cb0ef41Sopenharmony_ci ], 711cb0ef41Sopenharmony_ci ], 721cb0ef41Sopenharmony_ci } 731cb0ef41Sopenharmony_ci const q = new Queryable(fixture) 741cb0ef41Sopenharmony_ci t.strictSame( 751cb0ef41Sopenharmony_ci q.query(['foo.baz', 'lorem.dolor[0]']), 761cb0ef41Sopenharmony_ci { 771cb0ef41Sopenharmony_ci 'foo.baz': 'baz', 781cb0ef41Sopenharmony_ci 'lorem.dolor[0]': 'a', 791cb0ef41Sopenharmony_ci }, 801cb0ef41Sopenharmony_ci 'should retrieve property values when querying for multiple dot-sep names') 811cb0ef41Sopenharmony_ci t.strictSame( 821cb0ef41Sopenharmony_ci q.query('lorem.dolor[3].sit[0]'), 831cb0ef41Sopenharmony_ci { 841cb0ef41Sopenharmony_ci 'lorem.dolor[3].sit[0]': 'amet', 851cb0ef41Sopenharmony_ci }, 861cb0ef41Sopenharmony_ci 'should retrieve property from nested array items') 871cb0ef41Sopenharmony_ci t.strictSame( 881cb0ef41Sopenharmony_ci q.query('a[0][0][0].b[0][0].c'), 891cb0ef41Sopenharmony_ci { 901cb0ef41Sopenharmony_ci 'a[0][0][0].b[0][0].c': 'd', 911cb0ef41Sopenharmony_ci }, 921cb0ef41Sopenharmony_ci 'should retrieve property from deep nested array items') 931cb0ef41Sopenharmony_ci t.strictSame( 941cb0ef41Sopenharmony_ci q.query('o'), 951cb0ef41Sopenharmony_ci { 961cb0ef41Sopenharmony_ci o: 'o', 971cb0ef41Sopenharmony_ci }, 981cb0ef41Sopenharmony_ci 'should retrieve single level property value') 991cb0ef41Sopenharmony_ci t.strictSame( 1001cb0ef41Sopenharmony_ci q.query('list.name'), 1011cb0ef41Sopenharmony_ci { 1021cb0ef41Sopenharmony_ci 'list[0].name': 'first', 1031cb0ef41Sopenharmony_ci 'list[1].name': 'second', 1041cb0ef41Sopenharmony_ci }, 1051cb0ef41Sopenharmony_ci 'should automatically expand arrays') 1061cb0ef41Sopenharmony_ci t.strictSame( 1071cb0ef41Sopenharmony_ci q.query(['list.name']), 1081cb0ef41Sopenharmony_ci { 1091cb0ef41Sopenharmony_ci 'list[0].name': 'first', 1101cb0ef41Sopenharmony_ci 'list[1].name': 'second', 1111cb0ef41Sopenharmony_ci }, 1121cb0ef41Sopenharmony_ci 'should automatically expand multiple arrays') 1131cb0ef41Sopenharmony_ci t.strictSame( 1141cb0ef41Sopenharmony_ci q.query('w'), 1151cb0ef41Sopenharmony_ci { 1161cb0ef41Sopenharmony_ci w: ['a', 'b', 'c'], 1171cb0ef41Sopenharmony_ci }, 1181cb0ef41Sopenharmony_ci 'should return arrays') 1191cb0ef41Sopenharmony_ci t.strictSame( 1201cb0ef41Sopenharmony_ci q.query('single'), 1211cb0ef41Sopenharmony_ci { 1221cb0ef41Sopenharmony_ci single: 'item', 1231cb0ef41Sopenharmony_ci }, 1241cb0ef41Sopenharmony_ci 'should return single item') 1251cb0ef41Sopenharmony_ci t.strictSame( 1261cb0ef41Sopenharmony_ci q.query('missing'), 1271cb0ef41Sopenharmony_ci undefined, 1281cb0ef41Sopenharmony_ci 'should return undefined') 1291cb0ef41Sopenharmony_ci t.strictSame( 1301cb0ef41Sopenharmony_ci q.query('missing[bar]'), 1311cb0ef41Sopenharmony_ci undefined, 1321cb0ef41Sopenharmony_ci 'should return undefined also') 1331cb0ef41Sopenharmony_ci t.throws(() => q.query('lorem.dolor[]'), 1341cb0ef41Sopenharmony_ci { code: 'EINVALIDSYNTAX' }, 1351cb0ef41Sopenharmony_ci 'should throw if using empty brackets notation' 1361cb0ef41Sopenharmony_ci ) 1371cb0ef41Sopenharmony_ci t.throws(() => q.query('lorem.dolor[].sit[0]'), 1381cb0ef41Sopenharmony_ci { code: 'EINVALIDSYNTAX' }, 1391cb0ef41Sopenharmony_ci 'should throw if using nested empty brackets notation' 1401cb0ef41Sopenharmony_ci ) 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_ci const qq = new Queryable({ 1431cb0ef41Sopenharmony_ci foo: { 1441cb0ef41Sopenharmony_ci bar: 'bar', 1451cb0ef41Sopenharmony_ci }, 1461cb0ef41Sopenharmony_ci }) 1471cb0ef41Sopenharmony_ci t.strictSame( 1481cb0ef41Sopenharmony_ci qq.query(''), 1491cb0ef41Sopenharmony_ci { 1501cb0ef41Sopenharmony_ci '': { 1511cb0ef41Sopenharmony_ci foo: { 1521cb0ef41Sopenharmony_ci bar: 'bar', 1531cb0ef41Sopenharmony_ci }, 1541cb0ef41Sopenharmony_ci }, 1551cb0ef41Sopenharmony_ci }, 1561cb0ef41Sopenharmony_ci 'should return an object with results in an empty key' 1571cb0ef41Sopenharmony_ci ) 1581cb0ef41Sopenharmony_ci}) 1591cb0ef41Sopenharmony_ci 1601cb0ef41Sopenharmony_cit.test('missing key', async t => { 1611cb0ef41Sopenharmony_ci const fixture = { 1621cb0ef41Sopenharmony_ci foo: { 1631cb0ef41Sopenharmony_ci bar: 'bar', 1641cb0ef41Sopenharmony_ci }, 1651cb0ef41Sopenharmony_ci } 1661cb0ef41Sopenharmony_ci const q = new Queryable(fixture) 1671cb0ef41Sopenharmony_ci const query = 'foo.missing' 1681cb0ef41Sopenharmony_ci t.equal(q.query(query), undefined, 1691cb0ef41Sopenharmony_ci 'should retrieve no results') 1701cb0ef41Sopenharmony_ci}) 1711cb0ef41Sopenharmony_ci 1721cb0ef41Sopenharmony_cit.test('no data object', async t => { 1731cb0ef41Sopenharmony_ci t.throws( 1741cb0ef41Sopenharmony_ci () => new Queryable(), 1751cb0ef41Sopenharmony_ci { code: 'ENOQUERYABLEOBJ' }, 1761cb0ef41Sopenharmony_ci 'should throw ENOQUERYABLEOBJ error' 1771cb0ef41Sopenharmony_ci ) 1781cb0ef41Sopenharmony_ci t.throws( 1791cb0ef41Sopenharmony_ci () => new Queryable(1), 1801cb0ef41Sopenharmony_ci { code: 'ENOQUERYABLEOBJ' }, 1811cb0ef41Sopenharmony_ci 'should throw ENOQUERYABLEOBJ error' 1821cb0ef41Sopenharmony_ci ) 1831cb0ef41Sopenharmony_ci}) 1841cb0ef41Sopenharmony_ci 1851cb0ef41Sopenharmony_cit.test('get values', async t => { 1861cb0ef41Sopenharmony_ci const q = new Queryable({ 1871cb0ef41Sopenharmony_ci foo: { 1881cb0ef41Sopenharmony_ci bar: 'bar', 1891cb0ef41Sopenharmony_ci }, 1901cb0ef41Sopenharmony_ci }) 1911cb0ef41Sopenharmony_ci t.equal(q.get('foo.bar'), 'bar', 'should retrieve value') 1921cb0ef41Sopenharmony_ci t.equal(q.get('missing'), undefined, 'should return undefined') 1931cb0ef41Sopenharmony_ci}) 1941cb0ef41Sopenharmony_ci 1951cb0ef41Sopenharmony_cit.test('set property values', async t => { 1961cb0ef41Sopenharmony_ci const fixture = { 1971cb0ef41Sopenharmony_ci foo: { 1981cb0ef41Sopenharmony_ci bar: 'bar', 1991cb0ef41Sopenharmony_ci }, 2001cb0ef41Sopenharmony_ci } 2011cb0ef41Sopenharmony_ci const q = new Queryable(fixture) 2021cb0ef41Sopenharmony_ci q.set('foo.baz', 'baz') 2031cb0ef41Sopenharmony_ci t.strictSame( 2041cb0ef41Sopenharmony_ci q.toJSON(), 2051cb0ef41Sopenharmony_ci { 2061cb0ef41Sopenharmony_ci foo: { 2071cb0ef41Sopenharmony_ci bar: 'bar', 2081cb0ef41Sopenharmony_ci baz: 'baz', 2091cb0ef41Sopenharmony_ci }, 2101cb0ef41Sopenharmony_ci }, 2111cb0ef41Sopenharmony_ci 'should add new property and its assigned value' 2121cb0ef41Sopenharmony_ci ) 2131cb0ef41Sopenharmony_ci q.set('foo[lorem.ipsum]', 'LOREM IPSUM') 2141cb0ef41Sopenharmony_ci t.strictSame( 2151cb0ef41Sopenharmony_ci q.toJSON(), 2161cb0ef41Sopenharmony_ci { 2171cb0ef41Sopenharmony_ci foo: { 2181cb0ef41Sopenharmony_ci bar: 'bar', 2191cb0ef41Sopenharmony_ci baz: 'baz', 2201cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 2211cb0ef41Sopenharmony_ci }, 2221cb0ef41Sopenharmony_ci }, 2231cb0ef41Sopenharmony_ci 'should be able to set square brackets props' 2241cb0ef41Sopenharmony_ci ) 2251cb0ef41Sopenharmony_ci q.set('a.b[c.d]', 'omg') 2261cb0ef41Sopenharmony_ci t.strictSame( 2271cb0ef41Sopenharmony_ci q.toJSON(), 2281cb0ef41Sopenharmony_ci { 2291cb0ef41Sopenharmony_ci foo: { 2301cb0ef41Sopenharmony_ci bar: 'bar', 2311cb0ef41Sopenharmony_ci baz: 'baz', 2321cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 2331cb0ef41Sopenharmony_ci }, 2341cb0ef41Sopenharmony_ci a: { 2351cb0ef41Sopenharmony_ci b: { 2361cb0ef41Sopenharmony_ci 'c.d': 'omg', 2371cb0ef41Sopenharmony_ci }, 2381cb0ef41Sopenharmony_ci }, 2391cb0ef41Sopenharmony_ci }, 2401cb0ef41Sopenharmony_ci 'should be able to nest square brackets props' 2411cb0ef41Sopenharmony_ci ) 2421cb0ef41Sopenharmony_ci q.set('a.b[e][f.g][1.0.0]', 'multiple') 2431cb0ef41Sopenharmony_ci t.strictSame( 2441cb0ef41Sopenharmony_ci q.toJSON(), 2451cb0ef41Sopenharmony_ci { 2461cb0ef41Sopenharmony_ci foo: { 2471cb0ef41Sopenharmony_ci bar: 'bar', 2481cb0ef41Sopenharmony_ci baz: 'baz', 2491cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 2501cb0ef41Sopenharmony_ci }, 2511cb0ef41Sopenharmony_ci a: { 2521cb0ef41Sopenharmony_ci b: { 2531cb0ef41Sopenharmony_ci 'c.d': 'omg', 2541cb0ef41Sopenharmony_ci e: { 2551cb0ef41Sopenharmony_ci 'f.g': { 2561cb0ef41Sopenharmony_ci '1.0.0': 'multiple', 2571cb0ef41Sopenharmony_ci }, 2581cb0ef41Sopenharmony_ci }, 2591cb0ef41Sopenharmony_ci }, 2601cb0ef41Sopenharmony_ci }, 2611cb0ef41Sopenharmony_ci }, 2621cb0ef41Sopenharmony_ci 'should be able to nest multiple square brackets props' 2631cb0ef41Sopenharmony_ci ) 2641cb0ef41Sopenharmony_ci q.set('a.b[e][f.g][2.0.0].author.name', 'Ruy Adorno') 2651cb0ef41Sopenharmony_ci t.strictSame( 2661cb0ef41Sopenharmony_ci q.toJSON(), 2671cb0ef41Sopenharmony_ci { 2681cb0ef41Sopenharmony_ci foo: { 2691cb0ef41Sopenharmony_ci bar: 'bar', 2701cb0ef41Sopenharmony_ci baz: 'baz', 2711cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 2721cb0ef41Sopenharmony_ci }, 2731cb0ef41Sopenharmony_ci a: { 2741cb0ef41Sopenharmony_ci b: { 2751cb0ef41Sopenharmony_ci 'c.d': 'omg', 2761cb0ef41Sopenharmony_ci e: { 2771cb0ef41Sopenharmony_ci 'f.g': { 2781cb0ef41Sopenharmony_ci '1.0.0': 'multiple', 2791cb0ef41Sopenharmony_ci '2.0.0': { 2801cb0ef41Sopenharmony_ci author: { 2811cb0ef41Sopenharmony_ci name: 'Ruy Adorno', 2821cb0ef41Sopenharmony_ci }, 2831cb0ef41Sopenharmony_ci }, 2841cb0ef41Sopenharmony_ci }, 2851cb0ef41Sopenharmony_ci }, 2861cb0ef41Sopenharmony_ci }, 2871cb0ef41Sopenharmony_ci }, 2881cb0ef41Sopenharmony_ci }, 2891cb0ef41Sopenharmony_ci 'should be able to use dot-sep notation after square bracket props' 2901cb0ef41Sopenharmony_ci ) 2911cb0ef41Sopenharmony_ci q.set('a.b[e][f.g][2.0.0].author[url]', 'https://npmjs.com') 2921cb0ef41Sopenharmony_ci t.strictSame( 2931cb0ef41Sopenharmony_ci q.toJSON(), 2941cb0ef41Sopenharmony_ci { 2951cb0ef41Sopenharmony_ci foo: { 2961cb0ef41Sopenharmony_ci bar: 'bar', 2971cb0ef41Sopenharmony_ci baz: 'baz', 2981cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 2991cb0ef41Sopenharmony_ci }, 3001cb0ef41Sopenharmony_ci a: { 3011cb0ef41Sopenharmony_ci b: { 3021cb0ef41Sopenharmony_ci 'c.d': 'omg', 3031cb0ef41Sopenharmony_ci e: { 3041cb0ef41Sopenharmony_ci 'f.g': { 3051cb0ef41Sopenharmony_ci '1.0.0': 'multiple', 3061cb0ef41Sopenharmony_ci '2.0.0': { 3071cb0ef41Sopenharmony_ci author: { 3081cb0ef41Sopenharmony_ci name: 'Ruy Adorno', 3091cb0ef41Sopenharmony_ci url: 'https://npmjs.com', 3101cb0ef41Sopenharmony_ci }, 3111cb0ef41Sopenharmony_ci }, 3121cb0ef41Sopenharmony_ci }, 3131cb0ef41Sopenharmony_ci }, 3141cb0ef41Sopenharmony_ci }, 3151cb0ef41Sopenharmony_ci }, 3161cb0ef41Sopenharmony_ci }, 3171cb0ef41Sopenharmony_ci 'should be able to have multiple, separated, square brackets props' 3181cb0ef41Sopenharmony_ci ) 3191cb0ef41Sopenharmony_ci q.set('a.b[e][f.g][2.0.0].author[foo][bar].lorem.ipsum[dolor][sit][amet].omg', 'O_O') 3201cb0ef41Sopenharmony_ci t.strictSame( 3211cb0ef41Sopenharmony_ci q.toJSON(), 3221cb0ef41Sopenharmony_ci { 3231cb0ef41Sopenharmony_ci foo: { 3241cb0ef41Sopenharmony_ci bar: 'bar', 3251cb0ef41Sopenharmony_ci baz: 'baz', 3261cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 3271cb0ef41Sopenharmony_ci }, 3281cb0ef41Sopenharmony_ci a: { 3291cb0ef41Sopenharmony_ci b: { 3301cb0ef41Sopenharmony_ci 'c.d': 'omg', 3311cb0ef41Sopenharmony_ci e: { 3321cb0ef41Sopenharmony_ci 'f.g': { 3331cb0ef41Sopenharmony_ci '1.0.0': 'multiple', 3341cb0ef41Sopenharmony_ci '2.0.0': { 3351cb0ef41Sopenharmony_ci author: { 3361cb0ef41Sopenharmony_ci name: 'Ruy Adorno', 3371cb0ef41Sopenharmony_ci url: 'https://npmjs.com', 3381cb0ef41Sopenharmony_ci foo: { 3391cb0ef41Sopenharmony_ci bar: { 3401cb0ef41Sopenharmony_ci lorem: { 3411cb0ef41Sopenharmony_ci ipsum: { 3421cb0ef41Sopenharmony_ci dolor: { 3431cb0ef41Sopenharmony_ci sit: { 3441cb0ef41Sopenharmony_ci amet: { 3451cb0ef41Sopenharmony_ci omg: 'O_O', 3461cb0ef41Sopenharmony_ci }, 3471cb0ef41Sopenharmony_ci }, 3481cb0ef41Sopenharmony_ci }, 3491cb0ef41Sopenharmony_ci }, 3501cb0ef41Sopenharmony_ci }, 3511cb0ef41Sopenharmony_ci }, 3521cb0ef41Sopenharmony_ci }, 3531cb0ef41Sopenharmony_ci }, 3541cb0ef41Sopenharmony_ci }, 3551cb0ef41Sopenharmony_ci }, 3561cb0ef41Sopenharmony_ci }, 3571cb0ef41Sopenharmony_ci }, 3581cb0ef41Sopenharmony_ci }, 3591cb0ef41Sopenharmony_ci }, 3601cb0ef41Sopenharmony_ci 'many many times...' 3611cb0ef41Sopenharmony_ci ) 3621cb0ef41Sopenharmony_ci t.throws( 3631cb0ef41Sopenharmony_ci () => q.set('foo.bar.nest', 'should throw'), 3641cb0ef41Sopenharmony_ci { code: 'EOVERRIDEVALUE' }, 3651cb0ef41Sopenharmony_ci 'should throw if trying to override a literal value with an object' 3661cb0ef41Sopenharmony_ci ) 3671cb0ef41Sopenharmony_ci q.set('foo.bar.nest', 'use the force!', { force: true }) 3681cb0ef41Sopenharmony_ci t.strictSame( 3691cb0ef41Sopenharmony_ci q.toJSON().foo, 3701cb0ef41Sopenharmony_ci { 3711cb0ef41Sopenharmony_ci bar: { 3721cb0ef41Sopenharmony_ci nest: 'use the force!', 3731cb0ef41Sopenharmony_ci }, 3741cb0ef41Sopenharmony_ci baz: 'baz', 3751cb0ef41Sopenharmony_ci 'lorem.ipsum': 'LOREM IPSUM', 3761cb0ef41Sopenharmony_ci }, 3771cb0ef41Sopenharmony_ci 'should allow overriding literal values when using force option' 3781cb0ef41Sopenharmony_ci ) 3791cb0ef41Sopenharmony_ci 3801cb0ef41Sopenharmony_ci const qq = new Queryable({}) 3811cb0ef41Sopenharmony_ci qq.set('foo.bar.baz', 'BAZ') 3821cb0ef41Sopenharmony_ci t.strictSame( 3831cb0ef41Sopenharmony_ci qq.toJSON(), 3841cb0ef41Sopenharmony_ci { 3851cb0ef41Sopenharmony_ci foo: { 3861cb0ef41Sopenharmony_ci bar: { 3871cb0ef41Sopenharmony_ci baz: 'BAZ', 3881cb0ef41Sopenharmony_ci }, 3891cb0ef41Sopenharmony_ci }, 3901cb0ef41Sopenharmony_ci }, 3911cb0ef41Sopenharmony_ci 'should add new props to qq object' 3921cb0ef41Sopenharmony_ci ) 3931cb0ef41Sopenharmony_ci qq.set('foo.bar.bario', 'bario') 3941cb0ef41Sopenharmony_ci t.strictSame( 3951cb0ef41Sopenharmony_ci qq.toJSON(), 3961cb0ef41Sopenharmony_ci { 3971cb0ef41Sopenharmony_ci foo: { 3981cb0ef41Sopenharmony_ci bar: { 3991cb0ef41Sopenharmony_ci baz: 'BAZ', 4001cb0ef41Sopenharmony_ci bario: 'bario', 4011cb0ef41Sopenharmony_ci }, 4021cb0ef41Sopenharmony_ci }, 4031cb0ef41Sopenharmony_ci }, 4041cb0ef41Sopenharmony_ci 'should add new props to a previously existing object' 4051cb0ef41Sopenharmony_ci ) 4061cb0ef41Sopenharmony_ci qq.set('lorem', 'lorem') 4071cb0ef41Sopenharmony_ci t.strictSame( 4081cb0ef41Sopenharmony_ci qq.toJSON(), 4091cb0ef41Sopenharmony_ci { 4101cb0ef41Sopenharmony_ci foo: { 4111cb0ef41Sopenharmony_ci bar: { 4121cb0ef41Sopenharmony_ci baz: 'BAZ', 4131cb0ef41Sopenharmony_ci bario: 'bario', 4141cb0ef41Sopenharmony_ci }, 4151cb0ef41Sopenharmony_ci }, 4161cb0ef41Sopenharmony_ci lorem: 'lorem', 4171cb0ef41Sopenharmony_ci }, 4181cb0ef41Sopenharmony_ci 'should append new props added to object later' 4191cb0ef41Sopenharmony_ci ) 4201cb0ef41Sopenharmony_ci qq.set('foo.bar[foo.bar]', 'foo.bar.with.dots') 4211cb0ef41Sopenharmony_ci t.strictSame( 4221cb0ef41Sopenharmony_ci qq.toJSON(), 4231cb0ef41Sopenharmony_ci { 4241cb0ef41Sopenharmony_ci foo: { 4251cb0ef41Sopenharmony_ci bar: { 4261cb0ef41Sopenharmony_ci 'foo.bar': 'foo.bar.with.dots', 4271cb0ef41Sopenharmony_ci baz: 'BAZ', 4281cb0ef41Sopenharmony_ci bario: 'bario', 4291cb0ef41Sopenharmony_ci }, 4301cb0ef41Sopenharmony_ci }, 4311cb0ef41Sopenharmony_ci lorem: 'lorem', 4321cb0ef41Sopenharmony_ci }, 4331cb0ef41Sopenharmony_ci 'should append new props added to object later' 4341cb0ef41Sopenharmony_ci ) 4351cb0ef41Sopenharmony_ci}) 4361cb0ef41Sopenharmony_ci 4371cb0ef41Sopenharmony_cit.test('set arrays', async t => { 4381cb0ef41Sopenharmony_ci const q = new Queryable({}) 4391cb0ef41Sopenharmony_ci 4401cb0ef41Sopenharmony_ci q.set('foo[1]', 'b') 4411cb0ef41Sopenharmony_ci t.strictSame( 4421cb0ef41Sopenharmony_ci q.toJSON(), 4431cb0ef41Sopenharmony_ci { 4441cb0ef41Sopenharmony_ci foo: [ 4451cb0ef41Sopenharmony_ci undefined, 4461cb0ef41Sopenharmony_ci 'b', 4471cb0ef41Sopenharmony_ci ], 4481cb0ef41Sopenharmony_ci }, 4491cb0ef41Sopenharmony_ci 'should be able to set items in an array using index references' 4501cb0ef41Sopenharmony_ci ) 4511cb0ef41Sopenharmony_ci 4521cb0ef41Sopenharmony_ci q.set('foo[0]', 'a') 4531cb0ef41Sopenharmony_ci t.strictSame( 4541cb0ef41Sopenharmony_ci q.toJSON(), 4551cb0ef41Sopenharmony_ci { 4561cb0ef41Sopenharmony_ci foo: [ 4571cb0ef41Sopenharmony_ci 'a', 4581cb0ef41Sopenharmony_ci 'b', 4591cb0ef41Sopenharmony_ci ], 4601cb0ef41Sopenharmony_ci }, 4611cb0ef41Sopenharmony_ci 'should be able to set a previously missing item to an array' 4621cb0ef41Sopenharmony_ci ) 4631cb0ef41Sopenharmony_ci 4641cb0ef41Sopenharmony_ci q.set('foo[2]', 'c') 4651cb0ef41Sopenharmony_ci t.strictSame( 4661cb0ef41Sopenharmony_ci q.toJSON(), 4671cb0ef41Sopenharmony_ci { 4681cb0ef41Sopenharmony_ci foo: [ 4691cb0ef41Sopenharmony_ci 'a', 4701cb0ef41Sopenharmony_ci 'b', 4711cb0ef41Sopenharmony_ci 'c', 4721cb0ef41Sopenharmony_ci ], 4731cb0ef41Sopenharmony_ci }, 4741cb0ef41Sopenharmony_ci 'should be able to append more items to an array' 4751cb0ef41Sopenharmony_ci ) 4761cb0ef41Sopenharmony_ci 4771cb0ef41Sopenharmony_ci q.set('foo[2]', 'C') 4781cb0ef41Sopenharmony_ci t.strictSame( 4791cb0ef41Sopenharmony_ci q.toJSON(), 4801cb0ef41Sopenharmony_ci { 4811cb0ef41Sopenharmony_ci foo: [ 4821cb0ef41Sopenharmony_ci 'a', 4831cb0ef41Sopenharmony_ci 'b', 4841cb0ef41Sopenharmony_ci 'C', 4851cb0ef41Sopenharmony_ci ], 4861cb0ef41Sopenharmony_ci }, 4871cb0ef41Sopenharmony_ci 'should be able to override array items' 4881cb0ef41Sopenharmony_ci ) 4891cb0ef41Sopenharmony_ci 4901cb0ef41Sopenharmony_ci t.throws( 4911cb0ef41Sopenharmony_ci () => q.set('foo[2].bar', 'bar'), 4921cb0ef41Sopenharmony_ci { code: 'EOVERRIDEVALUE' }, 4931cb0ef41Sopenharmony_ci 'should throw if trying to override an array literal item with an obj' 4941cb0ef41Sopenharmony_ci ) 4951cb0ef41Sopenharmony_ci 4961cb0ef41Sopenharmony_ci q.set('foo[2].bar', 'bar', { force: true }) 4971cb0ef41Sopenharmony_ci t.strictSame( 4981cb0ef41Sopenharmony_ci q.toJSON(), 4991cb0ef41Sopenharmony_ci { 5001cb0ef41Sopenharmony_ci foo: [ 5011cb0ef41Sopenharmony_ci 'a', 5021cb0ef41Sopenharmony_ci 'b', 5031cb0ef41Sopenharmony_ci { bar: 'bar' }, 5041cb0ef41Sopenharmony_ci ], 5051cb0ef41Sopenharmony_ci }, 5061cb0ef41Sopenharmony_ci 'should be able to override an array string item with an obj' 5071cb0ef41Sopenharmony_ci ) 5081cb0ef41Sopenharmony_ci 5091cb0ef41Sopenharmony_ci q.set('foo[3].foo', 'surprise surprise, another foo') 5101cb0ef41Sopenharmony_ci t.strictSame( 5111cb0ef41Sopenharmony_ci q.toJSON(), 5121cb0ef41Sopenharmony_ci { 5131cb0ef41Sopenharmony_ci foo: [ 5141cb0ef41Sopenharmony_ci 'a', 5151cb0ef41Sopenharmony_ci 'b', 5161cb0ef41Sopenharmony_ci { bar: 'bar' }, 5171cb0ef41Sopenharmony_ci { 5181cb0ef41Sopenharmony_ci foo: 'surprise surprise, another foo', 5191cb0ef41Sopenharmony_ci }, 5201cb0ef41Sopenharmony_ci ], 5211cb0ef41Sopenharmony_ci }, 5221cb0ef41Sopenharmony_ci 'should be able to append more items to an array' 5231cb0ef41Sopenharmony_ci ) 5241cb0ef41Sopenharmony_ci 5251cb0ef41Sopenharmony_ci q.set('foo[3].foo', 'FOO') 5261cb0ef41Sopenharmony_ci t.strictSame( 5271cb0ef41Sopenharmony_ci q.toJSON(), 5281cb0ef41Sopenharmony_ci { 5291cb0ef41Sopenharmony_ci foo: [ 5301cb0ef41Sopenharmony_ci 'a', 5311cb0ef41Sopenharmony_ci 'b', 5321cb0ef41Sopenharmony_ci { bar: 'bar' }, 5331cb0ef41Sopenharmony_ci { 5341cb0ef41Sopenharmony_ci foo: 'FOO', 5351cb0ef41Sopenharmony_ci }, 5361cb0ef41Sopenharmony_ci ], 5371cb0ef41Sopenharmony_ci }, 5381cb0ef41Sopenharmony_ci 'should be able to override property of an obj inside an array' 5391cb0ef41Sopenharmony_ci ) 5401cb0ef41Sopenharmony_ci 5411cb0ef41Sopenharmony_ci const qq = new Queryable({}) 5421cb0ef41Sopenharmony_ci qq.set('foo[0].bar[1].baz.bario[0][0][0]', 'something') 5431cb0ef41Sopenharmony_ci t.strictSame( 5441cb0ef41Sopenharmony_ci qq.toJSON(), 5451cb0ef41Sopenharmony_ci { 5461cb0ef41Sopenharmony_ci foo: [ 5471cb0ef41Sopenharmony_ci { 5481cb0ef41Sopenharmony_ci bar: [ 5491cb0ef41Sopenharmony_ci undefined, 5501cb0ef41Sopenharmony_ci { 5511cb0ef41Sopenharmony_ci baz: { 5521cb0ef41Sopenharmony_ci bario: [[['something']]], 5531cb0ef41Sopenharmony_ci }, 5541cb0ef41Sopenharmony_ci }, 5551cb0ef41Sopenharmony_ci ], 5561cb0ef41Sopenharmony_ci }, 5571cb0ef41Sopenharmony_ci ], 5581cb0ef41Sopenharmony_ci }, 5591cb0ef41Sopenharmony_ci 'should append as many arrays as necessary' 5601cb0ef41Sopenharmony_ci ) 5611cb0ef41Sopenharmony_ci qq.set('foo[0].bar[1].baz.bario[0][1][0]', 'something else') 5621cb0ef41Sopenharmony_ci t.strictSame( 5631cb0ef41Sopenharmony_ci qq.toJSON(), 5641cb0ef41Sopenharmony_ci { 5651cb0ef41Sopenharmony_ci foo: [ 5661cb0ef41Sopenharmony_ci { 5671cb0ef41Sopenharmony_ci bar: [ 5681cb0ef41Sopenharmony_ci undefined, 5691cb0ef41Sopenharmony_ci { 5701cb0ef41Sopenharmony_ci baz: { 5711cb0ef41Sopenharmony_ci bario: [[ 5721cb0ef41Sopenharmony_ci ['something'], 5731cb0ef41Sopenharmony_ci ['something else'], 5741cb0ef41Sopenharmony_ci ]], 5751cb0ef41Sopenharmony_ci }, 5761cb0ef41Sopenharmony_ci }, 5771cb0ef41Sopenharmony_ci ], 5781cb0ef41Sopenharmony_ci }, 5791cb0ef41Sopenharmony_ci ], 5801cb0ef41Sopenharmony_ci }, 5811cb0ef41Sopenharmony_ci 'should append as many arrays as necessary' 5821cb0ef41Sopenharmony_ci ) 5831cb0ef41Sopenharmony_ci qq.set('foo', null) 5841cb0ef41Sopenharmony_ci t.strictSame( 5851cb0ef41Sopenharmony_ci qq.toJSON(), 5861cb0ef41Sopenharmony_ci { 5871cb0ef41Sopenharmony_ci foo: null, 5881cb0ef41Sopenharmony_ci }, 5891cb0ef41Sopenharmony_ci 'should be able to set a value to null' 5901cb0ef41Sopenharmony_ci ) 5911cb0ef41Sopenharmony_ci qq.set('foo.bar', 'bar') 5921cb0ef41Sopenharmony_ci t.strictSame( 5931cb0ef41Sopenharmony_ci qq.toJSON(), 5941cb0ef41Sopenharmony_ci { 5951cb0ef41Sopenharmony_ci foo: { 5961cb0ef41Sopenharmony_ci bar: 'bar', 5971cb0ef41Sopenharmony_ci }, 5981cb0ef41Sopenharmony_ci }, 5991cb0ef41Sopenharmony_ci 'should be able to replace a null value with properties' 6001cb0ef41Sopenharmony_ci ) 6011cb0ef41Sopenharmony_ci 6021cb0ef41Sopenharmony_ci const qqq = new Queryable({ 6031cb0ef41Sopenharmony_ci arr: [ 6041cb0ef41Sopenharmony_ci 'a', 6051cb0ef41Sopenharmony_ci 'b', 6061cb0ef41Sopenharmony_ci ], 6071cb0ef41Sopenharmony_ci }) 6081cb0ef41Sopenharmony_ci 6091cb0ef41Sopenharmony_ci qqq.set('arr[]', 'c') 6101cb0ef41Sopenharmony_ci t.strictSame( 6111cb0ef41Sopenharmony_ci qqq.toJSON(), 6121cb0ef41Sopenharmony_ci { 6131cb0ef41Sopenharmony_ci arr: [ 6141cb0ef41Sopenharmony_ci 'a', 6151cb0ef41Sopenharmony_ci 'b', 6161cb0ef41Sopenharmony_ci 'c', 6171cb0ef41Sopenharmony_ci ], 6181cb0ef41Sopenharmony_ci }, 6191cb0ef41Sopenharmony_ci 'should be able to append to array using empty bracket notation' 6201cb0ef41Sopenharmony_ci ) 6211cb0ef41Sopenharmony_ci 6221cb0ef41Sopenharmony_ci qqq.set('arr[].foo', 'foo') 6231cb0ef41Sopenharmony_ci t.strictSame( 6241cb0ef41Sopenharmony_ci qqq.toJSON(), 6251cb0ef41Sopenharmony_ci { 6261cb0ef41Sopenharmony_ci arr: [ 6271cb0ef41Sopenharmony_ci 'a', 6281cb0ef41Sopenharmony_ci 'b', 6291cb0ef41Sopenharmony_ci 'c', 6301cb0ef41Sopenharmony_ci { 6311cb0ef41Sopenharmony_ci foo: 'foo', 6321cb0ef41Sopenharmony_ci }, 6331cb0ef41Sopenharmony_ci ], 6341cb0ef41Sopenharmony_ci }, 6351cb0ef41Sopenharmony_ci 'should be able to append objects to array using empty bracket notation' 6361cb0ef41Sopenharmony_ci ) 6371cb0ef41Sopenharmony_ci 6381cb0ef41Sopenharmony_ci qqq.set('arr[].bar.name', 'BAR') 6391cb0ef41Sopenharmony_ci t.strictSame( 6401cb0ef41Sopenharmony_ci qqq.toJSON(), 6411cb0ef41Sopenharmony_ci { 6421cb0ef41Sopenharmony_ci arr: [ 6431cb0ef41Sopenharmony_ci 'a', 6441cb0ef41Sopenharmony_ci 'b', 6451cb0ef41Sopenharmony_ci 'c', 6461cb0ef41Sopenharmony_ci { 6471cb0ef41Sopenharmony_ci foo: 'foo', 6481cb0ef41Sopenharmony_ci }, 6491cb0ef41Sopenharmony_ci { 6501cb0ef41Sopenharmony_ci bar: { 6511cb0ef41Sopenharmony_ci name: 'BAR', 6521cb0ef41Sopenharmony_ci }, 6531cb0ef41Sopenharmony_ci }, 6541cb0ef41Sopenharmony_ci ], 6551cb0ef41Sopenharmony_ci }, 6561cb0ef41Sopenharmony_ci 'should be able to append more objects to array using empty brackets' 6571cb0ef41Sopenharmony_ci ) 6581cb0ef41Sopenharmony_ci 6591cb0ef41Sopenharmony_ci qqq.set('foo.bar.baz[].lorem.ipsum', 'something') 6601cb0ef41Sopenharmony_ci t.strictSame( 6611cb0ef41Sopenharmony_ci qqq.toJSON(), 6621cb0ef41Sopenharmony_ci { 6631cb0ef41Sopenharmony_ci arr: [ 6641cb0ef41Sopenharmony_ci 'a', 6651cb0ef41Sopenharmony_ci 'b', 6661cb0ef41Sopenharmony_ci 'c', 6671cb0ef41Sopenharmony_ci { 6681cb0ef41Sopenharmony_ci foo: 'foo', 6691cb0ef41Sopenharmony_ci }, 6701cb0ef41Sopenharmony_ci { 6711cb0ef41Sopenharmony_ci bar: { 6721cb0ef41Sopenharmony_ci name: 'BAR', 6731cb0ef41Sopenharmony_ci }, 6741cb0ef41Sopenharmony_ci }, 6751cb0ef41Sopenharmony_ci ], 6761cb0ef41Sopenharmony_ci foo: { 6771cb0ef41Sopenharmony_ci bar: { 6781cb0ef41Sopenharmony_ci baz: [ 6791cb0ef41Sopenharmony_ci { 6801cb0ef41Sopenharmony_ci lorem: { 6811cb0ef41Sopenharmony_ci ipsum: 'something', 6821cb0ef41Sopenharmony_ci }, 6831cb0ef41Sopenharmony_ci }, 6841cb0ef41Sopenharmony_ci ], 6851cb0ef41Sopenharmony_ci }, 6861cb0ef41Sopenharmony_ci }, 6871cb0ef41Sopenharmony_ci }, 6881cb0ef41Sopenharmony_ci 'should be able to append to array using empty brackets in nested objs' 6891cb0ef41Sopenharmony_ci ) 6901cb0ef41Sopenharmony_ci 6911cb0ef41Sopenharmony_ci qqq.set('foo.bar.baz[].lorem.array[]', 'new item') 6921cb0ef41Sopenharmony_ci t.strictSame( 6931cb0ef41Sopenharmony_ci qqq.toJSON(), 6941cb0ef41Sopenharmony_ci { 6951cb0ef41Sopenharmony_ci arr: [ 6961cb0ef41Sopenharmony_ci 'a', 6971cb0ef41Sopenharmony_ci 'b', 6981cb0ef41Sopenharmony_ci 'c', 6991cb0ef41Sopenharmony_ci { 7001cb0ef41Sopenharmony_ci foo: 'foo', 7011cb0ef41Sopenharmony_ci }, 7021cb0ef41Sopenharmony_ci { 7031cb0ef41Sopenharmony_ci bar: { 7041cb0ef41Sopenharmony_ci name: 'BAR', 7051cb0ef41Sopenharmony_ci }, 7061cb0ef41Sopenharmony_ci }, 7071cb0ef41Sopenharmony_ci ], 7081cb0ef41Sopenharmony_ci foo: { 7091cb0ef41Sopenharmony_ci bar: { 7101cb0ef41Sopenharmony_ci baz: [ 7111cb0ef41Sopenharmony_ci { 7121cb0ef41Sopenharmony_ci lorem: { 7131cb0ef41Sopenharmony_ci ipsum: 'something', 7141cb0ef41Sopenharmony_ci }, 7151cb0ef41Sopenharmony_ci }, 7161cb0ef41Sopenharmony_ci { 7171cb0ef41Sopenharmony_ci lorem: { 7181cb0ef41Sopenharmony_ci array: [ 7191cb0ef41Sopenharmony_ci 'new item', 7201cb0ef41Sopenharmony_ci ], 7211cb0ef41Sopenharmony_ci }, 7221cb0ef41Sopenharmony_ci }, 7231cb0ef41Sopenharmony_ci ], 7241cb0ef41Sopenharmony_ci }, 7251cb0ef41Sopenharmony_ci }, 7261cb0ef41Sopenharmony_ci }, 7271cb0ef41Sopenharmony_ci 'should be able to append to array using empty brackets in nested objs' 7281cb0ef41Sopenharmony_ci ) 7291cb0ef41Sopenharmony_ci 7301cb0ef41Sopenharmony_ci const qqqq = new Queryable({ 7311cb0ef41Sopenharmony_ci arr: [ 7321cb0ef41Sopenharmony_ci 'a', 7331cb0ef41Sopenharmony_ci 'b', 7341cb0ef41Sopenharmony_ci ], 7351cb0ef41Sopenharmony_ci }) 7361cb0ef41Sopenharmony_ci t.throws( 7371cb0ef41Sopenharmony_ci () => qqqq.set('arr.foo', 'foo'), 7381cb0ef41Sopenharmony_ci { code: 'ENOADDPROP' }, 7391cb0ef41Sopenharmony_ci 'should throw an override error' 7401cb0ef41Sopenharmony_ci ) 7411cb0ef41Sopenharmony_ci 7421cb0ef41Sopenharmony_ci qqqq.set('arr.foo', 'foo', { force: true }) 7431cb0ef41Sopenharmony_ci t.strictSame( 7441cb0ef41Sopenharmony_ci qqqq.toJSON(), 7451cb0ef41Sopenharmony_ci { 7461cb0ef41Sopenharmony_ci arr: { 7471cb0ef41Sopenharmony_ci 0: 'a', 7481cb0ef41Sopenharmony_ci 1: 'b', 7491cb0ef41Sopenharmony_ci foo: 'foo', 7501cb0ef41Sopenharmony_ci }, 7511cb0ef41Sopenharmony_ci }, 7521cb0ef41Sopenharmony_ci 'should be able to override arrays with objects when using force=true' 7531cb0ef41Sopenharmony_ci ) 7541cb0ef41Sopenharmony_ci 7551cb0ef41Sopenharmony_ci qqqq.set('bar[]', 'item', { force: true }) 7561cb0ef41Sopenharmony_ci t.strictSame( 7571cb0ef41Sopenharmony_ci qqqq.toJSON(), 7581cb0ef41Sopenharmony_ci { 7591cb0ef41Sopenharmony_ci arr: { 7601cb0ef41Sopenharmony_ci 0: 'a', 7611cb0ef41Sopenharmony_ci 1: 'b', 7621cb0ef41Sopenharmony_ci foo: 'foo', 7631cb0ef41Sopenharmony_ci }, 7641cb0ef41Sopenharmony_ci bar: [ 7651cb0ef41Sopenharmony_ci 'item', 7661cb0ef41Sopenharmony_ci ], 7671cb0ef41Sopenharmony_ci }, 7681cb0ef41Sopenharmony_ci 'should be able to create new array with item when using force=true' 7691cb0ef41Sopenharmony_ci ) 7701cb0ef41Sopenharmony_ci 7711cb0ef41Sopenharmony_ci qqqq.set('bar[]', 'something else', { force: true }) 7721cb0ef41Sopenharmony_ci t.strictSame( 7731cb0ef41Sopenharmony_ci qqqq.toJSON(), 7741cb0ef41Sopenharmony_ci { 7751cb0ef41Sopenharmony_ci arr: { 7761cb0ef41Sopenharmony_ci 0: 'a', 7771cb0ef41Sopenharmony_ci 1: 'b', 7781cb0ef41Sopenharmony_ci foo: 'foo', 7791cb0ef41Sopenharmony_ci }, 7801cb0ef41Sopenharmony_ci bar: [ 7811cb0ef41Sopenharmony_ci 'item', 7821cb0ef41Sopenharmony_ci 'something else', 7831cb0ef41Sopenharmony_ci ], 7841cb0ef41Sopenharmony_ci }, 7851cb0ef41Sopenharmony_ci 'should be able to append items to arrays when using force=true' 7861cb0ef41Sopenharmony_ci ) 7871cb0ef41Sopenharmony_ci 7881cb0ef41Sopenharmony_ci const qqqqq = new Queryable({ 7891cb0ef41Sopenharmony_ci arr: [ 7901cb0ef41Sopenharmony_ci null, 7911cb0ef41Sopenharmony_ci ], 7921cb0ef41Sopenharmony_ci }) 7931cb0ef41Sopenharmony_ci qqqqq.set('arr[]', 'b') 7941cb0ef41Sopenharmony_ci t.strictSame( 7951cb0ef41Sopenharmony_ci qqqqq.toJSON(), 7961cb0ef41Sopenharmony_ci { 7971cb0ef41Sopenharmony_ci arr: [ 7981cb0ef41Sopenharmony_ci null, 7991cb0ef41Sopenharmony_ci 'b', 8001cb0ef41Sopenharmony_ci ], 8011cb0ef41Sopenharmony_ci }, 8021cb0ef41Sopenharmony_ci 'should be able to append items with empty items' 8031cb0ef41Sopenharmony_ci ) 8041cb0ef41Sopenharmony_ci qqqqq.set('arr[0]', 'a') 8051cb0ef41Sopenharmony_ci t.strictSame( 8061cb0ef41Sopenharmony_ci qqqqq.toJSON(), 8071cb0ef41Sopenharmony_ci { 8081cb0ef41Sopenharmony_ci arr: [ 8091cb0ef41Sopenharmony_ci 'a', 8101cb0ef41Sopenharmony_ci 'b', 8111cb0ef41Sopenharmony_ci ], 8121cb0ef41Sopenharmony_ci }, 8131cb0ef41Sopenharmony_ci 'should be able to replace empty items in an array' 8141cb0ef41Sopenharmony_ci ) 8151cb0ef41Sopenharmony_ci qqqqq.set('lorem.ipsum', 3) 8161cb0ef41Sopenharmony_ci t.strictSame( 8171cb0ef41Sopenharmony_ci qqqqq.toJSON(), 8181cb0ef41Sopenharmony_ci { 8191cb0ef41Sopenharmony_ci arr: [ 8201cb0ef41Sopenharmony_ci 'a', 8211cb0ef41Sopenharmony_ci 'b', 8221cb0ef41Sopenharmony_ci ], 8231cb0ef41Sopenharmony_ci lorem: { 8241cb0ef41Sopenharmony_ci ipsum: 3, 8251cb0ef41Sopenharmony_ci }, 8261cb0ef41Sopenharmony_ci }, 8271cb0ef41Sopenharmony_ci 'should be able to replace empty items in an array' 8281cb0ef41Sopenharmony_ci ) 8291cb0ef41Sopenharmony_ci t.throws( 8301cb0ef41Sopenharmony_ci () => qqqqq.set('lorem[]', 4), 8311cb0ef41Sopenharmony_ci { code: 'ENOAPPEND' }, 8321cb0ef41Sopenharmony_ci 'should throw error if using empty square bracket in an non-array item' 8331cb0ef41Sopenharmony_ci ) 8341cb0ef41Sopenharmony_ci qqqqq.set('lorem[0]', 3) 8351cb0ef41Sopenharmony_ci t.strictSame( 8361cb0ef41Sopenharmony_ci qqqqq.toJSON(), 8371cb0ef41Sopenharmony_ci { 8381cb0ef41Sopenharmony_ci arr: [ 8391cb0ef41Sopenharmony_ci 'a', 8401cb0ef41Sopenharmony_ci 'b', 8411cb0ef41Sopenharmony_ci ], 8421cb0ef41Sopenharmony_ci lorem: { 8431cb0ef41Sopenharmony_ci 0: 3, 8441cb0ef41Sopenharmony_ci ipsum: 3, 8451cb0ef41Sopenharmony_ci }, 8461cb0ef41Sopenharmony_ci }, 8471cb0ef41Sopenharmony_ci 'should be able add indexes as props when finding an object' 8481cb0ef41Sopenharmony_ci ) 8491cb0ef41Sopenharmony_ci qqqqq.set('lorem.1', 3) 8501cb0ef41Sopenharmony_ci t.strictSame( 8511cb0ef41Sopenharmony_ci qqqqq.toJSON(), 8521cb0ef41Sopenharmony_ci { 8531cb0ef41Sopenharmony_ci arr: [ 8541cb0ef41Sopenharmony_ci 'a', 8551cb0ef41Sopenharmony_ci 'b', 8561cb0ef41Sopenharmony_ci ], 8571cb0ef41Sopenharmony_ci lorem: { 8581cb0ef41Sopenharmony_ci 0: 3, 8591cb0ef41Sopenharmony_ci 1: 3, 8601cb0ef41Sopenharmony_ci ipsum: 3, 8611cb0ef41Sopenharmony_ci }, 8621cb0ef41Sopenharmony_ci }, 8631cb0ef41Sopenharmony_ci 'should be able add numeric props to an obj' 8641cb0ef41Sopenharmony_ci ) 8651cb0ef41Sopenharmony_ci}) 8661cb0ef41Sopenharmony_ci 8671cb0ef41Sopenharmony_cit.test('delete values', async t => { 8681cb0ef41Sopenharmony_ci const q = new Queryable({ 8691cb0ef41Sopenharmony_ci foo: { 8701cb0ef41Sopenharmony_ci bar: { 8711cb0ef41Sopenharmony_ci lorem: 'lorem', 8721cb0ef41Sopenharmony_ci }, 8731cb0ef41Sopenharmony_ci }, 8741cb0ef41Sopenharmony_ci }) 8751cb0ef41Sopenharmony_ci q.delete('foo.bar.lorem') 8761cb0ef41Sopenharmony_ci t.strictSame( 8771cb0ef41Sopenharmony_ci q.toJSON(), 8781cb0ef41Sopenharmony_ci { 8791cb0ef41Sopenharmony_ci foo: { 8801cb0ef41Sopenharmony_ci bar: {}, 8811cb0ef41Sopenharmony_ci }, 8821cb0ef41Sopenharmony_ci }, 8831cb0ef41Sopenharmony_ci 'should delete queried item' 8841cb0ef41Sopenharmony_ci ) 8851cb0ef41Sopenharmony_ci q.delete('foo') 8861cb0ef41Sopenharmony_ci t.strictSame( 8871cb0ef41Sopenharmony_ci q.toJSON(), 8881cb0ef41Sopenharmony_ci {}, 8891cb0ef41Sopenharmony_ci 'should delete nested items' 8901cb0ef41Sopenharmony_ci ) 8911cb0ef41Sopenharmony_ci q.set('foo.a.b.c[0]', 'value') 8921cb0ef41Sopenharmony_ci q.delete('foo.a.b.c[0]') 8931cb0ef41Sopenharmony_ci t.strictSame( 8941cb0ef41Sopenharmony_ci q.toJSON(), 8951cb0ef41Sopenharmony_ci { 8961cb0ef41Sopenharmony_ci foo: { 8971cb0ef41Sopenharmony_ci a: { 8981cb0ef41Sopenharmony_ci b: { 8991cb0ef41Sopenharmony_ci c: [], 9001cb0ef41Sopenharmony_ci }, 9011cb0ef41Sopenharmony_ci }, 9021cb0ef41Sopenharmony_ci }, 9031cb0ef41Sopenharmony_ci }, 9041cb0ef41Sopenharmony_ci 'should delete array item' 9051cb0ef41Sopenharmony_ci ) 9061cb0ef41Sopenharmony_ci // creates an array that has an implicit empty first item 9071cb0ef41Sopenharmony_ci q.set('foo.a.b.c[1][0].foo.bar[0][0]', 'value') 9081cb0ef41Sopenharmony_ci q.delete('foo.a.b.c[1]') 9091cb0ef41Sopenharmony_ci t.strictSame( 9101cb0ef41Sopenharmony_ci q.toJSON(), 9111cb0ef41Sopenharmony_ci { 9121cb0ef41Sopenharmony_ci foo: { 9131cb0ef41Sopenharmony_ci a: { 9141cb0ef41Sopenharmony_ci b: { 9151cb0ef41Sopenharmony_ci c: [null], 9161cb0ef41Sopenharmony_ci }, 9171cb0ef41Sopenharmony_ci }, 9181cb0ef41Sopenharmony_ci }, 9191cb0ef41Sopenharmony_ci }, 9201cb0ef41Sopenharmony_ci 'should delete array item' 9211cb0ef41Sopenharmony_ci ) 9221cb0ef41Sopenharmony_ci}) 9231cb0ef41Sopenharmony_ci 9241cb0ef41Sopenharmony_cit.test('logger', async t => { 9251cb0ef41Sopenharmony_ci const q = new Queryable({}) 9261cb0ef41Sopenharmony_ci q.set('foo.bar[0].baz', 'baz') 9271cb0ef41Sopenharmony_ci t.strictSame( 9281cb0ef41Sopenharmony_ci inspect(q, { depth: 10 }), 9291cb0ef41Sopenharmony_ci inspect({ 9301cb0ef41Sopenharmony_ci foo: { 9311cb0ef41Sopenharmony_ci bar: [ 9321cb0ef41Sopenharmony_ci { 9331cb0ef41Sopenharmony_ci baz: 'baz', 9341cb0ef41Sopenharmony_ci }, 9351cb0ef41Sopenharmony_ci ], 9361cb0ef41Sopenharmony_ci }, 9371cb0ef41Sopenharmony_ci }, { depth: 10 }), 9381cb0ef41Sopenharmony_ci 'should retrieve expected data' 9391cb0ef41Sopenharmony_ci ) 9401cb0ef41Sopenharmony_ci}) 9411cb0ef41Sopenharmony_ci 9421cb0ef41Sopenharmony_cit.test('bracket lovers', async t => { 9431cb0ef41Sopenharmony_ci const q = new Queryable({}) 9441cb0ef41Sopenharmony_ci q.set('[iLoveBrackets]', 'seriously?') 9451cb0ef41Sopenharmony_ci t.strictSame( 9461cb0ef41Sopenharmony_ci q.toJSON(), 9471cb0ef41Sopenharmony_ci { 9481cb0ef41Sopenharmony_ci '[iLoveBrackets]': 'seriously?', 9491cb0ef41Sopenharmony_ci }, 9501cb0ef41Sopenharmony_ci 'should be able to set top-level props using square brackets notation' 9511cb0ef41Sopenharmony_ci ) 9521cb0ef41Sopenharmony_ci 9531cb0ef41Sopenharmony_ci t.equal(q.get('[iLoveBrackets]'), 'seriously?', 9541cb0ef41Sopenharmony_ci 'should bypass square bracket in top-level properties') 9551cb0ef41Sopenharmony_ci 9561cb0ef41Sopenharmony_ci q.set('[0]', '-.-') 9571cb0ef41Sopenharmony_ci t.strictSame( 9581cb0ef41Sopenharmony_ci q.toJSON(), 9591cb0ef41Sopenharmony_ci { 9601cb0ef41Sopenharmony_ci '[iLoveBrackets]': 'seriously?', 9611cb0ef41Sopenharmony_ci '[0]': '-.-', 9621cb0ef41Sopenharmony_ci }, 9631cb0ef41Sopenharmony_ci 'any top-level item can not be parsed with square bracket notation' 9641cb0ef41Sopenharmony_ci ) 9651cb0ef41Sopenharmony_ci}) 966