index.js 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use strict';
  2. var logUtils = require('../');
  3. exports['Helpers'] = {
  4. setUp: function(done) {
  5. done();
  6. },
  7. 'uncolor': function(test) {
  8. test.expect(1);
  9. test.equal(logUtils.uncolor('a'.red + 'b'.bold.green + 'c'.blue.underline), 'abc');
  10. test.done();
  11. },
  12. 'wordlist': function(test) {
  13. test.expect(2);
  14. test.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'])), 'a, b');
  15. test.equal(logUtils.uncolor(logUtils.wordlist(['a', 'b'], {separator: '-'})), 'a-b');
  16. test.done();
  17. },
  18. 'wraptext': function(test) {
  19. test.expect(8);
  20. // // I'm not writing out comprehensive unit tests for this right now.
  21. // function doAll(text) {
  22. // console.log('==========');
  23. // console.log('==========');
  24. // [4, 6, 10, 15, 20, 25, 30, 40, 60].forEach(function(n) {
  25. // doOne(n, text);
  26. // });
  27. // }
  28. // function doOne(n, text) {
  29. // console.log(new Array(n + 1).join('-'));
  30. // console.log(logUtils.wraptext(n, text));
  31. // }
  32. // var text = 'this is '.red + 'a simple'.yellow.inverse + ' test of'.green + ' ' + 'some wrapped'.blue + ' text over '.inverse.magenta + 'many lines'.red;
  33. // doAll(text);
  34. // text = 'foolish '.red.inverse + 'monkeys'.yellow + ' eating'.green + ' ' + 'delicious'.inverse.blue + ' bananas '.magenta + 'forever'.red;
  35. // doAll(text);
  36. // text = 'foolish monkeys eating delicious bananas forever'.rainbow;
  37. // doAll(text);
  38. test.equal(logUtils.wraptext(2, 'aabbc'), 'aa\nbb\nc');
  39. test.equal(logUtils.wraptext(2, 'aabbcc'), 'aa\nbb\ncc');
  40. test.equal(logUtils.wraptext(3, 'aaabbbc'), 'aaa\nbbb\nc');
  41. test.equal(logUtils.wraptext(3, 'aaabbbcc'), 'aaa\nbbb\ncc');
  42. test.equal(logUtils.wraptext(3, 'aaabbbccc'), 'aaa\nbbb\nccc');
  43. test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'c'.underline)), 'aaa\nbbb\nc');
  44. test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'cc'.underline)), 'aaa\nbbb\ncc');
  45. test.equal(logUtils.uncolor(logUtils.wraptext(3, 'aaa'.blue + 'bbb'.green + 'ccc'.underline)), 'aaa\nbbb\nccc');
  46. test.done();
  47. },
  48. 'table': function(test) {
  49. test.expect(1);
  50. test.equal(logUtils.table([3, 1, 5, 1, 8, 1, 12, 1, 20], [
  51. 'a aa aaa aaaa aaaaa',
  52. '|||||||',
  53. 'b bb bbb bbbb bbbbb',
  54. '|||||||',
  55. 'c cc ccc cccc ccccc',
  56. '|||||||',
  57. 'd dd ddd dddd ddddd',
  58. '|||||||',
  59. 'e ee eee eeee eeeee eeeeee',
  60. ]), 'a |b bb |c cc ccc|d dd ddd |e ee eee eeee eeeee \n' +
  61. 'aa |bbb |cccc |dddd ddddd |eeeeee \n' +
  62. 'aaa|bbbb |ccccc | |\n' +
  63. 'aaa|bbbbb| | |\n' +
  64. 'a | | | |\n' +
  65. 'aaa| | | |\n' +
  66. 'aa | | | |');
  67. test.done();
  68. },
  69. };