mol_regexp 0.0.203 → 0.0.207

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
@@ -701,23 +701,16 @@ var $;
701
701
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
702
702
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
703
703
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
704
- },
705
- 'Number'() {
706
704
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
707
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
708
705
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
709
706
  },
710
- 'empty POJOs'() {
707
+ 'POJO'() {
711
708
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
712
- },
713
- 'different POJOs'() {
714
709
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
715
- },
716
- 'different POJOs with same keys but different values'() {
717
710
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
718
- },
719
- 'different POJOs with different keys but same values'() {
720
711
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
712
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
713
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
721
714
  },
722
715
  'Array'() {
723
716
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -725,17 +718,12 @@ var $;
725
718
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
726
719
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
727
720
  },
728
- 'same POJO trees'() {
729
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
730
- },
731
- 'different classes with same values'() {
732
- class Obj {
733
- foo = 1;
721
+ 'Non POJO are different'() {
722
+ class Thing extends Object {
734
723
  }
735
- const a = new Obj;
736
- const b = new class extends Obj {
737
- };
738
- $.$mol_assert_not($.$mol_compare_deep(a, b));
724
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
725
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
726
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
739
727
  },
740
728
  'same POJOs with cyclic reference'() {
741
729
  const a = { foo: {} };
@@ -744,41 +732,6 @@ var $;
744
732
  b['self'] = b;
745
733
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
746
734
  },
747
- 'empty Element'() {
748
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
749
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
750
- },
751
- 'Element with attributes'() {
752
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
753
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
754
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
755
- },
756
- 'Element with styles'() {
757
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
758
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
759
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
760
- },
761
- 'Element with content'() {
762
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
763
- "foo",
764
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
765
- "foo",
766
- $.$mol_jsx("br", null))));
767
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
768
- "foo",
769
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
770
- "bar",
771
- $.$mol_jsx("br", null))));
772
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
773
- "foo",
774
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
775
- "foo",
776
- $.$mol_jsx("hr", null))));
777
- },
778
- 'Element with handlers'() {
779
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
780
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
781
- },
782
735
  'Date'() {
783
736
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
784
737
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -790,8 +743,9 @@ var $;
790
743
  },
791
744
  'Map'() {
792
745
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
793
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
746
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
794
747
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
748
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
795
749
  },
796
750
  'Set'() {
797
751
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -803,6 +757,21 @@ var $;
803
757
  $.$mol_assert_ok($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([0])));
804
758
  $.$mol_assert_not($.$mol_compare_deep(new Uint8Array([0]), new Uint8Array([1])));
805
759
  },
760
+ 'Custom comparator'() {
761
+ class User {
762
+ name;
763
+ rand;
764
+ constructor(name, rand = Math.random()) {
765
+ this.name = name;
766
+ this.rand = rand;
767
+ }
768
+ [Symbol.toPrimitive](mode) {
769
+ return this.name;
770
+ }
771
+ }
772
+ $.$mol_assert_ok($.$mol_compare_deep(new User('Jin'), new User('Jin')));
773
+ $.$mol_assert_not($.$mol_compare_deep(new User('Jin'), new User('John')));
774
+ },
806
775
  });
807
776
  })($ || ($ = {}));
808
777
  //deep.test.js.map
@@ -810,97 +779,123 @@ var $;
810
779
  "use strict";
811
780
  var $;
