UNPKG

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