123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976 |
- // ██████╗ ████████╗████████╗ ██████╗ ███████╗██████╗ ███████╗ ██████╗
- // ██╔══██╗╚══██╔══╝╚══██╔══╝██╔════╝ ██╔════╝██╔══██╗██╔════╝██╔════╝ ██╗██╗
- // ██████╔╝ ██║ ██║ ██║ ███████╗██████╔╝█████╗ ██║ ╚═╝╚═╝
- // ██╔══██╗ ██║ ██║ ██║ ╚════██║██╔═══╝ ██╔══╝ ██║ ██╗██╗
- // ██║ ██║ ██║ ██║ ╚██████╗ ███████║██║ ███████╗╚██████╗ ╚═╝╚═╝
- // ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚══════╝ ╚═════╝
- //
- // ██████╗ ██████╗ ███████╗██████╗ ██████╗██╗ ██████╗ ███╗ ██╗
- // ██╔════╝██╔═══██╗██╔════╝██╔══██╗██╔════╝██║██╔═══██╗████╗ ██║
- // ██║ ██║ ██║█████╗ ██████╔╝██║ ██║██║ ██║██╔██╗ ██║
- // ██║ ██║ ██║██╔══╝ ██╔══██╗██║ ██║██║ ██║██║╚██╗██║
- // ╚██████╗╚██████╔╝███████╗██║ ██║╚██████╗██║╚██████╔╝██║ ╚████║
- // ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝
- //
- // Export the array of tests below.
- module.exports = [
- ////////////////////////////////////////////
- // STRINGS
- ////////////////////////////////////////////
- { example: 'foo', actual: 'bar', result: 'bar' },
- { example: 'foo', actual: '', result: '' },
- { example: 'foo', actual: 0, result: '0' },
- { example: 'foo', actual: 1, result: '1' },
- { example: 'foo', actual: -1.1, result: '-1.1' },
- { example: 'foo', actual: -0, result: '0' },
- { example: 'foo', actual: +0, result: '0' },
- { example: 'foo', actual: true, result: 'true' },
- { example: 'foo', actual: false, result: 'false' },
- { example: 'foo', actual: {}, result: '' },
- { example: 'foo', actual: {foo:'bar'}, result: '' },
- { example: 'foo', actual: {foo:{bar:{baz:{}}}}, result: '' },
- { example: 'foo', actual: {foo:['bar']}, result: '' },
- { example: 'foo', actual: {foo:{bar:{baz:[{}]}}}, result: '' },
- { example: 'foo', actual: [], result: '' },
- { example: 'foo', actual: ['asdf'], result: '' },
- { example: 'foo', actual: [''], result: '' },
- { example: 'foo', actual: [235], result: '' },
- { example: 'foo', actual: [false], result: '' },
- { example: 'foo', actual: [{}], result: '' },
- { example: 'foo', actual: [{foo:'bar'}], result: '' },
- { example: 'foo', actual: undefined, result: '' },
- { example: 'foo', actual: NaN, result: '' },
- { example: 'foo', actual: Infinity, result: '' },
- { example: 'foo', actual: -Infinity, result: '' },
- { example: 'foo', actual: null, result: '' },
- { example: 'foo', actual: /some regexp/, result: '' },
- { example: 'foo', actual: function(){}, result: '' },
- { example: 'foo', actual: new Date('November 5, 1605 GMT'), result: '1605-11-05T00:00:00.000Z' },
- { example: 'foo', actual: new (require('stream').Readable)(), result: '' }, // TODO: consider buffering into a string..? needs community discussion
- { example: 'foo', actual: new Buffer('asdf'), result: '' }, // TODO: consider converting to string
- { example: 'foo', actual: new Error('asdf'), result: '' }, // TODO: consider converting to error stack trace
- ////////////////////////////////////////////
- // NUMBERS
- ////////////////////////////////////////////
- { example: 123, actual: 'bar', result: 0 },
- { example: 123, actual: '', result: 0 },
- { example: 123, actual: '0', result: 0 },
- { example: 123, actual: '1', result: 1 },
- { example: 123, actual: '-1.1', result: -1.1 },
- { example: 123, actual: 'NaN', result: 0 },
- { example: 123, actual: 'undefined', result: 0 },
- { example: 123, actual: 'null', result: 0 },
- { example: 123, actual: '-Infinity', result: 0 },
- { example: 123, actual: 'Infinity', result: 0 },
- { example: 123, actual: 0, result: 0 },
- { example: 123, actual: 1, result: 1 },
- { example: 123, actual: -1.1, result: -1.1 },
- { example: 123, actual: +0, result: 0 },
- { example: 123, actual: -0, result: 0 },
- { example: 123, actual: true, result: 1 },
- { example: 123, actual: false, result: 0 },
- { example: 123, actual: {}, result: 0 },
- { example: 123, actual: {foo:'bar'}, result: 0 },
- { example: 123, actual: {foo:{bar:{baz:{}}}}, result: 0 },
- { example: 123, actual: {foo:['bar']}, result: 0 },
- { example: 123, actual: {foo:{bar:{baz:[{}]}}}, result: 0 },
- { example: 123, actual: [], result: 0 },
- { example: 123, actual: ['asdf'], result: 0 },
- { example: 123, actual: [''], result: 0 },
- { example: 123, actual: [235], result: 0 },
- { example: 123, actual: [false], result: 0 },
- { example: 123, actual: [{}], result: 0 },
- { example: 123, actual: [{foo:'bar'}], result: 0 },
- { example: 123, actual: undefined, result: 0 },
- { example: 123, actual: NaN, result: 0 },
- { example: 123, actual: Infinity, result: 0 },
- { example: 123, actual: -Infinity, result: 0 },
- { example: 123, actual: null, result: 0 },
- { example: 123, actual: /some regexp/, result: 0 },
- { example: 123, actual: function(){}, result: 0 },
- { example: 123, actual: new Date('November 5, 1605 GMT'), result: -11491632000000 },
- { example: 123, actual: new (require('stream').Readable)(), result: 0 }, // TODO: ??? maybe num bytes read so far?
- { example: 123, actual: new Buffer('asdf'), result: 0 }, // TODO: ??? maybe size of the buffer in bytes?
- { example: 123, actual: new Error('asdf'), result: 0 }, // TODO: ??? maybe `.status`?
- ////////////////////////////////////////////
- // BOOLEANS
- ////////////////////////////////////////////
- { example: true, actual: 'bar', result: false },
- { example: true, actual: '', result: false },
- { example: true, actual: '-1.1', result: false },
- { example: true, actual: 'NaN', result: false },
- { example: true, actual: 'undefined', result: false },
- { example: true, actual: 'null', result: false },
- { example: true, actual: '-Infinity', result: false },
- { example: true, actual: 'Infinity', result: false },
- { example: true, actual: 'true', result: true },
- { example: true, actual: 'false', result: false },
- { example: true, actual: '0', result: false },
- { example: true, actual: '1', result: true },
- { example: true, actual: 0, result: false },
- { example: true, actual: 1, result: true },
- { example: true, actual: -1.1, result: false },
- { example: true, actual: +0, result: false },
- { example: true, actual: -0, result: false },
- { example: true, actual: true, result: true },
- { example: true, actual: false, result: false },
- { example: true, actual: {}, result: false },
- { example: true, actual: {foo:'bar'}, result: false },
- { example: true, actual: {foo:{bar:{baz:{}}}}, result: false },
- { example: true, actual: {foo:['bar']}, result: false },
- { example: true, actual: {foo:{bar:{baz:[{}]}}}, result: false },
- { example: true, actual: [], result: false },
- { example: true, actual: ['asdf'], result: false },
- { example: true, actual: [''], result: false },
- { example: true, actual: [235], result: false },
- { example: true, actual: [false], result: false },
- { example: true, actual: [{}], result: false },
- { example: true, actual: [{foo:'bar'}], result: false },
- { example: true, actual: undefined, result: false },
- { example: true, actual: NaN, result: false },
- { example: true, actual: Infinity, result: false },
- { example: true, actual: -Infinity, result: false },
- { example: true, actual: null, result: false },
- { example: true, actual: /some regexp/, result: false },
- { example: true, actual: function(){}, result: false },
- { example: true, actual: new Date('November 5, 1605 GMT'), result: false },
- { example: true, actual: new (require('stream').Readable)(), result: false },
- { example: true, actual: new Buffer('asdf'), result: false },
- { example: true, actual: new Error('asdf'), result: false },
- ////////////////////////////////////////////
- // DICTIONARIES (w/ json-serializable contents)
- // (note that `{}` in an exemplar indicates that any keys are permitted, but that their values must be json-serializable)
- // (there is no way to specifically indicate a dictionary of literally anything, including a mix of functions and other stuff
- // so in that scenario, just use `'==='` instead of `{}` and add additional checks in relevant code to ensure you're dealing
- // with a dictionary vs the other things `===` might produce; e.g. strings/functions/streams/whatever - literally anything.)
- ////////////////////////////////////////////
- { example: {}, actual: 'bar', result: {} },
- { example: {}, actual: 123, result: {} },
- { example: {}, actual: -0, result: {} },
- { example: {}, actual: +0, result: {} },
- { example: {}, actual: true, result: {} },
- { example: {}, actual: {}, result: {} },
- { example: {}, actual: {foo:'bar'}, result: {foo:'bar'} },
- { example: {}, actual: {foo:{bar:{baz:{}}}}, result: {foo:{bar:{baz:{}}}} },
- { example: {}, actual: {foo:['bar']}, result: {foo:['bar']} },
- { example: {}, actual: {foo:{bar:{baz:[{}]}}}, result: {foo:{bar:{baz:[{}]}}} },
- { example: {}, actual: [], result: {} },
- { example: {}, actual: ['asdf'], result: {} },
- { example: {}, actual: [''], result: {} },
- { example: {}, actual: [235], result: {} },
- { example: {}, actual: [false], result: {} },
- { example: {}, actual: [{}], result: {} },
- { example: {}, actual: [{foo:'bar'}], result: {} },
- { example: {}, actual: undefined, result: {} },
- { example: {}, actual: NaN, result: {} },
- { example: {}, actual: Infinity, result: {} },
- { example: {}, actual: -Infinity, result: {} },
- { example: {}, actual: null, result: {} },
- { example: {}, actual: /some regexp/, result: {} },
- { example: {}, actual: function(){}, result: {} },
- { example: {}, actual: new Date('November 5, 1605 GMT'), result: {} },
- // Skip Readable stream tests for now since the enumerable properties vary between Node.js versions.
- // TODO: bring back support for this by explicitly filtering properties of streams in `.exec()`
- // { example: {}, actual: new (require('stream').Readable)(), result: { _readableState: { highWaterMark: 16384, buffer: [], length: 0, pipes: null, pipesCount: 0, flowing: false, ended: false, endEmitted: false, reading: false, calledRead: false, sync: true, needReadable: false, emittedReadable: false, readableListening: false, objectMode: false, defaultEncoding: 'utf8', ranOut: false, awaitDrain: 0, readingMore: false, decoder: null, encoding: null }, readable: true, domain: null, _events: {}, _maxListeners: 10 } },
- // Skip Buffer tests for now since the enumerable properties vary between Node.js versions.
- // TODO: bring back support for this by explicitly filtering properties of buffers in `.exec()`
- // { example: {}, actual: new Buffer('asdf'), result: {} },
- { example: {}, actual: new Error('asdf'), result: {} }, // TODO: consider enhancing this behavior to guarantee e.g. `.message` (string), `.stack` (string), `.code` (string), and `.status` (number). Needs community discussion
- ////////////////////////////////////////////
- // ARRAYS (with json-serializable contents)
- // (note that `[]` in an exemplar is actually just shorthand for `['*']`)
- // (to indicate an array of literally anything, including a mix of functions and other stuff, use `['===']`)
- ////////////////////////////////////////////
- { example: [], actual: 'bar', result: [] },
- { example: [], actual: 123, result: [] },
- { example: [], actual: -0, result: [] },
- { example: [], actual: +0, result: [] },
- { example: [], actual: true, result: [] },
- { example: [], actual: {}, result: [] },
- { example: [], actual: {foo:'bar'}, result: [] },
- { example: [], actual: {foo:{bar:{baz:{}}}}, result: [] },
- { example: [], actual: {foo:['bar']}, result: [] },
- { example: [], actual: {foo:{bar:{baz:[{}]}}}, result: [] },
- { example: [], actual: [], result: [] },
- { example: [], actual: ['asdf'], result: ['asdf'] },
- { example: [], actual: [''], result: [''] },
- { example: [], actual: [235], result: [235] },
- { example: [], actual: [false], result: [false] },
- { example: [], actual: [{}], result: [{}] },
- { example: [], actual: [{foo:'bar'}], result: [{foo: 'bar'}] },
- { example: [], actual: undefined, result: [] },
- { example: [], actual: NaN, result: [] },
- { example: [], actual: Infinity, result: [] },
- { example: [], actual: -Infinity, result: [] },
- { example: [], actual: null, result: [] },
- { example: [], actual: /some regexp/, result: [] },
- { example: [], actual: function(){}, result: [] },
- { example: [], actual: new Date('November 5, 1605 GMT'), result: [] },
- // { example: [], actual: new (require('stream').Readable)(), result: [] }, // TODO: consider enhancing this behavior to concat the stream contents? Needs community discussion.
- // Skip Buffer tests for now since the enumerable properties vary between Node.js versions.
- // TODO: bring back support for this by explicitly filtering properties of buffers in `.exec()`
- // { example: [], actual: new Buffer('asdf'), result: [ 97, 115, 100, 102 ] },
- { example: [], actual: new Error('asdf'), result: [] },
- //////////////////////////////////////////////////////
- // nested contents of `example: []` and `example: {}`
- //////////////////////////////////////////////////////
- // Follow JSON-serialization rules for nested objects within `example: []` and `example: {}`
- // with the following exceptions:
- // • convert Error instances to their `.stack` property (a string)
- // • convert RegExp instances to a string
- // • convert functions to a string
- // • after doing the rest of the things, prune undefined/null items
- // • after doing the rest of the things, strip keys w/ undefined/null values
- { example: {}, actual: { x: undefined }, result: {} },
- { example: {}, actual: { x: NaN }, result: { x: 0 } },
- { example: {}, actual: { x: Infinity }, result: { x: 0 } },
- { example: {}, actual: { x: -Infinity }, result: { x: 0 } },
- { example: {}, actual: { x: null }, result: { x:null } },
- { example: {}, actual: { x: function foo(a,b){return a+' '+b;} }, result: { x: 'function foo(a,b){return a+\' \'+b;}' } },
- // { example: {}, actual: { x: undefined, null, NaN, -Infinity, Infinity, function(){} }, result: [] },
- { example: {}, actual: { x: /some regexp/ig }, result: {x:'/some regexp/gi' }},
- { example: {}, actual: { x: new Date('November 5, 1605 GMT') }, result: {x: '1605-11-05T00:00:00.000Z'} },
- // Skip Readable stream tests for now since the enumerable properties vary between Node.js versions.
- // { example: {}, actual: { x: new (require('stream').Readable)() }, result: { x: { _readableState: {},readable: true,_events: {},_maxListeners: 10 } } },
- // Skip Buffer stream tests for now since the enumerable properties vary between Node.js versions.
- // { example: {}, actual: { x: new Buffer('asdf') } , result: {x: {}} },
- (function (){
- // Hard-code a fake `.stack` to avoid differences between computers that would cause tests to fail
- var e = new Error('asdf');
- e.stack = 'fake_error';
- return { example: {}, actual: { x: e }, result: {x:'fake_error'} };
- })(),
- { example: [], actual: [undefined], result: [] },
- { example: [], actual: [null], result: [null] },
- { example: [], actual: [NaN], result: [0] },
- { example: [], actual: [Infinity], result: [0] },
- { example: [], actual: [-Infinity], result: [0] },
- { example: [], actual: [function foo(a,b){return a+' '+b;}], result: ['function foo(a,b){return a+\' \'+b;}'] },
- { example: [], actual: [/some regexp/gi], result: ['/some regexp/gi'] },
- { example: [], actual: [new Date('November 5, 1605 GMT')], result: ['1605-11-05T00:00:00.000Z'] },
- // { example: [], actual: [new (require('stream').Readable)()], result: [] },
- // { example: [], actual: [new Buffer('asdf')], result: [] },
- (function (){
- var e = new Error('asdf');
- e.stack = 'fake_error';
- return { example: [], actual: [e], result: ['fake_error'] };
- })(),
- ////////////////////////////////////////////
- // example: '*' (any JSON-serializable value)
- ////////////////////////////////////////////
- { example: '*', actual: 'bar', result: 'bar', },
- { example: '*', actual: '', result: '', },
- { example: '*', actual: '-1.1', result: '-1.1', },
- { example: '*', actual: 'NaN', result: 'NaN', },
- { example: '*', actual: 'undefined', result: 'undefined', },
- { example: '*', actual: 'null', result: 'null', },
- { example: '*', actual: '-Infinity', result: '-Infinity', },
- { example: '*', actual: 'Infinity', result: 'Infinity', },
- { example: '*', actual: 'true', result: 'true', },
- { example: '*', actual: 'false', result: 'false', },
- { example: '*', actual: '0', result: '0', },
- { example: '*', actual: '1', result: '1', },
- { example: '*', actual: -0, result: 0, },
- { example: '*', actual: +0, result: 0, },
- { example: '*', actual: 0, result: 0, },
- { example: '*', actual: 1, result: 1, },
- { example: '*', actual: -1.1, result: -1.1, },
- { example: '*', actual: true, result: true, },
- { example: '*', actual: false, result: false, },
- { example: '*', actual: {}, result: {}, },
- { example: '*', actual: {foo:'bar'}, result: {foo:'bar'}, },
- { example: '*', actual: {foo:{bar:{baz:{}}}}, result: {foo:{bar:{baz:{}}}}, },
- { example: '*', actual: {foo:['bar']}, result: {foo:['bar']}, },
- { example: '*', actual: {foo:{bar:{baz:[{}]}}}, result: {foo:{bar:{baz:[{}]}}}, },
- { example: '*', actual: [], result: [], },
- { example: '*', actual: ['asdf'], result: ['asdf'], },
- { example: '*', actual: [''], result: [''], },
- { example: '*', actual: [235], result: [235], },
- { example: '*', actual: [false], result: [false], },
- { example: '*', actual: [{}], result: [{}], },
- { example: '*', actual: [{foo:'bar'}], result: [{foo:'bar'}], },
- { example: '*', actual: undefined, result: null, },
- { example: '*', actual: NaN, result: 0, },
- { example: '*', actual: Infinity, result: 0, },
- { example: '*', actual: -Infinity, result: 0, },
- { example: '*', actual: null, result: null, },
- { example: '*', actual: /some regexp/gi, result: '/some regexp/gi' },
- { example: '*', actual: new Date('November 5, 1605 GMT'), result: '1605-11-05T00:00:00.000Z' },
- ////////////////////////////////////////////
- // example: '->' (any function)
- ////////////////////////////////////////////
- { example: '->', actual: 'bar', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: '', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: '-1.1', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 'NaN', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 'undefined', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 'null', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: '-Infinity', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 'Infinity', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 'true', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 'false', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: '0', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: '1', result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: -0, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: +0, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 0, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: 1, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: -1.1, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: true, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: false, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: {}, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: {foo:'bar'}, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: {foo:{bar:{baz:{}}}}, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: {foo:['bar']}, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: {foo:{bar:{baz:[{}]}}}, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: [], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: ['asdf'], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: [''], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: [235], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: [false], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: [{}], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: [{foo:'bar'}], result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: undefined, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: NaN, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: Infinity, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: -Infinity, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: null, result: function () { throw new Error('Not implemented! (this function was automatically created by `rttc`'); } },
- { example: '->', actual: function (inputs, exits){return exits.success();}, result: function (inputs, exits){return exits.success();} },
- ////////////////////////////////////////////
- // example: === (literally anything)
- // (undefined changes to '===' automatically)
- ////////////////////////////////////////////
- { example: undefined, actual: 'bar', result: 'bar', },
- { example: undefined, actual: '', result: '', },
- { example: undefined, actual: '-1.1', result: '-1.1', },
- { example: undefined, actual: 'NaN', result: 'NaN', },
- { example: undefined, actual: 'undefined', result: 'undefined', },
- { example: undefined, actual: 'null', result: 'null', },
- { example: undefined, actual: '-Infinity', result: '-Infinity', },
- { example: undefined, actual: 'Infinity', result: 'Infinity', },
- { example: undefined, actual: 'true', result: 'true', },
- { example: undefined, actual: 'false', result: 'false', },
- { example: undefined, actual: '0', result: '0', },
- { example: undefined, actual: '1', result: '1', },
- { example: undefined, actual: -0, result: -0, },
- { example: undefined, actual: +0, result: +0, },
- { example: undefined, actual: 0, result: 0, },
- { example: undefined, actual: 1, result: 1, },
- { example: undefined, actual: -1.1, result: -1.1, },
- { example: undefined, actual: true, result: true, },
- { example: undefined, actual: false, result: false, },
- { example: undefined, actual: {}, result: {}, },
- { example: undefined, actual: {foo:'bar'}, result: {foo:'bar'}, },
- { example: undefined, actual: {foo:{bar:{baz:{}}}}, result: {foo:{bar:{baz:{}}}}, },
- { example: undefined, actual: {foo:['bar']}, result: {foo:['bar']}, },
- { example: undefined, actual: {foo:{bar:{baz:[{}]}}}, result: {foo:{bar:{baz:[{}]}}}, },
- { example: undefined, actual: [], result: [], },
- { example: undefined, actual: ['asdf'], result: ['asdf'], },
- { example: undefined, actual: [''], result: [''], },
- { example: undefined, actual: [235], result: [235], },
- { example: undefined, actual: [false], result: [false], },
- { example: undefined, actual: [{}], result: [{}], },
- { example: undefined, actual: [{foo:'bar'}], result: [{foo:'bar'}], },
- { example: undefined, actual: undefined, result: null, },
- { example: undefined, actual: NaN, result: NaN, },
- { example: undefined, actual: Infinity, result: Infinity, },
- { example: undefined, actual: -Infinity, result: -Infinity, },
- { example: undefined, actual: null, result: null, },
- { example: undefined, actual: /some regexp/gi, result: /some regexp/gi },
- { example: undefined, actual: new Date('November 5, 1605 GMT'), result: new Date('November 5, 1605 GMT') },
- // $$\
- // \__|
- // $$$$$$\ $$$$$$\ $$$$$$$\ $$\ $$\ $$$$$$\ $$$$$$$\ $$\ $$\ $$\ $$$$$$\
- // $$ __$$\ $$ __$$\ $$ _____|$$ | $$ |$$ __$$\ $$ _____|$$ |\$$\ $$ |$$ __$$\
- // $$ | \__|$$$$$$$$ |$$ / $$ | $$ |$$ | \__|\$$$$$$\ $$ | \$$\$$ / $$$$$$$$ |
- // $$ | $$ ____|$$ | $$ | $$ |$$ | \____$$\ $$ | \$$$ / $$ ____|
- // $$ | \$$$$$$$\ \$$$$$$$\ \$$$$$$ |$$ | $$$$$$$ |$$ | \$ / \$$$$$$$\
- // \__| \_______| \_______| \______/ \__| \_______/ \__| \_/ \_______|
- //
- //
- //
- // Some basic deep objects
- { example: {a:1, b:'hi', c: false}, actual: {a: 23}, result: {a: 23, b: '', c: false} },
- { example: {a:1, b:'hi', c: false}, actual: {a: 23, d: true}, result: {a: 23, b: '', c: false} },
- // Ensure that this allows extra keys when coercing to `example: {}`
- {
- example: {},
- actual: {a: 23, d: true},
- result: {a: 23, d: true}
- },
- // Omit extra keys when coercing to `example: {...}`
- {
- example: { a:23 },
- actual: {a: 23, d: true},
- result: {a: 23}
- },
- // Coerce missing/undefined required keys to base value
- { example: {b: 235}, actual: {b: undefined}, result: {b: 0} },
- { example: {b: 235}, actual: {}, result: {b: 0} },
- // Strip keys with `undefined` values (`{...}` case)
- { example: {b: 235}, actual: {a: undefined, b: 3}, result: {b: 3} },
- // Strip nested keys with `undefined` values (`{...}` case)
- { example: {a: {}, b: 235}, actual: {a: {x: undefined}, b: 3}, result: {a: {}, b: 3} },
- // Strip keys with `undefined` values (`{}` case)
- { example: {}, actual: {a: undefined, b: 3}, result: {b: 3} },
- // Strip nested keys with `undefined` values (`{}` case)
- { example: {}, actual: {a: {x: undefined}, b: 3}, result: {a: {}, b: 3} },
- // Don't strip keys or nested keys with `undefined` values (`===` and nested `===` cases)
- { example: '===', actual: {a: undefined, b: 3, c: {x: undefined}}, result: {a: undefined, b: 3, c: {x: undefined}} },
- { example: {c:'==='}, actual: {a: undefined, b: 3, c: {x: undefined}}, result: { c: {x: undefined}} },
- // Ensure that this allows arbitary arrays when coercing to `example: []`
- {
- example: [],
- actual: [{a: 23, d: true}],
- result: [{a: 23, d: true}]
- },
- // Ensure that nested dictionaries inside of an array passed
- // through `example: []` are stripped of keys with undefined values
- {
- example: [],
- actual: [{a:3, b: undefined}, {a: undefined}],
- result: [{a: 3},{}]
- },
- {
- example: [],
- actual: [{a:3,someStuff: [{x: undefined, y: 'foo'}, {x: 'bar', y: undefined}]},{a: 5, b: undefined}],
- result: [{a: 3, someStuff: [{y:'foo'}, {x:'bar'}]}, {a: 5}]
- },
- // With `===`:
- // Leave `undefined` items from arrays and nested arrays alone
- {
- example: '===',
- actual: [{a:3}, undefined, {a: 5}, undefined, {a: 7}, {a:9, b: [undefined, 9,2,4,undefined,8]}],
- result: [{a:3}, undefined, {a: 5}, undefined, {a: 7}, {a:9, b: [undefined, 9,2,4,undefined,8]}]
- },
- // With [`===`]:
- // Leave `undefined` items from NESTED arrays alone
- // (because they are being compared as '===')
- {
- example: ['==='],
- actual: [{a:3}, undefined, {a: 5}, undefined, {a: 7}, {a:9, b: [undefined, 9,2,4,undefined,8]}],
- result: [{a:3}, {a: 5}, {a: 7}, {a:9, b: [undefined, 9,2,4,undefined,8]}]
- },
- // Prune `undefined` items from arrays and nested arrays (`[]` case)
- {
- example: [],
- actual: [{a:3}, undefined, {a: 5}, undefined, {a: 7}, {a:9, b: [undefined, 9,2,4,undefined,8]}],
- result: [{a: 3}, {a: 5}, {a:7}, {a:9, b:[9,2,4,8]}]
- },
- // Ensure that nested dictionaries inside of an array passed
- // through `example: ['===']` are NOT stripped of keys with undefined values--
- // and are left utterly alone
- {
- example: ['==='],
- actual: [{a:3, b: undefined}, {a: undefined}],
- result: [{a: 3, b: undefined},{a:undefined}]
- },
- {
- example: ['==='],
- actual: [{a:3,someStuff: [{x: undefined, y: 'foo'}, {x: 'bar', y: undefined}]},{a: 5, b: undefined}],
- result: [{a:3,someStuff: [{x: undefined, y: 'foo'}, {x: 'bar', y: undefined}]},{a: 5, b: undefined}]
- },
- // Ensure the recursive cloning / undefined-key-stripping doesn't get
- // stumped by circular dictionaries/arrays.
- // • dict keys whose values point to a past reference should be deleted
- // • array items that point to past references should be pruned
- (function (){
- var someDict = {};
- var someArray = [];
- someDict.x = {z: someDict, foo: undefined};
- someDict.y = someArray;
- someArray.push(someDict);
- someArray.push(someDict.x);
- var test = {
- example: {},
- actual: {
- someDict: someDict,
- someArray: someArray
- },
- result: {
- someDict: {
- x: {
- z: '[Circular ~.someDict]'
- },
- y: [
- '[Circular ~.someDict]',
- {
- z: '[Circular ~.someDict]'
- }
- ]
- },
- someArray: [
- {
- x: {
- z: '[Circular ~.someArray.0]'
- },
- y: '[Circular ~.someArray]'
- },
- {
- z: {
- x: '[Circular ~.someArray.1]',
- y: '[Circular ~.someArray]'
- }
- }
- ]
- }
- };
- return test;
- })(),
- // Wholistic, complex multi-item array test
- {
- example: [{
- id: 123,
- title: 'Scott',
- body: 'Scott',
- votes: 0,
- resolved: true
- }],
- actual: [{
- votes: 10,
- title: 'first',
- resolved: false
- }, {
- votes: -5,
- title: 'second',
- resolved: false
- }, {
- votes: 0,
- title: 'third',
- resolved: false
- }],
- result: [{
- id: 0,
- votes: 10,
- title: 'first',
- body: '',
- resolved: false
- }, {
- id: 0,
- votes: -5,
- title: 'second',
- body: '',
- resolved: false
- }, {
- id: 0,
- votes: 0,
- title: 'third',
- body: '',
- resolved: false
- }]
- },
- // Complex multi-item array test w/ edge cases
- {
- example: [{
- id: 123,
- title: 'Scott',
- body: 'Scott',
- votes: 0,
- resolved: true
- }],
- actual: [{
- votes: 10,
- title: 'first',
- resolved: false
- }, {
- votes: -5,
- title: 'second',
- resolved: false
- }, {
- votes: 0,
- title: 'third',
- resolved: false
- },
- {
- votes: null,
- title: 'fourth',
- resolved: false
- },
- {
- votes: undefined,
- title: 'fifth',
- resolved: false
- },
- {
- title: 'sixth',
- resolved: false
- }],
- result: [{
- id: 0,
- votes: 10,
- title: 'first',
- body: '',
- resolved: false
- }, {
- id: 0,
- votes: -5,
- title: 'second',
- body: '',
- resolved: false
- }, {
- id: 0,
- votes: 0,
- title: 'third',
- body: '',
- resolved: false
- },
- {
- id: 0,
- votes: 0,
- title: 'fourth',
- body: '',
- resolved: false
- },
- {
- id: 0,
- votes: 0,
- title: 'fifth',
- body: '',
- resolved: false
- },
- {
- id: 0,
- votes: 0,
- title: 'sixth',
- body: '',
- resolved: false
- }]
- },
- // Tricky multi-item array javascript black magic
- {
- example: [{
- id: 123,
- title: 'Scott',
- body: 'Scott',
- votes: 0,
- resolved: true
- }],
- actual: {
- 0: {
- votes: 10,
- title: 'first',
- resolved: false
- },
- 1: {
- votes: -5,
- title: 'second',
- resolved: false
- },
- 2: {
- votes: 0,
- title: 'third',
- resolved: false
- },
- 3: {
- votes: null,
- title: 'fourth',
- resolved: false
- },
- 4: {
- votes: undefined,
- title: 'fifth',
- resolved: false
- },
- 5: {
- title: 'sixth',
- resolved: false
- }
- },
- result: []
- },
- // $$\ $$\ $$\ $$$\ $$$\
- // $$ | \__| $$ | $$ _| \$$\
- // $$$$$$$\ $$$$$$\ $$$$$$\ $$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$\ $$ /$$$$\ $$$$\ $$$$\ \$$\
- // $$ _____|\_$$ _| $$ __$$\ $$ |$$ _____|\_$$ _| $$ __$$\ $$ __$$\ $$ | \____|\____|\____| $$ |
- // \$$$$$$\ $$ | $$ | \__|$$ |$$ / $$ | $$$$$$$$ |$$ / $$ | $$ | $$$$\ $$$$\ $$$$\ $$ |
- // \____$$\ $$ |$$\ $$ | $$ |$$ | $$ |$$\ $$ ____|$$ | $$ | \$$\ \____|\____|\____|$$ |
- // $$$$$$$ | \$$$$ |$$ | $$ |\$$$$$$$\ \$$$$ | \$$$$$$$\ \$$$$$$$ | \$$$\ $$$ /
- // \_______/ \____/ \__| \__| \_______| \____/ \_______| \____$$ | \___| \___/
- // $$ |
- // $$ |
- // \__|
- //
- // (strictEq / isNew checks to assert for and
- // against passing-by-reference in different
- // situations)
- ////////////////////////////////////////////////
- ////////////////////////////////////////////////
- // example: '==='
- // result value should always be strictly equal (===)
- ////////////////////////////////////////////////
- { example: undefined, actual: {}, strictEq: true },
- { example: undefined, actual: {a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}, strictEq: true },
- { example: undefined, actual: [], strictEq: true },
- { example: undefined, actual: [{a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}], strictEq: true },
- { example: undefined, actual: /some regexp/, strictEq: true },
- { example: undefined, actual: function (){}, strictEq: true },
- { example: undefined, actual: new Date('November 5, 1605 GMT'), strictEq: true },
- { example: undefined, actual: new (require('stream').Readable)(), strictEq: true },
- { example: undefined, actual: new Buffer('asdf'), strictEq: true },
- { example: undefined, actual: new Error('asdf'), strictEq: true },
- ////////////////////////////////////////////////////////////////////////////////////////////////
- // example: nested '===' in dictionaries/arrays
- // TODO: needs to be tested some other way, since we'd be checking reference passing within another nested obj.
- // also check against strict equality between sub-values (`!==` between nested things...)
- // This is prbly eaiest if we just pull it out into a separate test; ie. don't make the test declarative.
- ////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////
- // example: {} should perform a deep copy on things
- ////////////////////////////////////////////////
- { example: {}, actual: {}, isNew: true },
- { example: {}, actual: {a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}, isNew: true },
- ////////////////////////////////////////////////
- // example: {...} should perform a shallow copy
- // Assert pass-by-reference behavior for more specific `example`
- ////////////////////////////////////////////////
- {
- example: { id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true },
- actual: {},
- result: { id: 0, title: '', body: '', votes: 0, resolved: false },
- isNew: true
- },
- {
- example: { id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true },
- actual: {a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]},
- result: { id: 0, title: '', body: '', votes: 0, resolved: false },
- isNew: true
- },
- {
- example: { id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' },
- actual: {},
- result: { id: 0, title: '', body: '', votes: 0, resolved: false, something: null },
- isNew: true
- },
- {
- example: { id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' },
- actual: {a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]},
- result: { id: 0, title: '', body: '', votes: 0, resolved: false, something: null },
- isNew: true
- },
- {
- example: { id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' },
- actual: { something: new Date('November 5, 1605 GMT')},
- result: { id: 0, title: '', body: '', votes: 0, resolved: false, something: new Date('November 5, 1605 GMT') },
- isNew: true
- },
- {
- example: { id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' },
- actual: { something: new Date('November 5, 1605 GMT'), a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]},
- result: { id: 0, title: '', body: '', votes: 0, resolved: false, something: new Date('November 5, 1605 GMT') },
- isNew: true
- },
- ////////////////////////////////////////////////
- // example: [] should copy things
- ////////////////////////////////////////////////
- { example: [], actual: [], isNew: true },
- { example: [], actual: [{a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}], isNew: true },
- ////////////////////////////////////////////////
- // example: {...} should perform a shallow copy
- // Assert pass-by-reference behavior for more specific `example`s
- ////////////////////////////////////////////////
- {
- example: [{ id: 123, title: 'Scott', body: 'Scott', votes: 0, resolved: true }],
- actual: [],
- result: [],
- isNew: true
- },
- {
- example: [{ id: 123, title: 'Scott', body: 'Scott', votes: 0, resolved: true }],
- actual: [{a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}],
- result: [{ id: 0, title: '', body: '', votes: 0, resolved: false }],
- isNew: true
- },
- {
- example: [{ id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' }],
- actual: [],
- result: [],
- isNew: true
- },
- {
- example: [{ id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' }],
- actual: [{a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}],
- result: [{ id: 0, title: '', body: '', votes: 0, resolved: false, something: null }],
- isNew: true
- },
- {
- example: [{ id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' }],
- actual: [{ something: new Date('November 5, 1605 GMT')}],
- result: [{ id: 0, title: '', body: '', votes: 0, resolved: false, something: new Date('November 5, 1605 GMT') }],
- isNew: true
- },
- {
- example: [{ id: 123, title: 'Scott', body: 'Scott', votes: 33, resolved: true, something: '===' }],
- actual: [{ something: new Date('November 5, 1605 GMT'), a:23,b:'asdg',c:true,d: {x:32,y:'sagd',z: [{a:2,b:'gsda',c:false}]}, e: [2]}],
- result: [{ id: 0, title: '', body: '', votes: 0, resolved: false, something: new Date('November 5, 1605 GMT') }],
- isNew: true
- },
- ////////////////////////////////////////////////
- // objects which contain other crazy objects
- // with no `constructor` should not throw errors
- ////////////////////////////////////////////////
- {
- example: [{
- id: 123,
- title: 'Robinson Crusoe',
- surprise: {}
- }],
- actual: [{
- title: 'Hank the Cowdog',
- surprise: (function(){
- function Dog(){}
- var rover = new Dog();
- rover.coolProps = 'wow so cool';
- rover.constructo = 'hmm maybe ill try really annoying property names!';
- rover.prototype = null;
- rover.__proto__ = null;
- rover.constructor = null;
- // hehehehehhe
- return rover;
- })()
- }],
- result: [{
- id: 0,
- title: 'Hank the Cowdog',
- surprise: {
- coolProps: 'wow so cool',
- constructo: 'hmm maybe ill try really annoying property names!',
- prototype: null,
- constructor: null
- }
- }]
- }
- ];
|