/
fake_screen_tests.js
101 lines (98 loc) · 3.13 KB
/
fake_screen_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
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
var expect = require('chai').expect
var spy = require('sinon').spy
var screen = require('./fake_screen')
describe('FakeScreen', function(){
beforeEach(function(){
screen.$setSize(10, 10)
})
it('has initially', function(){
expect(screen.buffer).to.deep.equal(
[ ' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ' ])
})
it('does stuff', function(){
screen.position(0, 1)
screen.write('hello')
expect(screen.buffer[0]).to.equal('hello ')
screen.position(5, 1)
screen.write('world')
expect(screen.buffer[0]).to.equal('helloworld')
})
it('moves cursor when write', function(){
screen.position(0, 1)
screen.write('hello').write('world')
expect(screen.buffer[0]).to.equal('helloworld')
})
it('does colors but has no effect', function(){
screen.foreground('red')
screen.background('black')
screen.position(3, 1)
screen.write('hello')
screen.display('reset')
expect(screen.buffer[0]).to.equal(' hello ')
})
it('erases to end', function(){
screen.position(0, 1)
screen.write('helloworld')
screen.position(5, 1)
screen.erase('end')
expect(screen.buffer[0]).to.equal('hello ')
})
/* I am now thinking that screen should be smart and just
trim extra characters, so don't need these
it('throws if drawing out of bounds vertically', function(){
screen.position(11, 0)
expect(function(){ screen.write('hello') }).to.throw(/out of bounds/)
expect(screen.buffer).to.deep.equal([
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ' ])
})
it('throws if drawing out of bounds horizontally', function(){
screen.position(0, 1)
expect(function(){ screen.write('hello world') }).to.throw(/out of bounds/)
expect(screen.buffer).to.deep.equal([
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ',
' ' ])
})
*/
context('has 3 lines of text', function(){
beforeEach(function(){
screen.position(0, 1)
screen.write('hello')
screen.position(0, 2)
screen.write('there')
screen.position(0, 3)
screen.write('world')
})
it('gives lines', function(){
expect(screen.$lines(3)).to.deep.equal(['hello ', 'there ', 'world '])
})
it('gives lines (start, end)', function(){
expect(screen.$lines(1, 3)).to.deep.equal(['there ', 'world '])
})
})
})