UNPKG

2.13 kBJavaScriptView Raw
1require('./setup');
2var extend = require('util')._extend;
3
4describe('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
15describe('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
28describe('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
41describe('A simple example', function() {
42 var str, out, input;
43
44 beforeEach(function () {
45 input = 'var x = 2 + "hi"; /*yo*/';
46 out = hicat(input);
47 str = out.ansi;
48 });
49
50 it('produces .language', function () {
51 expect(out.language).be.eql('haxe');
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 expect(str).include('\033[33m2\033[0m');
69 });
70
71 it('highlights comments', function () {
72 expect(str).include('\033[30m/*yo*/\033[0m');
73 });
74});
75
76describe('Hicat.color', function () {
77 var oldcolors;
78
79 beforeEach(function () {
80 oldcolors = extend({}, hicat.colors);
81 });
82
83 afterEach(function () {
84 hicat.colors = oldcolors;
85 });
86
87 it('works for simple cases', function () {
88 hicat.colors = { string: '80' };
89 expect(hicat.color('string')).eql('80');
90 });
91
92 it('resolves references', function () {
93 hicat.colors = { string: '70', str: 'string', s: 'str' };
94 expect(hicat.color('s')).eql('70');
95 });
96});