]>
git.r.bdr.sh - rbdr/cologne/blob - test/utilities.js
2bff47fd59eadb049ea27763c67d9ab3c9129bcd
3 const Tap
= require('tap');
5 const Utilities
= require('../lib/utilities');
14 const preciseTime
= Utilities
.now();
16 // I don't think this test makes sense lol
17 Tap
.equal(typeof preciseTime
, 'bigint',
18 '::now() should give a precise bigint timestamp');
24 const regularObject
= {
32 const circularObject
= {
39 circularObject
.b
.circular
= circularObject
;
43 const regularStringify
= JSON
.stringify(regularObject
);
44 const cologneStringify
= Utilities
.stringify(regularObject
);
45 const circularStringify
= Utilities
.stringify(circularObject
);
46 const bigintStringify
= Utilities
.stringify(bigint
);
48 Tap
.equal(regularStringify
, cologneStringify
,
49 '::stringify() should behave like JSON.stringify for non-circular objects');
50 Tap
.equal(typeof JSON
.parse(circularStringify
).b
.circular
, 'string',
51 '::stringify() should replace circular references with a string');
52 Tap
.equal(bigintStringify
, '"666n"',
53 '::stringify() should convert bigint to string');
56 * TEST: ::getAnsiCode()
59 // NOTE: This isn't even trying to be a complete test... Just testing
60 // that we get distinct non-reset codes if valid, and the same as reset
61 // for all invalid ones. knowing that reset is [0m
63 Tap
.equal(Utilities
.getAnsiCode('reset'), '[0m',
64 '::getAnsiCode is sending the correct reset code');
65 Tap
.equal(Utilities
.getAnsiCode('someRandomString'), Utilities
.getAnsiCode('reset'),
66 '::getAnsiCode() should give us a reset code if something weird is sent');
68 const supportedCodes
= ['bold', 'italics', 'underline', 'inverse', 'strikethrough',
69 'bold_off', 'italics_off', 'underline_off', 'inverse_off', 'strikethrough_off',
70 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default',
71 'black_bg', 'red_bg', 'green_bg', 'yellow_bg', 'blue_bg', 'magenta_bg',
72 'cyan_bg', 'white_bg', 'default_bg'];
73 const resultingCodes
= supportedCodes
.map((code
) => Utilities
.getAnsiCode(code
));
74 const isThereReset
= resultingCodes
.some((code
) => code
=== '[0m');
76 Tap
.equal((new Set(resultingCodes
)).size
, supportedCodes
.length
,
77 '::getAnsiCode() should not have duplicated non-reset codes');
78 Tap
.false(isThereReset
,
79 '::getAnsiCode() should not return a reset code in any other supported code');
82 * TEST: ::getLevelAnsi()
85 // NOTE: This isn't even trying to be a complete test... Just testing
86 // that we get other than reset if valid, and the same as reset for all
87 // invalid ones. knowing that reset is [0m
89 Tap
.equal(Utilities
.getLevelAnsi(0), 'red',
90 '::gettLevelAnsi is red for emerg');
91 Tap
.equal(Utilities
.getLevelAnsi(1), 'red',
92 '::gettLevelAnsi is red for alert');
93 Tap
.equal(Utilities
.getLevelAnsi(2), 'red',
94 '::gettLevelAnsi is red for crit');
95 Tap
.equal(Utilities
.getLevelAnsi(3), 'red',
96 '::gettLevelAnsi is red for error');
97 Tap
.equal(Utilities
.getLevelAnsi(4), 'yellow',
98 '::gettLevelAnsi is yellow for warn');
99 Tap
.equal(Utilities
.getLevelAnsi(5), 'blue',
100 '::gettLevelAnsi is blue for notice');
101 Tap
.equal(Utilities
.getLevelAnsi(6), 'blue',
102 '::gettLevelAnsi is blue for info');
103 Tap
.equal(Utilities
.getLevelAnsi(7), 'green',
104 '::gettLevelAnsi is green for debug');
105 Tap
.equal(Utilities
.getLevelAnsi(8), 'default',
106 '::gettLevelAnsi is default for other values');