-
-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtest.js
160 lines (134 loc) · 5.27 KB
/
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
import test from 'ava';
import Terminal from 'terminal.js';
import {createLogUpdate} from './index.js';
const setup = options => {
const terminal = new Terminal(options);
terminal.rows = options.rows;
terminal.columns = options.columns;
terminal.state.setMode('crlf', true);
const log = createLogUpdate(terminal);
return {terminal, log};
};
test('output a single line', t => {
const {terminal, log} = setup({rows: 10, columns: 80});
log('goodbye, world');
t.is(terminal.state.getLine(0).str, 'goodbye, world');
});
test('update a single line', t => {
const {terminal, log} = setup({rows: 10, columns: 80});
log('greetings, world');
log('hello, world');
log('goodbye, world');
t.is(terminal.state.getLine(0).str, 'goodbye, world');
});
test('output a wrapped line', t => {
const {terminal, log} = setup({rows: 3, columns: 20});
log('this is a very long line that will wrap to the next line');
t.is(terminal.state.getLine(0).str, 'line that will wrap ');
t.is(terminal.state.getLine(1).str, 'to the next line');
});
test('output beyond terminal height', t => {
const {terminal, log} = setup({rows: 3, columns: 20});
log('line 1\nline 2\nline 3');
t.is(terminal.state.getLine(0).str, 'line 2');
t.is(terminal.state.getLine(1).str, 'line 3');
t.is(terminal.state.getLine(2).str, '');
});
test('output beyond terminal height with color', t => {
const {terminal, log} = setup({rows: 3, columns: 20});
log('\u001B[32m√\u001B[39mline 1\nline 2\nline 3');
t.is(terminal.state.getLine(0).str, 'line 2');
t.is(terminal.state.getLine(1).str, 'line 3');
t.is(terminal.state.getLine(2).str, '');
});
test('output beyond terminal height with multi-line color', t => {
const {terminal, log} = setup({rows: 3, columns: 20});
log('\u001B[32m√line 1\nline 2\nline 3\u001B[39m');
t.is(terminal.state.getLine(0).str, 'line 2');
t.is(terminal.state.getLine(1).str, 'line 3');
t.is(terminal.state.getLine(2).str, '');
});
test('growing output', t => {
const {terminal, log} = setup({rows: 4, columns: 20});
log('one line');
t.is(terminal.state.getLine(0).str, 'one line');
log('one line\ntwo line');
t.is(terminal.state.getLine(0).str, 'one line');
t.is(terminal.state.getLine(1).str, 'two line');
log('one line\ntwo line\nred line');
t.is(terminal.state.getLine(0).str, 'one line');
t.is(terminal.state.getLine(1).str, 'two line');
t.is(terminal.state.getLine(2).str, 'red line');
t.is(terminal.state.getLine(3).str, '');
log('one line\ntwo line\nred line\nblue line');
t.is(terminal.state.getLine(0).str, 'two line');
t.is(terminal.state.getLine(1).str, 'red line');
t.is(terminal.state.getLine(2).str, 'blue line');
t.is(terminal.state.getLine(3).str, ''); // Always a blank last line
});
test('growing output from top', t => {
const {terminal, log} = setup({rows: 4, columns: 20});
log('blue line');
t.is(terminal.state.getLine(0).str, 'blue line');
log('red line\nblue line');
t.is(terminal.state.getLine(0).str, 'red line');
t.is(terminal.state.getLine(1).str, 'blue line');
log('two line\nred line\nblue line');
t.is(terminal.state.getLine(0).str, 'two line');
t.is(terminal.state.getLine(1).str, 'red line');
t.is(terminal.state.getLine(2).str, 'blue line');
t.is(terminal.state.getLine(3).str, '');
log('one line\ntwo line\nred line\nblue line');
t.is(terminal.state.getLine(0).str, 'two line');
t.is(terminal.state.getLine(1).str, 'red line');
t.is(terminal.state.getLine(2).str, 'blue line');
t.is(terminal.state.getLine(3).str, ''); // Always a blank last line
});
test('shrinking output', t => {
const {terminal, log} = setup({rows: 4, columns: 20});
log('one line\ntwo line\nred line\nblue line');
t.is(terminal.state.getLine(0).str, 'two line');
t.is(terminal.state.getLine(1).str, 'red line');
t.is(terminal.state.getLine(2).str, 'blue line');
t.is(terminal.state.getLine(3).str, ''); // Always a blank last line
log('one line\ntwo line\nred line');
t.is(terminal.state.getLine(0).str, 'one line');
t.is(terminal.state.getLine(1).str, 'two line');
t.is(terminal.state.getLine(2).str, 'red line');
t.is(terminal.state.getLine(3).str, '');
log('one line\ntwo line');
t.is(terminal.state.getLine(0).str, 'one line');
t.is(terminal.state.getLine(1).str, 'two line');
log('one line');
t.is(terminal.state.getLine(0).str, 'one line');
});
test('lots of updates', t => {
const {terminal, log} = setup({rows: 4, columns: 20});
for (let i = 0; i < 100; i++) {
log([
`[1] ${(i ** 3) + 11}`,
`[2] ${(i ** 2) + (10 * i) - 100}`,
].join('\n'));
}
t.is(terminal.state.getLine(0).str, '[1] 970310');
t.is(terminal.state.getLine(1).str, '[2] 10691');
});
test('log.done', t => {
const {terminal, log} = setup({rows: 10, columns: 80});
log('Fun families are all similar');
log('Happy families are all similar');
log.done();
log('Happy families are all alike; every unhappy family has its own way');
log('Happy families are all alike; every unhappy family is unhappy in its own way');
log.done();
t.is(terminal.state.getLine(0).str, 'Happy families are all similar');
t.is(terminal.state.getLine(1).str, 'Happy families are all alike; every unhappy family is unhappy in its own way');
});
test('log.clear', t => {
const {terminal, log} = setup({rows: 10, columns: 80});
log('Info');
log.clear();
log.done();
log('Second Info');
t.is(terminal.state.getLine(0).str, 'Second Info');
});