test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import test from 'ava';
  2. import chalk from 'chalk';
  3. import stripAnsi from 'strip-ansi';
  4. import columns from './index';
  5. test('should print one column list', t => {
  6. const cols = columns(['foo', ['bar', 'baz'], ['bar', 'qux']], {
  7. width: 1
  8. });
  9. const expected =
  10. 'bar\n' +
  11. 'bar\n' +
  12. 'baz\n' +
  13. 'foo\n' +
  14. 'qux';
  15. t.is(cols, expected);
  16. });
  17. test('should print three column list', t => {
  18. const cols = columns(['foo', ['bar', 'baz'], ['bat', 'qux']], {
  19. width: 16
  20. });
  21. const expected =
  22. 'bar baz qux \n' +
  23. 'bat foo ';
  24. t.is(cols, expected);
  25. });
  26. test('should print complex list', t => {
  27. const cols = columns(
  28. [
  29. 'foo', 'bar', 'baz',
  30. chalk.cyan('嶜憃撊') + ' 噾噿嚁',
  31. 'blue' + chalk.bgBlue('berry'),
  32. chalk.red('apple'), 'pomegranate',
  33. 'durian', chalk.green('star fruit'),
  34. 'apricot', 'banana pineapple'
  35. ],
  36. {
  37. width: 80
  38. }
  39. );
  40. const expected =
  41. 'apple bar durian star fruit \n' +
  42. 'apricot baz foo 嶜憃撊 噾噿嚁 \n' +
  43. 'banana pineapple blueberry pomegranate ';
  44. t.is(stripAnsi(cols), expected);
  45. });
  46. test('should optionally not sort', t => {
  47. const cols = columns(
  48. [
  49. 'foo', 'bar', 'baz',
  50. chalk.cyan('嶜憃撊') + ' 噾噿嚁',
  51. 'blue' + chalk.bgBlue('berry'),
  52. chalk.red('apple'), 'pomegranate',
  53. 'durian', chalk.green('star fruit'),
  54. 'apricot', 'banana pineapple'
  55. ],
  56. {
  57. sort: false,
  58. width: 80
  59. }
  60. );
  61. const expected =
  62. 'foo 嶜憃撊 噾噿嚁 pomegranate apricot \n' +
  63. 'bar blueberry durian banana pineapple \n' +
  64. 'baz apple star fruit ';
  65. t.is(stripAnsi(cols), expected);
  66. });