added NaN special case...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-10-15 22:43:06 +03:00
parent a7573e8f19
commit 3be394b85d
2 changed files with 92 additions and 88 deletions

View File

@ -1393,6 +1393,8 @@ module.Types = {
// NOTE: we can't use a == b directly because of things like // NOTE: we can't use a == b directly because of things like
// [2] == 2 -> true... // [2] == 2 -> true...
return a === b return a === b
// special-case: NaN...
|| (isNaN(a) && isNaN(b))
// basic patters... // basic patters...
|| a === that.ANY || a === that.ANY
|| b === that.ANY || b === that.ANY
@ -1515,6 +1517,8 @@ module.Types = {
// NOTE: we can't use a == b directly because of things like // NOTE: we can't use a == b directly because of things like
// [2] == 2 -> true... // [2] == 2 -> true...
return a === b return a === b
// special-case: NaN...
|| (isNaN(a) && isNaN(b))
// basic patters... // basic patters...
|| a === that.ANY || a === that.ANY
|| b === that.ANY || b === that.ANY

176
test.js Normal file → Executable file
View File

@ -1,88 +1,88 @@
#!/usr/bin/env node #!/usr/bin/env node
/********************************************************************** /**********************************************************************
* *
* test.js * test.js
* *
* Repo and docs: * Repo and docs:
* https://github.com/flynx/test.js * https://github.com/flynx/test.js
* *
***********************************************/ /* c8 ignore next 2 */ ***********************************************/ /* c8 ignore next 2 */
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
(function(require){ var module={} // make module AMD/node compatible... (function(require){ var module={} // make module AMD/node compatible...
/*********************************************************************/ /*********************************************************************/
var test = require('ig-test') var test = require('ig-test')
var diff = require('./diff') var diff = require('./diff')
var format = require('./format') var format = require('./format')
//--------------------------------------------------------------------- //---------------------------------------------------------------------
test.Setups({ test.Setups({
// XXX make this return a list... // XXX make this return a list...
basic: function(assert){ basic: function(assert){
return [ return [
{ {
A: {}, B: {}, A: {}, B: {},
cmp: true, cmp: true,
}, },
{ {
A: [], B: [], A: [], B: [],
cmp: true, cmp: true,
}, },
{ {
A: 0, B: 0, A: 0, B: 0,
cmp: true, cmp: true,
}, },
{ {
A: 123, B: 123, A: 123, B: 123,
cmp: true, cmp: true,
}, },
{ {
A: false, B: false, A: false, B: false,
cmp: true, cmp: true,
}, },
{ {
A: undefined, B: undefined, A: undefined, B: undefined,
cmp: true, cmp: true,
}, },
// XXX special case -- fails.... // XXX special case -- fails....
{ {
A: NaN, B: NaN, A: NaN, B: NaN,
cmp: true, cmp: true,
}, },
] }, ] },
}) })
test.Tests({ test.Tests({
cmp: function(assert, setup){ cmp: function(assert, setup){
setup = setup instanceof Array ? setup : [setup] setup = setup instanceof Array ? setup : [setup]
setup.forEach(function(e){ setup.forEach(function(e){
var res var res
'cmp' in e 'cmp' in e
&& assert( && assert(
(res = diff.cmp(e.A, e.B)) == e.cmp, (res = diff.cmp(e.A, e.B)) == e.cmp,
`cmp(..): cmp(${e.A}, ${e.B}) should be ${e.cmp} got ${res}`) }) }, `cmp(..): cmp(${e.A}, ${e.B}) should be ${e.cmp} got ${res}`) }) },
}) })
test.Cases({ test.Cases({
'basics': function(assert){ 'basics': function(assert){
// XXX move reference objects + expected diffs to setups // XXX move reference objects + expected diffs to setups
a = {} a = {}
b = {} b = {}
assert(diff.Diff(a, b), 'Diff(..)') assert(diff.Diff(a, b), 'Diff(..)')
}, },
}) })
//--------------------------------------------------------------------- //---------------------------------------------------------------------
typeof(__filename) != 'undefined' typeof(__filename) != 'undefined'
&& __filename == (require.main || {}).filename && __filename == (require.main || {}).filename
&& test.run() && test.run()
/********************************************************************** /**********************************************************************
* vim:set ts=4 sw=4 : */ return module }) * vim:set ts=4 sw=4 : */ return module })