]>
git.proxmox.com Git - mirror_xterm.js.git/blob - src/test/escape-sequences-test.js
5b1ccb71e3dffc21776760ed40de2f75f96deae2
1 var glob
= require('glob');
2 var fs
= require('fs');
3 var os
= require('os');
4 var pty
= require('node-pty');
5 var Terminal
= require('../xterm');
7 if (os
.platform() === 'win32') {
8 // Skip tests on Windows since pty.open isn't supported
12 var CONSOLE_LOG
= console
.log
;
14 // expect files need terminal at 80x25!
18 /** some helpers for pty interaction */
19 // we need a pty in between to get the termios decorations
20 // for the basic test cases a raw pty device is enough
21 var primitive_pty
= pty
.native.open(COLS
, ROWS
);
23 // fake sychronous pty write - read
24 // we just pipe the data from slave to master as a child program would do
25 // pty.js opens pipe fds with O_NONBLOCK
26 // just wait 10ms instead of setting fds to blocking mode
27 function pty_write_read(s
, cb
) {
28 fs
.writeSync(primitive_pty
.slave
, s
);
30 var b
= Buffer(64000);
31 var bytes
= fs
.readSync(primitive_pty
.master
, b
, 0, 64000);
32 cb(b
.toString('utf8', 0, bytes
));
36 // make sure raw pty is at x=0 and has no pending data
37 function pty_reset(cb
) {
38 pty_write_read('\r\n', cb
);
42 // generate colorful noisy output to compare xterm and emulator cell states
43 function formatError(in_
, out_
, expected
) {
44 function addLineNumber(start
, color
) {
45 var counter
= start
|| 0;
48 return '\x1b[33m' + (' ' + counter
).slice(-2) + color
+ s
;
51 var line80
= '12345678901234567890123456789012345678901234567890123456789012345678901234567890';
53 s
+= '\n\x1b[34m' + JSON
.stringify(in_
);
54 s
+= '\n\x1b[33m ' + line80
+ '\n';
55 s
+= out_
.split('\n').map(addLineNumber(0, '\x1b[31m')).join('\n');
56 s
+= '\n\x1b[33m ' + line80
+ '\n';
57 s
+= expected
.split('\n').map(addLineNumber(0, '\x1b[32m')).join('\n');
61 // simple debug output of terminal cells
62 function terminalToString(term
) {
65 for (var line
= term
.ybase
; line
< term
.ybase
+ term
.rows
; line
++) {
67 for (var cell
=0; cell
<term
.cols
; ++cell
) {
68 line_s
+= term
.lines
.get(line
)[cell
][1];
70 // rtrim empty cells as xterm does
71 line_s
= line_s
.replace(/\s+$/, '');
79 describe('xterm output comparison', function() {
82 beforeEach(function () {
83 xterm
= new Terminal(COLS
, ROWS
);
84 xterm
.refresh = function() {};
86 syncScrollArea: function() {}
90 // omit stack trace for escape sequence files
91 Error
.stackTraceLimit
= 0;
92 var files
= glob
.sync('**/escape_sequence_files/*.in');
93 // only successful tests for now
95 10, 16, 17, 19, 32, 33, 34, 35, 36, 39,
96 40, 42, 43, 44, 45, 46, 47, 48, 49, 50,
97 51, 52, 54, 55, 56, 57, 58, 59, 60, 61,
100 if (os
.platform() === 'darwin') {
101 // These are failing on macOS only
102 skip
.push(3, 7, 11, 67);
104 for (var i
= 0; i
< files
.length
; i
++) {
105 if (skip
.indexOf(i
) >= 0) {
108 (function(filename
) {
109 it(filename
.split('/').slice(-1)[0], done
=> {
111 var in_file
= fs
.readFileSync(filename
, 'utf8');
112 pty_write_read(in_file
, from_pty
=> {
113 // uncomment this to get log from terminal
114 //console.log = function(){};
116 // Perform a synchronous .write(data)
117 xterm
.writeBuffer
.push(from_pty
);
120 var from_emulator
= terminalToString(xterm
);
121 console
.log
= CONSOLE_LOG
;
122 var expected
= fs
.readFileSync(filename
.split('.')[0] + '.text', 'utf8');
123 // Some of the tests have whitespace on the right of lines, we trim all the linex
124 // from xterm.js so ignore this for now at least.
125 var expectedRightTrimmed
= expected
.split('\n').map(function (l
) {
126 return l
.replace(/\s+$/, '');
128 if (from_emulator
!= expectedRightTrimmed
) {
129 // uncomment to get noisy output
130 throw new Error(formatError(in_file
, from_emulator
, expected
));
131 // throw new Error('mismatch');