@@ -5,12 +5,13 @@ import {
55 messageByString ,
66 messageByStringSpread ,
77 random ,
8+ randomOpts ,
89 randomStyleFn ,
910 randomStyleString ,
1011 stylesMap ,
11- } from '. /Color.ts' ;
12- import { styleEnum } from '. /enum.ts' ;
13- import type { Styles , StyleFn } from '. /Color.d.ts' ;
12+ } from 'trailmix/color /Color.ts' ;
13+ import { styleEnum } from 'trailmix/color /enum.ts' ;
14+ import type { Styles , StyleFn } from 'trailmix/color /Color.d.ts' ;
1415import { assertStrictEquals , assertNotEquals } from 'testing/asserts.ts' ;
1516import { Table , Row , Cell } from 'cliffy/table' ;
1617
@@ -38,22 +39,25 @@ function consoleMock(...data: string[]) {
3839 expected ,
3940 `console.log() messages failure: (actual !== expected)\n "${ actual } " !== "${ expected } "` ,
4041 ) ;
41- assertStrictEquals (
42- JSON . parse ( actual ) ,
43- JSON . parse ( expected ) ,
44- `console.log() JSON.parse() messages failure: (actual !== expected)\n "${ actual } " !== "${ expected } "` ,
45- ) ;
42+ if ( typeof JSON . parse ( actual ) !== 'object' )
43+ assertStrictEquals (
44+ JSON . parse ( actual ) ,
45+ JSON . parse ( expected ) ,
46+ `console.log() JSON.parse() messages failure: (actual !== expected)\n "${ actual } " !== "${ expected } "` ,
47+ ) ;
4648 table . push (
4749 Row . from ( [
4850 Cell . from ( '🧪🧪🧪🧪\t\x1b[1m\x1b[92m\x1b[4m' + testName . trim ( ) + '\x1b[24m\x1b[39m\x1b[22m\n' ) . colSpan ( 3 ) ,
4951 ] ) . border ( false ) ,
5052 [ actual , '===' , expected ] ,
51- [ JSON . parse ( actual ) , '===' , JSON . parse ( expected ) ] ,
5253 ) ;
54+ if ( typeof JSON . parse ( actual ) !== 'object' ) table . push ( [ JSON . parse ( actual ) , '===' , JSON . parse ( expected ) ] ) ;
5355 } catch ( e ) {
5456 table . push (
5557 Row . from ( [
56- Cell . from ( '🚨🚨🚨🚨\t\x1b[1m\x1b[91m\x1b[4m' + testName . trim ( ) + '\x1b[24m\x1b[39m\x1b[22m\n' ) . colSpan ( 3 ) ,
58+ Cell . from ( '🚨🚨🚨🚨\t\x1b[1m\x1b[91m\x1b[4m' + testName . trim ( ) + '\x1b[24m\x1b[39m\x1b[22m' + e + '\n' ) . colSpan (
59+ 3 ,
60+ ) ,
5761 ] ) . border ( false ) ,
5862 [ actual , '!==' , expected ] ,
5963 [ JSON . parse ( actual ?? [ ] ) , '!==' , JSON . parse ( expected ?? [ ] ) ] ,
@@ -74,6 +78,7 @@ const tests = {
7478 emphasis : false ,
7579 } ,
7680 } ,
81+ randomOpts : { ...Object . keys ( styleEnum ) . filter ( ( key ) => key !== 'suffix' ) } ,
7782 randomStyleFn : { ...Object . keys ( styleEnum ) . filter ( ( key ) => key !== 'suffix' ) } ,
7883 randomStyleString : { ...Object . keys ( styleEnum ) . filter ( ( key ) => key !== 'suffix' ) } ,
7984 } ,
@@ -88,6 +93,9 @@ const tests = {
8893 fixed : [ ] ,
8994 } ,
9095 } ,
96+ undefined : {
97+ random : undefined ,
98+ } ,
9199 stringUndefined : {
92100 random : {
93101 color : {
@@ -257,18 +265,20 @@ for (const test of Object.keys(tests)) {
257265 for ( const fn of Object . keys ( tests [ test ] ) ) {
258266 for ( const obj of [ true , false ] ) {
259267 // @ts -ignore
260- for ( const stylefn of Object . keys ( tests [ test ] [ fn ] ) ) {
268+ for ( const stylefn of Object . keys ( tests [ test ] [ fn ] ?? { undefined : undefined } ) ) {
261269 for ( const spread of [ true , false ] ) {
262270 Deno . test ( {
263271 name : `Color.ts` ,
264272 fn : ( ) => {
265273 testName = `${ test } , fn:${ fn } , styleFn:${ stylefn } , spread:${ spread } , fromObj:${ obj } \n` ;
274+ ogConsole ( testName ) ;
266275 // @ts -ignore
267- const args = tests [ test ] [ fn ] [ stylefn ] ;
276+ const args = stylefn === 'undefined' ? tests [ test ] [ fn ] : tests [ test ] [ fn ] [ stylefn ] ;
268277 let TmessageByStringSpread = messageByStringSpread ;
269278 let TmessageByString = messageByString ;
270279 let TmessageByFnSpread = messageByFnSpread ;
271280 let TmessageByFn = messageByFn ;
281+ let TrandomOpts = randomOpts ;
272282 let TrandomStyleFn = randomStyleFn ;
273283 let TrandomStyleString = randomStyleString ;
274284 let Trandom = random ;
@@ -277,6 +287,7 @@ for (const test of Object.keys(tests)) {
277287 TmessageByString = Color . messageByString ;
278288 TmessageByFnSpread = Color . messageByFnSpread ;
279289 TmessageByFn = Color . messageByFn ;
290+ TrandomOpts = Color . randomOpts ;
280291 TrandomStyleFn = Color . randomStyleFn ;
281292 TrandomStyleString = Color . randomStyleString ;
282293 Trandom = Color . random ;
@@ -290,6 +301,7 @@ for (const test of Object.keys(tests)) {
290301 if ( spread ) msg = JSON . stringify ( TmessageByFnSpread ( test , ...( args as StyleFn [ ] ) ) ) ;
291302 else msg = JSON . stringify ( TmessageByFn ( test , args as StyleFn [ ] ) ) ;
292303 }
304+ if ( fn === 'randomOpts' ) msg = JSON . stringify ( TrandomOpts ( args ) ) ;
293305 if ( fn === 'randomStyleFn' ) msg = JSON . stringify ( TrandomStyleFn ( args ) ( test ) ) ;
294306 if ( fn === 'randomStyleString' ) msg = JSON . stringify ( TrandomStyleString ( args ) ) ;
295307 if ( fn === 'random' ) msg = JSON . stringify ( Trandom ( test , args ) ) ;
0 commit comments