forked from drudru/ansi_up
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathansi_up-test.js
285 lines (209 loc) · 7.92 KB
/
ansi_up-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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
var ansi_up = require('../ansi_up');
var should = require('should');
describe('ansi_up', function() {
describe('escape_for_html', function() {
describe('ampersands', function() {
it('should escape a single ampersand', function() {
this.timeout(1);
var start = "&";
var expected = "&";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape some text with ampersands', function() {
this.timeout(1);
var start = "abcd&efgh";
var expected = "abcd&efgh";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape multiple ampersands', function() {
this.timeout(1);
var start = " & & ";
var expected = " & & ";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape an already escaped ampersand', function() {
this.timeout(1);
var start = " & ";
var expected = " & ";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
});
describe('less-than', function() {
it('should escape a single less-than', function() {
this.timeout(1);
var start = "<";
var expected = "<";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape some text with less-thans', function() {
this.timeout(1);
var start = "abcd<efgh";
var expected = "abcd<efgh";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape multiple less-thans', function() {
this.timeout(1);
var start = " < < ";
var expected = " < < ";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
});
describe('greater-than', function() {
it('should escape a single greater-than', function() {
this.timeout(1);
var start = ">";
var expected = ">";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape some text with greater-thans', function() {
this.timeout(1);
var start = "abcd>efgh";
var expected = "abcd>efgh";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
it('should escape multiple greater-thans', function() {
this.timeout(1);
var start = " > > ";
var expected = " > > ";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
});
describe('mixed characters', function() {
it('should escape a mix of characters that require escaping', function() {
this.timeout(1);
var start = "<&>/\\'\"";
var expected = "<&>/\\'\"";
var l = ansi_up.escape_for_html(start);
l.should.eql(expected);
});
});
});
describe('linkify', function() {
it('should linkify a url', function() {
this.timeout(1);
var start = "http://link.to/me";
var expected = "<a href=\"http://link.to/me\">http://link.to/me</a>";
var l = ansi_up.linkify(start);
l.should.eql(expected);
});
});
describe('ansi to html', function() {
describe('default colors', function() {
it('should transform a foreground to html', function() {
this.timeout(1);
var attr = 0;
var fg = 32;
var start = "\033[" + fg + "m " + fg + " \033[0m";
var expected = "<span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span>";
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});
it('should transform a attr;foreground to html', function() {
this.timeout(1);
var attr = 0;
var fg = 32;
var start = "\033[" + attr + ";" + fg + "m " + fg + " \033[0m";
var expected = "<span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span>";
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});
it('should transform an empty code to a normal/reset html', function() {
this.timeout(1);
var attr = 0;
var fg = 32;
var start = "\033[" + attr + ";" + fg + "m " + fg + " \033[m x";
var expected = "<span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span> x";
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});
it('should transform a bold attr;foreground to html', function() {
this.timeout(1);
var attr = 1;
var fg = 32;
var start = "\033[" + attr + ";" + fg + "m " + attr + ";" + fg + " \033[0m";
var expected = "<span style=\"color:rgb(0, 255, 0)\"> " + attr + ";" + fg + " </span>";
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});
it('should transform a bold attr;background;foreground to html', function() {
this.timeout(1);
var attr = 1;
var fg = 33;
var bg = 42;
var start = "\033[" + attr + ";" + bg + ";" + fg + "m " + attr + ";" + bg + ";" + fg + " \033[0m";
var expected = "<span style=\"color:rgb(255, 255, 85);background-color:rgb(0, 187, 0)\"> " + attr + ";" + bg + ";" + fg + " </span>";
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});
it('should transform a complex multi-line sequence to html', function() {
this.timeout(1);
var attr = 1;
var fg = 32;
var bg = 42;
var start = "\n \033[" + fg + "m " + fg + " \033[0m \n \033[" + bg + "m " + bg + " \033[0m \n zimpper ";
var expected = "\n <span style=\"color:rgb(0, 187, 0)\"> " + fg + " </span> \n <span style=\"background-color:rgb(0, 187, 0)\"> " + bg + " </span> \n zimpper ";
var l = ansi_up.ansi_to_html(start);
l.should.eql(expected);
});
});
describe('themed colors', function() {
it('should transform a foreground to html', function() {
this.timeout(1);
var attr = 0;
var fg = 32;
var start = "\033[" + fg + "m " + fg + " \033[0m";
var expected = "<span class=\"ansi-green-fg\"> " + fg + " </span>";
var l = ansi_up.ansi_to_html(start, {use_classes: true});
l.should.eql(expected);
});
it('should transform a attr;foreground to html', function() {
this.timeout(1);
var attr = 0;
var fg = 32;
var start = "\033[" + attr + ";" + fg + "m " + fg + " \033[0m";
var expected = "<span class=\"ansi-green-fg\"> " + fg + " </span>";
var l = ansi_up.ansi_to_html(start, {use_classes: true});
l.should.eql(expected);
});
it('should transform a bold attr;foreground to html', function() {
this.timeout(1);
var attr = 1;
var fg = 32;
var start = "\033[" + attr + ";" + fg + "m " + attr + ";" + fg + " \033[0m";
var expected = "<span class=\"ansi-bright-green-fg\"> " + attr + ";" + fg + " </span>";
var l = ansi_up.ansi_to_html(start, {use_classes: true});
l.should.eql(expected);
});
it('should transform a bold attr;background;foreground to html', function() {
this.timeout(1);
var attr = 1;
var fg = 33;
var bg = 42;
var start = "\033[" + attr + ";" + bg + ";" + fg + "m " + attr + ";" + bg + ";" + fg + " \033[0m";
var expected = "<span class=\"ansi-bright-yellow-fg ansi-green-bg\"> " + attr + ";" + bg + ";" + fg + " </span>";
var l = ansi_up.ansi_to_html(start, {use_classes: true});
l.should.eql(expected);
});
it('should transform a complex multi-line sequence to html', function() {
this.timeout(1);
var attr = 1;
var fg = 32;
var bg = 42;
var start = "\n \033[" + fg + "m " + fg + " \033[0m \n \033[" + bg + "m " + bg + " \033[0m \n zimpper ";
var expected = "\n <span class=\"ansi-green-fg\"> " + fg + " </span> \n <span class=\"ansi-green-bg\"> " + bg + " </span> \n zimpper ";
var l = ansi_up.ansi_to_html(start, {use_classes: true});
l.should.eql(expected);
});
});
});
});