mirror of
https://github.com/flynx/test.js.git
synced 2026-10-03 04:41:37 +00:00
notes and refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
791853fb2e
commit
9250679f3a
43
test.js
43
test.js
@ -263,17 +263,18 @@ object.Constructor('Assert', {
|
|||||||
|
|
||||||
// XXX
|
// XXX
|
||||||
var mergeIter = function(iter){
|
var mergeIter = function(iter){
|
||||||
// XXX should this get a function as argument???
|
|
||||||
return function(c){
|
return function(c){
|
||||||
c = c || this
|
c = c || this
|
||||||
return (c.members || [])
|
return (c.members || [])
|
||||||
.map(function(e){ return Object[iter](e) })
|
.map(function(e){
|
||||||
|
return Object[iter](e) })
|
||||||
.flat() } }
|
.flat() } }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
// Object representing the sum of all it's members.
|
||||||
//
|
//
|
||||||
// Merged(name, func)
|
// Merged(name, func)
|
||||||
// -> merged
|
// -> merged
|
||||||
@ -282,12 +283,23 @@ var mergeIter = function(iter){
|
|||||||
// -> merged
|
// -> merged
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// Merged is the sum of all its members.
|
// XXX revise: members either need to be mixed in or not, now both are
|
||||||
//
|
// done:
|
||||||
// XXX is this generic enough to be moved to ig-types???
|
// .__init__(..) - adds and mixes in
|
||||||
|
// .add(..) / .remove(..) / .clear() - only add
|
||||||
|
// another issue is the set of iterators, they either go through
|
||||||
|
// all attributes of al members (as-is now) or go through local
|
||||||
|
// attributes...
|
||||||
|
// -> decide if we mixin or store, and make this consistent.
|
||||||
var Merged =
|
var Merged =
|
||||||
module.Merged =
|
module.Merged =
|
||||||
object.Constructor('Merged', {
|
object.Constructor('Merged', {
|
||||||
|
// can be:
|
||||||
|
// 'warn' (default)
|
||||||
|
// 'fail'
|
||||||
|
// 'ignore'
|
||||||
|
__shadow_handling__: 'warn',
|
||||||
|
|
||||||
__members: undefined,
|
__members: undefined,
|
||||||
get members(){
|
get members(){
|
||||||
return this.__members == null ?
|
return this.__members == null ?
|
||||||
@ -310,6 +322,7 @@ object.Constructor('Merged', {
|
|||||||
var k = this.keys()
|
var k = this.keys()
|
||||||
return k.length - (k.includes('-') ? 1 : 0) },
|
return k.length - (k.includes('-') ? 1 : 0) },
|
||||||
|
|
||||||
|
// XXX should this object.mixinFlat(this, other) like is done in .__init__(..) ???
|
||||||
add: function(member){
|
add: function(member){
|
||||||
this.members.push(member)
|
this.members.push(member)
|
||||||
return this },
|
return this },
|
||||||
@ -323,6 +336,7 @@ object.Constructor('Merged', {
|
|||||||
delete this.__members
|
delete this.__members
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
|
// XXX if the above use mixin/mixout, should these simply use Object's API???
|
||||||
keys: mergeIter('keys'),
|
keys: mergeIter('keys'),
|
||||||
values: mergeIter('values'),
|
values: mergeIter('values'),
|
||||||
entries: mergeIter('entries'),
|
entries: mergeIter('entries'),
|
||||||
@ -349,14 +363,19 @@ object.Constructor('Merged', {
|
|||||||
.filter(function(k){
|
.filter(function(k){
|
||||||
return existing.has(k) }) })
|
return existing.has(k) }) })
|
||||||
.flat() },
|
.flat() },
|
||||||
handleShadowing: function(shadowed){
|
handleShadowing: function(shadowed, mode='warn'){
|
||||||
shadowed.length > 0
|
if(shadowed.length > 0
|
||||||
&& console.warn(` WARNING:`.bold, `shadowing: ${shadowed.join()}`)
|
&& mode != 'ignore'){
|
||||||
|
if(mode == 'fail'){
|
||||||
|
throw new Error('ERR:'.bold, `shadowing: ${ shadowing.join() }`) }
|
||||||
|
console.warn(` WARNING:`.bold, `shadowing: ${shadowed.join()}`) }
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
create: function(name){
|
create: function(name){
|
||||||
return object.Constructor(name || this.name, this, {}) },
|
return object.Constructor(name || this.name, this, {}) },
|
||||||
}, {
|
}, {
|
||||||
|
//__shadow_handling__: 'warn',
|
||||||
|
|
||||||
filename: undefined,
|
filename: undefined,
|
||||||
|
|
||||||
__init__: function(other){
|
__init__: function(other){
|
||||||
@ -374,7 +393,9 @@ object.Constructor('Merged', {
|
|||||||
|
|
||||||
// check for shadowing...
|
// check for shadowing...
|
||||||
this.constructor.handleShadowing(
|
this.constructor.handleShadowing(
|
||||||
this.constructor.checkShadowing(other))
|
this.constructor.checkShadowing(other),
|
||||||
|
this.__shadow_handling__
|
||||||
|
?? this.constructor.__shadow_handling__)
|
||||||
|
|
||||||
// mix and merge...
|
// mix and merge...
|
||||||
object.mixinFlat(this, other)
|
object.mixinFlat(this, other)
|
||||||
@ -387,7 +408,9 @@ object.Constructor('Merged', {
|
|||||||
|
|
||||||
// Get tests from a test object...
|
// Get tests from a test object...
|
||||||
//
|
//
|
||||||
var getTests = function(spec){
|
var getTests =
|
||||||
|
module.getTests =
|
||||||
|
function(spec){
|
||||||
var {setups, modifiers, tests, cases} = spec
|
var {setups, modifiers, tests, cases} = spec
|
||||||
;[setups, modifiers, tests, cases] =
|
;[setups, modifiers, tests, cases] =
|
||||||
[setups, modifiers, tests, cases]
|
[setups, modifiers, tests, cases]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user