/
ansispan-test.js
47 lines (42 loc) · 1.28 KB
/
ansispan-test.js
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
var assert = require('assert'),
vows = require('vows'),
ansispan = require('../');
require('colors');
var dataSets = {
simple: {
input: 'hello world'.green,
output: '<span style="color: green">hello world</span>'
},
nested: {
input: 'hello world'.green.red,
output: '<span style="color: red"><span style="color: green">hello world</span></span>'
},
many: {
input: 'hello '.green + 'world'.red,
output: '<span style="color: green">hello </span><span style="color: red">world</span>'
},
'many same colors': {
input: 'hello '.green + 'world'.green,
output: '<span style="color: green">hello </span><span style="color: green">world</span>'
},
'colors with \\033\\[0;Xm': {
input: '\033\[0;32mhello world\033\[39m',
output: '<span style="color: green">hello world</span>'
}
};
function getTopics() {
var topics = {};
Object.keys(dataSets).forEach(function (set) {
topics['when using ' + set + ' data set'] = {
topic: ansispan(dataSets[set].input),
'should return correct output': function (result) {
assert.isString(result);
assert.equal(result, dataSets[set].output);
}
};
});
return topics;
}
vows.describe('ansispan').addBatch({
'When using ansispan': getTopics()
}).export(module);