mol_regexp 0.0.1531 → 0.0.1533
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
|
@@ -3649,6 +3649,32 @@ var $;
|
|
|
3649
3649
|
$.$mol_tree2_to_string = $mol_tree2_to_string;
|
|
3650
3650
|
})($ || ($ = {}));
|
|
3651
3651
|
|
|
3652
|
+
;
|
|
3653
|
+
"use strict";
|
|
3654
|
+
var $;
|
|
3655
|
+
(function ($) {
|
|
3656
|
+
function $mol_maybe(value) {
|
|
3657
|
+
return (value == null) ? [] : [value];
|
|
3658
|
+
}
|
|
3659
|
+
$.$mol_maybe = $mol_maybe;
|
|
3660
|
+
})($ || ($ = {}));
|
|
3661
|
+
|
|
3662
|
+
;
|
|
3663
|
+
"use strict";
|
|
3664
|
+
var $;
|
|
3665
|
+
(function ($) {
|
|
3666
|
+
$mol_test({
|
|
3667
|
+
'all cases of using maybe'() {
|
|
3668
|
+
$mol_assert_equal($mol_maybe(0)[0], 0);
|
|
3669
|
+
$mol_assert_equal($mol_maybe(false)[0], false);
|
|
3670
|
+
$mol_assert_equal($mol_maybe(null)[0], void 0);
|
|
3671
|
+
$mol_assert_equal($mol_maybe(void 0)[0], void 0);
|
|
3672
|
+
$mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
|
|
3673
|
+
$mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
|
|
3674
|
+
},
|
|
3675
|
+
});
|
|
3676
|
+
})($ || ($ = {}));
|
|
3677
|
+
|
|
3652
3678
|
;
|
|
3653
3679
|
"use strict";
|
|
3654
3680
|
var $;
|
|
@@ -3716,33 +3742,38 @@ var $;
|
|
|
3716
3742
|
return $$.$mol_tree2_to_string(this);
|
|
3717
3743
|
}
|
|
3718
3744
|
insert(value, ...path) {
|
|
3745
|
+
return this.update($mol_maybe(value), ...path)[0];
|
|
3746
|
+
}
|
|
3747
|
+
update(value, ...path) {
|
|
3719
3748
|
if (path.length === 0)
|
|
3720
3749
|
return value;
|
|
3721
3750
|
const type = path[0];
|
|
3722
3751
|
if (typeof type === 'string') {
|
|
3723
3752
|
let replaced = false;
|
|
3724
|
-
const sub = this.kids.
|
|
3753
|
+
const sub = this.kids.flatMap((item, index) => {
|
|
3725
3754
|
if (item.type !== type)
|
|
3726
3755
|
return item;
|
|
3727
3756
|
replaced = true;
|
|
3728
|
-
return item.
|
|
3757
|
+
return item.update(value, ...path.slice(1));
|
|
3729
3758
|
}).filter(Boolean);
|
|
3730
3759
|
if (!replaced && value) {
|
|
3731
|
-
sub.push(this.struct(type, []).
|
|
3760
|
+
sub.push(...this.struct(type, []).update(value, ...path.slice(1)));
|
|
3732
3761
|
}
|
|
3733
|
-
return this.clone(sub);
|
|
3762
|
+
return [this.clone(sub)];
|
|
3734
3763
|
}
|
|
3735
3764
|
else if (typeof type === 'number') {
|
|
3736
|
-
const
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3765
|
+
const ins = (this.kids[type] || this.list([]))
|
|
3766
|
+
.update(value, ...path.slice(1));
|
|
3767
|
+
return [this.clone([
|
|
3768
|
+
...this.kids.slice(0, type),
|
|
3769
|
+
...ins,
|
|
3770
|
+
...this.kids.slice(type + 1),
|
|
3771
|
+
])];
|
|
3740
3772
|
}
|
|
3741
3773
|
else {
|
|
3742
3774
|
const kids = ((this.kids.length === 0) ? [this.list([])] : this.kids)
|
|
3743
|
-
.
|
|
3744
|
-
|
|
3745
|
-
return this.clone(kids);
|
|
3775
|
+
.flatMap(item => item.update(value, ...path.slice(1)));
|
|
3776
|
+
return [this.clone(kids)];
|
|
3746
3777
|
}
|
|
3747
3778
|
}
|
|
3748
3779
|
select(...path) {
|
|
@@ -3818,37 +3849,85 @@ var $;
|
|
|
3818
3849
|
"use strict";
|
|
3819
3850
|
var $;
|
|
3820
3851
|
(function ($_1) {
|
|
3852
|
+
function check(tree, ideal) {
|
|
3853
|
+
$mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
|
|
3854
|
+
}
|
|
3821
3855
|
$mol_test({
|
|
3822
3856
|
'inserting'($) {
|
|
3823
|
-
|
|
3824
|
-
|
|
3825
|
-
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3831
|
-
|
|
3832
|
-
|
|
3833
|
-
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
.insert($mol_tree2.struct('x'),
|
|
3837
|
-
|
|
3838
|
-
|
|
3839
|
-
|
|
3840
|
-
|
|
3857
|
+
check($.$mol_tree2_from_string(`
|
|
3858
|
+
a b c d
|
|
3859
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
|
|
3860
|
+
a b x
|
|
3861
|
+
`);
|
|
3862
|
+
check($.$mol_tree2_from_string(`
|
|
3863
|
+
a b
|
|
3864
|
+
`).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
|
|
3865
|
+
a b c x
|
|
3866
|
+
`);
|
|
3867
|
+
check($.$mol_tree2_from_string(`
|
|
3868
|
+
a b c d
|
|
3869
|
+
`)
|
|
3870
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0), `
|
|
3871
|
+
a b x
|
|
3872
|
+
`);
|
|
3873
|
+
check($.$mol_tree2_from_string(`
|
|
3874
|
+
a b
|
|
3875
|
+
`)
|
|
3876
|
+
.insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
|
|
3877
|
+
a b \\
|
|
3878
|
+
x
|
|
3879
|
+
`);
|
|
3880
|
+
check($.$mol_tree2_from_string(`
|
|
3881
|
+
a b c d
|
|
3882
|
+
`)
|
|
3883
|
+
.insert($mol_tree2.struct('x'), null, null, null), `
|
|
3884
|
+
a b x
|
|
3885
|
+
`);
|
|
3886
|
+
check($.$mol_tree2_from_string(`
|
|
3887
|
+
a b
|
|
3888
|
+
`)
|
|
3889
|
+
.insert($mol_tree2.struct('x'), null, null, null, null), `
|
|
3890
|
+
a b \\
|
|
3891
|
+
x
|
|
3892
|
+
`);
|
|
3893
|
+
},
|
|
3894
|
+
'updating'($) {
|
|
3895
|
+
check($.$mol_tree2_from_string(`
|
|
3896
|
+
a b c d
|
|
3897
|
+
`).update([], 'a', 'b', 'c')[0], `
|
|
3898
|
+
a b
|
|
3899
|
+
`);
|
|
3900
|
+
check($.$mol_tree2_from_string(`
|
|
3901
|
+
a b c d
|
|
3902
|
+
`).update([$mol_tree2.struct('x')])[0], `
|
|
3903
|
+
x
|
|
3904
|
+
`);
|
|
3905
|
+
check($.$mol_tree2_from_string(`
|
|
3906
|
+
a b c d
|
|
3907
|
+
`).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
|
|
3908
|
+
a b
|
|
3909
|
+
x
|
|
3910
|
+
y
|
|
3911
|
+
`);
|
|
3841
3912
|
},
|
|
3842
3913
|
'deleting'($) {
|
|
3843
|
-
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3914
|
+
const base = $.$mol_tree2_from_string(`
|
|
3915
|
+
a b c d
|
|
3916
|
+
`);
|
|
3917
|
+
check(base.insert(null, 'a', 'b', 'c'), `
|
|
3918
|
+
a b
|
|
3919
|
+
`);
|
|
3920
|
+
check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
|
|
3921
|
+
a b d
|
|
3922
|
+
`);
|
|
3923
|
+
check(base.insert(null, 0, 0, 0), `
|
|
3924
|
+
a b
|
|
3925
|
+
`);
|
|
3849
3926
|
},
|
|
3850
3927
|
'hack'($) {
|
|
3851
|
-
const res = $.$mol_tree2_from_string(`
|
|
3928
|
+
const res = $.$mol_tree2_from_string(`
|
|
3929
|
+
foo bar xxx
|
|
3930
|
+
`)
|
|
3852
3931
|
.hack({
|
|
3853
3932
|
'bar': (input, belt) => [input.struct('777', input.hack(belt))],
|
|
3854
3933
|
});
|