Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test.js « cli-columns « node_modules - github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1ff642cd54b879807c777d575b50ea1cfc0e83c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import test from 'ava';
import chalk from 'chalk';
import stripAnsi from 'strip-ansi';
import columns from './index';

test('should print one column list', t => {
	const cols = columns(['foo', ['bar', 'baz'], ['bar', 'qux']], {
		width: 1
	});

	const expected =
		'bar\n' +
		'bar\n' +
		'baz\n' +
		'foo\n' +
		'qux';

	t.is(cols, expected);
});

test('should print three column list', t => {
	const cols = columns(['foo', ['bar', 'baz'], ['bat', 'qux']], {
		width: 16
	});

	const expected =
		'bar  baz  qux  \n' +
		'bat  foo  ';

	t.is(cols, expected);
});

test('should print complex list', t => {
	const cols = columns(
		[
			'foo', 'bar', 'baz',
			chalk.cyan('嶜憃撊') + ' 噾噿嚁',
			'blue' + chalk.bgBlue('berry'),
			chalk.red('apple'), 'pomegranate',
			'durian', chalk.green('star fruit'),
			'apricot', 'banana pineapple'
		],
		{
			width: 80
		}
	);

	const expected =
		'apple             bar               durian            star fruit        \n' +
		'apricot           baz               foo               嶜憃撊 噾噿嚁     \n' +
		'banana pineapple  blueberry         pomegranate       ';

	t.is(stripAnsi(cols), expected);
});

test('should optionally not sort', t => {
	const cols = columns(
		[
			'foo', 'bar', 'baz',
			chalk.cyan('嶜憃撊') + ' 噾噿嚁',
			'blue' + chalk.bgBlue('berry'),
			chalk.red('apple'), 'pomegranate',
			'durian', chalk.green('star fruit'),
			'apricot', 'banana pineapple'
		],
		{
			sort: false,
			width: 80
		}
	);

	const expected =
		'foo               嶜憃撊 噾噿嚁     pomegranate       apricot           \n' +
		'bar               blueberry         durian            banana pineapple  \n' +
		'baz               apple             star fruit        ';

	t.is(stripAnsi(cols), expected);
});