No Description

test.js 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. var assert = require('assert'),
  2. colors = require('./colors');
  3. var s = 'string';
  4. function a(s, code) {
  5. return '\x1B[' + code.toString() + 'm' + s + '\x1B[39m';
  6. }
  7. function aE(s, color, code) {
  8. assert.equal(s[color], a(s, code));
  9. assert.equal(colors[color](s), a(s, code));
  10. assert.equal(s[color], colors[color](s));
  11. assert.equal(s[color].stripColors, s);
  12. assert.equal(s[color].stripColors, colors.stripColors(s));
  13. }
  14. function h(s, color) {
  15. return '<span style="color:' + color + ';">' + s + '</span>';
  16. }
  17. var stylesColors = ['white', 'black', 'blue', 'cyan', 'green', 'magenta', 'red', 'yellow'];
  18. var stylesAll = stylesColors.concat(['bold', 'italic', 'underline', 'inverse', 'rainbow']);
  19. colors.mode = 'console';
  20. assert.equal(s.bold, '\x1B[1m' + s + '\x1B[22m');
  21. assert.equal(s.italic, '\x1B[3m' + s + '\x1B[23m');
  22. assert.equal(s.underline, '\x1B[4m' + s + '\x1B[24m');
  23. assert.equal(s.strikethrough, '\x1B[9m' + s + '\x1B[29m');
  24. assert.equal(s.inverse, '\x1B[7m' + s + '\x1B[27m');
  25. assert.ok(s.rainbow);
  26. aE(s, 'white', 37);
  27. aE(s, 'grey', 90);
  28. aE(s, 'black', 30);
  29. aE(s, 'blue', 34);
  30. aE(s, 'cyan', 36);
  31. aE(s, 'green', 32);
  32. aE(s, 'magenta', 35);
  33. aE(s, 'red', 31);
  34. aE(s, 'yellow', 33);
  35. assert.equal(s, 'string');
  36. colors.setTheme({error:'red'});
  37. assert.equal(typeof("astring".red),'string');
  38. assert.equal(typeof("astring".error),'string');
  39. colors.mode = 'browser';
  40. assert.equal(s.bold, '<b>' + s + '</b>');
  41. assert.equal(s.italic, '<i>' + s + '</i>');
  42. assert.equal(s.underline, '<u>' + s + '</u>');
  43. assert.equal(s.strikethrough, '<del>' + s + '</del>');
  44. assert.equal(s.inverse, '<span style="background-color:black;color:white;">' + s + '</span>');
  45. assert.ok(s.rainbow);
  46. stylesColors.forEach(function (color) {
  47. assert.equal(s[color], h(s, color));
  48. assert.equal(colors[color](s), h(s, color));
  49. });
  50. assert.equal(typeof("astring".red),'string');
  51. assert.equal(typeof("astring".error),'string');
  52. colors.mode = 'none';
  53. stylesAll.forEach(function (style) {
  54. assert.equal(s[style], s);
  55. assert.equal(colors[style](s), s);
  56. });
  57. assert.equal(typeof("astring".red),'string');
  58. assert.equal(typeof("astring".error),'string');