From 4b0a26e6f7e5414af62c4b50a90143a42eac1696 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 4 Jun 2020 00:20:45 +0300 Subject: [PATCH] cleanup... Signed-off-by: Alex A. Naanou --- test.js | 103 +++++++++++++++++++------------------------------------- 1 file changed, 34 insertions(+), 69 deletions(-) diff --git a/test.js b/test.js index 2b0bbe2..6041ce2 100755 --- a/test.js +++ b/test.js @@ -66,43 +66,6 @@ module.VERBOSE = process ? //--------------------------------------------------------------------- // helpers... -/*/ Add colors to String... -var colors = -String.colors = { - reset: '\x1b[0m', - bold: '\x1b[1m', - dim: '\x1b[2m', - underscore: '\x1b[4m', - blink: '\x1b[5m', - reverse: '\x1b[7m', - hidden: '\x1b[8m', - - black: '\x1b[30m', - red: '\x1b[31m', - green: '\x1b[32m', - yellow: '\x1b[33m', - blue: '\x1b[34m', - magenta: '\x1b[35m', - cyan: '\x1b[36m', - white: '\x1b[37m', - - bgblack: '\x1b[40m', - bgred: '\x1b[41m', - bggreen: '\x1b[42m', - bgyellow: '\x1b[43m', - bgblue: '\x1b[44m', - bgmagenta: '\x1b[45m', - bgcyan: '\x1b[46m', - bgwhite: '\x1b[47m', -} -Object.entries(colors) - .forEach(function([color, seq]){ - Object.defineProperty(String.prototype, color, { - get: function(){ - return seq + (this.endsWith(colors.reset) ? - this - : this + String.colors.reset) } }) }) -//*/ Object.defineProperty(String.prototype, 'raw', { get: function(){ return this.replace(/\x1b\[..?m/g, '') }, }) @@ -116,6 +79,7 @@ var deepKeys = function(obj, stop){ obj = obj.__proto__ } return [...(new Set(res.flat()))] } + // compare two arrays by items... var arrayCmp = function(a, b){ var ka = Object.keys(a) @@ -131,6 +95,38 @@ var arrayCmp = function(a, b){ +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +// a constructor is a thing that starts with a capital and has a .prototype +var constructors = function(obj){ + return Object.entries(obj) + .filter(function([k, o]){ + return k[0] == k[0].toUpperCase() + && o.prototype }) } + +// an instance is a thing that starts with a lowercase and has a .constructor +var instances = function(obj){ + return Object.entries(obj) + .filter(function([k, o]){ + return k[0] == k[0].toLowerCase() + && o.constructor }) } + + +var makeAssert = function(pre, stats){ + return function(e, msg, ...args){ + stats + && (stats.assertions += 1) + && !e + && (stats.failures += 1) + module.VERBOSE + && console.log(pre +': '+ msg.bold, ...args) + console.assert(e, pre.bold +': '+ msg.bold.yellow, ...args) + return e } } + + + +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // basic argv parser... // // Format: @@ -316,37 +312,8 @@ var ArgvParser = function(spec){ -// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -// a constructor is a thing that starts with a capital and has a .prototype -var constructors = function(obj){ - return Object.entries(obj) - .filter(function([k, o]){ - return k[0] == k[0].toUpperCase() - && o.prototype }) } - -// an instance is a thing that starts with a lowercase and has a .constructor -var instances = function(obj){ - return Object.entries(obj) - .filter(function([k, o]){ - return k[0] == k[0].toLowerCase() - && o.constructor }) } - - -var makeAssert = function(pre, stats){ - return function(e, msg, ...args){ - stats - && (stats.assertions += 1) - && !e - && (stats.failures += 1) - module.VERBOSE - && console.log(pre +': '+ msg.bold, ...args) - console.assert(e, pre.bold +': '+ msg.bold.yellow, ...args) - return e } } - - - //--------------------------------------------------------------------- +// Tests... var setups = module.setups = { @@ -617,7 +584,6 @@ module.modifiers = { } - var tests = module.tests = { // instance creation... @@ -681,7 +647,6 @@ module.cases = { //--------------------------------------------------------------------- - // Test runner... // // runner()