1 | require('./setup');
|
2 | var extend = require('util')._extend;
|
3 |
|
4 | describe('Hicat the module', function() {
|
5 | it('is a function', function () {
|
6 | expect(hicat).be.a('function');
|
7 | });
|
8 |
|
9 | it('has colors', function () {
|
10 | expect(hicat.colors).be.a('object');
|
11 | expect(hicat.colors.string).be.a('string');
|
12 | });
|
13 | });
|
14 |
|
15 | describe('Explicitly setting the language', function() {
|
16 | var out, input;
|
17 |
|
18 | beforeEach(function () {
|
19 | input = 'var x = 2 + "hi"; /*yo*/';
|
20 | out = hicat(input, { lang: 'javascript' });
|
21 | });
|
22 |
|
23 | it('produces .language', function () {
|
24 | expect(out.language).be.eql('javascript');
|
25 | });
|
26 | });
|
27 |
|
28 | describe('Explicitly setting an invalid language', function() {
|
29 | var str, out, input;
|
30 |
|
31 | beforeEach(function () {
|
32 | input = '{"a":2}';
|
33 | out = hicat(input, { lang: 'aoeu' });
|
34 | });
|
35 |
|
36 | it('auto-detects the language', function () {
|
37 | expect(out.language).be.eql('json');
|
38 | });
|
39 | });
|
40 |
|
41 | describe('A simple example', function() {
|
42 | var str, out, input;
|
43 |
|
44 | beforeEach(function () {
|
45 | input = 'var x = 2345 + "hi"; /*yo*/ window.document.x = function($){};';
|
46 | out = hicat(input);
|
47 | str = out.ansi;
|
48 | });
|
49 |
|
50 | it('produces .language', function () {
|
51 | expect(out.language).be.eql('javascript');
|
52 | });
|
53 |
|
54 | it('produces .ansi', function () {
|
55 | expect(out.ansi).be.a('string');
|
56 | });
|
57 |
|
58 | it('produces .raw', function () {
|
59 | expect(out.raw).eql(input);
|
60 | });
|
61 |
|
62 | it('produces ansi codes', function () {
|
63 | var code = str.replace(/\033[^m]+m/g, '');
|
64 | expect(code).eql(input);
|
65 | });
|
66 |
|
67 | it('highlights numbers', function () {
|
68 | var fragment = hicat.colorize('2345', hicat.color('number', 'javascript'));
|
69 | expect(str).include(str);
|
70 | });
|
71 |
|
72 | it('highlights comments', function () {
|
73 | var fragment = hicat.colorize('/*yo*/', hicat.color('comment', 'javascript'));
|
74 | expect(str).include(fragment);
|
75 | });
|
76 | });
|
77 |
|
78 | describe('Hicat.color', function () {
|
79 | var oldcolors;
|
80 |
|
81 | beforeEach(function () {
|
82 | oldcolors = extend({}, hicat.colors);
|
83 | });
|
84 |
|
85 | afterEach(function () {
|
86 | hicat.colors = oldcolors;
|
87 | });
|
88 |
|
89 | it('works for simple cases', function () {
|
90 | hicat.colors = { string: '80' };
|
91 | expect(hicat.color('string')).eql('80');
|
92 | });
|
93 |
|
94 | it('resolves references', function () {
|
95 | hicat.colors = { string: '70', str: 'string', s: 'str' };
|
96 | expect(hicat.color('s')).eql('70');
|
97 | });
|
98 |
|
99 | it('accounts for languages', function () {
|
100 | hicat.colors = { val: '20', 'json:val': '30' };
|
101 | expect(hicat.color('val')).eql('20');
|
102 | expect(hicat.color('json:val')).eql('30');
|
103 | });
|
104 |
|
105 | });
|
106 |
|
107 | describe('Hicat.colorize', function () {
|
108 | it('works', function () {
|
109 | var fragment = hicat.colorize('yo', '32');
|
110 | expect(fragment).eql('\033[32m' + 'yo' + '\033[0m');
|
111 | });
|
112 | });
|