mol_db 0.0.1623 → 0.0.1624

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 CHANGED
@@ -156,21 +156,7 @@ var $node = new Proxy({ require }, {
156
156
  $$.$mol_fail_log(e);
157
157
  }
158
158
  }
159
- try {
160
- return target.require(name);
161
- }
162
- catch (error) {
163
- if ($$.$mol_promise_like(error))
164
- $$.$mol_fail_hidden(error);
165
- if (error && typeof error === 'object' && error.code === 'ERR_REQUIRE_ESM') {
166
- const module = cache.get(name);
167
- if (module)
168
- return module;
169
- throw Object.assign(import(name).then(module => cache.set(name, module)), { cause: error });
170
- }
171
- $$.$mol_fail_log(error);
172
- return null;
173
- }
159
+ return target.require(name);
174
160
  },
175
161
  set(target, name, value) {
176
162
  target[name] = value;
@@ -2485,134 +2471,55 @@ var $;
2485
2471
  "use strict";
2486
2472
  var $;
2487
2473
  (function ($) {
2488
- function $mol_assert_ok(value) {
2489
- if (value)
2490
- return;
2491
- $mol_fail(new Error(`${value} true`));
2492
- }
2493
- $.$mol_assert_ok = $mol_assert_ok;
2494
- function $mol_assert_not(value) {
2495
- if (!value)
2496
- return;
2497
- $mol_fail(new Error(`${value} ≠ false`));
2498
- }
2499
- $.$mol_assert_not = $mol_assert_not;
2500
- function $mol_assert_fail(handler, ErrorRight) {
2501
- const fail = $.$mol_fail;
2502
- try {
2503
- $.$mol_fail = $.$mol_fail_hidden;
2504
- handler();
2505
- }
2506
- catch (error) {
2507
- $.$mol_fail = fail;
2508
- if (typeof ErrorRight === 'string') {
2509
- $mol_assert_equal(error.message ?? error, ErrorRight);
2474
+ function $mol_dom_render_children(el, childNodes) {
2475
+ const node_set = new Set(childNodes);
2476
+ let nextNode = el.firstChild;
2477
+ for (let view of childNodes) {
2478
+ if (view == null)
2479
+ continue;
2480
+ if (view instanceof $mol_dom_context.Node) {
2481
+ while (true) {
2482
+ if (!nextNode) {
2483
+ el.appendChild(view);
2484
+ break;
2485
+ }
2486
+ if (nextNode == view) {
2487
+ nextNode = nextNode.nextSibling;
2488
+ break;
2489
+ }
2490
+ else {
2491
+ if (node_set.has(nextNode)) {
2492
+ el.insertBefore(view, nextNode);
2493
+ break;
2494
+ }
2495
+ else {
2496
+ const nn = nextNode.nextSibling;
2497
+ el.removeChild(nextNode);
2498
+ nextNode = nn;
2499
+ }
2500
+ }
2501
+ }
2510
2502
  }
2511
2503
  else {
2512
- $mol_assert_equal(error instanceof ErrorRight, true);
2513
- }
2514
- return error;
2515
- }
2516
- finally {
2517
- $.$mol_fail = fail;
2518
- }
2519
- $mol_fail(new Error('Not failed'));
2520
- }
2521
- $.$mol_assert_fail = $mol_assert_fail;
2522
- function $mol_assert_like(...args) {
2523
- $mol_assert_equal(...args);
2524
- }
2525
- $.$mol_assert_like = $mol_assert_like;
2526
- function $mol_assert_unique(...args) {
2527
- for (let i = 0; i < args.length; ++i) {
2528
- for (let j = 0; j < args.length; ++j) {
2529
- if (i === j)
2530
- continue;
2531
- if (!$mol_compare_deep(args[i], args[j]))
2532
- continue;
2533
- return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
2504
+ if (nextNode && nextNode.nodeName === '#text') {
2505
+ const str = String(view);
2506
+ if (nextNode.nodeValue !== str)
2507
+ nextNode.nodeValue = str;
2508
+ nextNode = nextNode.nextSibling;
2509
+ }
2510
+ else {
2511
+ const textNode = $mol_dom_context.document.createTextNode(String(view));
2512
+ el.insertBefore(textNode, nextNode);
2513
+ }
2534
2514
  }
2535
2515
  }
2536
- }
2537
- $.$mol_assert_unique = $mol_assert_unique;
2538
- function $mol_assert_equal(...args) {
2539
- for (let i = 1; i < args.length; ++i) {
2540
- if ($mol_compare_deep(args[0], args[i]))
2541
- continue;
2542
- return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
2516
+ while (nextNode) {
2517
+ const currNode = nextNode;
2518
+ nextNode = currNode.nextSibling;
2519
+ el.removeChild(currNode);
2543
2520
  }
2544
2521
  }
2545
- $.$mol_assert_equal = $mol_assert_equal;
2546
- })($ || ($ = {}));
2547
-
2548
- ;
2549
- "use strict";
2550
- var $;
2551
- (function ($) {
2552
- $mol_test({
2553
- 'must be false'() {
2554
- $mol_assert_not(0);
2555
- },
2556
- 'must be true'() {
2557
- $mol_assert_ok(1);
2558
- },
2559
- 'two must be equal'() {
2560
- $mol_assert_equal(2, 2);
2561
- },
2562
- 'three must be equal'() {
2563
- $mol_assert_equal(2, 2, 2);
2564
- },
2565
- 'two must be unique'() {
2566
- $mol_assert_unique([2], [3]);
2567
- },
2568
- 'three must be unique'() {
2569
- $mol_assert_unique([1], [2], [3]);
2570
- },
2571
- 'two must be alike'() {
2572
- $mol_assert_equal([3], [3]);
2573
- },
2574
- 'three must be alike'() {
2575
- $mol_assert_equal([3], [3], [3]);
2576
- },
2577
- 'two object must be alike'() {
2578
- $mol_assert_equal({ a: 1 }, { a: 1 });
2579
- },
2580
- 'three object must be alike'() {
2581
- $mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
2582
- },
2583
- });
2584
- })($ || ($ = {}));
2585
-
2586
- ;
2587
- "use strict";
2588
- var $;
2589
- (function ($) {
2590
- $mol_test({
2591
- 'return result without errors'() {
2592
- $mol_assert_equal($mol_try(() => false), false);
2593
- },
2594
- });
2595
- })($ || ($ = {}));
2596
-
2597
- ;
2598
- "use strict";
2599
- var $;
2600
- (function ($_1) {
2601
- $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
2602
- })($ || ($ = {}));
2603
-
2604
- ;
2605
- "use strict";
2606
- var $;
2607
- (function ($_1) {
2608
- $mol_test_mocks.push($ => {
2609
- $.$mol_log3_come = () => { };
2610
- $.$mol_log3_done = () => { };
2611
- $.$mol_log3_fail = () => { };
2612
- $.$mol_log3_warn = () => { };
2613
- $.$mol_log3_rise = () => { };
2614
- $.$mol_log3_area = () => () => { };
2615
- });
2522
+ $.$mol_dom_render_children = $mol_dom_render_children;
2616
2523
  })($ || ($ = {}));
2617
2524
 
2618
2525
  ;
@@ -2630,122 +2537,136 @@ var $;
2630
2537
  ;
2631
2538
  "use strict";
2632
2539
 
2633
- ;
2634
- "use strict";
2635
-
2636
2540
  ;
2637
2541
  "use strict";
2638
2542
  var $;
2639
2543
  (function ($) {
2640
- $mol_test({
2641
- 'get'() {
2642
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
2643
- $mol_assert_equal(proxy.foo, 777);
2644
- },
2645
- 'has'() {
2646
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
2647
- $mol_assert_equal('foo' in proxy, true);
2648
- },
2649
- 'set'() {
2650
- const target = { foo: 777 };
2651
- const proxy = $mol_delegate({}, () => target);
2652
- proxy.foo = 123;
2653
- $mol_assert_equal(target.foo, 123);
2654
- },
2655
- 'getOwnPropertyDescriptor'() {
2656
- const proxy = $mol_delegate({}, () => ({ foo: 777 }));
2657
- $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
2658
- value: 777,
2659
- writable: true,
2660
- enumerable: true,
2661
- configurable: true,
2662
- });
2663
- },
2664
- 'ownKeys'() {
2665
- const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
2666
- $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
2667
- },
2668
- 'getPrototypeOf'() {
2669
- class Foo {
2670
- }
2671
- const proxy = $mol_delegate({}, () => new Foo);
2672
- $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
2673
- },
2674
- 'setPrototypeOf'() {
2675
- class Foo {
2676
- }
2677
- const target = {};
2678
- const proxy = $mol_delegate({}, () => target);
2679
- Object.setPrototypeOf(proxy, Foo.prototype);
2680
- $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
2681
- },
2682
- 'instanceof'() {
2683
- class Foo {
2684
- }
2685
- const proxy = $mol_delegate({}, () => new Foo);
2686
- $mol_assert_ok(proxy instanceof Foo);
2687
- $mol_assert_ok(proxy instanceof $mol_delegate);
2688
- },
2689
- 'autobind'() {
2690
- class Foo {
2691
- }
2692
- const proxy = $mol_delegate({}, () => new Foo);
2693
- $mol_assert_ok(proxy instanceof Foo);
2694
- $mol_assert_ok(proxy instanceof $mol_delegate);
2695
- },
2696
- });
2544
+ function $mol_dom_serialize(node) {
2545
+ const serializer = new $mol_dom_context.XMLSerializer;
2546
+ return serializer.serializeToString(node);
2547
+ }
2548
+ $.$mol_dom_serialize = $mol_dom_serialize;
2697
2549
  })($ || ($ = {}));
2698
2550
 
2699
2551
  ;
2700
2552
  "use strict";
2701
2553
  var $;
2702
- (function ($_1) {
2703
- $mol_test({
2704
- 'span for same uri'($) {
2705
- const span = new $mol_span('test.ts', '', 1, 3, 4);
2706
- const child = span.span(4, 5, 8);
2707
- $mol_assert_equal(child.uri, 'test.ts');
2708
- $mol_assert_equal(child.row, 4);
2709
- $mol_assert_equal(child.col, 5);
2710
- $mol_assert_equal(child.length, 8);
2711
- },
2712
- 'span after of given position'($) {
2713
- const span = new $mol_span('test.ts', '', 1, 3, 4);
2714
- const child = span.after(11);
2715
- $mol_assert_equal(child.uri, 'test.ts');
2716
- $mol_assert_equal(child.row, 1);
2717
- $mol_assert_equal(child.col, 7);
2718
- $mol_assert_equal(child.length, 11);
2719
- },
2720
- 'slice span - regular'($) {
2721
- const span = new $mol_span('test.ts', '', 1, 3, 5);
2722
- const child = span.slice(1, 4);
2723
- $mol_assert_equal(child.row, 1);
2724
- $mol_assert_equal(child.col, 4);
2725
- $mol_assert_equal(child.length, 3);
2726
- const child2 = span.slice(2, 2);
2727
- $mol_assert_equal(child2.col, 5);
2728
- $mol_assert_equal(child2.length, 0);
2729
- },
2730
- 'slice span - negative'($) {
2731
- const span = new $mol_span('test.ts', '', 1, 3, 5);
2732
- const child = span.slice(-3, -1);
2733
- $mol_assert_equal(child.row, 1);
2734
- $mol_assert_equal(child.col, 5);
2735
- $mol_assert_equal(child.length, 2);
2736
- },
2737
- 'slice span - out of range'($) {
2738
- const span = new $mol_span('test.ts', '', 1, 3, 5);
2739
- $mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
2740
- $mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
2741
- $mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
2742
- },
2743
- 'error handling'($) {
2744
- const span = new $mol_span('test.ts', '', 1, 3, 4);
2745
- const error = span.error('Some error');
2746
- $mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
2554
+ (function ($) {
2555
+ $.$mol_jsx_prefix = '';
2556
+ $.$mol_jsx_crumbs = '';
2557
+ $.$mol_jsx_booked = null;
2558
+ $.$mol_jsx_document = {
2559
+ getElementById: () => null,
2560
+ createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
2561
+ createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
2562
+ };
2563
+ $.$mol_jsx_frag = '';
2564
+ function $mol_jsx(Elem, props, ...childNodes) {
2565
+ const id = props && props.id || '';
2566
+ const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
2567
+ const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
2568
+ if (Elem && $.$mol_jsx_booked) {
2569
+ if ($.$mol_jsx_booked.has(id)) {
2570
+ $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
2571
+ }
2572
+ else {
2573
+ $.$mol_jsx_booked.add(id);
2574
+ }
2747
2575
  }
2748
- });
2576
+ let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
2577
+ if ($.$mol_jsx_prefix) {
2578
+ const prefix_ext = $.$mol_jsx_prefix;
2579
+ const booked_ext = $.$mol_jsx_booked;
2580
+ const crumbs_ext = $.$mol_jsx_crumbs;
2581
+ for (const field in props) {
2582
+ const func = props[field];
2583
+ if (typeof func !== 'function')
2584
+ continue;
2585
+ const wrapper = function (...args) {
2586
+ const prefix = $.$mol_jsx_prefix;
2587
+ const booked = $.$mol_jsx_booked;
2588
+ const crumbs = $.$mol_jsx_crumbs;
2589
+ try {
2590
+ $.$mol_jsx_prefix = prefix_ext;
2591
+ $.$mol_jsx_booked = booked_ext;
2592
+ $.$mol_jsx_crumbs = crumbs_ext;
2593
+ return func.call(this, ...args);
2594
+ }
2595
+ finally {
2596
+ $.$mol_jsx_prefix = prefix;
2597
+ $.$mol_jsx_booked = booked;
2598
+ $.$mol_jsx_crumbs = crumbs;
2599
+ }
2600
+ };
2601
+ $mol_func_name_from(wrapper, func);
2602
+ props[field] = wrapper;
2603
+ }
2604
+ }
2605
+ if (typeof Elem !== 'string') {
2606
+ if ('prototype' in Elem) {
2607
+ const view = node && node[String(Elem)] || new Elem;
2608
+ Object.assign(view, props);
2609
+ view[Symbol.toStringTag] = guid;
2610
+ view.childNodes = childNodes;
2611
+ if (!view.ownerDocument)
2612
+ view.ownerDocument = $.$mol_jsx_document;
2613
+ view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2614
+ node = view.valueOf();
2615
+ node[String(Elem)] = view;
2616
+ return node;
2617
+ }
2618
+ else {
2619
+ const prefix = $.$mol_jsx_prefix;
2620
+ const booked = $.$mol_jsx_booked;
2621
+ const crumbs = $.$mol_jsx_crumbs;
2622
+ try {
2623
+ $.$mol_jsx_prefix = guid;
2624
+ $.$mol_jsx_booked = new Set;
2625
+ $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
2626
+ return Elem(props, ...childNodes);
2627
+ }
2628
+ finally {
2629
+ $.$mol_jsx_prefix = prefix;
2630
+ $.$mol_jsx_booked = booked;
2631
+ $.$mol_jsx_crumbs = crumbs;
2632
+ }
2633
+ }
2634
+ }
2635
+ if (!node) {
2636
+ node = Elem
2637
+ ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
2638
+ : $.$mol_jsx_document.createDocumentFragment();
2639
+ }
2640
+ $mol_dom_render_children(node, [].concat(...childNodes));
2641
+ if (!Elem)
2642
+ return node;
2643
+ if (guid)
2644
+ node.id = guid;
2645
+ for (const key in props) {
2646
+ if (key === 'id')
2647
+ continue;
2648
+ if (typeof props[key] === 'string') {
2649
+ if (typeof node[key] === 'string')
2650
+ node[key] = props[key];
2651
+ node.setAttribute(key, props[key]);
2652
+ }
2653
+ else if (props[key] &&
2654
+ typeof props[key] === 'object' &&
2655
+ Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
2656
+ if (typeof node[key] === 'object') {
2657
+ Object.assign(node[key], props[key]);
2658
+ continue;
2659
+ }
2660
+ }
2661
+ else {
2662
+ node[key] = props[key];
2663
+ }
2664
+ }
2665
+ if ($.$mol_jsx_crumbs)
2666
+ node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
2667
+ return node;
2668
+ }
2669
+ $.$mol_jsx = $mol_jsx;
2749
2670
  })($ || ($ = {}));
2750
2671
 
2751
2672
  ;
@@ -2753,204 +2674,100 @@ var $;
2753
2674
  var $;
2754
2675
  (function ($) {
2755
2676
  $mol_test({
2756
- 'all cases of using maybe'() {
2757
- $mol_assert_equal($mol_maybe(0)[0], 0);
2758
- $mol_assert_equal($mol_maybe(false)[0], false);
2759
- $mol_assert_equal($mol_maybe(null)[0], void 0);
2760
- $mol_assert_equal($mol_maybe(void 0)[0], void 0);
2761
- $mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
2762
- $mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
2763
- },
2764
- });
2765
- })($ || ($ = {}));
2766
-
2767
- ;
2768
- "use strict";
2769
- var $;
2770
- (function ($_1) {
2771
- function check(tree, ideal) {
2772
- $mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
2773
- }
2774
- $mol_test({
2775
- 'inserting'($) {
2776
- check($.$mol_tree2_from_string(`
2777
- a b c d
2778
- `).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
2779
- a b x
2780
- `);
2781
- check($.$mol_tree2_from_string(`
2782
- a b
2783
- `).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
2784
- a b c x
2785
- `);
2786
- check($.$mol_tree2_from_string(`
2787
- a b c d
2788
- `)
2789
- .insert($mol_tree2.struct('x'), 0, 0, 0), `
2790
- a b x
2791
- `);
2792
- check($.$mol_tree2_from_string(`
2793
- a b
2794
- `)
2795
- .insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
2796
- a b \\
2797
- x
2798
- `);
2799
- check($.$mol_tree2_from_string(`
2800
- a b c d
2801
- `)
2802
- .insert($mol_tree2.struct('x'), null, null, null), `
2803
- a b x
2804
- `);
2805
- check($.$mol_tree2_from_string(`
2806
- a b
2807
- `)
2808
- .insert($mol_tree2.struct('x'), null, null, null, null), `
2809
- a b \\
2810
- x
2811
- `);
2812
- },
2813
- 'updating'($) {
2814
- check($.$mol_tree2_from_string(`
2815
- a b c d
2816
- `).update([], 'a', 'b', 'c')[0], `
2817
- a b
2818
- `);
2819
- check($.$mol_tree2_from_string(`
2820
- a b c d
2821
- `).update([$mol_tree2.struct('x')])[0], `
2822
- x
2823
- `);
2824
- check($.$mol_tree2_from_string(`
2825
- a b c d
2826
- `).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
2827
- a b
2828
- x
2829
- y
2830
- `);
2831
- },
2832
- 'deleting'($) {
2833
- const base = $.$mol_tree2_from_string(`
2834
- a b c d
2835
- `);
2836
- check(base.insert(null, 'a', 'b', 'c'), `
2837
- a b
2838
- `);
2839
- check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
2840
- a b d
2841
- `);
2842
- check(base.insert(null, 0, 0, 0), `
2843
- a b
2844
- `);
2845
- },
2846
- 'hack'($) {
2847
- const res = $.$mol_tree2_from_string(`
2848
- foo bar xxx
2849
- `)
2850
- .hack({
2851
- 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
2852
- });
2853
- $mol_assert_equal(res.map(String), ['foo 777 xxx\n']);
2854
- },
2855
- });
2856
- })($ || ($ = {}));
2857
-
2858
- ;
2859
- "use strict";
2860
- var $;
2861
- (function ($_1) {
2862
- $mol_test({
2863
- 'tree parsing'($) {
2864
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
2865
- $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
2866
- $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
2867
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
2868
- $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
2869
- $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
2870
- $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
2871
- $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
2872
- },
2873
- 'Too many tabs'($) {
2874
- const tree = `
2875
- foo
2876
- bar
2877
- `;
2878
- $mol_assert_fail(() => {
2879
- $.$mol_tree2_from_string(tree, 'test');
2880
- }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
2881
- },
2882
- 'Too few tabs'($) {
2883
- const tree = `
2884
- foo
2885
- bar
2886
- `;
2887
- $mol_assert_fail(() => {
2888
- $.$mol_tree2_from_string(tree, 'test');
2889
- }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
2890
- },
2891
- 'Wrong nodes separator at start'($) {
2892
- const tree = `foo\n \tbar\n`;
2893
- $mol_assert_fail(() => {
2894
- $.$mol_tree2_from_string(tree, 'test');
2895
- }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
2896
- },
2897
- 'Wrong nodes separator in the middle'($) {
2898
- const tree = `foo bar\n`;
2899
- $mol_assert_fail(() => {
2900
- $.$mol_tree2_from_string(tree, 'test');
2901
- }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
2902
- },
2903
- 'Unexpected EOF, LF required'($) {
2904
- const tree = ` foo`;
2905
- $mol_assert_fail(() => {
2906
- $.$mol_tree2_from_string(tree, 'test');
2907
- }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
2908
- },
2909
- 'Errors skip and collect'($) {
2910
- const tree = `foo bar`;
2911
- const errors = [];
2912
- const $$ = $.$mol_ambient({
2913
- $mol_fail: (error) => {
2914
- errors.push(error.message);
2915
- return null;
2916
- }
2917
- });
2918
- const res = $$.$mol_tree2_from_string(tree, 'test');
2919
- $mol_assert_like(errors, [
2920
- 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
2921
- 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
2922
- ]);
2923
- $mol_assert_equal(res.toString(), 'foo bar\n');
2924
- },
2925
- });
2926
- })($ || ($ = {}));
2927
-
2928
- ;
2929
- "use strict";
2930
- var $;
2931
- (function ($) {
2932
- $mol_test({
2933
- 'fromJSON'() {
2934
- $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
2935
- $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
2936
- $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
2937
- $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
2938
- $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
2939
- $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
2940
- },
2941
- });
2942
- })($ || ($ = {}));
2943
-
2944
- ;
2945
- "use strict";
2946
- var $;
2947
- (function ($_1) {
2948
- $mol_test({
2949
- 'FQN of anon function'($) {
2950
- const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
2951
- $mol_assert_equal($$.$mol_func_name_test.name, '');
2952
- $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
2953
- $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
2677
+ 'Make empty div'() {
2678
+ $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
2679
+ },
2680
+ 'Define native field'() {
2681
+ const dom = $mol_jsx("input", { value: '123' });
2682
+ $mol_assert_equal(dom.outerHTML, '<input value="123">');
2683
+ $mol_assert_equal(dom.value, '123');
2684
+ },
2685
+ 'Define classes'() {
2686
+ const dom = $mol_jsx("div", { class: 'foo bar' });
2687
+ $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
2688
+ },
2689
+ 'Define styles'() {
2690
+ const dom = $mol_jsx("div", { style: { color: 'red' } });
2691
+ $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
2692
+ },
2693
+ 'Define dataset'() {
2694
+ const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
2695
+ $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
2696
+ },
2697
+ 'Define attributes'() {
2698
+ const dom = $mol_jsx("div", { lang: "ru", hidden: true });
2699
+ $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
2700
+ },
2701
+ 'Define child nodes'() {
2702
+ const dom = $mol_jsx("div", null,
2703
+ "hello",
2704
+ $mol_jsx("strong", null, "world"),
2705
+ "!");
2706
+ $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
2707
+ },
2708
+ 'Make fragment'() {
2709
+ const dom = $mol_jsx($mol_jsx_frag, null,
2710
+ $mol_jsx("br", null),
2711
+ $mol_jsx("hr", null));
2712
+ $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
2713
+ },
2714
+ 'Spread fragment'() {
2715
+ const dom = $mol_jsx("div", null,
2716
+ $mol_jsx($mol_jsx_frag, null,
2717
+ $mol_jsx("br", null),
2718
+ $mol_jsx("hr", null)));
2719
+ $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
2720
+ },
2721
+ 'Function as component'() {
2722
+ const Button = (props, target) => {
2723
+ return $mol_jsx("button", { title: props.hint }, target());
2724
+ };
2725
+ const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
2726
+ $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
2727
+ },
2728
+ 'Nested guid generation'() {
2729
+ const Foo = () => {
2730
+ return $mol_jsx("div", null,
2731
+ $mol_jsx(Bar, { id: "bar" },
2732
+ $mol_jsx("img", { id: "icon" })));
2733
+ };
2734
+ const Bar = (props, icon) => {
2735
+ return $mol_jsx("span", null,
2736
+ icon,
2737
+ $mol_jsx("i", { id: "label" }));
2738
+ };
2739
+ const dom = $mol_jsx(Foo, { id: "foo" });
2740
+ $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
2741
+ },
2742
+ 'Fail on non unique ids'() {
2743
+ const App = () => {
2744
+ return $mol_jsx("div", null,
2745
+ $mol_jsx("span", { id: "bar" }),
2746
+ $mol_jsx("span", { id: "bar" }));
2747
+ };
2748
+ $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
2749
+ },
2750
+ 'Owner based guid generationn'() {
2751
+ const Foo = () => {
2752
+ return $mol_jsx("div", null,
2753
+ $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
2754
+ };
2755
+ const Bar = (props) => {
2756
+ return $mol_jsx("span", null, props.icon());
2757
+ };
2758
+ const dom = $mol_jsx(Foo, { id: "app" });
2759
+ $mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
2760
+ },
2761
+ 'Fail on same ids from different caller'() {
2762
+ const Foo = () => {
2763
+ return $mol_jsx("div", null,
2764
+ $mol_jsx("img", { id: "icon" }),
2765
+ $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
2766
+ };
2767
+ const Bar = (props) => {
2768
+ return $mol_jsx("span", null, props.icon());
2769
+ };
2770
+ $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
2954
2771
  },
2955
2772
  });
2956
2773
  })($ || ($ = {}));
@@ -2959,163 +2776,287 @@ var $;
2959
2776
  "use strict";
2960
2777
  var $;
2961
2778
  (function ($) {
2962
- $mol_test({
2963
- 'auto name'() {
2964
- class Invalid extends $mol_error_mix {
2965
- }
2966
- const mix = new Invalid('foo');
2967
- $mol_assert_equal(mix.name, 'Invalid_Error');
2968
- },
2969
- 'simpe mix'() {
2970
- const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
2971
- $mol_assert_equal(mix.message, 'foo');
2972
- $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
2973
- },
2974
- 'provide additional info'() {
2975
- class Invalid extends $mol_error_mix {
2976
- }
2977
- const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
2978
- const hints = [];
2979
- if (mix instanceof $mol_error_mix) {
2980
- for (const er of mix.errors) {
2981
- if (er instanceof Invalid) {
2982
- hints.push(er.cause?.hint ?? '');
2983
- }
2984
- }
2985
- }
2986
- $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
2987
- },
2988
- });
2989
- })($ || ($ = {}));
2990
-
2991
- ;
2992
- "use strict";
2993
- var $;
2994
- (function ($_1) {
2995
- $mol_test({
2996
- 'init with overload'() {
2997
- class X extends $mol_object {
2998
- foo() {
2999
- return 1;
2779
+ function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
2780
+ const source = typeof item === 'function' ? new $mol_range2_array() : item;
2781
+ if (typeof item !== 'function') {
2782
+ item = index => source[index];
2783
+ size = () => source.length;
2784
+ }
2785
+ return new Proxy(source, {
2786
+ get(target, field) {
2787
+ if (typeof field === 'string') {
2788
+ if (field === 'length')
2789
+ return size();
2790
+ const index = Number(field);
2791
+ if (index < 0)
2792
+ return undefined;
2793
+ if (index >= size())
2794
+ return undefined;
2795
+ if (index === Math.trunc(index))
2796
+ return item(index);
3000
2797
  }
2798
+ return $mol_range2_array.prototype[field];
2799
+ },
2800
+ set(target, field) {
2801
+ return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
2802
+ },
2803
+ ownKeys(target) {
2804
+ return [...Array(size())].map((v, i) => String(i)).concat('length');
2805
+ },
2806
+ getOwnPropertyDescriptor(target, field) {
2807
+ if (field === "length")
2808
+ return {
2809
+ value: size(),
2810
+ writable: true,
2811
+ enumerable: false,
2812
+ configurable: false,
2813
+ };
2814
+ const index = Number(field);
2815
+ if (index === Math.trunc(index))
2816
+ return {
2817
+ get: () => this.get(target, field, this),
2818
+ enumerable: true,
2819
+ configurable: true,
2820
+ };
2821
+ return Object.getOwnPropertyDescriptor(target, field);
3001
2822
  }
3002
- var x = X.make({
3003
- foo: () => 2,
3004
- });
3005
- $mol_assert_equal(x.foo(), 2);
3006
- },
3007
- 'Context in instance inherits from class'($) {
3008
- const custom = $.$mol_ambient({});
3009
- class X extends $.$mol_object {
3010
- static $ = custom;
3011
- }
3012
- $mol_assert_equal(new X().$, custom);
3013
- },
3014
- });
3015
- })($ || ($ = {}));
3016
-
3017
- ;
3018
- "use strict";
3019
- var $;
3020
- (function ($_1) {
3021
- $mol_test({
3022
- 'Collect deps'() {
3023
- const pub1 = new $mol_wire_pub;
3024
- const pub2 = new $mol_wire_pub;
3025
- const sub = new $mol_wire_pub_sub;
3026
- const bu1 = sub.track_on();
3027
- try {
3028
- pub1.promote();
3029
- pub2.promote();
3030
- pub2.promote();
3031
- }
3032
- finally {
3033
- sub.track_cut();
3034
- sub.track_off(bu1);
2823
+ });
2824
+ }
2825
+ $.$mol_range2 = $mol_range2;
2826
+ class $mol_range2_array extends Array {
2827
+ concat(...tail) {
2828
+ if (tail.length === 0)
2829
+ return this;
2830
+ if (tail.length > 1) {
2831
+ let list = this;
2832
+ for (let item of tail)
2833
+ list = list.concat(item);
2834
+ return list;
3035
2835
  }
3036
- pub1.emit();
3037
- pub2.emit();
3038
- $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3039
- const bu2 = sub.track_on();
3040
- try {
3041
- pub1.promote();
3042
- pub1.promote();
3043
- pub2.promote();
2836
+ return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
2837
+ }
2838
+ filter(check, context) {
2839
+ const filtered = [];
2840
+ let cursor = -1;
2841
+ return $mol_range2(index => {
2842
+ while (cursor < this.length && index >= filtered.length - 1) {
2843
+ const val = this[++cursor];
2844
+ if (check(val, cursor, this))
2845
+ filtered.push(val);
2846
+ }
2847
+ return filtered[index];
2848
+ }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
2849
+ }
2850
+ forEach(proceed, context) {
2851
+ for (let [key, value] of this.entries())
2852
+ proceed.call(context, value, key, this);
2853
+ }
2854
+ map(proceed, context) {
2855
+ return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
2856
+ }
2857
+ reduce(merge, result) {
2858
+ let index = 0;
2859
+ if (arguments.length === 1) {
2860
+ result = this[index++];
3044
2861
  }
3045
- finally {
3046
- sub.track_cut();
3047
- sub.track_off(bu2);
2862
+ for (; index < this.length; ++index) {
2863
+ result = merge(result, this[index], index, this);
3048
2864
  }
3049
- pub1.emit();
3050
- pub2.emit();
3051
- $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3052
- },
3053
- 'cyclic detection'($) {
3054
- const sub1 = new $mol_wire_pub_sub;
3055
- const sub2 = new $mol_wire_pub_sub;
3056
- const bu1 = sub1.track_on();
3057
- try {
3058
- const bu2 = sub2.track_on();
3059
- try {
3060
- $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3061
- }
3062
- finally {
3063
- sub2.track_cut();
3064
- sub2.track_off(bu2);
3065
- }
2865
+ return result;
2866
+ }
2867
+ toReversed() {
2868
+ return $mol_range2(index => this[this.length - 1 - index], () => this.length);
2869
+ }
2870
+ slice(from = 0, to = this.length) {
2871
+ return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
2872
+ }
2873
+ some(check, context) {
2874
+ for (let index = 0; index < this.length; ++index) {
2875
+ if (check.call(context, this[index], index, this))
2876
+ return true;
3066
2877
  }
3067
- finally {
3068
- sub1.track_cut();
3069
- sub1.track_off(bu1);
2878
+ return false;
2879
+ }
2880
+ every(check, context) {
2881
+ for (let index = 0; index < this.length; ++index) {
2882
+ if (!check.call(context, this[index], index, this))
2883
+ return false;
3070
2884
  }
3071
- },
3072
- });
3073
- })($ || ($ = {}));
3074
-
3075
- ;
3076
- "use strict";
3077
- var $;
3078
- (function ($) {
3079
- $.$mol_after_mock_queue = [];
3080
- function $mol_after_mock_warp() {
3081
- const queue = $.$mol_after_mock_queue.splice(0);
3082
- for (const task of queue)
3083
- task();
3084
- }
3085
- $.$mol_after_mock_warp = $mol_after_mock_warp;
3086
- class $mol_after_mock_commmon extends $mol_object2 {
3087
- task;
3088
- promise = Promise.resolve();
3089
- cancelled = false;
3090
- id;
3091
- constructor(task) {
3092
- super();
3093
- this.task = task;
3094
- $.$mol_after_mock_queue.push(task);
2885
+ return true;
3095
2886
  }
3096
- destructor() {
3097
- const index = $.$mol_after_mock_queue.indexOf(this.task);
3098
- if (index >= 0)
3099
- $.$mol_after_mock_queue.splice(index, 1);
2887
+ reverse() {
2888
+ return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
3100
2889
  }
3101
- }
3102
- $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3103
- class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3104
- delay;
3105
- constructor(delay, task) {
3106
- super(task);
3107
- this.delay = delay;
2890
+ sort() {
2891
+ return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
2892
+ }
2893
+ indexOf(needle) {
2894
+ return this.findIndex(item => item === needle);
2895
+ }
2896
+ [Symbol.toPrimitive]() {
2897
+ return $mol_guid();
3108
2898
  }
3109
2899
  }
3110
- $.$mol_after_mock_timeout = $mol_after_mock_timeout;
2900
+ $.$mol_range2_array = $mol_range2_array;
3111
2901
  })($ || ($ = {}));
3112
2902
 
3113
2903
  ;
3114
2904
  "use strict";
3115
2905
  var $;
3116
- (function ($_1) {
3117
- $mol_test_mocks.push($ => {
3118
- $.$mol_after_tick = $mol_after_mock_commmon;
2906
+ (function ($) {
2907
+ $mol_test({
2908
+ 'lazy calls'() {
2909
+ let calls = 0;
2910
+ const list = $mol_range2(index => (++calls, index), () => 10);
2911
+ $mol_assert_equal(true, list instanceof Array);
2912
+ $mol_assert_equal(list.length, 10);
2913
+ $mol_assert_equal(list[-1], undefined);
2914
+ $mol_assert_equal(list[0], 0);
2915
+ $mol_assert_equal(list[9], 9);
2916
+ $mol_assert_equal(list[9.5], undefined);
2917
+ $mol_assert_equal(list[10], undefined);
2918
+ $mol_assert_equal(calls, 2);
2919
+ },
2920
+ 'infinity list'() {
2921
+ let calls = 0;
2922
+ const list = $mol_range2(index => (++calls, index));
2923
+ $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
2924
+ $mol_assert_equal(list[0], 0);
2925
+ $mol_assert_equal(list[4], 4);
2926
+ $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
2927
+ $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
2928
+ $mol_assert_equal(calls, 3);
2929
+ },
2930
+ 'stringify'() {
2931
+ const list = $mol_range2(i => i, () => 5);
2932
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
2933
+ $mol_assert_equal(list.join(';'), '0;1;2;3;4');
2934
+ },
2935
+ 'for-of'() {
2936
+ let log = '';
2937
+ for (let i of $mol_range2(i => i + 1, () => 5)) {
2938
+ log += i;
2939
+ }
2940
+ $mol_assert_equal(log, '12345');
2941
+ },
2942
+ 'for-in'() {
2943
+ let log = '';
2944
+ for (let i in $mol_range2(i => i, () => 5)) {
2945
+ log += i;
2946
+ }
2947
+ $mol_assert_equal(log, '01234');
2948
+ },
2949
+ 'forEach'() {
2950
+ let log = '';
2951
+ $mol_range2(i => i, () => 5).forEach(i => log += i);
2952
+ $mol_assert_equal(log, '01234');
2953
+ },
2954
+ 'reduce'() {
2955
+ let calls = 0;
2956
+ const list = $mol_range2().slice(1, 6);
2957
+ $mol_assert_equal(list.reduce((s, v) => s + v), 15);
2958
+ $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
2959
+ },
2960
+ 'lazy concat'() {
2961
+ let calls1 = 0;
2962
+ let calls2 = 0;
2963
+ const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
2964
+ $mol_assert_equal(true, list instanceof Array);
2965
+ $mol_assert_equal(list.length, 15);
2966
+ $mol_assert_equal(list[0], 0);
2967
+ $mol_assert_equal(list[4], 4);
2968
+ $mol_assert_equal(list[5], 0);
2969
+ $mol_assert_equal(list[9], 4);
2970
+ $mol_assert_equal(list[10], 0);
2971
+ $mol_assert_equal(list[14], 4);
2972
+ $mol_assert_equal(list[15], undefined);
2973
+ $mol_assert_equal(calls1, 2);
2974
+ $mol_assert_equal(calls2, 2);
2975
+ },
2976
+ 'lazy filter'() {
2977
+ let calls = 0;
2978
+ const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
2979
+ $mol_assert_equal(true, list instanceof Array);
2980
+ $mol_assert_equal(list.length, 3);
2981
+ $mol_assert_equal(list[0], 1);
2982
+ $mol_assert_equal(list[2], 5);
2983
+ $mol_assert_equal(list[3], undefined);
2984
+ $mol_assert_equal(calls, 8);
2985
+ },
2986
+ 'lazy reverse'() {
2987
+ let calls = 0;
2988
+ const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
2989
+ $mol_assert_equal(true, list instanceof Array);
2990
+ $mol_assert_equal(list.length, 3);
2991
+ $mol_assert_equal(list[0], 9);
2992
+ $mol_assert_equal(list[2], 7);
2993
+ $mol_assert_equal(list[3], undefined);
2994
+ $mol_assert_equal(calls, 2);
2995
+ },
2996
+ 'lazy map'() {
2997
+ let calls1 = 0;
2998
+ let calls2 = 0;
2999
+ const source = $mol_range2(index => (++calls1, index), () => 5);
3000
+ const target = source.map((item, index, self) => {
3001
+ ++calls2;
3002
+ $mol_assert_equal(source, self);
3003
+ return index + 10;
3004
+ }, () => 5);
3005
+ $mol_assert_equal(true, target instanceof Array);
3006
+ $mol_assert_equal(target.length, 5);
3007
+ $mol_assert_equal(target[0], 10);
3008
+ $mol_assert_equal(target[4], 14);
3009
+ $mol_assert_equal(target[5], undefined);
3010
+ $mol_assert_equal(calls1, 2);
3011
+ $mol_assert_equal(calls2, 2);
3012
+ },
3013
+ 'lazy slice'() {
3014
+ let calls = 0;
3015
+ const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
3016
+ $mol_assert_equal(true, list instanceof Array);
3017
+ $mol_assert_equal(list.length, 4);
3018
+ $mol_assert_equal(list[0], 3);
3019
+ $mol_assert_equal(list[3], 6);
3020
+ $mol_assert_equal(list[4], undefined);
3021
+ $mol_assert_equal(calls, 2);
3022
+ },
3023
+ 'lazy some'() {
3024
+ let calls = 0;
3025
+ $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
3026
+ $mol_assert_equal(calls, 3);
3027
+ $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
3028
+ $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
3029
+ },
3030
+ 'lazy every'() {
3031
+ let calls = 0;
3032
+ $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
3033
+ $mol_assert_equal(calls, 3);
3034
+ $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
3035
+ $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
3036
+ },
3037
+ 'lazyfy'() {
3038
+ let calls = 0;
3039
+ const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
3040
+ $mol_assert_equal(true, list instanceof Array);
3041
+ $mol_assert_equal(list.length, 4);
3042
+ $mol_assert_equal(calls, 0);
3043
+ $mol_assert_equal(list[0], 12);
3044
+ $mol_assert_equal(list[3], 15);
3045
+ $mol_assert_equal(list[4], undefined);
3046
+ $mol_assert_equal(calls, 2);
3047
+ },
3048
+ 'prevent modification'() {
3049
+ const list = $mol_range2(i => i, () => 5);
3050
+ $mol_assert_fail(() => list.push(4), TypeError);
3051
+ $mol_assert_fail(() => list.pop(), TypeError);
3052
+ $mol_assert_fail(() => list.unshift(4), TypeError);
3053
+ $mol_assert_fail(() => list.shift(), TypeError);
3054
+ $mol_assert_fail(() => list.splice(1, 2), TypeError);
3055
+ $mol_assert_fail(() => list[1] = 2, TypeError);
3056
+ $mol_assert_fail(() => list.reverse(), TypeError);
3057
+ $mol_assert_fail(() => list.sort(), TypeError);
3058
+ $mol_assert_equal(list.toString(), '0,1,2,3,4');
3059
+ }
3119
3060
  });
3120
3061
  })($ || ($ = {}));
3121
3062
 
@@ -3124,79 +3065,125 @@ var $;
3124
3065
  var $;
3125
3066
  (function ($) {
3126
3067
  $mol_test({
3127
- 'Sync execution'() {
3128
- class Sync extends $mol_object2 {
3129
- static calc(a, b) {
3130
- return a + b;
3131
- }
3132
- }
3133
- __decorate([
3134
- $mol_wire_method
3135
- ], Sync, "calc", null);
3136
- $mol_assert_equal(Sync.calc(1, 2), 3);
3068
+ 'nulls & undefineds'() {
3069
+ $mol_assert_ok($mol_compare_deep(null, null));
3070
+ $mol_assert_ok($mol_compare_deep(undefined, undefined));
3071
+ $mol_assert_not($mol_compare_deep(undefined, null));
3072
+ $mol_assert_not($mol_compare_deep({}, null));
3137
3073
  },
3138
- async 'async <=> sync'() {
3139
- class SyncAsync extends $mol_object2 {
3140
- static async val(a) {
3141
- return a;
3142
- }
3143
- static sum(a, b) {
3144
- const syn = $mol_wire_sync(this);
3145
- return syn.val(a) + syn.val(b);
3146
- }
3147
- static async calc(a, b) {
3148
- return 5 + await $mol_wire_async(this).sum(a, b);
3149
- }
3150
- }
3151
- $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3074
+ 'number'() {
3075
+ $mol_assert_ok($mol_compare_deep(1, 1));
3076
+ $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
3077
+ $mol_assert_not($mol_compare_deep(1, 2));
3078
+ $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
3079
+ $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
3080
+ },
3081
+ 'POJO'() {
3082
+ $mol_assert_ok($mol_compare_deep({}, {}));
3083
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
3084
+ $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
3085
+ $mol_assert_not($mol_compare_deep({}, { a: undefined }));
3086
+ $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
3087
+ $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
3088
+ $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
3089
+ },
3090
+ 'Array'() {
3091
+ $mol_assert_ok($mol_compare_deep([], []));
3092
+ $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
3093
+ $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
3094
+ $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
3095
+ $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
3096
+ $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
3152
3097
  },
3153
- async 'Idempotence control'() {
3154
- class Idempotence extends $mol_object2 {
3155
- static logs_idemp = 0;
3156
- static logs_unidemp = 0;
3157
- static log_idemp() {
3158
- this.logs_idemp += 1;
3159
- }
3160
- static log_unidemp() {
3161
- this.logs_unidemp += 1;
3162
- }
3163
- static async val(a) {
3164
- return a;
3165
- }
3166
- static sum(a, b) {
3167
- this.log_idemp();
3168
- this.log_unidemp();
3169
- const syn = $mol_wire_sync(this);
3170
- return syn.val(a) + syn.val(b);
3171
- }
3172
- static async calc(a, b) {
3173
- return 5 + await $mol_wire_async(this).sum(a, b);
3174
- }
3098
+ 'Non POJO are different'() {
3099
+ class Thing extends Object {
3175
3100
  }
3176
- __decorate([
3177
- $mol_wire_method
3178
- ], Idempotence, "log_idemp", null);
3179
- $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3180
- $mol_assert_equal(Idempotence.logs_idemp, 1);
3181
- $mol_assert_equal(Idempotence.logs_unidemp, 3);
3101
+ $mol_assert_not($mol_compare_deep(new Thing, new Thing));
3102
+ $mol_assert_not($mol_compare_deep(() => 1, () => 1));
3103
+ $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
3182
3104
  },
3183
- async 'Error handling'() {
3184
- class Handle extends $mol_object2 {
3185
- static async sum(a, b) {
3186
- $mol_fail(new Error('test error ' + (a + b)));
3105
+ 'POJO with symbols'() {
3106
+ const sym = Symbol();
3107
+ $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
3108
+ $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
3109
+ },
3110
+ 'same POJOs with cyclic reference'() {
3111
+ const a = { foo: {} };
3112
+ a['self'] = a;
3113
+ const b = { foo: {} };
3114
+ b['self'] = b;
3115
+ $mol_assert_ok($mol_compare_deep(a, b));
3116
+ },
3117
+ 'same POJOs with cyclic reference with cache warmup'() {
3118
+ const obj1 = { test: 1, obj3: null };
3119
+ const obj1_copy = { test: 1, obj3: null };
3120
+ const obj2 = { test: 2, obj1 };
3121
+ const obj2_copy = { test: 2, obj1: obj1_copy };
3122
+ const obj3 = { test: 3, obj2 };
3123
+ const obj3_copy = { test: 3, obj2: obj2_copy };
3124
+ obj1.obj3 = obj3;
3125
+ obj1_copy.obj3 = obj3_copy;
3126
+ $mol_assert_not($mol_compare_deep(obj1, {}));
3127
+ $mol_assert_not($mol_compare_deep(obj2, {}));
3128
+ $mol_assert_not($mol_compare_deep(obj3, {}));
3129
+ $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
3130
+ },
3131
+ 'Date'() {
3132
+ $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
3133
+ $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
3134
+ },
3135
+ 'RegExp'() {
3136
+ $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
3137
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
3138
+ $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
3139
+ },
3140
+ 'Error'() {
3141
+ $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
3142
+ const fail = (message) => new Error(message);
3143
+ $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
3144
+ $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
3145
+ },
3146
+ 'Map'() {
3147
+ $mol_assert_ok($mol_compare_deep(new Map, new Map));
3148
+ $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
3149
+ $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
3150
+ $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
3151
+ $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
3152
+ },
3153
+ 'Set'() {
3154
+ $mol_assert_ok($mol_compare_deep(new Set, new Set));
3155
+ $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
3156
+ $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
3157
+ },
3158
+ 'Uint8Array'() {
3159
+ $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
3160
+ $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
3161
+ $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
3162
+ },
3163
+ 'DataView'() {
3164
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
3165
+ $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
3166
+ $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
3167
+ },
3168
+ 'Serializale'() {
3169
+ class User {
3170
+ name;
3171
+ rand;
3172
+ constructor(name, rand = Math.random()) {
3173
+ this.name = name;
3174
+ this.rand = rand;
3187
3175
  }
3188
- static check() {
3189
- try {
3190
- return $mol_wire_sync(Handle).sum(1, 2);
3191
- }
3192
- catch (error) {
3193
- if ($mol_promise_like(error))
3194
- $mol_fail_hidden(error);
3195
- $mol_assert_equal(error.message, 'test error 3');
3196
- }
3176
+ [Symbol.toPrimitive](mode) {
3177
+ return this.name;
3197
3178
  }
3198
3179
  }
3199
- await $mol_wire_async(Handle).check();
3180
+ $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
3181
+ $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
3182
+ },
3183
+ 'Iterable'() {
3184
+ $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
3185
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
3186
+ $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
3200
3187
  },
3201
3188
  });
3202
3189
  })($ || ($ = {}));
@@ -3205,246 +3192,290 @@ var $;
3205
3192
  "use strict";
3206
3193
  var $;
3207
3194
  (function ($) {
3208
- function $mol_wire_async(obj) {
3209
- let fiber;
3210
- const temp = $mol_wire_task.getter(obj);
3211
- return new Proxy(obj, {
3212
- get(obj, field) {
3213
- const val = obj[field];
3214
- if (typeof val !== 'function')
3215
- return val;
3216
- let fiber;
3217
- const temp = $mol_wire_task.getter(val);
3218
- return function $mol_wire_async(...args) {
3219
- fiber?.destructor();
3220
- fiber = temp(obj, args);
3221
- return fiber.async();
3222
- };
3223
- },
3224
- apply(obj, self, args) {
3225
- fiber?.destructor();
3226
- fiber = temp(self, args);
3227
- return fiber.async();
3228
- },
3229
- });
3195
+ function $mol_assert_ok(value) {
3196
+ if (value)
3197
+ return;
3198
+ $mol_fail(new Error(`${value} ≠ true`));
3230
3199
  }
3231
- $.$mol_wire_async = $mol_wire_async;
3232
- })($ || ($ = {}));
3233
-
3234
- ;
3235
- "use strict";
3236
- var $;
3237
- (function ($_1) {
3238
- $mol_test({
3239
- 'test types'($) {
3240
- class A {
3241
- static a() {
3242
- return '';
3243
- }
3244
- static b() {
3245
- return $mol_wire_async(this).a();
3246
- }
3200
+ $.$mol_assert_ok = $mol_assert_ok;
3201
+ function $mol_assert_not(value) {
3202
+ if (!value)
3203
+ return;
3204
+ $mol_fail(new Error(`${value} ≠ false`));
3205
+ }
3206
+ $.$mol_assert_not = $mol_assert_not;
3207
+ function $mol_assert_fail(handler, ErrorRight) {
3208
+ const fail = $.$mol_fail;
3209
+ try {
3210
+ $.$mol_fail = $.$mol_fail_hidden;
3211
+ handler();
3212
+ }
3213
+ catch (error) {
3214
+ $.$mol_fail = fail;
3215
+ if (typeof ErrorRight === 'string') {
3216
+ $mol_assert_equal(error.message ?? error, ErrorRight);
3247
3217
  }
3248
- },
3249
- async 'Latest method calls wins'($) {
3250
- class NameLogger extends $mol_object2 {
3251
- static $ = $;
3252
- static first = [];
3253
- static last = [];
3254
- static send(next) {
3255
- $mol_wire_sync(this.first).push(next);
3256
- $$.$mol_wait_timeout(0);
3257
- this.last.push(next);
3258
- }
3218
+ else {
3219
+ $mol_assert_equal(error instanceof ErrorRight, true);
3259
3220
  }
3260
- const name = $mol_wire_async(NameLogger).send;
3261
- name('john');
3262
- const promise = name('jin');
3263
- $.$mol_after_mock_warp();
3264
- await promise;
3265
- $mol_assert_equal(NameLogger.first, ['john', 'jin']);
3266
- $mol_assert_equal(NameLogger.last, ['jin']);
3267
- },
3268
- async 'Latest function calls wins'($) {
3269
- const first = [];
3270
- const last = [];
3271
- function send_name(next) {
3272
- $mol_wire_sync(first).push(next);
3273
- $$.$mol_wait_timeout(0);
3274
- last.push(next);
3221
+ return error;
3222
+ }
3223
+ finally {
3224
+ $.$mol_fail = fail;
3225
+ }
3226
+ $mol_fail(new Error('Not failed'));
3227
+ }
3228
+ $.$mol_assert_fail = $mol_assert_fail;
3229
+ function $mol_assert_like(...args) {
3230
+ $mol_assert_equal(...args);
3231
+ }
3232
+ $.$mol_assert_like = $mol_assert_like;
3233
+ function $mol_assert_unique(...args) {
3234
+ for (let i = 0; i < args.length; ++i) {
3235
+ for (let j = 0; j < args.length; ++j) {
3236
+ if (i === j)
3237
+ continue;
3238
+ if (!$mol_compare_deep(args[i], args[j]))
3239
+ continue;
3240
+ return $mol_fail(new Error(`Uniquesess assertion failure`, { cause: { [i]: args[i], [i]: args[i] } }));
3275
3241
  }
3276
- const name = $mol_wire_async(send_name);
3277
- name('john');
3278
- const promise = name('jin');
3279
- $.$mol_after_mock_warp();
3280
- await promise;
3281
- $mol_assert_equal(first, ['john', 'jin']);
3282
- $mol_assert_equal(last, ['jin']);
3283
- },
3284
- });
3242
+ }
3243
+ }
3244
+ $.$mol_assert_unique = $mol_assert_unique;
3245
+ function $mol_assert_equal(...args) {
3246
+ for (let i = 1; i < args.length; ++i) {
3247
+ if ($mol_compare_deep(args[0], args[i]))
3248
+ continue;
3249
+ return $mol_fail(new Error(`Equality assertion failure`, { cause: { 0: args[0], [i]: args[i] } }));
3250
+ }
3251
+ }
3252
+ $.$mol_assert_equal = $mol_assert_equal;
3285
3253
  })($ || ($ = {}));
3286
3254
 
3287
3255
  ;
3288
3256
  "use strict";
3289
3257
  var $;
3290
3258
  (function ($) {
3291
- function $mol_wire_method(host, field, descr) {
3292
- if (!descr)
3293
- descr = Reflect.getOwnPropertyDescriptor(host, field);
3294
- const orig = descr?.value ?? host[field];
3295
- const sup = Reflect.getPrototypeOf(host);
3296
- if (typeof sup[field] === 'function') {
3297
- Object.defineProperty(orig, 'name', { value: sup[field].name });
3298
- }
3299
- const temp = $mol_wire_task.getter(orig);
3300
- const value = function (...args) {
3301
- const fiber = temp(this ?? null, args);
3302
- return fiber.sync();
3303
- };
3304
- Object.defineProperty(value, 'name', { value: orig.name + ' ' });
3305
- Object.assign(value, { orig });
3306
- const descr2 = { ...descr, value };
3307
- Reflect.defineProperty(host, field, descr2);
3308
- return descr2;
3309
- }
3310
- $.$mol_wire_method = $mol_wire_method;
3259
+ $mol_test({
3260
+ 'must be false'() {
3261
+ $mol_assert_not(0);
3262
+ },
3263
+ 'must be true'() {
3264
+ $mol_assert_ok(1);
3265
+ },
3266
+ 'two must be equal'() {
3267
+ $mol_assert_equal(2, 2);
3268
+ },
3269
+ 'three must be equal'() {
3270
+ $mol_assert_equal(2, 2, 2);
3271
+ },
3272
+ 'two must be unique'() {
3273
+ $mol_assert_unique([2], [3]);
3274
+ },
3275
+ 'three must be unique'() {
3276
+ $mol_assert_unique([1], [2], [3]);
3277
+ },
3278
+ 'two must be alike'() {
3279
+ $mol_assert_equal([3], [3]);
3280
+ },
3281
+ 'three must be alike'() {
3282
+ $mol_assert_equal([3], [3], [3]);
3283
+ },
3284
+ 'two object must be alike'() {
3285
+ $mol_assert_equal({ a: 1 }, { a: 1 });
3286
+ },
3287
+ 'three object must be alike'() {
3288
+ $mol_assert_equal({ a: 1 }, { a: 1 }, { a: 1 });
3289
+ },
3290
+ });
3311
3291
  })($ || ($ = {}));
3312
3292
 
3313
3293
  ;
3314
3294
  "use strict";
3315
3295
  var $;
3316
- (function ($_1) {
3296
+ (function ($) {
3317
3297
  $mol_test({
3318
- 'test types'($) {
3319
- class A {
3320
- static a() {
3321
- return Promise.resolve('');
3322
- }
3323
- static b() {
3324
- return $mol_wire_sync(this).a();
3325
- }
3298
+ async 'put, get, drop, count records and clear store'() {
3299
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
3300
+ const trans = db.change('letters');
3301
+ try {
3302
+ const { letters } = trans.stores;
3303
+ $mol_assert_like(await letters.get(1), undefined);
3304
+ $mol_assert_like(await letters.get(2), undefined);
3305
+ $mol_assert_like(await letters.count(), 0);
3306
+ await letters.put('a');
3307
+ await letters.put('b', 1);
3308
+ await letters.put('c', 2);
3309
+ $mol_assert_like(await letters.get(1), 'b');
3310
+ $mol_assert_like(await letters.get(2), 'c');
3311
+ $mol_assert_like(await letters.count(), 2);
3312
+ await letters.drop(1);
3313
+ $mol_assert_like(await letters.get(1), undefined);
3314
+ $mol_assert_like(await letters.count(), 1);
3315
+ await letters.clear();
3316
+ $mol_assert_like(await letters.count(), 0);
3326
3317
  }
3327
- },
3328
- async 'test method from host'($) {
3329
- let count = 0;
3330
- class A {
3331
- static a() {
3332
- return $mol_wire_sync(this).b();
3333
- }
3334
- static b() { return Promise.resolve(++count); }
3318
+ finally {
3319
+ trans.abort();
3320
+ db.kill();
3335
3321
  }
3336
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
3337
3322
  },
3338
- async 'test function'($) {
3339
- let count = 0;
3340
- class A {
3341
- static a() {
3342
- return $mol_wire_sync(this.b)();
3343
- }
3344
- static b() { return Promise.resolve(++count); }
3323
+ async 'select by query'() {
3324
+ const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
3325
+ const trans = db.change('letters');
3326
+ try {
3327
+ const { letters } = trans.stores;
3328
+ await letters.put('a');
3329
+ await letters.put('b');
3330
+ await letters.put('c');
3331
+ await letters.put('d');
3332
+ $mol_assert_like(await letters.select(), ['a', 'b', 'c', 'd']);
3333
+ $mol_assert_like(await letters.select(null, 2), ['a', 'b']);
3334
+ $mol_assert_like(await letters.select($mol_dom_context.IDBKeyRange.bound(2, 3)), ['b', 'c']);
3345
3335
  }
3346
- $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
3347
- },
3348
- async 'test construct itself'($) {
3349
- class A {
3350
- static instances = [];
3351
- static a() {
3352
- const a = new ($mol_wire_sync(A))();
3353
- this.instances.push(a);
3354
- $mol_wire_sync(this).b();
3355
- }
3356
- static b() { return Promise.resolve(); }
3336
+ finally {
3337
+ trans.abort();
3338
+ db.kill();
3357
3339
  }
3358
- await $mol_wire_async(A).a();
3359
- $mol_assert_equal(A.instances.length, 2);
3360
- $mol_assert_equal(A.instances[0] instanceof A, true);
3361
- $mol_assert_equal(A.instances[0], A.instances[1]);
3362
- }
3340
+ },
3363
3341
  });
3364
3342
  })($ || ($ = {}));
3365
3343
 
3366
3344
  ;
3367
3345
  "use strict";
3368
3346
  var $;
3369
- (function ($) {
3370
- class $mol_promise extends Promise {
3371
- done;
3372
- fail;
3373
- constructor(executor) {
3374
- let done;
3375
- let fail;
3376
- super((d, f) => {
3377
- done = d;
3378
- fail = f;
3379
- executor?.(d, f);
3380
- });
3381
- this.done = done;
3382
- this.fail = fail;
3383
- }
3384
- }
3385
- $.$mol_promise = $mol_promise;
3347
+ (function ($_1) {
3348
+ $mol_test_mocks.push($ => {
3349
+ $.$mol_log3_come = () => { };
3350
+ $.$mol_log3_done = () => { };
3351
+ $.$mol_log3_fail = () => { };
3352
+ $.$mol_log3_warn = () => { };
3353
+ $.$mol_log3_rise = () => { };
3354
+ $.$mol_log3_area = () => () => { };
3355
+ });
3386
3356
  })($ || ($ = {}));
3387
3357
 
3388
3358
  ;
3389
3359
  "use strict";
3390
- var $;
3391
- (function ($) {
3392
- class $mol_after_timeout extends $mol_object2 {
3393
- delay;
3394
- task;
3395
- id;
3396
- constructor(delay, task) {
3397
- super();
3398
- this.delay = delay;
3399
- this.task = task;
3400
- this.id = setTimeout(task, delay);
3401
- }
3402
- destructor() {
3403
- clearTimeout(this.id);
3404
- }
3405
- }
3406
- $.$mol_after_timeout = $mol_after_timeout;
3407
- })($ || ($ = {}));
3408
3360
 
3409
3361
  ;
3410
3362
  "use strict";
3411
- var $;
3412
- (function ($_1) {
3413
- $mol_test_mocks.push($ => {
3414
- $.$mol_after_timeout = $mol_after_mock_timeout;
3415
- });
3416
- })($ || ($ = {}));
3363
+
3364
+ ;
3365
+ "use strict";
3417
3366
 
3418
3367
  ;
3419
3368
  "use strict";
3420
3369
  var $;
3421
3370
  (function ($) {
3422
- class $mol_after_work extends $mol_object2 {
3423
- delay;
3424
- task;
3425
- id;
3426
- constructor(delay, task) {
3427
- super();
3428
- this.delay = delay;
3429
- this.task = task;
3430
- this.id = requestIdleCallback(task, { timeout: delay });
3431
- }
3432
- destructor() {
3433
- cancelIdleCallback(this.id);
3434
- }
3435
- }
3436
- $.$mol_after_work = $mol_after_work;
3437
- if (typeof requestIdleCallback !== 'function') {
3438
- $.$mol_after_work = $mol_after_timeout;
3439
- }
3371
+ $mol_test({
3372
+ 'get'() {
3373
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3374
+ $mol_assert_equal(proxy.foo, 777);
3375
+ },
3376
+ 'has'() {
3377
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3378
+ $mol_assert_equal('foo' in proxy, true);
3379
+ },
3380
+ 'set'() {
3381
+ const target = { foo: 777 };
3382
+ const proxy = $mol_delegate({}, () => target);
3383
+ proxy.foo = 123;
3384
+ $mol_assert_equal(target.foo, 123);
3385
+ },
3386
+ 'getOwnPropertyDescriptor'() {
3387
+ const proxy = $mol_delegate({}, () => ({ foo: 777 }));
3388
+ $mol_assert_like(Object.getOwnPropertyDescriptor(proxy, 'foo'), {
3389
+ value: 777,
3390
+ writable: true,
3391
+ enumerable: true,
3392
+ configurable: true,
3393
+ });
3394
+ },
3395
+ 'ownKeys'() {
3396
+ const proxy = $mol_delegate({}, () => ({ foo: 777, [Symbol.toStringTag]: 'bar' }));
3397
+ $mol_assert_like(Reflect.ownKeys(proxy), ['foo', Symbol.toStringTag]);
3398
+ },
3399
+ 'getPrototypeOf'() {
3400
+ class Foo {
3401
+ }
3402
+ const proxy = $mol_delegate({}, () => new Foo);
3403
+ $mol_assert_equal(Object.getPrototypeOf(proxy), Foo.prototype);
3404
+ },
3405
+ 'setPrototypeOf'() {
3406
+ class Foo {
3407
+ }
3408
+ const target = {};
3409
+ const proxy = $mol_delegate({}, () => target);
3410
+ Object.setPrototypeOf(proxy, Foo.prototype);
3411
+ $mol_assert_equal(Object.getPrototypeOf(target), Foo.prototype);
3412
+ },
3413
+ 'instanceof'() {
3414
+ class Foo {
3415
+ }
3416
+ const proxy = $mol_delegate({}, () => new Foo);
3417
+ $mol_assert_ok(proxy instanceof Foo);
3418
+ $mol_assert_ok(proxy instanceof $mol_delegate);
3419
+ },
3420
+ 'autobind'() {
3421
+ class Foo {
3422
+ }
3423
+ const proxy = $mol_delegate({}, () => new Foo);
3424
+ $mol_assert_ok(proxy instanceof Foo);
3425
+ $mol_assert_ok(proxy instanceof $mol_delegate);
3426
+ },
3427
+ });
3440
3428
  })($ || ($ = {}));
3441
3429
 
3442
3430
  ;
3443
3431
  "use strict";
3444
3432
  var $;
3445
3433
  (function ($_1) {
3446
- $mol_test_mocks.push($ => {
3447
- $.$mol_after_work = $mol_after_mock_timeout;
3434
+ $mol_test({
3435
+ 'span for same uri'($) {
3436
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3437
+ const child = span.span(4, 5, 8);
3438
+ $mol_assert_equal(child.uri, 'test.ts');
3439
+ $mol_assert_equal(child.row, 4);
3440
+ $mol_assert_equal(child.col, 5);
3441
+ $mol_assert_equal(child.length, 8);
3442
+ },
3443
+ 'span after of given position'($) {
3444
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3445
+ const child = span.after(11);
3446
+ $mol_assert_equal(child.uri, 'test.ts');
3447
+ $mol_assert_equal(child.row, 1);
3448
+ $mol_assert_equal(child.col, 7);
3449
+ $mol_assert_equal(child.length, 11);
3450
+ },
3451
+ 'slice span - regular'($) {
3452
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3453
+ const child = span.slice(1, 4);
3454
+ $mol_assert_equal(child.row, 1);
3455
+ $mol_assert_equal(child.col, 4);
3456
+ $mol_assert_equal(child.length, 3);
3457
+ const child2 = span.slice(2, 2);
3458
+ $mol_assert_equal(child2.col, 5);
3459
+ $mol_assert_equal(child2.length, 0);
3460
+ },
3461
+ 'slice span - negative'($) {
3462
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3463
+ const child = span.slice(-3, -1);
3464
+ $mol_assert_equal(child.row, 1);
3465
+ $mol_assert_equal(child.col, 5);
3466
+ $mol_assert_equal(child.length, 2);
3467
+ },
3468
+ 'slice span - out of range'($) {
3469
+ const span = new $mol_span('test.ts', '', 1, 3, 5);
3470
+ $mol_assert_fail(() => span.slice(-1, 3), `End value '3' can't be less than begin value (test.ts#1:3/5)`);
3471
+ $mol_assert_fail(() => span.slice(1, 6), `End value '6' out of range (test.ts#1:3/5)`);
3472
+ $mol_assert_fail(() => span.slice(1, 10), `End value '10' out of range (test.ts#1:3/5)`);
3473
+ },
3474
+ 'error handling'($) {
3475
+ const span = new $mol_span('test.ts', '', 1, 3, 4);
3476
+ const error = span.error('Some error');
3477
+ $mol_assert_equal(error.message, 'Some error (test.ts#1:3/4)');
3478
+ }
3448
3479
  });
3449
3480
  })($ || ($ = {}));
3450
3481
 
@@ -3452,60 +3483,107 @@ var $;
3452
3483
  "use strict";
3453
3484
  var $;
3454
3485
  (function ($) {
3455
- function $mol_wait_rest_async() {
3456
- return new Promise(done => {
3457
- new this.$mol_after_work(16, () => done(null));
3458
- });
3459
- }
3460
- $.$mol_wait_rest_async = $mol_wait_rest_async;
3461
- function $mol_wait_rest() {
3462
- return this.$mol_wire_sync(this).$mol_wait_rest_async();
3463
- }
3464
- $.$mol_wait_rest = $mol_wait_rest;
3486
+ $mol_test({
3487
+ 'all cases of using maybe'() {
3488
+ $mol_assert_equal($mol_maybe(0)[0], 0);
3489
+ $mol_assert_equal($mol_maybe(false)[0], false);
3490
+ $mol_assert_equal($mol_maybe(null)[0], void 0);
3491
+ $mol_assert_equal($mol_maybe(void 0)[0], void 0);
3492
+ $mol_assert_equal($mol_maybe(void 0).map(v => v.toString())[0], void 0);
3493
+ $mol_assert_equal($mol_maybe(0).map(v => v.toString())[0], '0');
3494
+ },
3495
+ });
3465
3496
  })($ || ($ = {}));
3466
3497
 
3467
3498
  ;
3468
3499
  "use strict";
3469
3500
  var $;
3470
3501
  (function ($_1) {
3471
- var $$;
3472
- (function ($$) {
3473
- $mol_test_mocks.push($ => {
3474
- $.$mol_wait_timeout = function $mol_wait_timeout_mock(timeout) { };
3475
- $.$mol_wait_timeout_async = async function $mol_wait_timeout_async_mock(timeout) { };
3476
- });
3477
- })($$ = $_1.$$ || ($_1.$$ = {}));
3478
- })($ || ($ = {}));
3479
-
3480
- ;
3481
- "use strict";
3482
- var $;
3483
- (function ($) {
3484
- function $mol_wait_timeout_async(timeout) {
3485
- const promise = new $mol_promise();
3486
- const task = new this.$mol_after_timeout(timeout, () => promise.done());
3487
- return Object.assign(promise, {
3488
- destructor: () => task.destructor()
3489
- });
3490
- }
3491
- $.$mol_wait_timeout_async = $mol_wait_timeout_async;
3492
- function $mol_wait_timeout(timeout) {
3493
- return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
3502
+ function check(tree, ideal) {
3503
+ $mol_assert_equal(tree.toString(), $$.$mol_tree2_from_string(ideal).toString());
3494
3504
  }
3495
- $.$mol_wait_timeout = $mol_wait_timeout;
3496
- })($ || ($ = {}));
3497
-
3498
- ;
3499
- "use strict";
3500
- var $;
3501
- (function ($_1) {
3502
- var $$;
3503
- (function ($$) {
3504
- $mol_test_mocks.push($ => {
3505
- $.$mol_wait_rest = function $mol_wait_rest_mock() { };
3506
- $.$mol_wait_rest_async = async function $mol_wait_rest_async_mock() { };
3507
- });
3508
- })($$ = $_1.$$ || ($_1.$$ = {}));
3505
+ $mol_test({
3506
+ 'inserting'($) {
3507
+ check($.$mol_tree2_from_string(`
3508
+ a b c d
3509
+ `).insert($mol_tree2.struct('x'), 'a', 'b', 'c'), `
3510
+ a b x
3511
+ `);
3512
+ check($.$mol_tree2_from_string(`
3513
+ a b
3514
+ `).insert($mol_tree2.struct('x'), 'a', 'b', 'c', 'd'), `
3515
+ a b c x
3516
+ `);
3517
+ check($.$mol_tree2_from_string(`
3518
+ a b c d
3519
+ `)
3520
+ .insert($mol_tree2.struct('x'), 0, 0, 0), `
3521
+ a b x
3522
+ `);
3523
+ check($.$mol_tree2_from_string(`
3524
+ a b
3525
+ `)
3526
+ .insert($mol_tree2.struct('x'), 0, 0, 0, 0), `
3527
+ a b \\
3528
+ x
3529
+ `);
3530
+ check($.$mol_tree2_from_string(`
3531
+ a b c d
3532
+ `)
3533
+ .insert($mol_tree2.struct('x'), null, null, null), `
3534
+ a b x
3535
+ `);
3536
+ check($.$mol_tree2_from_string(`
3537
+ a b
3538
+ `)
3539
+ .insert($mol_tree2.struct('x'), null, null, null, null), `
3540
+ a b \\
3541
+ x
3542
+ `);
3543
+ },
3544
+ 'updating'($) {
3545
+ check($.$mol_tree2_from_string(`
3546
+ a b c d
3547
+ `).update([], 'a', 'b', 'c')[0], `
3548
+ a b
3549
+ `);
3550
+ check($.$mol_tree2_from_string(`
3551
+ a b c d
3552
+ `).update([$mol_tree2.struct('x')])[0], `
3553
+ x
3554
+ `);
3555
+ check($.$mol_tree2_from_string(`
3556
+ a b c d
3557
+ `).update([$mol_tree2.struct('x'), $mol_tree2.struct('y')], 'a', 'b', 'c')[0], `
3558
+ a b
3559
+ x
3560
+ y
3561
+ `);
3562
+ },
3563
+ 'deleting'($) {
3564
+ const base = $.$mol_tree2_from_string(`
3565
+ a b c d
3566
+ `);
3567
+ check(base.insert(null, 'a', 'b', 'c'), `
3568
+ a b
3569
+ `);
3570
+ check(base.update(base.select('a', 'b', 'c', null).kids, 'a', 'b', 'c')[0], `
3571
+ a b d
3572
+ `);
3573
+ check(base.insert(null, 0, 0, 0), `
3574
+ a b
3575
+ `);
3576
+ },
3577
+ 'hack'($) {
3578
+ const res = $.$mol_tree2_from_string(`
3579
+ foo bar xxx
3580
+ `)
3581
+ .hack({
3582
+ 'bar': (input, belt) => [input.struct('777', input.hack(belt))],
3583
+ });
3584
+ $mol_assert_equal(res.map(String), ['foo 777 xxx\n']);
3585
+ },
3586
+ });
3509
3587
  })($ || ($ = {}));
3510
3588
 
3511
3589
  ;
@@ -3513,52 +3591,68 @@ var $;
3513
3591
  var $;
3514
3592
  (function ($_1) {
3515
3593
  $mol_test({
3516
- async 'exec timeout auto kill child process'($) {
3517
- let close_mock = () => { };
3518
- const error_message = 'Run error, timeout';
3519
- function mol_run_spawn_sync_mock() {
3520
- return {
3521
- output: [],
3522
- stdout: error_message,
3523
- stderr: '',
3524
- status: 0,
3525
- signal: null,
3526
- pid: 123,
3527
- };
3528
- }
3529
- function mol_run_spawn_mock() {
3530
- return {
3531
- on(name, cb) {
3532
- if (name === 'exit')
3533
- close_mock = cb;
3534
- },
3535
- kill() { close_mock(); }
3536
- };
3537
- }
3538
- const context_mock = $.$mol_ambient({
3539
- $mol_run_spawn_sync: mol_run_spawn_sync_mock,
3540
- $mol_run_spawn: mol_run_spawn_mock
3541
- });
3542
- class $mol_run_mock extends $mol_run {
3543
- static get $() { return context_mock; }
3544
- static async_enabled() {
3545
- return true;
3594
+ 'tree parsing'($) {
3595
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids.length, 2);
3596
+ $mol_assert_equal($.$mol_tree2_from_string("foo\nbar\n").kids[1].type, "bar");
3597
+ $mol_assert_equal($.$mol_tree2_from_string("foo\n\n\n").kids.length, 1);
3598
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids.length, 2);
3599
+ $mol_assert_equal($.$mol_tree2_from_string("=foo\n\\bar\n").kids[1].value, "bar");
3600
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar \\pol\n").kids[0].kids[0].kids[0].value, "pol");
3601
+ $mol_assert_equal($.$mol_tree2_from_string("foo bar\n\t\\pol\n\t\\men\n").kids[0].kids[0].kids[1].value, "men");
3602
+ $mol_assert_equal($.$mol_tree2_from_string('foo bar \\text\n').toString(), 'foo bar \\text\n');
3603
+ },
3604
+ 'Too many tabs'($) {
3605
+ const tree = `
3606
+ foo
3607
+ bar
3608
+ `;
3609
+ $mol_assert_fail(() => {
3610
+ $.$mol_tree2_from_string(tree, 'test');
3611
+ }, 'Too many tabs\ntest#3:1/6\n!!!!!!\n\t\t\t\t\t\tbar');
3612
+ },
3613
+ 'Too few tabs'($) {
3614
+ const tree = `
3615
+ foo
3616
+ bar
3617
+ `;
3618
+ $mol_assert_fail(() => {
3619
+ $.$mol_tree2_from_string(tree, 'test');
3620
+ }, 'Too few tabs\ntest#3:1/4\n!!!!\n\t\t\t\tbar');
3621
+ },
3622
+ 'Wrong nodes separator at start'($) {
3623
+ const tree = `foo\n \tbar\n`;
3624
+ $mol_assert_fail(() => {
3625
+ $.$mol_tree2_from_string(tree, 'test');
3626
+ }, 'Wrong nodes separator\ntest#2:1/2\n!!\n \tbar');
3627
+ },
3628
+ 'Wrong nodes separator in the middle'($) {
3629
+ const tree = `foo bar\n`;
3630
+ $mol_assert_fail(() => {
3631
+ $.$mol_tree2_from_string(tree, 'test');
3632
+ }, 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar');
3633
+ },
3634
+ 'Unexpected EOF, LF required'($) {
3635
+ const tree = ` foo`;
3636
+ $mol_assert_fail(() => {
3637
+ $.$mol_tree2_from_string(tree, 'test');
3638
+ }, 'Unexpected EOF, LF required\ntest#1:5/1\n !\n foo');
3639
+ },
3640
+ 'Errors skip and collect'($) {
3641
+ const tree = `foo bar`;
3642
+ const errors = [];
3643
+ const $$ = $.$mol_ambient({
3644
+ $mol_fail: (error) => {
3645
+ errors.push(error.message);
3646
+ return null;
3546
3647
  }
3547
- }
3548
- let message = '';
3549
- try {
3550
- const res = await $mol_wire_async($mol_run_mock).spawn({
3551
- command: 'sleep 10',
3552
- dir: '.',
3553
- timeout: 10,
3554
- env: { 'MOL_RUN_ASYNC': '1' }
3555
- });
3556
- }
3557
- catch (e) {
3558
- message = e.message;
3559
- }
3560
- $mol_assert_equal(message, error_message);
3561
- }
3648
+ });
3649
+ const res = $$.$mol_tree2_from_string(tree, 'test');
3650
+ $mol_assert_like(errors, [
3651
+ 'Wrong nodes separator\ntest#1:5/1\n !\nfoo bar',
3652
+ 'Unexpected EOF, LF required\ntest#1:9/1\n !\nfoo bar',
3653
+ ]);
3654
+ $mol_assert_equal(res.toString(), 'foo bar\n');
3655
+ },
3562
3656
  });
3563
3657
  })($ || ($ = {}));
3564
3658
 
@@ -3567,48 +3661,13 @@ var $;
3567
3661
  var $;
3568
3662
  (function ($) {
3569
3663
  $mol_test({
3570
- async 'put, get, drop, count records and clear store'() {
3571
- const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
3572
- const trans = db.change('letters');
3573
- try {
3574
- const { letters } = trans.stores;
3575
- $mol_assert_like(await letters.get(1), undefined);
3576
- $mol_assert_like(await letters.get(2), undefined);
3577
- $mol_assert_like(await letters.count(), 0);
3578
- await letters.put('a');
3579
- await letters.put('b', 1);
3580
- await letters.put('c', 2);
3581
- $mol_assert_like(await letters.get(1), 'b');
3582
- $mol_assert_like(await letters.get(2), 'c');
3583
- $mol_assert_like(await letters.count(), 2);
3584
- await letters.drop(1);
3585
- $mol_assert_like(await letters.get(1), undefined);
3586
- $mol_assert_like(await letters.count(), 1);
3587
- await letters.clear();
3588
- $mol_assert_like(await letters.count(), 0);
3589
- }
3590
- finally {
3591
- trans.abort();
3592
- db.kill();
3593
- }
3594
- },
3595
- async 'select by query'() {
3596
- const db = await $$.$mol_db('$mol_db_test', mig => mig.store_make('letters'));
3597
- const trans = db.change('letters');
3598
- try {
3599
- const { letters } = trans.stores;
3600
- await letters.put('a');
3601
- await letters.put('b');
3602
- await letters.put('c');
3603
- await letters.put('d');
3604
- $mol_assert_like(await letters.select(), ['a', 'b', 'c', 'd']);
3605
- $mol_assert_like(await letters.select(null, 2), ['a', 'b']);
3606
- $mol_assert_like(await letters.select($mol_dom_context.IDBKeyRange.bound(2, 3)), ['b', 'c']);
3607
- }
3608
- finally {
3609
- trans.abort();
3610
- db.kill();
3611
- }
3664
+ 'fromJSON'() {
3665
+ $mol_assert_equal($mol_tree2_from_json([]).toString(), '/\n');
3666
+ $mol_assert_equal($mol_tree2_from_json([false, true]).toString(), '/\n\tfalse\n\ttrue\n');
3667
+ $mol_assert_equal($mol_tree2_from_json([0, 1, 2.3]).toString(), '/\n\t0\n\t1\n\t2.3\n');
3668
+ $mol_assert_equal($mol_tree2_from_json(new Uint16Array([1, 10, 256])).toString(), '\\\x01\x00\n\\\x00\x00\x01\n');
3669
+ $mol_assert_equal($mol_tree2_from_json(['', 'foo', 'bar\nbaz']).toString(), '/\n\t\\\n\t\\foo\n\t\\\n\t\t\\bar\n\t\t\\baz\n');
3670
+ $mol_assert_equal($mol_tree2_from_json({ 'foo': false, 'bar\nbaz': 'lol' }).toString(), '*\n\tfoo false\n\t\\\n\t\t\\bar\n\t\t\\baz\n\t\t\\lol\n');
3612
3671
  },
3613
3672
  });
3614
3673
  })($ || ($ = {}));
@@ -3616,194 +3675,179 @@ var $;
3616
3675
  ;
3617
3676
  "use strict";
3618
3677
  var $;
3619
- (function ($) {
3620
- function $mol_dom_render_children(el, childNodes) {
3621
- const node_set = new Set(childNodes);
3622
- let nextNode = el.firstChild;
3623
- for (let view of childNodes) {
3624
- if (view == null)
3625
- continue;
3626
- if (view instanceof $mol_dom_context.Node) {
3627
- while (true) {
3628
- if (!nextNode) {
3629
- el.appendChild(view);
3630
- break;
3631
- }
3632
- if (nextNode == view) {
3633
- nextNode = nextNode.nextSibling;
3634
- break;
3635
- }
3636
- else {
3637
- if (node_set.has(nextNode)) {
3638
- el.insertBefore(view, nextNode);
3639
- break;
3640
- }
3641
- else {
3642
- const nn = nextNode.nextSibling;
3643
- el.removeChild(nextNode);
3644
- nextNode = nn;
3645
- }
3646
- }
3647
- }
3648
- }
3649
- else {
3650
- if (nextNode && nextNode.nodeName === '#text') {
3651
- const str = String(view);
3652
- if (nextNode.nodeValue !== str)
3653
- nextNode.nodeValue = str;
3654
- nextNode = nextNode.nextSibling;
3655
- }
3656
- else {
3657
- const textNode = $mol_dom_context.document.createTextNode(String(view));
3658
- el.insertBefore(textNode, nextNode);
3659
- }
3660
- }
3661
- }
3662
- while (nextNode) {
3663
- const currNode = nextNode;
3664
- nextNode = currNode.nextSibling;
3665
- el.removeChild(currNode);
3666
- }
3667
- }
3668
- $.$mol_dom_render_children = $mol_dom_render_children;
3678
+ (function ($_1) {
3679
+ $mol_test({
3680
+ 'FQN of anon function'($) {
3681
+ const $$ = Object.assign($, { $mol_func_name_test: (() => () => { })() });
3682
+ $mol_assert_equal($$.$mol_func_name_test.name, '');
3683
+ $mol_assert_equal($$.$mol_func_name($$.$mol_func_name_test), '$mol_func_name_test');
3684
+ $mol_assert_equal($$.$mol_func_name_test.name, '$mol_func_name_test');
3685
+ },
3686
+ });
3669
3687
  })($ || ($ = {}));
3670
3688
 
3671
- ;
3672
- "use strict";
3673
-
3674
- ;
3675
- "use strict";
3676
-
3677
3689
  ;
3678
3690
  "use strict";
3679
3691
  var $;
3680
3692
  (function ($) {
3681
- function $mol_dom_serialize(node) {
3682
- const serializer = new $mol_dom_context.XMLSerializer;
3683
- return serializer.serializeToString(node);
3684
- }
3685
- $.$mol_dom_serialize = $mol_dom_serialize;
3693
+ $mol_test({
3694
+ 'auto name'() {
3695
+ class Invalid extends $mol_error_mix {
3696
+ }
3697
+ const mix = new Invalid('foo');
3698
+ $mol_assert_equal(mix.name, 'Invalid_Error');
3699
+ },
3700
+ 'simpe mix'() {
3701
+ const mix = new $mol_error_mix('foo', {}, new Error('bar'), new Error('lol'));
3702
+ $mol_assert_equal(mix.message, 'foo');
3703
+ $mol_assert_equal(mix.errors.map(e => e.message), ['bar', 'lol']);
3704
+ },
3705
+ 'provide additional info'() {
3706
+ class Invalid extends $mol_error_mix {
3707
+ }
3708
+ const mix = new $mol_error_mix('Wrong password', {}, new Invalid('Too short', { value: 'p@ssw0rd', hint: '> 8 letters' }), new Invalid('Too simple', { value: 'p@ssw0rd', hint: 'need capital letter' }));
3709
+ const hints = [];
3710
+ if (mix instanceof $mol_error_mix) {
3711
+ for (const er of mix.errors) {
3712
+ if (er instanceof Invalid) {
3713
+ hints.push(er.cause?.hint ?? '');
3714
+ }
3715
+ }
3716
+ }
3717
+ $mol_assert_equal(hints, ['> 8 letters', 'need capital letter']);
3718
+ },
3719
+ });
3686
3720
  })($ || ($ = {}));
3687
3721
 
3688
3722
  ;
3689
3723
  "use strict";
3690
3724
  var $;
3691
- (function ($) {
3692
- $.$mol_jsx_prefix = '';
3693
- $.$mol_jsx_crumbs = '';
3694
- $.$mol_jsx_booked = null;
3695
- $.$mol_jsx_document = {
3696
- getElementById: () => null,
3697
- createElementNS: (space, name) => $mol_dom_context.document.createElementNS(space, name),
3698
- createDocumentFragment: () => $mol_dom_context.document.createDocumentFragment(),
3699
- };
3700
- $.$mol_jsx_frag = '';
3701
- function $mol_jsx(Elem, props, ...childNodes) {
3702
- const id = props && props.id || '';
3703
- const guid = id ? $.$mol_jsx_prefix ? $.$mol_jsx_prefix + '/' + id : id : $.$mol_jsx_prefix;
3704
- const crumbs_self = id ? $.$mol_jsx_crumbs.replace(/(\S+)/g, `$1_${id.replace(/\/.*/i, '')}`) : $.$mol_jsx_crumbs;
3705
- if (Elem && $.$mol_jsx_booked) {
3706
- if ($.$mol_jsx_booked.has(id)) {
3707
- $mol_fail(new Error(`JSX already has tag with id ${JSON.stringify(guid)}`));
3725
+ (function ($_1) {
3726
+ $mol_test({
3727
+ 'init with overload'() {
3728
+ class X extends $mol_object {
3729
+ foo() {
3730
+ return 1;
3731
+ }
3708
3732
  }
3709
- else {
3710
- $.$mol_jsx_booked.add(id);
3733
+ var x = X.make({
3734
+ foo: () => 2,
3735
+ });
3736
+ $mol_assert_equal(x.foo(), 2);
3737
+ },
3738
+ 'Context in instance inherits from class'($) {
3739
+ const custom = $.$mol_ambient({});
3740
+ class X extends $.$mol_object {
3741
+ static $ = custom;
3711
3742
  }
3712
- }
3713
- let node = guid ? $.$mol_jsx_document.getElementById(guid) : null;
3714
- if ($.$mol_jsx_prefix) {
3715
- const prefix_ext = $.$mol_jsx_prefix;
3716
- const booked_ext = $.$mol_jsx_booked;
3717
- const crumbs_ext = $.$mol_jsx_crumbs;
3718
- for (const field in props) {
3719
- const func = props[field];
3720
- if (typeof func !== 'function')
3721
- continue;
3722
- const wrapper = function (...args) {
3723
- const prefix = $.$mol_jsx_prefix;
3724
- const booked = $.$mol_jsx_booked;
3725
- const crumbs = $.$mol_jsx_crumbs;
3726
- try {
3727
- $.$mol_jsx_prefix = prefix_ext;
3728
- $.$mol_jsx_booked = booked_ext;
3729
- $.$mol_jsx_crumbs = crumbs_ext;
3730
- return func.call(this, ...args);
3731
- }
3732
- finally {
3733
- $.$mol_jsx_prefix = prefix;
3734
- $.$mol_jsx_booked = booked;
3735
- $.$mol_jsx_crumbs = crumbs;
3736
- }
3737
- };
3738
- $mol_func_name_from(wrapper, func);
3739
- props[field] = wrapper;
3743
+ $mol_assert_equal(new X().$, custom);
3744
+ },
3745
+ });
3746
+ })($ || ($ = {}));
3747
+
3748
+ ;
3749
+ "use strict";
3750
+ var $;
3751
+ (function ($_1) {
3752
+ $mol_test({
3753
+ 'Collect deps'() {
3754
+ const pub1 = new $mol_wire_pub;
3755
+ const pub2 = new $mol_wire_pub;
3756
+ const sub = new $mol_wire_pub_sub;
3757
+ const bu1 = sub.track_on();
3758
+ try {
3759
+ pub1.promote();
3760
+ pub2.promote();
3761
+ pub2.promote();
3740
3762
  }
3741
- }
3742
- if (typeof Elem !== 'string') {
3743
- if ('prototype' in Elem) {
3744
- const view = node && node[String(Elem)] || new Elem;
3745
- Object.assign(view, props);
3746
- view[Symbol.toStringTag] = guid;
3747
- view.childNodes = childNodes;
3748
- if (!view.ownerDocument)
3749
- view.ownerDocument = $.$mol_jsx_document;
3750
- view.className = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3751
- node = view.valueOf();
3752
- node[String(Elem)] = view;
3753
- return node;
3763
+ finally {
3764
+ sub.track_cut();
3765
+ sub.track_off(bu1);
3754
3766
  }
3755
- else {
3756
- const prefix = $.$mol_jsx_prefix;
3757
- const booked = $.$mol_jsx_booked;
3758
- const crumbs = $.$mol_jsx_crumbs;
3767
+ pub1.emit();
3768
+ pub2.emit();
3769
+ $mol_assert_like(sub.pub_list, [pub1, pub2, pub2]);
3770
+ const bu2 = sub.track_on();
3771
+ try {
3772
+ pub1.promote();
3773
+ pub1.promote();
3774
+ pub2.promote();
3775
+ }
3776
+ finally {
3777
+ sub.track_cut();
3778
+ sub.track_off(bu2);
3779
+ }
3780
+ pub1.emit();
3781
+ pub2.emit();
3782
+ $mol_assert_like(sub.pub_list, [pub1, pub1, pub2]);
3783
+ },
3784
+ 'cyclic detection'($) {
3785
+ const sub1 = new $mol_wire_pub_sub;
3786
+ const sub2 = new $mol_wire_pub_sub;
3787
+ const bu1 = sub1.track_on();
3788
+ try {
3789
+ const bu2 = sub2.track_on();
3759
3790
  try {
3760
- $.$mol_jsx_prefix = guid;
3761
- $.$mol_jsx_booked = new Set;
3762
- $.$mol_jsx_crumbs = (crumbs_self ? crumbs_self + ' ' : '') + (Elem['name'] || Elem);
3763
- return Elem(props, ...childNodes);
3791
+ $mol_assert_fail(() => sub1.promote(), 'Circular subscription');
3764
3792
  }
3765
3793
  finally {
3766
- $.$mol_jsx_prefix = prefix;
3767
- $.$mol_jsx_booked = booked;
3768
- $.$mol_jsx_crumbs = crumbs;
3794
+ sub2.track_cut();
3795
+ sub2.track_off(bu2);
3769
3796
  }
3770
3797
  }
3798
+ finally {
3799
+ sub1.track_cut();
3800
+ sub1.track_off(bu1);
3801
+ }
3802
+ },
3803
+ });
3804
+ })($ || ($ = {}));
3805
+
3806
+ ;
3807
+ "use strict";
3808
+ var $;
3809
+ (function ($) {
3810
+ $.$mol_after_mock_queue = [];
3811
+ function $mol_after_mock_warp() {
3812
+ const queue = $.$mol_after_mock_queue.splice(0);
3813
+ for (const task of queue)
3814
+ task();
3815
+ }
3816
+ $.$mol_after_mock_warp = $mol_after_mock_warp;
3817
+ class $mol_after_mock_commmon extends $mol_object2 {
3818
+ task;
3819
+ promise = Promise.resolve();
3820
+ cancelled = false;
3821
+ id;
3822
+ constructor(task) {
3823
+ super();
3824
+ this.task = task;
3825
+ $.$mol_after_mock_queue.push(task);
3771
3826
  }
3772
- if (!node) {
3773
- node = Elem
3774
- ? $.$mol_jsx_document.createElementNS(props?.xmlns ?? 'http://www.w3.org/1999/xhtml', Elem)
3775
- : $.$mol_jsx_document.createDocumentFragment();
3827
+ destructor() {
3828
+ const index = $.$mol_after_mock_queue.indexOf(this.task);
3829
+ if (index >= 0)
3830
+ $.$mol_after_mock_queue.splice(index, 1);
3776
3831
  }
3777
- $mol_dom_render_children(node, [].concat(...childNodes));
3778
- if (!Elem)
3779
- return node;
3780
- if (guid)
3781
- node.id = guid;
3782
- for (const key in props) {
3783
- if (key === 'id')
3784
- continue;
3785
- if (typeof props[key] === 'string') {
3786
- if (typeof node[key] === 'string')
3787
- node[key] = props[key];
3788
- node.setAttribute(key, props[key]);
3789
- }
3790
- else if (props[key] &&
3791
- typeof props[key] === 'object' &&
3792
- Reflect.getPrototypeOf(props[key]) === Reflect.getPrototypeOf({})) {
3793
- if (typeof node[key] === 'object') {
3794
- Object.assign(node[key], props[key]);
3795
- continue;
3796
- }
3797
- }
3798
- else {
3799
- node[key] = props[key];
3800
- }
3832
+ }
3833
+ $.$mol_after_mock_commmon = $mol_after_mock_commmon;
3834
+ class $mol_after_mock_timeout extends $mol_after_mock_commmon {
3835
+ delay;
3836
+ constructor(delay, task) {
3837
+ super(task);
3838
+ this.delay = delay;
3801
3839
  }
3802
- if ($.$mol_jsx_crumbs)
3803
- node.className = (props?.['class'] ? props['class'] + ' ' : '') + crumbs_self;
3804
- return node;
3805
3840
  }
3806
- $.$mol_jsx = $mol_jsx;
3841
+ $.$mol_after_mock_timeout = $mol_after_mock_timeout;
3842
+ })($ || ($ = {}));
3843
+
3844
+ ;
3845
+ "use strict";
3846
+ var $;
3847
+ (function ($_1) {
3848
+ $mol_test_mocks.push($ => {
3849
+ $.$mol_after_tick = $mol_after_mock_commmon;
3850
+ });
3807
3851
  })($ || ($ = {}));
3808
3852
 
3809
3853
  ;
@@ -3811,100 +3855,79 @@ var $;
3811
3855
  var $;
3812
3856
  (function ($) {
3813
3857
  $mol_test({
3814
- 'Make empty div'() {
3815
- $mol_assert_equal(($mol_jsx("div", null)).outerHTML, '<div></div>');
3816
- },
3817
- 'Define native field'() {
3818
- const dom = $mol_jsx("input", { value: '123' });
3819
- $mol_assert_equal(dom.outerHTML, '<input value="123">');
3820
- $mol_assert_equal(dom.value, '123');
3821
- },
3822
- 'Define classes'() {
3823
- const dom = $mol_jsx("div", { class: 'foo bar' });
3824
- $mol_assert_equal(dom.outerHTML, '<div class="foo bar"></div>');
3825
- },
3826
- 'Define styles'() {
3827
- const dom = $mol_jsx("div", { style: { color: 'red' } });
3828
- $mol_assert_equal(dom.outerHTML, '<div style="color: red;"></div>');
3829
- },
3830
- 'Define dataset'() {
3831
- const dom = $mol_jsx("div", { dataset: { foo: 'bar' } });
3832
- $mol_assert_equal(dom.outerHTML, '<div data-foo="bar"></div>');
3833
- },
3834
- 'Define attributes'() {
3835
- const dom = $mol_jsx("div", { lang: "ru", hidden: true });
3836
- $mol_assert_equal(dom.outerHTML, '<div lang="ru" hidden=""></div>');
3837
- },
3838
- 'Define child nodes'() {
3839
- const dom = $mol_jsx("div", null,
3840
- "hello",
3841
- $mol_jsx("strong", null, "world"),
3842
- "!");
3843
- $mol_assert_equal(dom.outerHTML, '<div>hello<strong>world</strong>!</div>');
3844
- },
3845
- 'Make fragment'() {
3846
- const dom = $mol_jsx($mol_jsx_frag, null,
3847
- $mol_jsx("br", null),
3848
- $mol_jsx("hr", null));
3849
- $mol_assert_equal($mol_dom_serialize(dom), '<br xmlns="http://www.w3.org/1999/xhtml" /><hr xmlns="http://www.w3.org/1999/xhtml" />');
3850
- },
3851
- 'Spread fragment'() {
3852
- const dom = $mol_jsx("div", null,
3853
- $mol_jsx($mol_jsx_frag, null,
3854
- $mol_jsx("br", null),
3855
- $mol_jsx("hr", null)));
3856
- $mol_assert_equal(dom.outerHTML, '<div><br><hr></div>');
3857
- },
3858
- 'Function as component'() {
3859
- const Button = (props, target) => {
3860
- return $mol_jsx("button", { title: props.hint }, target());
3861
- };
3862
- const dom = $mol_jsx(Button, { id: "foo", hint: "click me" }, () => 'hey!');
3863
- $mol_assert_equal(dom.outerHTML, '<button id="foo" title="click me" class="Button">hey!</button>');
3864
- },
3865
- 'Nested guid generation'() {
3866
- const Foo = () => {
3867
- return $mol_jsx("div", null,
3868
- $mol_jsx(Bar, { id: "bar" },
3869
- $mol_jsx("img", { id: "icon" })));
3870
- };
3871
- const Bar = (props, icon) => {
3872
- return $mol_jsx("span", null,
3873
- icon,
3874
- $mol_jsx("i", { id: "label" }));
3875
- };
3876
- const dom = $mol_jsx(Foo, { id: "foo" });
3877
- $mol_assert_equal(dom.outerHTML, '<div id="foo" class="Foo"><span id="foo/bar" class="Foo_bar Bar"><img id="foo/icon" class="Foo_icon"><i id="foo/bar/label" class="Foo_bar_label Bar_label"></i></span></div>');
3878
- },
3879
- 'Fail on non unique ids'() {
3880
- const App = () => {
3881
- return $mol_jsx("div", null,
3882
- $mol_jsx("span", { id: "bar" }),
3883
- $mol_jsx("span", { id: "bar" }));
3884
- };
3885
- $mol_assert_fail(() => $mol_jsx(App, { id: "foo" }), 'JSX already has tag with id "foo/bar"');
3858
+ 'Sync execution'() {
3859
+ class Sync extends $mol_object2 {
3860
+ static calc(a, b) {
3861
+ return a + b;
3862
+ }
3863
+ }
3864
+ __decorate([
3865
+ $mol_wire_method
3866
+ ], Sync, "calc", null);
3867
+ $mol_assert_equal(Sync.calc(1, 2), 3);
3886
3868
  },
3887
- 'Owner based guid generationn'() {
3888
- const Foo = () => {
3889
- return $mol_jsx("div", null,
3890
- $mol_jsx(Bar, { id: "middle", icon: () => $mol_jsx("img", { id: "icon" }) }));
3891
- };
3892
- const Bar = (props) => {
3893
- return $mol_jsx("span", null, props.icon());
3894
- };
3895
- const dom = $mol_jsx(Foo, { id: "app" });
3896
- $mol_assert_equal(dom.outerHTML, '<div id="app" class="Foo"><span id="app/middle" class="Foo_middle Bar"><img id="app/icon" class="Foo_icon"></span></div>');
3869
+ async 'async <=> sync'() {
3870
+ class SyncAsync extends $mol_object2 {
3871
+ static async val(a) {
3872
+ return a;
3873
+ }
3874
+ static sum(a, b) {
3875
+ const syn = $mol_wire_sync(this);
3876
+ return syn.val(a) + syn.val(b);
3877
+ }
3878
+ static async calc(a, b) {
3879
+ return 5 + await $mol_wire_async(this).sum(a, b);
3880
+ }
3881
+ }
3882
+ $mol_assert_equal(await SyncAsync.calc(1, 2), 8);
3897
3883
  },
3898
- 'Fail on same ids from different caller'() {
3899
- const Foo = () => {
3900
- return $mol_jsx("div", null,
3901
- $mol_jsx("img", { id: "icon" }),
3902
- $mol_jsx(Bar, { id: "bar", icon: () => $mol_jsx("img", { id: "icon" }) }));
3903
- };
3904
- const Bar = (props) => {
3905
- return $mol_jsx("span", null, props.icon());
3906
- };
3907
- $mol_assert_fail(() => $mol_jsx(Foo, { id: "foo" }), 'JSX already has tag with id "foo/icon"');
3884
+ async 'Idempotence control'() {
3885
+ class Idempotence extends $mol_object2 {
3886
+ static logs_idemp = 0;
3887
+ static logs_unidemp = 0;
3888
+ static log_idemp() {
3889
+ this.logs_idemp += 1;
3890
+ }
3891
+ static log_unidemp() {
3892
+ this.logs_unidemp += 1;
3893
+ }
3894
+ static async val(a) {
3895
+ return a;
3896
+ }
3897
+ static sum(a, b) {
3898
+ this.log_idemp();
3899
+ this.log_unidemp();
3900
+ const syn = $mol_wire_sync(this);
3901
+ return syn.val(a) + syn.val(b);
3902
+ }
3903
+ static async calc(a, b) {
3904
+ return 5 + await $mol_wire_async(this).sum(a, b);
3905
+ }
3906
+ }
3907
+ __decorate([
3908
+ $mol_wire_method
3909
+ ], Idempotence, "log_idemp", null);
3910
+ $mol_assert_equal(await Idempotence.calc(1, 2), 8);
3911
+ $mol_assert_equal(Idempotence.logs_idemp, 1);
3912
+ $mol_assert_equal(Idempotence.logs_unidemp, 3);
3913
+ },
3914
+ async 'Error handling'() {
3915
+ class Handle extends $mol_object2 {
3916
+ static async sum(a, b) {
3917
+ $mol_fail(new Error('test error ' + (a + b)));
3918
+ }
3919
+ static check() {
3920
+ try {
3921
+ return $mol_wire_sync(Handle).sum(1, 2);
3922
+ }
3923
+ catch (error) {
3924
+ if ($mol_promise_like(error))
3925
+ $mol_fail_hidden(error);
3926
+ $mol_assert_equal(error.message, 'test error 3');
3927
+ }
3928
+ }
3929
+ }
3930
+ await $mol_wire_async(Handle).check();
3908
3931
  },
3909
3932
  });
3910
3933
  })($ || ($ = {}));
@@ -3913,287 +3936,246 @@ var $;
3913
3936
  "use strict";
3914
3937
  var $;
3915
3938
  (function ($) {
3916
- function $mol_range2(item = index => index, size = () => Number.POSITIVE_INFINITY) {
3917
- const source = typeof item === 'function' ? new $mol_range2_array() : item;
3918
- if (typeof item !== 'function') {
3919
- item = index => source[index];
3920
- size = () => source.length;
3921
- }
3922
- return new Proxy(source, {
3923
- get(target, field) {
3924
- if (typeof field === 'string') {
3925
- if (field === 'length')
3926
- return size();
3927
- const index = Number(field);
3928
- if (index < 0)
3929
- return undefined;
3930
- if (index >= size())
3931
- return undefined;
3932
- if (index === Math.trunc(index))
3933
- return item(index);
3934
- }
3935
- return $mol_range2_array.prototype[field];
3936
- },
3937
- set(target, field) {
3938
- return $mol_fail(new TypeError(`Lazy range is read only (trying to set field ${JSON.stringify(field)})`));
3939
+ function $mol_wire_async(obj) {
3940
+ let fiber;
3941
+ const temp = $mol_wire_task.getter(obj);
3942
+ return new Proxy(obj, {
3943
+ get(obj, field) {
3944
+ const val = obj[field];
3945
+ if (typeof val !== 'function')
3946
+ return val;
3947
+ let fiber;
3948
+ const temp = $mol_wire_task.getter(val);
3949
+ return function $mol_wire_async(...args) {
3950
+ fiber?.destructor();
3951
+ fiber = temp(obj, args);
3952
+ return fiber.async();
3953
+ };
3939
3954
  },
3940
- ownKeys(target) {
3941
- return [...Array(size())].map((v, i) => String(i)).concat('length');
3955
+ apply(obj, self, args) {
3956
+ fiber?.destructor();
3957
+ fiber = temp(self, args);
3958
+ return fiber.async();
3942
3959
  },
3943
- getOwnPropertyDescriptor(target, field) {
3944
- if (field === "length")
3945
- return {
3946
- value: size(),
3947
- writable: true,
3948
- enumerable: false,
3949
- configurable: false,
3950
- };
3951
- const index = Number(field);
3952
- if (index === Math.trunc(index))
3953
- return {
3954
- get: () => this.get(target, field, this),
3955
- enumerable: true,
3956
- configurable: true,
3957
- };
3958
- return Object.getOwnPropertyDescriptor(target, field);
3959
- }
3960
3960
  });
3961
3961
  }
3962
- $.$mol_range2 = $mol_range2;
3963
- class $mol_range2_array extends Array {
3964
- concat(...tail) {
3965
- if (tail.length === 0)
3966
- return this;
3967
- if (tail.length > 1) {
3968
- let list = this;
3969
- for (let item of tail)
3970
- list = list.concat(item);
3971
- return list;
3962
+ $.$mol_wire_async = $mol_wire_async;
3963
+ })($ || ($ = {}));
3964
+
3965
+ ;
3966
+ "use strict";
3967
+ var $;
3968
+ (function ($_1) {
3969
+ $mol_test({
3970
+ 'test types'($) {
3971
+ class A {
3972
+ static a() {
3973
+ return '';
3974
+ }
3975
+ static b() {
3976
+ return $mol_wire_async(this).a();
3977
+ }
3972
3978
  }
3973
- return $mol_range2(index => index < this.length ? this[index] : tail[0][index - this.length], () => this.length + tail[0].length);
3974
- }
3975
- filter(check, context) {
3976
- const filtered = [];
3977
- let cursor = -1;
3978
- return $mol_range2(index => {
3979
- while (cursor < this.length && index >= filtered.length - 1) {
3980
- const val = this[++cursor];
3981
- if (check(val, cursor, this))
3982
- filtered.push(val);
3979
+ },
3980
+ async 'Latest method calls wins'($) {
3981
+ class NameLogger extends $mol_object2 {
3982
+ static $ = $;
3983
+ static first = [];
3984
+ static last = [];
3985
+ static send(next) {
3986
+ $mol_wire_sync(this.first).push(next);
3987
+ $$.$mol_wait_timeout(0);
3988
+ this.last.push(next);
3983
3989
  }
3984
- return filtered[index];
3985
- }, () => cursor < this.length ? Number.POSITIVE_INFINITY : filtered.length);
3986
- }
3987
- forEach(proceed, context) {
3988
- for (let [key, value] of this.entries())
3989
- proceed.call(context, value, key, this);
3990
- }
3991
- map(proceed, context) {
3992
- return $mol_range2(index => proceed.call(context, this[index], index, this), () => this.length);
3993
- }
3994
- reduce(merge, result) {
3995
- let index = 0;
3996
- if (arguments.length === 1) {
3997
- result = this[index++];
3998
3990
  }
3999
- for (; index < this.length; ++index) {
4000
- result = merge(result, this[index], index, this);
3991
+ const name = $mol_wire_async(NameLogger).send;
3992
+ name('john');
3993
+ const promise = name('jin');
3994
+ $.$mol_after_mock_warp();
3995
+ await promise;
3996
+ $mol_assert_equal(NameLogger.first, ['john', 'jin']);
3997
+ $mol_assert_equal(NameLogger.last, ['jin']);
3998
+ },
3999
+ async 'Latest function calls wins'($) {
4000
+ const first = [];
4001
+ const last = [];
4002
+ function send_name(next) {
4003
+ $mol_wire_sync(first).push(next);
4004
+ $$.$mol_wait_timeout(0);
4005
+ last.push(next);
4001
4006
  }
4002
- return result;
4003
- }
4004
- toReversed() {
4005
- return $mol_range2(index => this[this.length - 1 - index], () => this.length);
4006
- }
4007
- slice(from = 0, to = this.length) {
4008
- return $mol_range2(index => this[from + index], () => Math.min(to, this.length) - from);
4007
+ const name = $mol_wire_async(send_name);
4008
+ name('john');
4009
+ const promise = name('jin');
4010
+ $.$mol_after_mock_warp();
4011
+ await promise;
4012
+ $mol_assert_equal(first, ['john', 'jin']);
4013
+ $mol_assert_equal(last, ['jin']);
4014
+ },
4015
+ });
4016
+ })($ || ($ = {}));
4017
+
4018
+ ;
4019
+ "use strict";
4020
+ var $;
4021
+ (function ($) {
4022
+ function $mol_wire_method(host, field, descr) {
4023
+ if (!descr)
4024
+ descr = Reflect.getOwnPropertyDescriptor(host, field);
4025
+ const orig = descr?.value ?? host[field];
4026
+ const sup = Reflect.getPrototypeOf(host);
4027
+ if (typeof sup[field] === 'function') {
4028
+ Object.defineProperty(orig, 'name', { value: sup[field].name });
4009
4029
  }
4010
- some(check, context) {
4011
- for (let index = 0; index < this.length; ++index) {
4012
- if (check.call(context, this[index], index, this))
4013
- return true;
4030
+ const temp = $mol_wire_task.getter(orig);
4031
+ const value = function (...args) {
4032
+ const fiber = temp(this ?? null, args);
4033
+ return fiber.sync();
4034
+ };
4035
+ Object.defineProperty(value, 'name', { value: orig.name + ' ' });
4036
+ Object.assign(value, { orig });
4037
+ const descr2 = { ...descr, value };
4038
+ Reflect.defineProperty(host, field, descr2);
4039
+ return descr2;
4040
+ }
4041
+ $.$mol_wire_method = $mol_wire_method;
4042
+ })($ || ($ = {}));
4043
+
4044
+ ;
4045
+ "use strict";
4046
+ var $;
4047
+ (function ($_1) {
4048
+ $mol_test({
4049
+ 'test types'($) {
4050
+ class A {
4051
+ static a() {
4052
+ return Promise.resolve('');
4053
+ }
4054
+ static b() {
4055
+ return $mol_wire_sync(this).a();
4056
+ }
4057
+ }
4058
+ },
4059
+ async 'test method from host'($) {
4060
+ let count = 0;
4061
+ class A {
4062
+ static a() {
4063
+ return $mol_wire_sync(this).b();
4064
+ }
4065
+ static b() { return Promise.resolve(++count); }
4014
4066
  }
4015
- return false;
4016
- }
4017
- every(check, context) {
4018
- for (let index = 0; index < this.length; ++index) {
4019
- if (!check.call(context, this[index], index, this))
4020
- return false;
4067
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
4068
+ },
4069
+ async 'test function'($) {
4070
+ let count = 0;
4071
+ class A {
4072
+ static a() {
4073
+ return $mol_wire_sync(this.b)();
4074
+ }
4075
+ static b() { return Promise.resolve(++count); }
4021
4076
  }
4022
- return true;
4023
- }
4024
- reverse() {
4025
- return $mol_fail(new TypeError(`Mutable reverse is forbidden. Use toReversed instead.`));
4077
+ $mol_assert_equal(await $mol_wire_async(A).a(), 1, count);
4078
+ },
4079
+ async 'test construct itself'($) {
4080
+ class A {
4081
+ static instances = [];
4082
+ static a() {
4083
+ const a = new ($mol_wire_sync(A))();
4084
+ this.instances.push(a);
4085
+ $mol_wire_sync(this).b();
4086
+ }
4087
+ static b() { return Promise.resolve(); }
4088
+ }
4089
+ await $mol_wire_async(A).a();
4090
+ $mol_assert_equal(A.instances.length, 2);
4091
+ $mol_assert_equal(A.instances[0] instanceof A, true);
4092
+ $mol_assert_equal(A.instances[0], A.instances[1]);
4026
4093
  }
4027
- sort() {
4028
- return $mol_fail(new TypeError(`Mutable sort is forbidden. Use toSorted instead.`));
4094
+ });
4095
+ })($ || ($ = {}));
4096
+
4097
+ ;
4098
+ "use strict";
4099
+ var $;
4100
+ (function ($) {
4101
+ class $mol_promise extends Promise {
4102
+ done;
4103
+ fail;
4104
+ constructor(executor) {
4105
+ let done;
4106
+ let fail;
4107
+ super((d, f) => {
4108
+ done = d;
4109
+ fail = f;
4110
+ executor?.(d, f);
4111
+ });
4112
+ this.done = done;
4113
+ this.fail = fail;
4029
4114
  }
4030
- indexOf(needle) {
4031
- return this.findIndex(item => item === needle);
4115
+ }
4116
+ $.$mol_promise = $mol_promise;
4117
+ })($ || ($ = {}));
4118
+
4119
+ ;
4120
+ "use strict";
4121
+ var $;
4122
+ (function ($) {
4123
+ class $mol_after_timeout extends $mol_object2 {
4124
+ delay;
4125
+ task;
4126
+ id;
4127
+ constructor(delay, task) {
4128
+ super();
4129
+ this.delay = delay;
4130
+ this.task = task;
4131
+ this.id = setTimeout(task, delay);
4032
4132
  }
4033
- [Symbol.toPrimitive]() {
4034
- return $mol_guid();
4133
+ destructor() {
4134
+ clearTimeout(this.id);
4035
4135
  }
4036
4136
  }
4037
- $.$mol_range2_array = $mol_range2_array;
4137
+ $.$mol_after_timeout = $mol_after_timeout;
4138
+ })($ || ($ = {}));
4139
+
4140
+ ;
4141
+ "use strict";
4142
+ var $;
4143
+ (function ($_1) {
4144
+ $mol_test_mocks.push($ => {
4145
+ $.$mol_after_timeout = $mol_after_mock_timeout;
4146
+ });
4038
4147
  })($ || ($ = {}));
4039
4148
 
4040
4149
  ;
4041
4150
  "use strict";
4042
4151
  var $;
4043
4152
  (function ($) {
4044
- $mol_test({
4045
- 'lazy calls'() {
4046
- let calls = 0;
4047
- const list = $mol_range2(index => (++calls, index), () => 10);
4048
- $mol_assert_equal(true, list instanceof Array);
4049
- $mol_assert_equal(list.length, 10);
4050
- $mol_assert_equal(list[-1], undefined);
4051
- $mol_assert_equal(list[0], 0);
4052
- $mol_assert_equal(list[9], 9);
4053
- $mol_assert_equal(list[9.5], undefined);
4054
- $mol_assert_equal(list[10], undefined);
4055
- $mol_assert_equal(calls, 2);
4056
- },
4057
- 'infinity list'() {
4058
- let calls = 0;
4059
- const list = $mol_range2(index => (++calls, index));
4060
- $mol_assert_equal(list.length, Number.POSITIVE_INFINITY);
4061
- $mol_assert_equal(list[0], 0);
4062
- $mol_assert_equal(list[4], 4);
4063
- $mol_assert_equal(list[Number.MAX_SAFE_INTEGER], Number.MAX_SAFE_INTEGER);
4064
- $mol_assert_equal(list[Number.POSITIVE_INFINITY], undefined);
4065
- $mol_assert_equal(calls, 3);
4066
- },
4067
- 'stringify'() {
4068
- const list = $mol_range2(i => i, () => 5);
4069
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
4070
- $mol_assert_equal(list.join(';'), '0;1;2;3;4');
4071
- },
4072
- 'for-of'() {
4073
- let log = '';
4074
- for (let i of $mol_range2(i => i + 1, () => 5)) {
4075
- log += i;
4076
- }
4077
- $mol_assert_equal(log, '12345');
4078
- },
4079
- 'for-in'() {
4080
- let log = '';
4081
- for (let i in $mol_range2(i => i, () => 5)) {
4082
- log += i;
4083
- }
4084
- $mol_assert_equal(log, '01234');
4085
- },
4086
- 'forEach'() {
4087
- let log = '';
4088
- $mol_range2(i => i, () => 5).forEach(i => log += i);
4089
- $mol_assert_equal(log, '01234');
4090
- },
4091
- 'reduce'() {
4092
- let calls = 0;
4093
- const list = $mol_range2().slice(1, 6);
4094
- $mol_assert_equal(list.reduce((s, v) => s + v), 15);
4095
- $mol_assert_equal(list.reduce((s, v) => s + v, 5), 20);
4096
- },
4097
- 'lazy concat'() {
4098
- let calls1 = 0;
4099
- let calls2 = 0;
4100
- const list = $mol_range2(index => (++calls1, index), () => 5).concat([0, 1, 2, 3, 4], $mol_range2(index => (++calls2, index), () => 5));
4101
- $mol_assert_equal(true, list instanceof Array);
4102
- $mol_assert_equal(list.length, 15);
4103
- $mol_assert_equal(list[0], 0);
4104
- $mol_assert_equal(list[4], 4);
4105
- $mol_assert_equal(list[5], 0);
4106
- $mol_assert_equal(list[9], 4);
4107
- $mol_assert_equal(list[10], 0);
4108
- $mol_assert_equal(list[14], 4);
4109
- $mol_assert_equal(list[15], undefined);
4110
- $mol_assert_equal(calls1, 2);
4111
- $mol_assert_equal(calls2, 2);
4112
- },
4113
- 'lazy filter'() {
4114
- let calls = 0;
4115
- const list = $mol_range2(index => (++calls, index), () => 15).filter(v => v % 2).slice(0, 3);
4116
- $mol_assert_equal(true, list instanceof Array);
4117
- $mol_assert_equal(list.length, 3);
4118
- $mol_assert_equal(list[0], 1);
4119
- $mol_assert_equal(list[2], 5);
4120
- $mol_assert_equal(list[3], undefined);
4121
- $mol_assert_equal(calls, 8);
4122
- },
4123
- 'lazy reverse'() {
4124
- let calls = 0;
4125
- const list = $mol_range2(index => (++calls, index), () => 10).toReversed().slice(0, 3);
4126
- $mol_assert_equal(true, list instanceof Array);
4127
- $mol_assert_equal(list.length, 3);
4128
- $mol_assert_equal(list[0], 9);
4129
- $mol_assert_equal(list[2], 7);
4130
- $mol_assert_equal(list[3], undefined);
4131
- $mol_assert_equal(calls, 2);
4132
- },
4133
- 'lazy map'() {
4134
- let calls1 = 0;
4135
- let calls2 = 0;
4136
- const source = $mol_range2(index => (++calls1, index), () => 5);
4137
- const target = source.map((item, index, self) => {
4138
- ++calls2;
4139
- $mol_assert_equal(source, self);
4140
- return index + 10;
4141
- }, () => 5);
4142
- $mol_assert_equal(true, target instanceof Array);
4143
- $mol_assert_equal(target.length, 5);
4144
- $mol_assert_equal(target[0], 10);
4145
- $mol_assert_equal(target[4], 14);
4146
- $mol_assert_equal(target[5], undefined);
4147
- $mol_assert_equal(calls1, 2);
4148
- $mol_assert_equal(calls2, 2);
4149
- },
4150
- 'lazy slice'() {
4151
- let calls = 0;
4152
- const list = $mol_range2(index => (++calls, index), () => 10).slice(3, 7);
4153
- $mol_assert_equal(true, list instanceof Array);
4154
- $mol_assert_equal(list.length, 4);
4155
- $mol_assert_equal(list[0], 3);
4156
- $mol_assert_equal(list[3], 6);
4157
- $mol_assert_equal(list[4], undefined);
4158
- $mol_assert_equal(calls, 2);
4159
- },
4160
- 'lazy some'() {
4161
- let calls = 0;
4162
- $mol_assert_equal(true, $mol_range2(index => (++calls, index), () => 5).some(v => v >= 2));
4163
- $mol_assert_equal(calls, 3);
4164
- $mol_assert_equal(false, $mol_range2(i => i, () => 0).some(v => true));
4165
- $mol_assert_equal(true, $mol_range2(i => i).some(v => v > 5));
4166
- },
4167
- 'lazy every'() {
4168
- let calls = 0;
4169
- $mol_assert_equal(false, $mol_range2(index => (++calls, index), () => 5).every(v => v < 2));
4170
- $mol_assert_equal(calls, 3);
4171
- $mol_assert_equal(true, $mol_range2(i => i, () => 0).every(v => false));
4172
- $mol_assert_equal(false, $mol_range2(i => i).every(v => v < 5));
4173
- },
4174
- 'lazyfy'() {
4175
- let calls = 0;
4176
- const list = $mol_range2([0, 1, 2, 3, 4, 5]).map(i => (++calls, i + 10)).slice(2);
4177
- $mol_assert_equal(true, list instanceof Array);
4178
- $mol_assert_equal(list.length, 4);
4179
- $mol_assert_equal(calls, 0);
4180
- $mol_assert_equal(list[0], 12);
4181
- $mol_assert_equal(list[3], 15);
4182
- $mol_assert_equal(list[4], undefined);
4183
- $mol_assert_equal(calls, 2);
4184
- },
4185
- 'prevent modification'() {
4186
- const list = $mol_range2(i => i, () => 5);
4187
- $mol_assert_fail(() => list.push(4), TypeError);
4188
- $mol_assert_fail(() => list.pop(), TypeError);
4189
- $mol_assert_fail(() => list.unshift(4), TypeError);
4190
- $mol_assert_fail(() => list.shift(), TypeError);
4191
- $mol_assert_fail(() => list.splice(1, 2), TypeError);
4192
- $mol_assert_fail(() => list[1] = 2, TypeError);
4193
- $mol_assert_fail(() => list.reverse(), TypeError);
4194
- $mol_assert_fail(() => list.sort(), TypeError);
4195
- $mol_assert_equal(list.toString(), '0,1,2,3,4');
4153
+ class $mol_after_work extends $mol_object2 {
4154
+ delay;
4155
+ task;
4156
+ id;
4157
+ constructor(delay, task) {
4158
+ super();
4159
+ this.delay = delay;
4160
+ this.task = task;
4161
+ this.id = requestIdleCallback(task, { timeout: delay });
4196
4162
  }
4163
+ destructor() {
4164
+ cancelIdleCallback(this.id);
4165
+ }
4166
+ }
4167
+ $.$mol_after_work = $mol_after_work;
4168
+ if (typeof requestIdleCallback !== 'function') {
4169
+ $.$mol_after_work = $mol_after_timeout;
4170
+ }
4171
+ })($ || ($ = {}));
4172
+
4173
+ ;
4174
+ "use strict";
4175
+ var $;
4176
+ (function ($_1) {
4177
+ $mol_test_mocks.push($ => {
4178
+ $.$mol_after_work = $mol_after_mock_timeout;
4197
4179
  });
4198
4180
  })($ || ($ = {}));
4199
4181
 
@@ -4201,130 +4183,134 @@ var $;
4201
4183
  "use strict";
4202
4184
  var $;
4203
4185
  (function ($) {
4186
+ function $mol_wait_rest_async() {
4187
+ return new Promise(done => {
4188
+ new this.$mol_after_work(16, () => done(null));
4189
+ });
4190
+ }
4191
+ $.$mol_wait_rest_async = $mol_wait_rest_async;
4192
+ function $mol_wait_rest() {
4193
+ return this.$mol_wire_sync(this).$mol_wait_rest_async();
4194
+ }
4195
+ $.$mol_wait_rest = $mol_wait_rest;
4196
+ })($ || ($ = {}));
4197
+
4198
+ ;
4199
+ "use strict";
4200
+ var $;
4201
+ (function ($_1) {
4202
+ var $$;
4203
+ (function ($$) {
4204
+ $mol_test_mocks.push($ => {
4205
+ $.$mol_wait_timeout = function $mol_wait_timeout_mock(timeout) { };
4206
+ $.$mol_wait_timeout_async = async function $mol_wait_timeout_async_mock(timeout) { };
4207
+ });
4208
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4209
+ })($ || ($ = {}));
4210
+
4211
+ ;
4212
+ "use strict";
4213
+ var $;
4214
+ (function ($) {
4215
+ function $mol_wait_timeout_async(timeout) {
4216
+ const promise = new $mol_promise();
4217
+ const task = new this.$mol_after_timeout(timeout, () => promise.done());
4218
+ return Object.assign(promise, {
4219
+ destructor: () => task.destructor()
4220
+ });
4221
+ }
4222
+ $.$mol_wait_timeout_async = $mol_wait_timeout_async;
4223
+ function $mol_wait_timeout(timeout) {
4224
+ return this.$mol_wire_sync(this).$mol_wait_timeout_async(timeout);
4225
+ }
4226
+ $.$mol_wait_timeout = $mol_wait_timeout;
4227
+ })($ || ($ = {}));
4228
+
4229
+ ;
4230
+ "use strict";
4231
+ var $;
4232
+ (function ($_1) {
4233
+ var $$;
4234
+ (function ($$) {
4235
+ $mol_test_mocks.push($ => {
4236
+ $.$mol_wait_rest = function $mol_wait_rest_mock() { };
4237
+ $.$mol_wait_rest_async = async function $mol_wait_rest_async_mock() { };
4238
+ });
4239
+ })($$ = $_1.$$ || ($_1.$$ = {}));
4240
+ })($ || ($ = {}));
4241
+
4242
+ ;
4243
+ "use strict";
4244
+ var $;
4245
+ (function ($_1) {
4204
4246
  $mol_test({
4205
- 'nulls & undefineds'() {
4206
- $mol_assert_ok($mol_compare_deep(null, null));
4207
- $mol_assert_ok($mol_compare_deep(undefined, undefined));
4208
- $mol_assert_not($mol_compare_deep(undefined, null));
4209
- $mol_assert_not($mol_compare_deep({}, null));
4210
- },
4211
- 'number'() {
4212
- $mol_assert_ok($mol_compare_deep(1, 1));
4213
- $mol_assert_ok($mol_compare_deep(Number.NaN, Number.NaN));
4214
- $mol_assert_not($mol_compare_deep(1, 2));
4215
- $mol_assert_ok($mol_compare_deep(Object(1), Object(1)));
4216
- $mol_assert_not($mol_compare_deep(Object(1), Object(2)));
4217
- },
4218
- 'POJO'() {
4219
- $mol_assert_ok($mol_compare_deep({}, {}));
4220
- $mol_assert_not($mol_compare_deep({ a: 1 }, { b: 2 }));
4221
- $mol_assert_not($mol_compare_deep({ a: 1 }, { a: 2 }));
4222
- $mol_assert_not($mol_compare_deep({}, { a: undefined }));
4223
- $mol_assert_not($mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
4224
- $mol_assert_ok($mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
4225
- $mol_assert_ok($mol_compare_deep(Object.create(null), Object.create(null)));
4226
- },
4227
- 'Array'() {
4228
- $mol_assert_ok($mol_compare_deep([], []));
4229
- $mol_assert_ok($mol_compare_deep([1, [2]], [1, [2]]));
4230
- $mol_assert_not($mol_compare_deep([1, 2], [1, 3]));
4231
- $mol_assert_not($mol_compare_deep([1, 2,], [1, 3, undefined]));
4232
- $mol_assert_not($mol_compare_deep($mol_range2().slice(0, 0), new Array()));
4233
- $mol_assert_not($mol_compare_deep($mol_range2(), $mol_range2()));
4234
- },
4235
- 'Non POJO are different'() {
4236
- class Thing extends Object {
4247
+ async 'exec timeout auto kill child process'($) {
4248
+ let close_mock = () => { };
4249
+ const error_message = 'Run error, timeout';
4250
+ function mol_run_spawn_sync_mock() {
4251
+ return {
4252
+ output: [],
4253
+ stdout: error_message,
4254
+ stderr: '',
4255
+ status: 0,
4256
+ signal: null,
4257
+ pid: 123,
4258
+ };
4237
4259
  }
4238
- $mol_assert_not($mol_compare_deep(new Thing, new Thing));
4239
- $mol_assert_not($mol_compare_deep(() => 1, () => 1));
4240
- $mol_assert_not($mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
4241
- },
4242
- 'POJO with symbols'() {
4243
- const sym = Symbol();
4244
- $mol_assert_ok($mol_compare_deep({ [sym]: true }, { [sym]: true }));
4245
- $mol_assert_not($mol_compare_deep({ [Symbol()]: true }, { [Symbol()]: true }));
4246
- },
4247
- 'same POJOs with cyclic reference'() {
4248
- const a = { foo: {} };
4249
- a['self'] = a;
4250
- const b = { foo: {} };
4251
- b['self'] = b;
4252
- $mol_assert_ok($mol_compare_deep(a, b));
4253
- },
4254
- 'same POJOs with cyclic reference with cache warmup'() {
4255
- const obj1 = { test: 1, obj3: null };
4256
- const obj1_copy = { test: 1, obj3: null };
4257
- const obj2 = { test: 2, obj1 };
4258
- const obj2_copy = { test: 2, obj1: obj1_copy };
4259
- const obj3 = { test: 3, obj2 };
4260
- const obj3_copy = { test: 3, obj2: obj2_copy };
4261
- obj1.obj3 = obj3;
4262
- obj1_copy.obj3 = obj3_copy;
4263
- $mol_assert_not($mol_compare_deep(obj1, {}));
4264
- $mol_assert_not($mol_compare_deep(obj2, {}));
4265
- $mol_assert_not($mol_compare_deep(obj3, {}));
4266
- $mol_assert_ok($mol_compare_deep(obj3, obj3_copy));
4267
- },
4268
- 'Date'() {
4269
- $mol_assert_ok($mol_compare_deep(new Date(12345), new Date(12345)));
4270
- $mol_assert_not($mol_compare_deep(new Date(12345), new Date(12346)));
4271
- },
4272
- 'RegExp'() {
4273
- $mol_assert_ok($mol_compare_deep(/\x22/mig, /\x22/mig));
4274
- $mol_assert_not($mol_compare_deep(/\x22/mig, /\x21/mig));
4275
- $mol_assert_not($mol_compare_deep(/\x22/mig, /\x22/mg));
4276
- },
4277
- 'Error'() {
4278
- $mol_assert_not($mol_compare_deep(new Error('xxx'), new Error('xxx')));
4279
- const fail = (message) => new Error(message);
4280
- $mol_assert_ok($mol_compare_deep(...['xxx', 'xxx'].map(msg => new Error(msg))));
4281
- $mol_assert_not($mol_compare_deep(...['xxx', 'yyy'].map(msg => new Error(msg))));
4282
- },
4283
- 'Map'() {
4284
- $mol_assert_ok($mol_compare_deep(new Map, new Map));
4285
- $mol_assert_ok($mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
4286
- $mol_assert_ok($mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
4287
- $mol_assert_not($mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
4288
- $mol_assert_not($mol_compare_deep(new Map([[[1], 2]]), new Map([[[3], 2]])));
4289
- },
4290
- 'Set'() {
4291
- $mol_assert_ok($mol_compare_deep(new Set, new Set));
4292
- $mol_assert_ok($mol_compare_deep(new Set([1, [2]]), new Set([1, [2]])));
4293
- $mol_assert_not($mol_compare_deep(new Set([1]), new Set([2])));
4294
- },
4295
- 'Uint8Array'() {
4296
- $mol_assert_ok($mol_compare_deep(new Uint8Array, new Uint8Array));
4297
- $mol_assert_ok($mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
4298
- $mol_assert_not($mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
4299
- },
4300
- 'DataView'() {
4301
- $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array().buffer), new DataView(new Uint8Array().buffer)));
4302
- $mol_assert_ok($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([0]).buffer)));
4303
- $mol_assert_not($mol_compare_deep(new DataView(new Uint8Array([0]).buffer), new DataView(new Uint8Array([1]).buffer)));
4304
- },
4305
- 'Serializale'() {
4306
- class User {
4307
- name;
4308
- rand;
4309
- constructor(name, rand = Math.random()) {
4310
- this.name = name;
4311
- this.rand = rand;
4312
- }
4313
- [Symbol.toPrimitive](mode) {
4314
- return this.name;
4260
+ function mol_run_spawn_mock() {
4261
+ return {
4262
+ on(name, cb) {
4263
+ if (name === 'exit')
4264
+ close_mock = cb;
4265
+ },
4266
+ kill() { close_mock(); }
4267
+ };
4268
+ }
4269
+ const context_mock = $.$mol_ambient({
4270
+ $mol_run_spawn_sync: mol_run_spawn_sync_mock,
4271
+ $mol_run_spawn: mol_run_spawn_mock
4272
+ });
4273
+ class $mol_run_mock extends $mol_run {
4274
+ static get $() { return context_mock; }
4275
+ static async_enabled() {
4276
+ return true;
4315
4277
  }
4316
4278
  }
4317
- $mol_assert_ok($mol_compare_deep(new User('Jin'), new User('Jin')));
4318
- $mol_assert_not($mol_compare_deep(new User('Jin'), new User('John')));
4319
- },
4320
- 'Iterable'() {
4321
- $mol_assert_ok($mol_compare_deep(new URLSearchParams({ foo: 'bar' }), new URLSearchParams({ foo: 'bar' })));
4322
- $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx' }), new URLSearchParams({ foo: 'yyy' })));
4323
- $mol_assert_not($mol_compare_deep(new URLSearchParams({ foo: 'xxx', bar: 'yyy' }), new URLSearchParams({ bar: 'yyy', foo: 'xxx' })));
4279
+ let message = '';
4280
+ try {
4281
+ const res = await $mol_wire_async($mol_run_mock).spawn({
4282
+ command: 'sleep 10',
4283
+ dir: '.',
4284
+ timeout: 10,
4285
+ env: { 'MOL_RUN_ASYNC': '1' }
4286
+ });
4287
+ }
4288
+ catch (e) {
4289
+ message = e.message;
4290
+ }
4291
+ $mol_assert_equal(message, error_message);
4292
+ }
4293
+ });
4294
+ })($ || ($ = {}));
4295
+
4296
+ ;
4297
+ "use strict";
4298
+ var $;
4299
+ (function ($) {
4300
+ $mol_test({
4301
+ 'return result without errors'() {
4302
+ $mol_assert_equal($mol_try(() => false), false);
4324
4303
  },
4325
4304
  });
4326
4305
  })($ || ($ = {}));
4327
4306
 
4307
+ ;
4308
+ "use strict";
4309
+ var $;
4310
+ (function ($_1) {
4311
+ $mol_test_mocks.push($ => $.$mol_fail_log = () => false);
4312
+ })($ || ($ = {}));
4313
+
4328
4314
  ;
4329
4315
  "use strict";
4330
4316
  var $;