mirror of
https://github.com/flynx/serialize.js.git
synced 2026-08-26 09:46:41 +00:00
tests and docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6ae2d66457
commit
91b0c776dc
39
README.md
39
README.md
@ -11,5 +11,44 @@ This extends the default JSON serialization adding the following:
|
||||
|
||||
## Motivation
|
||||
|
||||
This was originally built as a companion to a testing module for a
|
||||
programming class, illustrating several concepts, including: guaranteed
|
||||
clean isolation of data structures via serialization, instrumenting code
|
||||
and tooling design, basic parsing, among others.
|
||||
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
## Introduction
|
||||
|
||||
|
||||
### Serializing functions
|
||||
|
||||
Due to how JavaScript is designed it is not possible to trivially and
|
||||
fully clone a function with all of it's references, `.serilaize(..)` will
|
||||
not attempt to clone any state a function may have, this will lead to
|
||||
loosing:
|
||||
|
||||
- Function closure
|
||||
- Attributes set on the function or any of it's prototypes, including the
|
||||
`.__proto__` value if it was changed.
|
||||
|
||||
Thus, care must be taken when serializing structures containing function.
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### `serialize(..)` / `eJSON.stringify(..)`
|
||||
|
||||
### `deserialize(..)` / 'eJSON.parse(..)'
|
||||
|
||||
### `deepCopy(..)`
|
||||
|
||||
### `partialDeepCopy(..)`
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
42
test.js
42
test.js
@ -26,6 +26,8 @@ var eJSON = require('./serialize')
|
||||
var json = true
|
||||
var ejson = false
|
||||
|
||||
var pre_cycle = true
|
||||
|
||||
// XXX test whitespace handling...
|
||||
var setups = test.Setups({
|
||||
'true': function(assert){
|
||||
@ -53,9 +55,9 @@ var setups = test.Setups({
|
||||
return ['999999999999999999999n'] },
|
||||
// XXX need a way to test this...
|
||||
//'float-a': function(assert){
|
||||
// return '.123' },
|
||||
// return ['.123'] },
|
||||
//'float-c': function(assert){
|
||||
// return '123.' },
|
||||
// return ['123.'] },
|
||||
// XXX also test:
|
||||
// hex/bin/orc/...
|
||||
Infinity: function(assert){
|
||||
@ -179,17 +181,47 @@ test.Tests({
|
||||
//*/
|
||||
})
|
||||
|
||||
/* XXX these break things...
|
||||
test.Cases({
|
||||
/* XXX for some magical reason hese break as soon as we add [setup] to arguments...
|
||||
'deep-copy-function': function(assert, [setup]){
|
||||
// XXX check function isolation...
|
||||
},
|
||||
//*/
|
||||
|
||||
'partial-deep-copy-function': function(assert, [setup]){
|
||||
// NOTE: these syntax variants are not output by .serialize(..) this it
|
||||
// is less critical to test them in the main loop.
|
||||
// XXX though it would be nice to do so...
|
||||
tests: [
|
||||
// numbers/floats...
|
||||
['.123', '0.123'],
|
||||
['123.', '123'],
|
||||
|
||||
// string quotes...
|
||||
['"abc"', "'abc'"],
|
||||
['"abc"', '`abc`'],
|
||||
|
||||
// arrays...
|
||||
['[1,2,]', '[1,2]'],
|
||||
|
||||
// sparse arrays...
|
||||
['[<empty>]', '[,]'],
|
||||
['[1,2,<empty>]', '[1,2,,]'],
|
||||
['[1,2,<empty>]', '[1,2,<empty>,]'],
|
||||
],
|
||||
'syntax-simplifications': function(assert){
|
||||
var aa, bb
|
||||
for(var [a, b] of this.tests){
|
||||
assert(eJSON.serialize(aa = eJSON.deserialize(a)) == eJSON.serialize(bb = eJSON.deserialize(b)),
|
||||
`"${ a }" and "${ b }" should deserialize to the samve value.`,
|
||||
'got:', aa, 'and', bb, 'resp.') } },
|
||||
|
||||
'deep-copy-function': function(assert){
|
||||
// XXX check function isolation...
|
||||
},
|
||||
'partial-deep-copy-function': function(assert){
|
||||
// XXX check function isolation...
|
||||
},
|
||||
})
|
||||
//*/
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user