UNPKG

3.54 kBJavaScriptView Raw
1require('./setup');
2
3var run = require('./cli_helpers').run,
4 pipe = require('./cli_helpers').pipe;
5 success = require('./cli_helpers').success;
6
7describe('pipe', function () {
8
9 var input = 'var x = 2';
10 pipe(input);
11 success();
12
13 it('has no stderr', function () {
14 expect(result.stderr).eql('');
15 });
16
17 it('has results', function () {
18 expect(result.out).eql(hicat(input).ansi);
19 });
20});
21
22describe('--help', function () {
23 run('--help');
24 success();
25
26 it('shows --help', function () {
27 expect(result.out).include('-h, --help');
28 expect(result.out).include('print usage information');
29 });
30});
31
32describe('--version', function () {
33 run('--version');
34 success();
35
36 it('shows version info', function () {
37 expect(result.out).include(require('../package.json').version);
38 });
39});
40
41describe('-v', function () {
42 run('-v');
43 success();
44
45 it('shows version info', function () {
46 expect(result.out).include(require('../package.json').version);
47 });
48});
49
50describe('--languages', function () {
51 run('--languages');
52 success();
53
54 it('has color constants', function () {
55 var out = hicat.listLanguages().sort().join('\n');
56 expect(result.out.trim()).eql(out);
57 });
58});
59
60describe('--list-colors', function () {
61 run('--list-colors');
62 success();
63
64 it('has color constants', function () {
65 expect(result.out).match(/RED=[0-9;]+/);
66 expect(result.out).match(/GREEN=[0-9;]+/);
67 expect(result.out).match(/BLUE=[0-9;]+/);
68 expect(result.out).match(/CYAN=[0-9;]+/);
69 expect(result.out).match(/YELLOW=[0-9;]+/);
70 });
71
72 it('has "value"', function () {
73 expect(result.out).match(/value=.*/);
74 });
75});
76
77describe('a ruby example', function () {
78 run('samples/ruby.rb --no-pager');
79 success();
80
81 it('highlights', function () {
82 expect(result.out).match(/method/);
83 expect(result.out).match(/string/);
84 });
85});
86
87describe('coercing via --lang', function () {
88 run('samples/ruby.rb --no-pager --lang markdown --debug');
89 success();
90
91 it('works', function () {
92 expect(result.out).match(/language: markdown/);
93 });
94});
95
96describe('--numbers', function () {
97 run('samples/ruby.rb --numbers');
98 success();
99
100 it('prefixes with numbers', function () {
101 expect(result.stripped).match(/ 1 class MyClass/);
102 expect(result.stripped).match(/ 2 NUMBER = 200/);
103 expect(result.stripped).match(/ 4 def method/);
104 });
105
106 it('colors the numbers', function () {
107 expect(result.out).include(hicat.colorize(' 3 ', hicat.color('line_number')));
108 });
109});
110
111describe('coercing via -l', function () {
112 run('samples/ruby.rb --no-pager -l markdown --debug');
113 success();
114
115 it('works', function () {
116 expect(result.out).match(/language: markdown/);
117 });
118});
119
120describe('a ruby example with --debug', function () {
121 run('samples/ruby.rb --debug');
122 success();
123
124 it('highlights tags', function () {
125 expect(result.out).match(/\[string\].*\[\/string\]/);
126 });
127
128 it('tells the language', function () {
129 var strip = result.out.replace(/\033[^m]*m/g, '');
130 expect(strip).include('hicat language: rb');
131 });
132});
133
134describe('not found', function () {
135 run('xxx yyy zzz --no-pager');
136
137 it('fails', function () {
138 expect(result.code).eql(8);
139 });
140
141 it('does no output', function () {
142 expect(result.out).eql('');
143 });
144
145 it('reports errors', function () {
146 expect(result.stderr).match(/xxx/);
147 expect(result.stderr).match(/yyy/);
148 expect(result.stderr).match(/zzz/);
149 expect(result.stderr).match(/no such file or directory/);
150 });
151});