From cae9613c70c684d1225af5ad8a8e9dc639176637 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Mon, 8 Jun 2020 19:23:41 +0300 Subject: [PATCH] more tests, getting close to 100% coverage, still experimental ;) Signed-off-by: Alex A. Naanou --- object.js | 1 + test.js | 46 +++++++++++++++++++++++++++++++--------------- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/object.js b/object.js index 36cd38a..9cbf411 100755 --- a/object.js +++ b/object.js @@ -469,6 +469,7 @@ function(proto, name, that, ...args){ // NOTE: this will not transfer several the special variables not listed // by Object.keys(..). // This includes things like .__proto__ +// NOTE: this can and will overwrite attributes... var mixinFlat = module.mixinFlat = function(base, ...objects){ diff --git a/test.js b/test.js index 8970159..11fce24 100755 --- a/test.js +++ b/test.js @@ -495,25 +495,30 @@ module.setups = { __proto__: b, x: 'c', method: function(){ + var x, y assert(arrayCmp( - object.values(c, 'x'), - ['c', 'a', 'b']), - 'reach all values of attr') + x = object.values(c, 'x'), + y = ['c', 'a', 'b']), + 'reach all values of attr: expected:', x, 'got:'.bold.yellow, y) assert(arrayCmp( - object.values(c, 'x', function(v, o){ + x = object.values(c, 'x', function(v, o){ return v.toUpperCase() }), - ['C', 'A', 'B']), - 'reach all values of attr') + y = ['C', 'A', 'B']), + 'reach all values of attr: expected:', x, 'got:'.bold.yellow, y) assert(arrayCmp( - object.sources(c, 'method'), - [c, a]), - 'reach all values of method') + x = object.sources(c, 'method'), + // NOTE: not passing an explicit list as we need + // to account for mixins... + y = object.sources(c) + .filter(function(s){ + return s.hasOwnProperty('method') })), + 'reach all values of method: expected:', y, 'got:'.bold.yellow, x) assert( - object.parent(c, 'x') == 'b', - 'reach parent attr') + (x = object.parent(c, 'x')) == 'b', + 'reach parent attr: expected:', 'b', 'got:'.bold.yellow, x) assert( - object.parentCall(c.method, this) == 'a', - 'reach parent method', 'c') + (x = object.parentCall(c.method, this)) == (y = a.method()), + 'reach parent method: expected:', y, 'got:'.bold.yellow, x) return 'c' }, }, d: d = { @@ -628,16 +633,27 @@ module.modifiers = { return res }, // mixins... + // XXX might be a good idea to get the method name from the context... how? mixin_instance: function(assert, setup, flat, filter, get){ filter = filter || instances - // XXX might be a good idea to get the method name from the context... var attr = '__mixin_' + filter.name var mixin = setup[attr] = { + __mixin: true, [attr]: true, __mixin_flat: !!flat, - // XXX + method: function(){ + var res = object.parent(mixin.method, this) !== undefined ? + assert( + object.parentCall(mixin.method, this, ...arguments), + 'mixin method parent call') + : false + return res + || 'mixin' }, + + mixinMethod: function(){ + return 'mixin' }, } mixin[attr] = mixin