mol_time_all 1.1.1371 → 1.1.1373
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/node.test.js +115 -36
- package/node.test.js.map +1 -1
- package/package.json +1 -1
package/node.test.js
CHANGED
|
@@ -4068,6 +4068,32 @@ var $;
|
|
|
4068
4068
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
4069
4069
|
})($ || ($ = {}));
|
|
4070
4070
|
|
|
4071
|
+
;
|
|
4072
|
+
"use strict";
|
|
4073
|
+
var $;
|
|
4074
|
+
(function ($) {
|
|
4075
|
+
function $mol_maybe(value) {
|
|
4076
|
+
return (value == null) ? [] : [value];
|
|
4077
|
+
}
|
|
4078
|
+
$.$mol_maybe = $mol_maybe;
|
|
4079
|
+
})($ || ($ = {}));
|
|
4080
|
+
|
|
4081
|
+
;
|
|
4082
|
+
"use strict";
|
|
4083
|
+
var $;
|
|
4084
|
+
(function ($) {
|
|
4085
|
+
$mol_test({
|
|
4086
|
+
'all cases of using maybe'() {
|
|
4087
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
|
4088
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
|
4089
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
|
4090
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
|
4091
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
|
4092
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
|
4093
|
+
},
|
|
4094
|
+
});
|
|
4095
|
+
})($ || ($ = {}));
|
|
4096
|
+
|
|
4071
4097
|
;
|
|
4072
4098
|
"use strict";
|
|
4073
4099
|
var $;
|
|
@@ -4135,33 +4161,38 @@ var $;
|
|
|
4135
4161
|
return $$.$mol_tree2_to_string(this);
|
|
4136
4162
|
}
|
|
4137
4163
|
insert(value, ...path) {
|
|
4164
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
4165
|
+
}
|
|
4166
|
+
update(value, ...path) {
|
|
4138
4167
|
if (path.length === 0)
|
|
4139
4168
|
return value;
|
|
4140
4169
|
const type = path[0];
|
|
4141
4170
|
if (typeof type === 'string') {
|
|
4142
4171
|
let replaced = false;
|
|
4143
|
-
const sub = this.kids.
|
|
4172
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
4144
4173
|
if (item.type !== type)
|
|
4145
4174
|
return item;
|
|
4146
4175
|
replaced = true;
|
|
4147
|
-
return item.
|
|
4176
|
+
return item.update(value, ...path.slice(1));
|
|
4148
4177
|
}).filter(Boolean);
|
|
4149
4178
|
if (!replaced && value) {
|
|
4150
|
-
sub.push(this.struct(type, []).
|
|
4179
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
4151
4180
|
}
|
|
4152
|
-
return this.clone(sub);
|
|
4181
|
+
return [this.clone(sub)];
|
|
4153
4182
|
}
|
|
4154
4183
|
else if (typeof type === 'number') {
|
|
4155
|
-
const
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
|
|
4184
|
+
const ins = (this.kids[type] || this.list([]))
|
|
4185
|
+
.update(value, ...path.slice(1));
|
|
4186
|
+
return [this.clone([
|
|
4187
|
+
...this.kids.slice(0, type),
|
|
4188
|
+
...ins,
|
|
4189
|
+
...this.kids.slice(type + 1),
|
|
4190
|
+
])];
|
|
4159
4191
|
}
|
|
4160
4192
|
else {
|
|
4161
4193
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
4162
|
-
.
|
|
4163
|
-
|
|
4164
|
-
return this.clone(kids);
|
|
4194
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
4195
|
+
return [this.clone(kids)];
|
|
4165
4196
|
}
|
|
4166
4197
|
}
|
|
4167
4198
|
select(...path) {
|
|
@@ -4237,37 +4268,85 @@ var $;
|
|
|
4237
4268
|
"use strict";
|
|
4238
4269
|
var $;
|
|
4239
4270
|
(function ($_1) {
|
|
4271
|
+
function check(tree, ideal) {
|
|
4272
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
|
4273
|
+
}
|
|
4240
4274
|
$mol_test({
|
|
4241
4275
|
'inserting'($) {
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
|
|
4254
|
-
|
|
4255
|
-
.insert($mol_tree2.struct('x'),
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4276
|
+
check($.$mol_tree2_from_string(`
|
|
4277
|
+
a b c d
|
|
4278
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
|
4279
|
+
a b x
|
|
4280
|
+
`);
|
|
4281
|
+
check($.$mol_tree2_from_string(`
|
|
4282
|
+
a b
|
|
4283
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
|
4284
|
+
a b c x
|
|
4285
|
+
`);
|
|
4286
|
+
check($.$mol_tree2_from_string(`
|
|
4287
|
+
a b c d
|
|
4288
|
+
`)
|
|
4289
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
|
4290
|
+
a b x
|
|
4291
|
+
`);
|
|
4292
|
+
check($.$mol_tree2_from_string(`
|
|
4293
|
+
a b
|
|
4294
|
+
`)
|
|
4295
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
|
4296
|
+
a b \\
|
|
4297
|
+
x
|
|
4298
|
+
`);
|
|
4299
|
+
check($.$mol_tree2_from_string(`
|
|
4300
|
+
a b c d
|
|
4301
|
+
`)
|
|
4302
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
|
4303
|
+
a b x
|
|
4304
|
+
`);
|
|
4305
|
+
check($.$mol_tree2_from_string(`
|
|
4306
|
+
a b
|
|
4307
|
+
`)
|
|
4308
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
|
4309
|
+
a b \\
|
|
4310
|
+
x
|
|
4311
|
+
`);
|
|
4312
|
+
},
|
|
4313
|
+
'updating'($) {
|
|
4314
|
+
check($.$mol_tree2_from_string(`
|
|
4315
|
+
a b c d
|
|
4316
|
+
`).update([], 'a', 'b', 'c')[0], `
|
|
4317
|
+
a b
|
|
4318
|
+
`);
|
|
4319
|
+
check($.$mol_tree2_from_string(`
|
|
4320
|
+
a b c d
|
|
4321
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
|
4322
|
+
x
|
|
4323
|
+
`);
|
|
4324
|
+
check($.$mol_tree2_from_string(`
|
|
4325
|
+
a b c d
|
|
4326
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
|
4327
|
+
a b
|
|
4328
|
+
x
|
|
4329
|
+
y
|
|
4330
|
+
`);
|
|
4260
4331
|
},
|
|
4261
4332
|
'deleting'($) {
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4333
|
+
const base = $.$mol_tree2_from_string(`
|
|
4334
|
+
a b c d
|
|
4335
|
+
`);
|
|
4336
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
|
4337
|
+
a b
|
|
4338
|
+
`);
|
|
4339
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
|
4340
|
+
a b d
|
|
4341
|
+
`);
|
|
4342
|
+
check(base.insert(null, 0, 0, 0), `
|
|
4343
|
+
a b
|
|
4344
|
+
`);
|
|
4268
4345
|
},
|
|
4269
4346
|
'hack'($) {
|
|
4270
|
-
const res = $.$mol_tree2_from_string(`
|
|
4347
|
+
const res = $.$mol_tree2_from_string(`
|
|
4348
|
+
foo bar xxx
|
|
4349
|
+
`)
|
|
4271
4350
|
.hack({
|
|
4272
4351
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
4273
4352
|
});
|