812
781
  (function ($) {
813
- const a_stack = [];
814
- const b_stack = [];
815
- let cache = null;
816
- function $mol_compare_deep(a, b) {
817
- if (Object.is(a, b))
782
+ let cache = new WeakMap();
783
+ function $mol_compare_deep(left, right) {
784
+ if (Object.is(left, right))
818
785
  return true;
819
- const a_type = typeof a;
820
- const b_type = typeof b;
821
- if (a_type !== b_type)
786
+ if (left === null)
822
787
  return false;
823
- if (a_type === 'function')
824
- return a['toString']() === b['toString']();
825
- if (a_type !== 'object')
788
+ if (right === null)
826
789
  return false;
827
- if (!a || !b)
790
+ if (typeof left !== 'object')
828
791
  return false;
829
- if (a instanceof Error)
792
+ if (typeof right !== 'object')
830
793
  return false;
831
- if (a['constructor'] !== b['constructor'])
794
+ const left_proto = Reflect.getPrototypeOf(left);
795
+ const right_proto = Reflect.getPrototypeOf(right);
796
+ if (left_proto !== right_proto)
832
797
  return false;
833
- if (a instanceof RegExp)
834
- return a.toString() === b['toString']();
835
- const ref = a_stack.indexOf(a);
836
- if (ref >= 0) {
837
- return Object.is(b_stack[ref], b);
838
- }
839
- if (!cache)
840
- cache = new WeakMap;
841
- let a_cache = cache.get(a);
842
- if (a_cache) {
843
- const b_cache = a_cache.get(b);
844
- if (typeof b_cache === 'boolean')
845
- return b_cache;
798
+ if (left instanceof Boolean)
799
+ return Object.is(left.valueOf(), right['valueOf']());
800
+ if (left instanceof Number)
801
+ return Object.is(left.valueOf(), right['valueOf']());
802
+ if (left instanceof String)
803
+ return Object.is(left.valueOf(), right['valueOf']());
804
+ if (left instanceof Date)
805
+ return Object.is(left.valueOf(), right['valueOf']());
806
+ if (left instanceof RegExp)
807
+ return left.source === right['source'] && left.flags === right['flags'];
808
+ let left_cache = cache.get(left);
809
+ if (left_cache) {
810
+ const right_cache = left_cache.get(right);
811
+ if (typeof right_cache === 'boolean')
812
+ return right_cache;
846
813
  }
847
814
  else {
848
- a_cache = new WeakMap();
849
- cache.set(a, a_cache);
815
+ left_cache = new WeakMap([[right, true]]);
816
+ cache.set(left, left_cache);
850
817
  }
851
- a_stack.push(a);
852
- b_stack.push(b);
853
818
  let result;
854
819
  try {
855
- if (Symbol.iterator in a) {
856
- const a_iter = a[Symbol.iterator]();
857
- const b_iter = b[Symbol.iterator]();
858
- while (true) {
859
- const a_next = a_iter.next();
860
- const b_next = b_iter.next();
861
- if (a_next.done !== b_next.done)
862
- return result = false;
863
- if (a_next.done)
864
- break;
865
- if (!$mol_compare_deep(a_next.value, b_next.value))
866
- return result = false;
867
- }
868
- return result = true;
869
- }
870
- let count = 0;
871
- for (let key in a) {
872
- try {
873
- if (!$mol_compare_deep(a[key], b[key]))
874
- return result = false;
875
- }
876
- catch (error) {
877
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
878
- }
879
- ++count;
880
- }
881
- for (let key in b) {
882
- --count;
883
- if (count < 0)
884
- return result = false;
885
- }
886
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
887
- if (!Object.is(a['valueOf'](), b['valueOf']()))
888
- return result = false;
889
- }
890
- return result = true;
820
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
821
+ result = compare_pojo(left, right);
822
+ else if (Array.isArray(left))
823
+ result = compare_array(left, right);
824
+ else if (left instanceof Set)
825
+ result = compare_set(left, right);
826
+ else if (left instanceof Map)
827
+ result = compare_map(left, right);
828
+ else if (ArrayBuffer.isView(left))
829
+ result = compare_buffer(left, right);
830
+ else if (Symbol.toPrimitive in left)
831
+ result = compare_primitive(left, right);
832
+ else
833
+ result = false;
891
834
  }
892
835
  finally {
893
- a_stack.pop();
894
- b_stack.pop();
895
- if (a_stack.length === 0) {
896
- cache = null;
897
- }
898
- else {
899
- a_cache.set(b, result);
900
- }
836
+ left_cache.set(right, result);
901
837
  }
838
+ return result;
902
839
  }
903
840
  $.$mol_compare_deep = $mol_compare_deep;
841
+ function compare_array(left, right) {
842
+ const len = left.length;
843
+ if (len !== right.length)
844
+ return false;
845
+ for (let i = 0; i < len; ++i) {
846
+ if (!$mol_compare_deep(left[i], right[i]))
847
+ return false;
848
+ }
849
+ return true;
850
+ }
851
+ function compare_buffer(left, right) {
852
+ const len = left.byteLength;
853
+ if (len !== right.byteLength)
854
+ return false;
855
+ for (let i = 0; i < len; ++i) {
856
+ if (left[i] !== right[i])
857
+ return false;
858
+ }
859
+ return true;
860
+ }
861
+ function compare_iterator(left, right, compare) {
862
+ while (true) {
863
+ const left_next = left.next();
864
+ const right_next = right.next();
865
+ if (left_next.done !== right_next.done)
866
+ return false;
867
+ if (left_next.done)
868
+ break;
869
+ if (!compare(left_next.value, right_next.value))
870
+ return false;
871
+ }
872
+ return true;
873
+ }
874
+ function compare_set(left, right) {
875
+ if (left.size !== right.size)
876
+ return false;
877
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
878
+ }
879
+ function compare_map(left, right) {
880
+ if (left.size !== right.size)
881
+ return false;
882
+ return compare_iterator(left.keys(), right.keys(), Object.is)
883
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
884
+ }
885
+ function compare_pojo(left, right) {
886
+ const left_keys = Object.getOwnPropertyNames(left);
887
+ const right_keys = Object.getOwnPropertyNames(right);
888
+ if (left_keys.length !== right_keys.length)
889
+ return false;
890
+ for (let key of left_keys) {
891
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
892
+ return false;
893
+ }
894
+ return true;
895
+ }
896
+ function compare_primitive(left, right) {
897
+ return Object.is(left[Symbol.toPrimitive]('default'), right[Symbol.toPrimitive]('default'));
898
+ }
904
899
  })($ || ($ = {}));
905
900
  //deep.js.map
906
901
  ;
@@ -2061,91 +2056,5 @@ var $;
2061
2056
  $.$mol_tree = $mol_tree;
2062
2057
  })($ || ($ = {}));
