mirror of
https://github.com/flynx/object.js.git
synced 2025-10-29 18:40:08 +00:00
more tests, getting close to 100% coverage, still experimental ;)
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ca24b2ed54
commit
cae9613c70
@ -469,6 +469,7 @@ function(proto, name, that, ...args){
|
|||||||
// NOTE: this will not transfer several the special variables not listed
|
// NOTE: this will not transfer several the special variables not listed
|
||||||
// by Object.keys(..).
|
// by Object.keys(..).
|
||||||
// This includes things like .__proto__
|
// This includes things like .__proto__
|
||||||
|
// NOTE: this can and will overwrite attributes...
|
||||||
var mixinFlat =
|
var mixinFlat =
|
||||||
module.mixinFlat =
|
module.mixinFlat =
|
||||||
function(base, ...objects){
|
function(base, ...objects){
|
||||||
|
|||||||
46
test.js
46
test.js
@ -495,25 +495,30 @@ module.setups = {
|
|||||||
__proto__: b,
|
__proto__: b,
|
||||||
x: 'c',
|
x: 'c',
|
||||||
method: function(){
|
method: function(){
|
||||||
|
var x, y
|
||||||
assert(arrayCmp(
|
assert(arrayCmp(
|
||||||
object.values(c, 'x'),
|
x = object.values(c, 'x'),
|
||||||
['c', 'a', 'b']),
|
y = ['c', 'a', 'b']),
|
||||||
'reach all values of attr')
|
'reach all values of attr: expected:', x, 'got:'.bold.yellow, y)
|
||||||
assert(arrayCmp(
|
assert(arrayCmp(
|
||||||
object.values(c, 'x', function(v, o){
|
x = object.values(c, 'x', function(v, o){
|
||||||
return v.toUpperCase() }),
|
return v.toUpperCase() }),
|
||||||
['C', 'A', 'B']),
|
y = ['C', 'A', 'B']),
|
||||||
'reach all values of attr')
|
'reach all values of attr: expected:', x, 'got:'.bold.yellow, y)
|
||||||
assert(arrayCmp(
|
assert(arrayCmp(
|
||||||
object.sources(c, 'method'),
|
x = object.sources(c, 'method'),
|
||||||
[c, a]),
|
// NOTE: not passing an explicit list as we need
|
||||||
'reach all values of method')
|
// 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(
|
assert(
|
||||||
object.parent(c, 'x') == 'b',
|
(x = object.parent(c, 'x')) == 'b',
|
||||||
'reach parent attr')
|
'reach parent attr: expected:', 'b', 'got:'.bold.yellow, x)
|
||||||
assert(
|
assert(
|
||||||
object.parentCall(c.method, this) == 'a',
|
(x = object.parentCall(c.method, this)) == (y = a.method()),
|
||||||
'reach parent method', 'c')
|
'reach parent method: expected:', y, 'got:'.bold.yellow, x)
|
||||||
return 'c' },
|
return 'c' },
|
||||||
},
|
},
|
||||||
d: d = {
|
d: d = {
|
||||||
@ -628,16 +633,27 @@ module.modifiers = {
|
|||||||
return res },
|
return res },
|
||||||
|
|
||||||
// mixins...
|
// mixins...
|
||||||
|
// XXX might be a good idea to get the method name from the context... how?
|
||||||
mixin_instance: function(assert, setup, flat, filter, get){
|
mixin_instance: function(assert, setup, flat, filter, get){
|
||||||
filter = filter || instances
|
filter = filter || instances
|
||||||
// XXX might be a good idea to get the method name from the context...
|
|
||||||
var attr = '__mixin_' + filter.name
|
var attr = '__mixin_' + filter.name
|
||||||
|
|
||||||
var mixin = setup[attr] = {
|
var mixin = setup[attr] = {
|
||||||
|
__mixin: true,
|
||||||
[attr]: true,
|
[attr]: true,
|
||||||
__mixin_flat: !!flat,
|
__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
|
mixin[attr] = mixin
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user