1 var assert = require('assert'),
2 colors = require('./colors');
5 // This is a pretty nice example on how tests shouldn't be written. However,
6 // it's more about API stability than about really testing it (although it's
7 // a pretty complete test suite).
13 return '\033[' + code.toString() + 'm' + s + '\033[39m';
16 function aE(s, color, code) {
17 assert.equal(s[color], a(s, code));
18 assert.equal(colors[color](s), a(s, code));
19 assert.equal(s[color], colors[color](s));
20 assert.equal(s[color].stripColors, s);
21 assert.equal(s[color].stripColors, colors.stripColors(s));
24 function h(s, color) {
25 return '<span style="color:' + color + ';">' + s + '</span>';
26 // that's pretty dumb approach to testing it
29 var stylesColors = ['white', 'grey', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
30 var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
32 colors.mode = 'console';
33 assert.equal(s.bold, '\033[1m' + s + '\033[22m');
34 assert.equal(s.italic, '\033[3m' + s + '\033[23m');
35 assert.equal(s.underline, '\033[4m' + s + '\033[24m');
36 assert.equal(s.inverse, '\033[7m' + s + '\033[27m');
47 assert.equal(s, 'string');
49 colors.mode = 'browser';
50 assert.equal(s.bold, '<b>' + s + '</b>');
51 assert.equal(s.italic, '<i>' + s + '</i>');
52 assert.equal(s.underline, '<u>' + s + '</u>');
53 assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
55 stylesColors.forEach(function (color) {
56 assert.equal(s[color], h(s, color));
57 assert.equal(colors[color](s), h(s, color));
61 stylesAll.forEach(function (style) {
62 assert.equal(s[style], s);
63 assert.equal(colors[style](s), s);