mol_data_all 1.1.149 → 1.1.153

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
@@ -792,23 +792,16 @@ var $;
792
792
  $.$mol_assert_ok($.$mol_compare_deep(1, 1));
793
793
  $.$mol_assert_ok($.$mol_compare_deep(Number.NaN, Number.NaN));
794
794
  $.$mol_assert_not($.$mol_compare_deep(1, 2));
795
- },
796
- 'Number'() {
797
795
  $.$mol_assert_ok($.$mol_compare_deep(Object(1), Object(1)));
798
- $.$mol_assert_ok($.$mol_compare_deep(Object(Number.NaN), Object(Number.NaN)));
799
796
  $.$mol_assert_not($.$mol_compare_deep(Object(1), Object(2)));
800
797
  },
801
- 'empty POJOs'() {
798
+ 'POJO'() {
802
799
  $.$mol_assert_ok($.$mol_compare_deep({}, {}));
803
- },
804
- 'different POJOs'() {
805
800
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { b: 2 }));
806
- },
807
- 'different POJOs with same keys but different values'() {
808
801
  $.$mol_assert_not($.$mol_compare_deep({ a: 1 }, { a: 2 }));
809
- },
810
- 'different POJOs with different keys but same values'() {
811
802
  $.$mol_assert_not($.$mol_compare_deep({}, { a: undefined }));
803
+ $.$mol_assert_ok($.$mol_compare_deep({ a: 1, b: 2 }, { b: 2, a: 1 }));
804
+ $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
812
805
  },
813
806
  'Array'() {
814
807
  $.$mol_assert_ok($.$mol_compare_deep([], []));
@@ -816,17 +809,12 @@ var $;
816
809
  $.$mol_assert_not($.$mol_compare_deep([1, 2], [1, 3]));
817
810
  $.$mol_assert_not($.$mol_compare_deep([1, 2,], [1, 3, undefined]));
818
811
  },
819
- 'same POJO trees'() {
820
- $.$mol_assert_ok($.$mol_compare_deep({ a: { b: 1 } }, { a: { b: 1 } }));
821
- },
822
- 'different classes with same values'() {
823
- class Obj {
824
- foo = 1;
812
+ 'Non POJO are different'() {
813
+ class Thing extends Object {
825
814
  }
826
- const a = new Obj;
827
- const b = new class extends Obj {
828
- };
829
- $.$mol_assert_not($.$mol_compare_deep(a, b));
815
+ $.$mol_assert_not($.$mol_compare_deep(new Thing, new Thing));
816
+ $.$mol_assert_not($.$mol_compare_deep(() => 1, () => 1));
817
+ $.$mol_assert_not($.$mol_compare_deep(new RangeError('Test error'), new RangeError('Test error')));
830
818
  },
831
819
  'same POJOs with cyclic reference'() {
832
820
  const a = { foo: {} };
@@ -835,41 +823,6 @@ var $;
835
823
  b['self'] = b;
836
824
  $.$mol_assert_ok($.$mol_compare_deep(a, b));
837
825
  },
838
- 'empty Element'() {
839
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("div", null)));
840
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null), $.$mol_jsx("span", null)));
841
- },
842
- 'Element with attributes'() {
843
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "rtl" })));
844
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", null)));
845
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { dir: "rtl" }), $.$mol_jsx("div", { dir: "ltr" })));
846
- },
847
- 'Element with styles'() {
848
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'red' } })));
849
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: {} })));
850
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { style: { color: 'red' } }), $.$mol_jsx("div", { style: { color: 'blue' } })));
851
- },
852
- 'Element with content'() {
853
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", null,
854
- "foo",
855
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
856
- "foo",
857
- $.$mol_jsx("br", null))));
858
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
859
- "foo",
860
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
861
- "bar",
862
- $.$mol_jsx("br", null))));
863
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", null,
864
- "foo",
865
- $.$mol_jsx("br", null)), $.$mol_jsx("div", null,
866
- "foo",
867
- $.$mol_jsx("hr", null))));
868
- },
869
- 'Element with handlers'() {
870
- $.$mol_assert_ok($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 1 })));
871
- $.$mol_assert_not($.$mol_compare_deep($.$mol_jsx("div", { onclick: () => 1 }), $.$mol_jsx("div", { onclick: () => 2 })));
872
- },
873
826
  'Date'() {
874
827
  $.$mol_assert_ok($.$mol_compare_deep(new Date(12345), new Date(12345)));
875
828
  $.$mol_assert_not($.$mol_compare_deep(new Date(12345), new Date(12346)));
@@ -881,8 +834,9 @@ var $;
881
834
  },
