Comparing version 4.1.4 to 4.1.5
116
lib/tests.js
@@ -64,2 +64,11 @@ // Generated by CoffeeScript 1.10.0 | ||
T.eq(CND.type_of(new ArrayBuffer(42)), 'arraybuffer'); | ||
T.eq(CND.type_of(new Int8Array(5)), 'int8array'); | ||
T.eq(CND.type_of(new Uint8Array(5)), 'uint8array'); | ||
T.eq(CND.type_of(new Uint8ClampedArray(5)), 'uint8clampedarray'); | ||
T.eq(CND.type_of(new Int16Array(5)), 'int16array'); | ||
T.eq(CND.type_of(new Uint16Array(5)), 'uint16array'); | ||
T.eq(CND.type_of(new Int32Array(5)), 'int32array'); | ||
T.eq(CND.type_of(new Uint32Array(5)), 'uint32array'); | ||
T.eq(CND.type_of(new Float32Array(5)), 'float32array'); | ||
T.eq(CND.type_of(new Float64Array(5)), 'float64array'); | ||
return null; | ||
@@ -116,2 +125,45 @@ }; | ||
this["is_subset"] = function(T) { | ||
T.eq(false, CND.is_subset(Array.from('abcde'), Array.from('abcd'))); | ||
T.eq(false, CND.is_subset(Array.from('abcx'), Array.from('abcd'))); | ||
T.eq(false, CND.is_subset(Array.from('abcd'), [])); | ||
T.eq(true, CND.is_subset(Array.from('abcd'), Array.from('abcd'))); | ||
T.eq(true, CND.is_subset(Array.from('abc'), Array.from('abcd'))); | ||
T.eq(true, CND.is_subset([], Array.from('abcd'))); | ||
T.eq(true, CND.is_subset([], Array.from([]))); | ||
T.eq(false, CND.is_subset(new Set('abcde'), new Set('abcd'))); | ||
T.eq(false, CND.is_subset(new Set('abcx'), new Set('abcd'))); | ||
T.eq(false, CND.is_subset(new Set('abcx'), new Set())); | ||
T.eq(true, CND.is_subset(new Set('abcd'), new Set('abcd'))); | ||
T.eq(true, CND.is_subset(new Set('abc'), new Set('abcd'))); | ||
T.eq(true, CND.is_subset(new Set(), new Set('abcd'))); | ||
T.eq(true, CND.is_subset(new Set(), new Set())); | ||
return null; | ||
}; | ||
this["deep_copy"] = function(T) { | ||
/* TAINT set comparison doesn't work */ | ||
var i, len, probe, probes, result; | ||
probes = [ | ||
[ | ||
'foo', 42, [ | ||
'bar', (function() { | ||
return 'xxx'; | ||
}) | ||
], { | ||
q: 'Q', | ||
s: 'S' | ||
} | ||
] | ||
]; | ||
for (i = 0, len = probes.length; i < len; i++) { | ||
probe = probes[i]; | ||
result = CND.deep_copy(probe); | ||
T.eq(result, probe); | ||
T.ok(result !== probe); | ||
} | ||
return null; | ||
}; | ||
this["XJSON (1)"] = function(T) { | ||
@@ -157,42 +209,26 @@ var d, e; | ||
this["is_subset"] = function(T) { | ||
T.eq(false, CND.is_subset(Array.from('abcde'), Array.from('abcd'))); | ||
T.eq(false, CND.is_subset(Array.from('abcx'), Array.from('abcd'))); | ||
T.eq(false, CND.is_subset(Array.from('abcd'), [])); | ||
T.eq(true, CND.is_subset(Array.from('abcd'), Array.from('abcd'))); | ||
T.eq(true, CND.is_subset(Array.from('abc'), Array.from('abcd'))); | ||
T.eq(true, CND.is_subset([], Array.from('abcd'))); | ||
T.eq(true, CND.is_subset([], Array.from([]))); | ||
T.eq(false, CND.is_subset(new Set('abcde'), new Set('abcd'))); | ||
T.eq(false, CND.is_subset(new Set('abcx'), new Set('abcd'))); | ||
T.eq(false, CND.is_subset(new Set('abcx'), new Set())); | ||
T.eq(true, CND.is_subset(new Set('abcd'), new Set('abcd'))); | ||
T.eq(true, CND.is_subset(new Set('abc'), new Set('abcd'))); | ||
T.eq(true, CND.is_subset(new Set(), new Set('abcd'))); | ||
T.eq(true, CND.is_subset(new Set(), new Set())); | ||
return null; | ||
}; | ||
this["XJSON (3)"] = function(T) { | ||
var d, d_json, d_ng, d_ng_text; | ||
d = { | ||
my_number: 42, | ||
my_buffer: Buffer.from([127, 128, 129]), | ||
my_null: null, | ||
my_nan: NaN, | ||
my_local_symbol: Symbol('local-symbol'), | ||
my_global_symbol: Symbol["for"]('global-symbol') | ||
}; | ||
d[Symbol["for"]('foo')] = 'bar'; | ||
d[Symbol('FOO')] = 'BAR'; | ||
d_json = CND.XJSON.stringify(d); | ||
d_ng = CND.XJSON.parse(d_json); | ||
T.eq(d_ng.my_number, d.my_number); | ||
T.eq(d_ng.my_buffer, d.my_buffer); | ||
T.eq(d_ng.my_null, d.my_null); | ||
T.eq(d_ng.my_nan, d.my_nan); | ||
T.eq(d_ng.my_global_symbol, d.my_global_symbol); | ||
this["deep_copy"] = function(T) { | ||
/* TAINT set comparison doesn't work */ | ||
var i, len, probe, probes, result; | ||
probes = [ | ||
[ | ||
'foo', 42, [ | ||
'bar', (function() { | ||
return 'xxx'; | ||
}) | ||
], { | ||
q: 'Q', | ||
s: 'S' | ||
} | ||
] | ||
]; | ||
for (i = 0, len = probes.length; i < len; i++) { | ||
probe = probes[i]; | ||
result = CND.deep_copy(probe); | ||
T.eq(result, probe); | ||
T.ok(result !== probe); | ||
} | ||
/* NOTE it's not possible to recreate the identity of a local symbol, so we check value and status: */ | ||
T.eq(d_ng.my_local_symbol.toString(), d.my_local_symbol.toString()); | ||
d_ng_text = d_ng.my_local_symbol.toString().replace(/^Symbol\((.*)\)$/, '$1'); | ||
T.ok(d.my_local_symbol !== Symbol["for"](d_ng_text)); | ||
return null; | ||
@@ -222,3 +258,3 @@ }; | ||
if (module.parent == null) { | ||
include = ["test type_of", "test size_of", "XJSON (1)", "XJSON (2)", "is_subset", "deep_copy"]; | ||
include = ["XJSON (3)"]; | ||
this._prune(); | ||
@@ -225,0 +261,0 @@ this._main(); |
@@ -12,44 +12,62 @@ // Generated by CoffeeScript 1.10.0 | ||
this.replacer = function(key, value) { | ||
var R, type; | ||
/* NOTE Buffers are treated specially; at this point, they are already converted into sth that looks | ||
like `{ type: 'Buffer', data: [ ... ], }`. | ||
*/ | ||
var data, local, type; | ||
if ((CND.isa_pod(value)) && (value['type'] === 'Buffer') && (CND.isa_list(data = value['data']))) { | ||
return { | ||
'~isa': '-x-buffer', | ||
'%self': data | ||
}; | ||
} | ||
switch (type = CND.type_of(value)) { | ||
case 'nan': | ||
return { | ||
'~isa': '-x-nan' | ||
}; | ||
case 'set': | ||
R = { | ||
return { | ||
'~isa': '-x-set', | ||
'%self': Array.from(value) | ||
}; | ||
break; | ||
case 'map': | ||
R = { | ||
return { | ||
'~isa': '-x-map', | ||
'%self': Array.from(value) | ||
}; | ||
break; | ||
case 'function': | ||
R = { | ||
return { | ||
'~isa': '-x-function', | ||
'%self': value.toString() | ||
}; | ||
break; | ||
default: | ||
R = value; | ||
case 'symbol': | ||
data = value.toString().replace(/^Symbol\((.*)\)$/, '$1'); | ||
local = value === Symbol["for"](data); | ||
return { | ||
'~isa': '-x-symbol', | ||
local: local, | ||
'%self': data | ||
}; | ||
} | ||
return R; | ||
return value; | ||
}; | ||
this.reviver = function(key, value) { | ||
var R, type; | ||
var type; | ||
switch (type = CND.type_of(value)) { | ||
case '-x-nan': | ||
return NaN; | ||
case '-x-buffer': | ||
return Buffer.from(value['%self']); | ||
case '-x-set': | ||
R = new Set(value['%self']); | ||
break; | ||
return new Set(value['%self']); | ||
case '-x-map': | ||
R = new Map(value['%self']); | ||
break; | ||
return new Map(value['%self']); | ||
case '-x-function': | ||
R = (eval("[ " + value['%self'] + " ]"))[0]; | ||
break; | ||
default: | ||
R = value; | ||
return (eval("[ " + value['%self'] + " ]"))[0]; | ||
case '-x-symbol': | ||
return Symbol["for"](value['%self']); | ||
} | ||
return R; | ||
return value; | ||
}; | ||
@@ -71,13 +89,2 @@ | ||
this._demo = function() { | ||
var XJSON, d, e; | ||
XJSON = this; | ||
e = new Set('xy'); | ||
e.add(new Set('abc')); | ||
d = ['A', 'B', e]; | ||
help(d); | ||
info(XJSON.stringify(d)); | ||
return info(XJSON.parse(XJSON.stringify(d))); | ||
}; | ||
this.replacer = this.replacer.bind(this); | ||
@@ -91,10 +98,4 @@ | ||
this._demo = this._demo.bind(this); | ||
if (module.parent == null) { | ||
this._demo(); | ||
} | ||
}).call(this); | ||
//# sourceMappingURL=XJSON.js.map |
{ | ||
"name": "cnd", | ||
"version": "4.1.4", | ||
"version": "4.1.5", | ||
"description": "a grab-bag NodeJS package mainly for functionalities that used to live in coffeenode-trm, coffeenode-bitsnpieces, and coffeenode-types", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
247849
2437