2063
2058
  //tree.js.map
2064
- ;
2065
- "use strict";
2066
- var $;
2067
- (function ($) {
2068
- $.$mol_test({
2069
- 'equal paths'() {
2070
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]);
2071
- $.$mol_assert_like(diff, {
2072
- prefix: [1, 2, 3, 4],
2073
- suffix: [[], [], []],
2074
- });
2075
- },
2076
- 'different suffix'() {
2077
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2, 3, 5], [1, 2, 5, 4]);
2078
- $.$mol_assert_like(diff, {
2079
- prefix: [1, 2],
2080
- suffix: [[3, 4], [3, 5], [5, 4]],
2081
- });
2082
- },
2083
- 'one contains other'() {
2084
- const diff = $.$mol_diff_path([1, 2, 3, 4], [1, 2], [1, 2, 3]);
2085
- $.$mol_assert_like(diff, {
2086
- prefix: [1, 2],
2087
- suffix: [[3, 4], [], [3]],
2088
- });
2089
- },
2090
- 'fully different'() {
2091
- const diff = $.$mol_diff_path([1, 2], [3, 4], [5, 6]);
2092
- $.$mol_assert_like(diff, {
2093
- prefix: [],
2094
- suffix: [[1, 2], [3, 4], [5, 6]],
2095
- });
2096
- },
2097
- });
2098
- })($ || ($ = {}));
2099
- //path.test.js.map
2100
- ;
2101
- "use strict";
2102
- var $;
2103
- (function ($) {
2104
- function $mol_diff_path(...paths) {
2105
- const limit = Math.min(...paths.map(path => path.length));
2106
- lookup: for (var i = 0; i < limit; ++i) {
2107
- const first = paths[0][i];
2108
- for (let j = 1; j < paths.length; ++j) {
2109
- if (paths[j][i] !== first)
2110
- break lookup;
2111
- }
2112
- }
2113
- return {
2114
- prefix: paths[0].slice(0, i),
2115
- suffix: paths.map(path => path.slice(i)),
2116
- };
2117
- }
2118
- $.$mol_diff_path = $mol_diff_path;
2119
- })($ || ($ = {}));
2120
- //path.js.map
2121
- ;
2122
- "use strict";
2123
- var $;
2124
- (function ($) {
2125
- class $mol_error_mix extends Error {
2126
- errors;
2127
- constructor(message, ...errors) {
2128
- super(message);
2129
- this.errors = errors;
2130
- if (errors.length) {
2131
- const stacks = [...errors.map(error => error.stack), this.stack];
2132
- const diff = $.$mol_diff_path(...stacks.map(stack => {
2133
- if (!stack)
2134
- return [];
2135
- return stack.split('\n').reverse();
2136
- }));
2137
- const head = diff.prefix.reverse().join('\n');
2138
- const tails = diff.suffix.map(path => path.reverse().map(line => line.replace(/^(?!\s+at)/, '\tat (.) ')).join('\n')).join('\n\tat (.) -----\n');
2139
- this.stack = `Error: ${this.constructor.name}\n\tat (.) /"""\\\n${tails}\n\tat (.) \\___/\n${head}`;
2140
- this.message += errors.map(error => '\n' + error.message).join('');
2141
- }
2142
- }
2143
- toJSON() {
2144
- return this.message;
2145
- }
2146
- }
2147
- $.$mol_error_mix = $mol_error_mix;
2148
- })($ || ($ = {}));
2149
- //mix.js.map
2150
2059
 
2151
2060
  //# sourceMappingURL=node.test.js.map