-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.js
48 lines (40 loc) · 1.37 KB
/
tests.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
47
48
var assert = require("node:assert");
var test = require("node:test");
var chalk = require('chalk');
var parser = require('./');
var tst = function(t, src, expected){
assert.deepEqual(parser(src), expected);
};
test('basics', function(t){
tst(t, 'hello world', [
{styles: [], text: 'hello world'}
]);
tst(t, chalk.green('hello'), [
{styles: ['green'], text: 'hello'}
]);
tst(t, 'hello ' + chalk.green('world') + chalk.red('!'), [
{styles: [], text: 'hello '},
{styles: ['green'], text: 'world'},
{styles: ['red'], text: '!'}
]);
tst(t, 'wat?\033[33m is\033[34m[34m\033[31m? \033[mend', [
{styles: [], text: 'wat?'},
{styles: ['yellow'], text: ' is'},
{styles: ['blue'], text: '[34m'},
{styles: ['red'], text: '? '},
{styles: [], text: 'end'}
]);
});
test('nested_styles', function(t){
tst(t, chalk.green.bgRed.underline('world'), [
{styles: ['green', 'bgRed', 'underline'], text: 'world'}
]);
tst(t, chalk.green('h'+chalk.bgRed('e'+chalk.bold('l'+chalk.blue('l') +chalk.underline('o')))+'!'), [
{text: 'h', styles: ['green']},
{text: 'e', styles: ['green', 'bgRed']},
{text: 'l', styles: ['green', 'bgRed', 'bold']},
{text: 'l', styles: ['bgRed', 'bold', 'blue']},
{text: 'o', styles: ['bgRed', 'bold', 'green', 'underline']},
{text: '!', styles: ['green']}
]);
});