UNPKG

deep-equal-diagnostics

Version:

Ultra-fast robust diagnostic testing for strict deep equality

212 lines (178 loc) 7.66 kB
const {deepStrictEqual} = require('../deep-strict-equal.js') const assert = require('assert') function assertEqual(x,y) { try { assert.deepStrictEqual(x,y) return true } catch(e) { return false } } function claim(b, message) { if(b) console.log(`\u2713 ${message} is true`) else console.log(`\u2639 ${message} is false: should be true`) } const symbol = Symbol() const error = new Error('msg') const eval_error = new EvalError('msg') const range_error = new RangeError('msg') const reference_error = new ReferenceError('msg') const syntax_error = new SyntaxError('msg') const type_error = new TypeError('msg') const uri_error = new URIError('msg') function getWildCircle() { const buffer = new ArrayBuffer(4); const view = new DataView(buffer); view.setInt8(0, 127); view.setInt8(1, 11); view.setInt8(2, 17); view.setInt8(3, -17); buffer[0] = "fred"; view[0] = "fred"; const map1 = new Map([ [ [1,2], /*new Date()*/], [7,true], ['key1', 'value1'], [buffer, view] ]); const map2 = new Map([ ['key2', {a:1,b:2}], [new Boolean(true), new Number(7)] ]); map1.buf = buffer; buffer.z = map1; map2.view = view; view.x = new Boolean(true); buffer.x = new Boolean(true); const x = new Set([map1, map2]); x[1] = "fred"; x.a = {} //new Date(1618595373337); Date OK but sometimes JAVASCRIPT BUG makesDate 1618595373338 x.a.b = new Set(["cat", "dog", buffer, view, ["a", new String("b")]]); x.a.b.c = x; x.buff = buffer; map1.Q = x.a.b; map1.set(x.a.b, x.a); return x } function getObject() { const x = new Boolean(true) x.a = new Number(7) x.a.b = new String("my-string") x.a.b.c = /abc/g x.a.b.c.d = [1,2,3] x.a.b.c.d.e = {} //function bax(){const hamster = 'pier'} x.a.b.c.d.e.f = new Int8Array([1,2,3]) x.a.b.c.d.e.f.g = new Uint8Array([1,2,3]) x.a.b.c.d.e.f.g.h = new Uint8ClampedArray([1,2,3]) x.a.b.c.d.e.f.g.h.i = new Int16Array([1,2,3]) x.a.b.c.d.e.f.g.h.i.j = new Uint16Array([1,2,3]) x.a.b.c.d.e.f.g.h.i.j.k = new Int32Array([1,2,3]) x.a.b.c.d.e.f.g.h.i.j.k.l = new Uint32Array([1,2,3]) x.a.b.c.d.e.f.g.h.i.j.k.l.m = new Float32Array([1,2,3]) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n = new Float64Array([1,2,3]) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o = new BigInt64Array([1n,2n,3n]) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p = new BigUint64Array([1n,2n,3n]) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q = new Set([1,2,3]) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r = new Map([[{},{}]]) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s = new ArrayBuffer(8) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t = new DataView(new Uint8Array([1,2,3]).buffer) x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.zz = -0 x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.zzz = -Infinity const xx = x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t xx.a = Object.create(Boolean.prototype) xx.a.b = Object.create(Number.prototype) xx.a.b.c = Object.create(String.prototype) xx.a.b.c.d = Object.create(Date.prototype) xx.a.b.c.d.e = Object.create(RegExp.prototype) xx.a.b.c.d.e.f = Object.create(Error.prototype) xx.a.b.c.d.e.f.g = Object.create(EvalError.prototype) xx.a.b.c.d.e.f.g.h = Object.create(RangeError.prototype) xx.a.b.c.d.e.f.g.h.i = Object.create(ReferenceError.prototype) xx.a.b.c.d.e.f.g.h.i.j = Object.create(SyntaxError.prototype) xx.a.b.c.d.e.f.g.h.i.j = Object.create(TypeError.prototype) xx.a.b.c.d.e.f.g.h.i.j.k = Object.create(URIError.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l = Object.create(Int8Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m = Object.create(Uint8Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n = Object.create(Uint8ClampedArray.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o = Object.create(Int16Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p = Object.create(Uint16Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q = Object.create(Int32Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r = Object.create(Uint32Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s = Object.create(Float32Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t = Object.create(Float64Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u = Object.create(BigInt64Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v = Object.create(BigUint64Array.prototype) xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w = Object.create(BigUint64Array.prototype) const xxx = xx.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w xxx.a = Object.create(WeakSet.prototype) xxx.a.b = Object.create(WeakMap.prototype) xxx.a.b.c = Object.create(Set.prototype) xxx.a.b.c.d = Object.create(Map.prototype) xxx.a.b.c.d.e = Object.create(ArrayBuffer.prototype) xxx.a.b.c.d.e = Object.create(DataView.prototype) xxx.a.b.c.d.e.f = Object.create(BigInt.prototype) xxx.a.b.c.d.e.f = Object.create(Symbol.prototype) xxx.a.b.c.d.e.f.g = Object.create(Function.prototype) const xxxx = xxx.a.b.c.d.e.f.g xxxx.plusZero = +0 xxxx.negZero = -0 xxxx.Zero = 0 xxxx.Infinity = Infinity xxxx.negInfinity = -Infinity xxxx.NaN = NaN xxxx.number = 7 xxxx.string = 'my-string' xxxx.regexp = /abc/g xxxx.date = {} //new Date(1650043372813) xxxx.symbol = symbol xxxx.bigint = 123n xxxx.error = new Error() xxxx.error.message = error.message xxxx.error.stack = error.stack xxxx.eval_error = new EvalError() xxxx.eval_error.message = eval_error.message xxxx.eval_error.stack = eval_error.stack xxxx.range_error = new RangeError() xxxx.range_error.message = range_error.message xxxx.range_error.stack = range_error.stack xxxx.reference_error = new ReferenceError() xxxx.reference_error.message = reference_error.message xxxx.reference_error.stack = reference_error.stack xxxx.syntax_error = new SyntaxError() xxxx.syntax_error.message = syntax_error.message xxxx.syntax_error.stack = syntax_error.stack xxxx.type_error = new TypeError() xxxx.type_error.message = type_error.message xxxx.type_error.stack = type_error.stack xxxx.uri_error = new URIError() xxxx.uri_error.message = uri_error.message xxxx.uri_error.stack = uri_error.stack Object.defineProperty(xxxx.uri_error, 'p', { get:function(){return 7}, set:function (value){const x = value} }) xx.a.b.c.d.e.f.g.circle = x.a.b.c xx.wildCircle = getWildCircle() xx.wildCircle.circle = x xx.wildCircle.buf = Buffer.alloc(8) xx.wildCircle.buf.proto = Object.create(Buffer.prototype) xx.wildCircle.buf.proto.xx = xx return x } console.log('-------------------------------------') function test_1() { console.log("Test 1") const x = getObject() const y = getObject() console.log(assertEqual(x,y)) claim(deepStrictEqual(x,y), 'deepStrictEqual(x,y)' ) console.log(deepStrictEqual.message) } test_1() console.log('-------------------------------------') function test_2() { console.log("Test 2") const x = getObject() const y = getObject() x.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.Q = 1 y.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.Q = 2 claim(!deepStrictEqual(x,y), '!deepStrictEqual(x,y)' ) console.log(deepStrictEqual.message) } test_2()