882
835
  'Map'() {
883
836
  $.$mol_assert_ok($.$mol_compare_deep(new Map, new Map));
884
- $.$mol_assert_ok($.$mol_compare_deep(new Map([[[1], [2]]]), new Map([[[1], [2]]])));
837
+ $.$mol_assert_ok($.$mol_compare_deep(new Map([[1, [2]]]), new Map([[1, [2]]])));
885
838
  $.$mol_assert_not($.$mol_compare_deep(new Map([[1, 2]]), new Map([[1, 3]])));
839
+ $.$mol_assert_not($.$mol_compare_deep(new Map([[[1], 2]]), new Map([[[1], 2]])));
886
840
  },
887
841
  'Set'() {
888
842
  $.$mol_assert_ok($.$mol_compare_deep(new Set, new Set));
@@ -901,97 +855,118 @@ var $;
901
855
  "use strict";
902
856
  var $;
903
857
  (function ($) {
904
- const a_stack = [];
905
- const b_stack = [];
906
- let cache = null;
907
- function $mol_compare_deep(a, b) {
908
- if (Object.is(a, b))
858
+ let cache = new WeakMap();
859
+ function $mol_compare_deep(left, right) {
860
+ if (Object.is(left, right))
909
861
  return true;
910
- const a_type = typeof a;
911
- const b_type = typeof b;
912
- if (a_type !== b_type)
862
+ if (left === null)
913
863
  return false;
914
- if (a_type === 'function')
915
- return a['toString']() === b['toString']();
916
- if (a_type !== 'object')
864
+ if (right === null)
917
865
  return false;
918
- if (!a || !b)
866
+ if (typeof left !== 'object')
919
867
  return false;
920
- if (a instanceof Error)
868
+ if (typeof right !== 'object')
921
869
  return false;
922
- if (a['constructor'] !== b['constructor'])
870
+ const left_proto = Reflect.getPrototypeOf(left);
871
+ const right_proto = Reflect.getPrototypeOf(right);
872
+ if (left_proto !== right_proto)
923
873
  return false;
924
- if (a instanceof RegExp)
925
- return a.toString() === b['toString']();
926
- const ref = a_stack.indexOf(a);
927
- if (ref >= 0) {
928
- return Object.is(b_stack[ref], b);
929
- }
930
- if (!cache)
931
- cache = new WeakMap;
932
- let a_cache = cache.get(a);
933
- if (a_cache) {
934
- const b_cache = a_cache.get(b);
935
- if (typeof b_cache === 'boolean')
936
- return b_cache;
874
+ if (left instanceof Boolean)
875
+ return Object.is(left.valueOf(), right['valueOf']());
876
+ if (left instanceof Number)
877
+ return Object.is(left.valueOf(), right['valueOf']());
878
+ if (left instanceof String)
879
+ return Object.is(left.valueOf(), right['valueOf']());
880
+ if (left instanceof Date)
881
+ return Object.is(left.valueOf(), right['valueOf']());
882
+ if (left instanceof RegExp)
883
+ return left.source === right['source'] && left.flags === right['flags'];
884
+ let left_cache = cache.get(left);
885
+ if (left_cache) {
886
+ const right_cache = left_cache.get(right);
887
+ if (typeof right_cache === 'boolean')
888
+ return right_cache;
937
889
  }
938
890
  else {
939
- a_cache = new WeakMap();
940
- cache.set(a, a_cache);
891
+ left_cache = new WeakMap([[right, true]]);
892
+ cache.set(left, left_cache);
941
893
  }
942
- a_stack.push(a);
943
- b_stack.push(b);
944
894
  let result;
945
895
  try {
946
- if (Symbol.iterator in a) {
947
- const a_iter = a[Symbol.iterator]();
948
- const b_iter = b[Symbol.iterator]();
949
- while (true) {
950
- const a_next = a_iter.next();
951
- const b_next = b_iter.next();
952
- if (a_next.done !== b_next.done)
953
- return result = false;
954
- if (a_next.done)
955
- break;
956
- if (!$mol_compare_deep(a_next.value, b_next.value))
957
- return result = false;
958
- }
959
- return result = true;
960
- }
961
- let count = 0;
962
- for (let key in a) {
963
- try {
964
- if (!$mol_compare_deep(a[key], b[key]))
965
- return result = false;
966
- }
967
- catch (error) {
968
- $.$mol_fail_hidden(new $.$mol_error_mix(`Failed ${JSON.stringify(key)} fields comparison of ${a} and ${b}`, error));
969
- }
970
- ++count;
971
- }
972
- for (let key in b) {
973
- --count;
974
- if (count < 0)
975
- return result = false;
976
- }
977
- if (a instanceof Number || a instanceof String || a instanceof Symbol || a instanceof Boolean || a instanceof Date) {
978
- if (!Object.is(a['valueOf'](), b['valueOf']()))
979
- return result = false;
980
- }
981
- return result = true;
896
+ if (left_proto && !Reflect.getPrototypeOf(left_proto))
897
+ result = compare_pojo(left, right);
898
+ else if (Array.isArray(left))
899
+ result = compare_array(left, right);
900
+ else if (left instanceof Set)
901
+ result = compare_set(left, right);
902
+ else if (left instanceof Map)
903
+ result = compare_map(left, right);
904
+ else if (ArrayBuffer.isView(left))
905
+ result = compare_buffer(left, right);
906
+ else
907
+ result = false;
982
908
  }
983
909
  finally {
984
- a_stack.pop();
985
- b_stack.pop();
986
- if (a_stack.length === 0) {
987
- cache = null;
988
- }
989
- else {
990
- a_cache.set(b, result);
991
- }
910
+ left_cache.set(right, result);
992
911
  }
912
+ return result;
993
913
  }
994
914
  $.$mol_compare_deep = $mol_compare_deep;
915
+ function compare_array(left, right) {
916
+ const len = left.length;
917
+ if (len !== right.length)
918
+ return false;
919
+ for (let i = 0; i < len; ++i) {
920
+ if (!$mol_compare_deep(left[i], right[i]))
921
+ return false;
922
+ }
923
+ return true;
924
+ }
925
+ function compare_buffer(left, right) {
926
+ const len = left.byteLength;
927
+ if (len !== right.byteLength)
928
+ return false;
929
+ for (let i = 0; i < len; ++i) {
930
+ if (left[i] !== right[i])
931
+ return false;
932
+ }
933
+ return true;
934
+ }
935
+ function compare_iterator(left, right, compare) {
936
+ while (true) {
937
+ const left_next = left.next();
938
+ const right_next = right.next();
939
+ if (left_next.done !== right_next.done)
940
+ return false;
941
+ if (left_next.done)
942
+ break;
943
+ if (!compare(left_next.value, right_next.value))
944
+ return false;
945
+ }
946
+ return true;
947
+ }
948
+ function compare_set(left, right) {
949
+ if (left.size !== right.size)
950
+ return false;
951
+ return compare_iterator(left.values(), right.values(), $mol_compare_deep);
952
+ }
953
+ function compare_map(left, right) {
954
+ if (left.size !== right.size)
955
+ return false;
956
+ return compare_iterator(left.keys(), right.keys(), Object.is)
957
+ && compare_iterator(left.values(), right.values(), $mol_compare_deep);
958
+ }
959
+ function compare_pojo(left, right) {
960
+ const left_keys = Object.getOwnPropertyNames(left);
961
+ const right_keys = Object.getOwnPropertyNames(right);
962
+ if (left_keys.length !== right_keys.length)
963
+ return false;
964
+ for (let key of left_keys) {
965
+ if (!$mol_compare_deep(left[key], Reflect.get(right, key)))
966
+ return false;
967
+ }
968
+ return true;
969
+ }
995
970
  })($ || ($ = {}));
996
971
  //deep.js.map
997
972
  ;
@@ -1788,7 +1763,8 @@ var $;
1788
1763
  }
1789
1764
  }
1790
1765
  const boxify = $.$mol_data_pipe((input) => input.toString(), Box);
1791
- $.$mol_assert_like(boxify(5), new Box('5'));
1766
+ $.$mol_assert_ok(boxify(5) instanceof Box);
1767
+ $.$mol_assert_like(boxify(5).value, '5');
1792
1768
  },
1793
1769
  });
1794
1770
  })($ || ($ = {}));