vedeu 0.4.8 → 0.4.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -1
- data/docs/object_graph.md +14 -0
- data/examples/borders_app.rb +19 -19
- data/lib/vedeu/api.rb +134 -22
- data/lib/vedeu/buffers/buffer.rb +11 -8
- data/lib/vedeu/cursor/cursor.rb +2 -1
- data/lib/vedeu/dsl/shared/colour.rb +1 -1
- data/lib/vedeu/geometry/area.rb +25 -20
- data/lib/vedeu/geometry/canvas.rb +12 -2
- data/lib/vedeu/geometry/dimension.rb +68 -21
- data/lib/vedeu/geometry/geometry.rb +70 -224
- data/lib/vedeu/geometry/position.rb +1 -6
- data/lib/vedeu/models/cell.rb +1 -6
- data/lib/vedeu/models/char.rb +1 -6
- data/lib/vedeu/output/compositor.rb +3 -3
- data/lib/vedeu/output/viewport.rb +6 -0
- data/test/lib/vedeu/distributed/server_test.rb +4 -0
- data/test/lib/vedeu/dsl/components/geometry_test.rb +4 -0
- data/test/lib/vedeu/geometry/area_test.rb +95 -7
- data/test/lib/vedeu/geometry/canvas_test.rb +10 -2
- data/test/lib/vedeu/geometry/dimension_test.rb +112 -33
- data/test/lib/vedeu/geometry/geometry_test.rb +71 -240
- data/test/lib/vedeu/geometry/position_test.rb +5 -9
- data/test/lib/vedeu/models/cell_test.rb +1 -15
- data/test/lib/vedeu/models/char_test.rb +14 -0
- data/test/lib/vedeu/output/colour_test.rb +16 -0
- data/test/lib/vedeu/output/compositor_test.rb +3 -1
- data/vedeu.gemspec +1 -1
- metadata +4 -3
@@ -4,267 +4,98 @@ module Vedeu
|
|
4
4
|
|
5
5
|
describe Geometry do
|
6
6
|
|
7
|
-
let(:described) { Geometry
|
8
|
-
let(:instance) {
|
9
|
-
let(:attributes) {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
let(:described) { Vedeu::Geometry }
|
8
|
+
let(:instance) { described.new(attributes) }
|
9
|
+
let(:attributes) {
|
10
|
+
{
|
11
|
+
centred: centred,
|
12
|
+
height: height,
|
13
|
+
name: _name,
|
14
|
+
width: width,
|
15
|
+
x: x,
|
16
|
+
xn: xn,
|
17
|
+
y: y,
|
18
|
+
yn: yn,
|
19
|
+
}
|
20
|
+
}
|
21
|
+
let(:centred) {}
|
22
|
+
let(:height) {}
|
23
|
+
let(:_name) {}
|
24
|
+
let(:width) {}
|
25
|
+
let(:x) {}
|
26
|
+
let(:xn) {}
|
27
|
+
let(:y) {}
|
28
|
+
let(:yn) {}
|
29
|
+
|
30
|
+
before { Terminal.stubs(:size).returns([12, 40]) }
|
14
31
|
|
15
32
|
describe '#initialize' do
|
16
33
|
it { instance.must_be_instance_of(Geometry) }
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
y: 1,
|
28
|
-
yn: 25,
|
29
|
-
})
|
30
|
-
}
|
31
|
-
it { instance.instance_variable_get('@centred').must_equal(false) }
|
32
|
-
it { instance.instance_variable_get('@height').must_equal(25) }
|
33
|
-
it { instance.instance_variable_get('@name').must_equal('') }
|
34
|
-
it { instance.instance_variable_get('@width').must_equal(80) }
|
35
|
-
it { instance.instance_variable_get('@x').must_equal(1) }
|
36
|
-
it { instance.instance_variable_get('@xn').must_equal(80) }
|
37
|
-
it { instance.instance_variable_get('@y').must_equal(1) }
|
38
|
-
it { instance.instance_variable_get('@yn').must_equal(25) }
|
39
|
-
it { instance.instance_variable_get('@repository').must_equal(Vedeu.geometries) }
|
40
|
-
end
|
34
|
+
it { instance.instance_variable_get('@attributes').must_equal(attributes) }
|
35
|
+
it { instance.instance_variable_get('@centred').must_equal(centred) }
|
36
|
+
it { instance.instance_variable_get('@height').must_equal(height) }
|
37
|
+
it { instance.instance_variable_get('@name').must_equal(_name) }
|
38
|
+
it { instance.instance_variable_get('@width').must_equal(width) }
|
39
|
+
it { instance.instance_variable_get('@x').must_equal(x) }
|
40
|
+
it { instance.instance_variable_get('@xn').must_equal(xn) }
|
41
|
+
it { instance.instance_variable_get('@y').must_equal(y) }
|
42
|
+
it { instance.instance_variable_get('@yn').must_equal(yn) }
|
43
|
+
it { instance.instance_variable_get('@repository').must_equal(Vedeu.geometries) }
|
41
44
|
end
|
42
45
|
|
43
|
-
describe '#
|
44
|
-
|
45
|
-
|
46
|
-
context 'when it is a proc' do
|
47
|
-
let(:attributes) { { y: proc { 17 } } }
|
46
|
+
describe '#top, #right, #bottom, #left' do
|
47
|
+
context 'centred is true' do
|
48
|
+
let(:attributes) { { height: 6, width: 18, centred: true } }
|
48
49
|
|
49
|
-
it {
|
50
|
+
it { instance.top.must_equal(3) }
|
51
|
+
it { instance.right.must_equal(29) }
|
52
|
+
it { instance.bottom.must_equal(9) }
|
53
|
+
it { instance.left.must_equal(11) }
|
50
54
|
end
|
51
55
|
|
52
|
-
context '
|
53
|
-
let(:attributes) { { y:
|
56
|
+
context 'centred is true and y is set, y is ignored' do
|
57
|
+
let(:attributes) { { height: 6, width: 18, centred: true, y: 4 } }
|
54
58
|
|
55
|
-
it {
|
59
|
+
it { instance.top.must_equal(3) }
|
60
|
+
it { instance.right.must_equal(29) }
|
61
|
+
it { instance.bottom.must_equal(9) }
|
62
|
+
it { instance.left.must_equal(11) }
|
56
63
|
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe '#yn' do
|
60
|
-
subject { instance.yn }
|
61
64
|
|
62
|
-
context '
|
63
|
-
let(:attributes) { {
|
65
|
+
context 'centred is true and x is set, x is ignored' do
|
66
|
+
let(:attributes) { { height: 6, width: 18, centred: true, x: 4 } }
|
64
67
|
|
65
|
-
it {
|
68
|
+
it { instance.top.must_equal(3) }
|
69
|
+
it { instance.right.must_equal(29) }
|
70
|
+
it { instance.bottom.must_equal(9) }
|
71
|
+
it { instance.left.must_equal(11) }
|
66
72
|
end
|
67
73
|
|
68
|
-
context '
|
69
|
-
let(:attributes) { {
|
70
|
-
|
71
|
-
it { subject.must_equal(19) }
|
72
|
-
end
|
73
|
-
end
|
74
|
+
context 'centred is false' do
|
75
|
+
let(:attributes) { { height: 6, width: 18 } }
|
74
76
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
it { instance.top.must_equal(1) }
|
78
|
+
it { instance.right.must_equal(18) }
|
79
|
+
it { instance.bottom.must_equal(6) }
|
80
|
+
it { instance.left.must_equal(1) }
|
79
81
|
end
|
80
82
|
|
81
|
-
|
82
|
-
|
83
|
-
geometry.x.must_equal(64)
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe '#xn' do
|
88
|
-
it 'returns the value of xn when it is a proc' do
|
89
|
-
geometry = Geometry.new({ xn: proc { 58 } })
|
90
|
-
geometry.xn.must_equal(58)
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'returns the value of xn when just an attribute' do
|
94
|
-
geometry = Geometry.new({ xn: 64 })
|
95
|
-
geometry.xn.must_equal(64)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe '#width' do
|
100
|
-
it 'returns the viewport width when the interface fits the terminal' do
|
101
|
-
geometry = Geometry.new({ width: 60, height: 1, x: 5, y: 1 })
|
102
|
-
geometry.width.must_equal(60)
|
103
|
-
end
|
83
|
+
context 'centred is false and y is set' do
|
84
|
+
let(:attributes) { { height: 6, width: 18, y: 4 } }
|
104
85
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
geometry.width.must_equal(55)
|
110
|
-
end
|
86
|
+
it { instance.top.must_equal(4) }
|
87
|
+
it { instance.right.must_equal(18) }
|
88
|
+
it { instance.bottom.must_equal(10) }
|
89
|
+
it { instance.left.must_equal(1) }
|
111
90
|
end
|
112
91
|
|
113
|
-
|
114
|
-
|
115
|
-
geometry = Geometry.new({ width: 60, height: 1, x: 5, y: 1 })
|
116
|
-
geometry.width.must_equal(1)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
describe '#height' do
|
122
|
-
it 'returns the viewport height when the interface fits the terminal' do
|
123
|
-
geometry = Geometry.new({ width: 5, height: 20, x: 1, y: 5 })
|
124
|
-
geometry.height.must_equal(20)
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'returns the viewport height when the interface does not fit the ' \
|
128
|
-
'terminal' do
|
129
|
-
IO.console.stub(:winsize, [15, 80]) do
|
130
|
-
geometry = Geometry.new({ width: 5, height: 20, x: 1, y: 5 })
|
131
|
-
geometry.height.must_equal(10)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
it 'returns an unusable viewport height when the terminal is tiny' do
|
136
|
-
IO.console.stub(:winsize, [-10, 80]) do
|
137
|
-
geometry = Geometry.new({ width: 60, height: 20, x: 1, y: 5 })
|
138
|
-
geometry.height.must_equal(1)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
describe '#top' do
|
144
|
-
it 'centred is true' do
|
145
|
-
console = IO.console
|
146
|
-
console.stub :winsize, [12, 80] do
|
147
|
-
geometry = Geometry.new({ height: 6, width: 18, centred: true })
|
148
|
-
geometry.top.must_equal(3)
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
it 'centred is false' do
|
153
|
-
geometry = Geometry.new({ height: 6, width: 18 })
|
154
|
-
geometry.top.must_equal(1)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'centred is false and y is set' do
|
158
|
-
geometry = Geometry.new({ height: 6, width: 18, y: 4 })
|
159
|
-
geometry.top.must_equal(4)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
describe '#north' do
|
164
|
-
it 'returns the top minus the value when the value is provided' do
|
165
|
-
geometry = Geometry.new({ height: 6, width: 18, y: 4 })
|
166
|
-
geometry.north(2).must_equal(2)
|
167
|
-
end
|
168
|
-
|
169
|
-
it 'returns the top minus 1 without a value' do
|
170
|
-
geometry = Geometry.new({ height: 6, width: 18, y: 4 })
|
171
|
-
geometry.north.must_equal(3)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe '#left' do
|
176
|
-
it 'centred is true' do
|
177
|
-
console = IO.console
|
178
|
-
console.stub :winsize, [25, 40] do
|
179
|
-
geometry = Geometry.new({ height: 6, width: 18, centred: true })
|
180
|
-
geometry.left.must_equal(11)
|
181
|
-
end
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'centred is false' do
|
185
|
-
geometry = Geometry.new({ height: 6, width: 18 })
|
186
|
-
geometry.left.must_equal(1)
|
187
|
-
end
|
188
|
-
|
189
|
-
it 'centred is false and x is set' do
|
190
|
-
geometry = Geometry.new({ height: 6, width: 18, x: 5 })
|
191
|
-
geometry.left.must_equal(5)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
describe '#west' do
|
196
|
-
it 'returns the left minus the value when the value is provided' do
|
197
|
-
geometry = Geometry.new({ height: 6, width: 18, x: 7 })
|
198
|
-
geometry.west(2).must_equal(5)
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'returns the left minus 1 without a value' do
|
202
|
-
geometry = Geometry.new({ height: 6, width: 18, x: 7 })
|
203
|
-
geometry.west.must_equal(6)
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
describe '#bottom' do
|
208
|
-
it 'centred is true' do
|
209
|
-
console = IO.console
|
210
|
-
console.stub :winsize, [20, 40] do
|
211
|
-
geometry = Geometry.new({ height: 6, width: 18, centred: true })
|
212
|
-
geometry.bottom.must_equal(13)
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
it 'centred is false' do
|
217
|
-
geometry = Geometry.new({ height: 6, width: 18 })
|
218
|
-
geometry.bottom.must_equal(7)
|
219
|
-
end
|
220
|
-
|
221
|
-
it 'centred is false and y is set' do
|
222
|
-
geometry = Geometry.new({ height: 6, width: 18, y: 5 })
|
223
|
-
geometry.bottom.must_equal(11)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
|
227
|
-
describe '#south' do
|
228
|
-
it 'returns the bottom plus the value when the value is provided' do
|
229
|
-
geometry = Geometry.new({ height: 6, width: 18, y: 3 })
|
230
|
-
geometry.south(2).must_equal(11)
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'returns the bottom plus 1 without a value' do
|
234
|
-
geometry = Geometry.new({ height: 6, width: 18, y: 3 })
|
235
|
-
geometry.south.must_equal(10)
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
describe '#right' do
|
240
|
-
it 'centred is true' do
|
241
|
-
console = IO.console
|
242
|
-
console.stub :winsize, [25, 40] do
|
243
|
-
geometry = Geometry.new({ height: 6, width: 18, centred: true })
|
244
|
-
geometry.right.must_equal(29)
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'centred is false' do
|
249
|
-
geometry = Geometry.new({ height: 6, width: 18 })
|
250
|
-
geometry.right.must_equal(19)
|
251
|
-
end
|
252
|
-
|
253
|
-
it 'centred is false and x is set' do
|
254
|
-
geometry = Geometry.new({ height: 6, width: 18, x: 5 })
|
255
|
-
geometry.right.must_equal(23)
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
describe '#east' do
|
260
|
-
it 'returns the right plus the value when the value is provided' do
|
261
|
-
geometry = Geometry.new({ height: 6, width: 18, x: 7 })
|
262
|
-
geometry.east(2).must_equal(27)
|
263
|
-
end
|
92
|
+
context 'centred is false and x is set' do
|
93
|
+
let(:attributes) { { height: 6, width: 18, x: 4 } }
|
264
94
|
|
265
|
-
|
266
|
-
|
267
|
-
|
95
|
+
it { instance.top.must_equal(1) }
|
96
|
+
it { instance.right.must_equal(22) }
|
97
|
+
it { instance.bottom.must_equal(6) }
|
98
|
+
it { instance.left.must_equal(4) }
|
268
99
|
end
|
269
100
|
end
|
270
101
|
|
@@ -58,18 +58,14 @@ module Vedeu
|
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
-
describe '
|
62
|
-
let(:other) {}
|
61
|
+
describe '#eql?' do
|
62
|
+
let(:other) { described.new(12, 19) }
|
63
63
|
|
64
|
-
subject { instance
|
64
|
+
subject { instance.eql?(other) }
|
65
65
|
|
66
|
-
|
67
|
-
let(:other) { described.new(12, 19) }
|
66
|
+
it { subject.must_equal(true) }
|
68
67
|
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
context 'when they are not equal' do
|
68
|
+
context 'when different to other' do
|
73
69
|
let(:other) { described.new(2, 9) }
|
74
70
|
|
75
71
|
it { subject.must_equal(false) }
|
@@ -33,22 +33,8 @@ module Vedeu
|
|
33
33
|
it { instance.instance_variable_get('@y').must_equal(y) }
|
34
34
|
end
|
35
35
|
|
36
|
-
describe '#==' do
|
37
|
-
let(:other) { instance }
|
38
|
-
|
39
|
-
subject { instance.==(other) }
|
40
|
-
|
41
|
-
it { subject.must_equal(true) }
|
42
|
-
|
43
|
-
context 'when different to other' do
|
44
|
-
let(:other) { described.new({}) }
|
45
|
-
|
46
|
-
it { subject.must_equal(false) }
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
36
|
describe '#eql?' do
|
51
|
-
let(:other) {
|
37
|
+
let(:other) { described.new({ background: '#000000' }) }
|
52
38
|
|
53
39
|
subject { instance.eql?(other) }
|
54
40
|
|
@@ -43,6 +43,20 @@ module Vedeu
|
|
43
43
|
it { instance.must_respond_to(:value) }
|
44
44
|
end
|
45
45
|
|
46
|
+
describe '#eql?' do
|
47
|
+
let(:other) { instance }
|
48
|
+
|
49
|
+
subject { instance.eql?(other) }
|
50
|
+
|
51
|
+
it { subject.must_equal(true) }
|
52
|
+
|
53
|
+
context 'when different to other' do
|
54
|
+
let(:other) { described.new({ value: 'b' }) }
|
55
|
+
|
56
|
+
it { subject.must_equal(false) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
46
60
|
describe '#inspect' do
|
47
61
|
let(:colour) { Vedeu::Colour.new({ foreground: '#00ff00',
|
48
62
|
background: '#005500' }) }
|
@@ -42,6 +42,14 @@ module Vedeu
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
describe '#background=' do
|
46
|
+
let(:value) { '#000000' }
|
47
|
+
|
48
|
+
subject { instance.background=(value) }
|
49
|
+
|
50
|
+
it { subject.must_equal(value) }
|
51
|
+
end
|
52
|
+
|
45
53
|
describe '#foreground' do
|
46
54
|
subject { instance.foreground }
|
47
55
|
|
@@ -66,6 +74,14 @@ module Vedeu
|
|
66
74
|
end
|
67
75
|
end
|
68
76
|
|
77
|
+
describe '#foreground=' do
|
78
|
+
let(:value) { '#ff0000' }
|
79
|
+
|
80
|
+
subject { instance.foreground=(value) }
|
81
|
+
|
82
|
+
it { subject.must_equal(value) }
|
83
|
+
end
|
84
|
+
|
69
85
|
describe '#to_s' do
|
70
86
|
subject { instance.to_s }
|
71
87
|
|
@@ -32,13 +32,15 @@ module Vedeu
|
|
32
32
|
end
|
33
33
|
|
34
34
|
describe '#initialize' do
|
35
|
-
it { instance.must_be_instance_of(
|
35
|
+
it { instance.must_be_instance_of(described) }
|
36
36
|
it { instance.instance_variable_get('@name').must_equal(_name) }
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '.compose' do
|
40
40
|
subject { described.compose(_name) }
|
41
41
|
|
42
|
+
it { subject.must_be_instance_of(Array) }
|
43
|
+
it { subject.first.must_be_instance_of(Vedeu::Interface) }
|
42
44
|
end
|
43
45
|
|
44
46
|
end # Compositor
|