]>
git.proxmox.com Git - mirror_xterm.js.git/blob - test/escape_sequences.js
1 var glob
= require('glob');
2 var fs
= require('fs');
3 var pty
= require('pty.js');
4 var sleep
= require('sleep');
5 var Terminal
= require('../src/xterm');
7 var CONSOLE_LOG
= console
.log
;
9 // expect files need terminal at 80x25!
13 /** some helpers for pty interaction */
14 // we need a pty in between to get the termios decorations
15 // for the basic test cases a raw pty device is enough
16 var primitive_pty
= pty
.native.open(COLS
, ROWS
);
18 // fake sychronous pty write - read
19 // we just pipe the data from slave to master as a child program would do
20 // pty.js opens pipe fds with O_NONBLOCK
21 // just wait 10ms instead of setting fds to blocking mode
22 function pty_write_read(s
) {
23 fs
.writeSync(primitive_pty
.slave
, s
);
25 var b
= Buffer(64000);
26 var bytes
= fs
.readSync(primitive_pty
.master
, b
, 0, 64000);
27 return b
.toString('utf8', 0, bytes
);
30 // make sure raw pty is at x=0 and has no pending data
31 function pty_reset() {
32 pty_write_read('\r\n');
36 // generate colorful noisy output to compare xterm and emulator cell states
37 function formatError(in_
, out_
, expected
) {
38 function addLineNumber(start
, color
) {
39 var counter
= start
|| 0;
42 return '\x1b[33m' + (' ' + counter
).slice(-2) + color
+ s
;
45 var line80
= '12345678901234567890123456789012345678901234567890123456789012345678901234567890';
47 s
+= '\n\x1b[34m' + JSON
.stringify(in_
);
48 s
+= '\n\x1b[33m ' + line80
+ '\n';
49 s
+= out_
.split('\n').map(addLineNumber(0, '\x1b[31m')).join('\n');
50 s
+= '\n\x1b[33m ' + line80
+ '\n';
51 s
+= expected
.split('\n').map(addLineNumber(0, '\x1b[32m')).join('\n');
55 // simple debug output of terminal cells
56 function terminalToString(term
) {
59 for (var line
=0; line
<term
.rows
; ++line
) {
61 for (var cell
=0; cell
<term
.cols
; ++cell
) {
62 line_s
+= term
.lines
[line
][cell
][1];
64 // rtrim empty cells as xterm does
65 line_s
= line_s
.replace(/\s+$/, '');
73 describe('xterm output comparison', function() {
76 beforeEach(function () {
77 xterm
= new Terminal(COLS
, ROWS
);
78 xterm
.refresh = function() {};
81 // omit stack trace for escape sequence files
82 Error
.stackTraceLimit
= 0;
83 var files
= glob
.sync('test/escape_sequence_files/*.in');
84 // only successful tests for now
85 var successful
= [0, 2, 6, 12, 13, 18, 20, 22, 27, 28];
86 for (var a
in successful
) {
87 var i
= successful
[a
];
89 it(filename
.split('/').slice(-1)[0], function () {
91 var in_file
= fs
.readFileSync(filename
, 'utf8');
92 var from_pty
= pty_write_read(in_file
);
93 // uncomment this to get log from terminal
94 console
.log = function(){};
95 xterm
.write(from_pty
);
96 var from_emulator
= terminalToString(xterm
);
97 console
.log
= CONSOLE_LOG
;
98 var expected
= fs
.readFileSync(filename
.split('.')[0] + '.text', 'utf8');
99 if (from_emulator
!= expected
) {
100 // uncomment to get noisy output
101 //throw new Error(formatError(in_file, from_emulator, expected));
102 throw new Error('mismatch');