vedeu 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +4 -4
  2. data/docs/api.md +2 -0
  3. data/docs/events.md +0 -4
  4. data/examples/cursor_app/cursor_app.rb +56 -44
  5. data/lib/vedeu/api/api.rb +4 -6
  6. data/lib/vedeu/api/composition.rb +3 -7
  7. data/lib/vedeu/api/interface.rb +2 -3
  8. data/lib/vedeu/api/menu.rb +5 -3
  9. data/lib/vedeu/api/stream.rb +34 -0
  10. data/lib/vedeu/application.rb +4 -7
  11. data/lib/vedeu/configuration/api.rb +0 -5
  12. data/lib/vedeu/configuration/cli.rb +0 -1
  13. data/lib/vedeu/configuration/configuration.rb +0 -12
  14. data/lib/vedeu/input/input.rb +0 -3
  15. data/lib/vedeu/launcher.rb +0 -1
  16. data/lib/vedeu/models/{attributes/background.rb → background.rb} +0 -4
  17. data/lib/vedeu/models/char.rb +43 -0
  18. data/lib/vedeu/models/colour.rb +0 -1
  19. data/lib/vedeu/models/composition.rb +4 -3
  20. data/lib/vedeu/models/cursor.rb +70 -146
  21. data/lib/vedeu/models/{attributes/foreground.rb → foreground.rb} +0 -4
  22. data/lib/vedeu/models/geometry.rb +19 -20
  23. data/lib/vedeu/models/interface.rb +36 -5
  24. data/lib/vedeu/models/keymap.rb +7 -4
  25. data/lib/vedeu/models/line.rb +31 -11
  26. data/lib/vedeu/models/offset.rb +84 -0
  27. data/lib/vedeu/models/stream.rb +37 -13
  28. data/lib/vedeu/models/style.rb +0 -1
  29. data/lib/vedeu/output/area.rb +284 -0
  30. data/lib/vedeu/output/clear.rb +2 -4
  31. data/lib/vedeu/output/compositor.rb +0 -4
  32. data/lib/vedeu/output/refresh.rb +1 -2
  33. data/lib/vedeu/output/render.rb +12 -163
  34. data/lib/vedeu/output/view.rb +0 -2
  35. data/lib/vedeu/output/viewport.rb +132 -0
  36. data/lib/vedeu/repositories/buffers.rb +11 -22
  37. data/lib/vedeu/repositories/cursors.rb +20 -47
  38. data/lib/vedeu/repositories/events.rb +2 -1
  39. data/lib/vedeu/repositories/focus.rb +16 -16
  40. data/lib/vedeu/repositories/groups.rb +1 -4
  41. data/lib/vedeu/repositories/interfaces.rb +10 -3
  42. data/lib/vedeu/repositories/keymaps.rb +0 -3
  43. data/lib/vedeu/repositories/menus.rb +0 -2
  44. data/lib/vedeu/repositories/offsets.rb +47 -0
  45. data/lib/vedeu/{models/attributes → support}/coercions.rb +0 -0
  46. data/lib/vedeu/{models/attributes → support}/colour_translator.rb +0 -16
  47. data/lib/vedeu/support/esc.rb +0 -22
  48. data/lib/vedeu/support/event.rb +1 -17
  49. data/lib/vedeu/support/exceptions.rb +0 -3
  50. data/lib/vedeu/support/grid.rb +0 -3
  51. data/lib/vedeu/support/log.rb +13 -14
  52. data/lib/vedeu/support/move.rb +50 -0
  53. data/lib/vedeu/support/position.rb +17 -9
  54. data/lib/vedeu/{models/attributes → support}/presentation.rb +1 -4
  55. data/lib/vedeu/support/registrar.rb +2 -2
  56. data/lib/vedeu/support/repository.rb +23 -2
  57. data/lib/vedeu/support/terminal.rb +0 -2
  58. data/lib/vedeu/support/trace.rb +0 -11
  59. data/lib/vedeu.rb +11 -5
  60. data/test/lib/vedeu/api/api_test.rb +14 -5
  61. data/test/lib/vedeu/api/composition_test.rb +9 -26
  62. data/test/lib/vedeu/api/keymap_test.rb +1 -1
  63. data/test/lib/vedeu/api/menu_test.rb +6 -0
  64. data/test/lib/vedeu/api/stream_test.rb +32 -0
  65. data/test/lib/vedeu/models/{attributes/background_test.rb → background_test.rb} +0 -0
  66. data/test/lib/vedeu/models/char_test.rb +46 -0
  67. data/test/lib/vedeu/models/composition_test.rb +7 -0
  68. data/test/lib/vedeu/models/cursor_test.rb +63 -80
  69. data/test/lib/vedeu/models/{attributes/foreground_test.rb → foreground_test.rb} +0 -0
  70. data/test/lib/vedeu/models/geometry_test.rb +8 -10
  71. data/test/lib/vedeu/models/interface_test.rb +26 -21
  72. data/test/lib/vedeu/models/keymap_test.rb +6 -0
  73. data/test/lib/vedeu/models/line_test.rb +82 -3
  74. data/test/lib/vedeu/models/offset_test.rb +121 -0
  75. data/test/lib/vedeu/models/stream_test.rb +107 -8
  76. data/test/lib/vedeu/output/area_test.rb +242 -0
  77. data/test/lib/vedeu/output/compositor_test.rb +12 -3
  78. data/test/lib/vedeu/output/render_test.rb +34 -39
  79. data/test/lib/vedeu/output/viewport_test.rb +36 -0
  80. data/test/lib/vedeu/repositories/cursors_test.rb +32 -9
  81. data/test/lib/vedeu/repositories/focus_test.rb +8 -0
  82. data/test/lib/vedeu/repositories/offsets_test.rb +32 -0
  83. data/test/lib/vedeu/{models/attributes → support}/coercions_test.rb +0 -0
  84. data/test/lib/vedeu/{models/attributes → support}/colour_translator_test.rb +0 -0
  85. data/test/lib/vedeu/support/move_test.rb +35 -0
  86. data/test/lib/vedeu/{models/attributes → support}/presentation_test.rb +0 -0
  87. data/test/lib/vedeu/support/registrar_test.rb +6 -0
  88. data/test/lib/vedeu_test.rb +5 -0
  89. data/vedeu.gemspec +1 -1
  90. metadata +37 -17
@@ -0,0 +1,242 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+ describe Area do
5
+ let(:area) { Area.new(attributes) }
6
+ let(:attributes) {
7
+ {
8
+ y_min: 1,
9
+ x_min: 1,
10
+ height: 3,
11
+ width: 3,
12
+ }
13
+ }
14
+
15
+ describe '#initialize' do
16
+ it 'returns an instance of itself' do
17
+ area.must_be_instance_of(Area)
18
+ end
19
+ end
20
+
21
+ describe '#y_range' do
22
+ let(:attributes) { { y_min: 7, x_min: 1, height: 4, width: 3 } }
23
+
24
+ it 'returns the actual y range' do
25
+ area.y_range.must_equal([7, 8, 9, 10])
26
+ end
27
+
28
+ context 'when the height is 0' do
29
+ let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 3 } }
30
+
31
+ it 'returns an empty range' do
32
+ area.y_range.must_equal([])
33
+ end
34
+ end
35
+ end
36
+
37
+ describe '#x_range' do
38
+ let(:attributes) { { y_min: 1, x_min: 4, height: 3, width: 10 } }
39
+
40
+ it 'returns the actual x range' do
41
+ area.x_range.must_equal([4, 5, 6, 7, 8, 9, 10, 11, 12, 13])
42
+ end
43
+
44
+ context 'when the width is 0' do
45
+ let(:attributes) { { y_min: 1, x_min: 4, height: 3, width: 0 } }
46
+
47
+ it 'returns an empty range' do
48
+ area.x_range.must_equal([])
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#y_indices' do
54
+ let(:attributes) { { y_min: 7, x_min: 1, height: 4, width: 3 } }
55
+
56
+ it 'returns the indices for y' do
57
+ area.y_indices.must_equal([0, 1, 2, 3])
58
+ end
59
+
60
+ context 'when the height is 0' do
61
+ let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 3 } }
62
+
63
+ it { area.y_indices.must_be_empty }
64
+ end
65
+
66
+ context 'when the height is less than 0' do
67
+ let(:attributes) { { y_min: 7, x_min: 1, height: -3, width: 3 } }
68
+
69
+ it { area.y_indices.must_be_empty }
70
+ end
71
+ end
72
+
73
+ describe '#x_indices' do
74
+ let(:attributes) { { y_min: 1, x_min: 4, height: 3, width: 10 } }
75
+
76
+ it 'returns the indices for x' do
77
+ area.x_indices.must_equal([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
78
+ end
79
+
80
+ context 'when the width is 0' do
81
+ let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: 0 } }
82
+
83
+ it { area.x_indices.must_be_empty }
84
+ end
85
+
86
+ context 'when the width is less than 0' do
87
+ let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: -2 } }
88
+
89
+ it { area.x_indices.must_be_empty }
90
+ end
91
+ end
92
+
93
+ describe '#y_max' do
94
+ context 'when the height is > 0' do
95
+ let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: 6 } }
96
+
97
+ it { area.y_max.must_equal(10) }
98
+ end
99
+
100
+ context 'when the height is 0 or negative' do
101
+ let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 6 } }
102
+
103
+ it { area.y_max.must_equal(0) }
104
+ end
105
+ end
106
+
107
+ describe '#x_max' do
108
+ context 'when the width is > 0' do
109
+ let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 6 } }
110
+
111
+ it { area.x_max.must_equal(7) }
112
+ end
113
+
114
+ context 'when the width is 0 or negative' do
115
+ let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 0 } }
116
+
117
+ it { area.x_max.must_equal(0) }
118
+ end
119
+ end
120
+
121
+ describe '#y_max_index' do
122
+ context 'when the height is > 0' do
123
+ let(:attributes) { { y_min: 7, x_min: 1, height: 3, width: 6 } }
124
+
125
+ it { area.y_max_index.must_equal(2) }
126
+ end
127
+
128
+ context 'when the height is 0' do
129
+ let(:attributes) { { y_min: 7, x_min: 1, height: 0, width: 6 } }
130
+
131
+ it { area.y_max_index.must_equal(0) }
132
+ end
133
+
134
+ context 'when the height is < 0' do
135
+ let(:attributes) { { y_min: 9, x_min: 1, height: -3, width: 6 } }
136
+
137
+ it { area.y_max_index.must_equal(0) }
138
+ end
139
+ end
140
+
141
+ describe '#x_max_index' do
142
+ context 'when the width is > 0' do
143
+ let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 6 } }
144
+
145
+ it { area.x_max_index.must_equal(5) }
146
+ end
147
+
148
+ context 'when the width is 0' do
149
+ let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: 0 } }
150
+
151
+ it { area.x_max_index.must_equal(0) }
152
+ end
153
+
154
+ context 'when the width is < 0' do
155
+ let(:attributes) { { y_min: 9, x_min: 1, height: 3, width: -2 } }
156
+
157
+ it { area.x_max_index.must_equal(0) }
158
+ end
159
+ end
160
+
161
+ describe '#y_index' do
162
+ let(:attributes) { { y_min: 7, x_min: 4, height: height, width: 10, x: 8, y: y } }
163
+ let(:height) { 3 }
164
+ let(:y) { 8 }
165
+
166
+ it 'returns the offset index of the cursors y position' do
167
+ area.y_index.must_equal(1)
168
+ end
169
+
170
+ context 'when the area height is 0' do
171
+ let(:height) { 0 }
172
+
173
+ it { area.y_index.must_equal(0) }
174
+ end
175
+
176
+ context 'when the cursor y is less than or equal to the area y_min' do
177
+ let(:y) { 6 }
178
+
179
+ it { area.y_index.must_equal(0) }
180
+ end
181
+
182
+ context 'when the cursor y is more than or equal to the area y_max' do
183
+ let(:y) { 20 }
184
+
185
+ it 'returns the last y coordinate as an index' do
186
+ area.y_index.must_equal(2)
187
+ end
188
+ end
189
+ end
190
+
191
+ describe '#x_index' do
192
+ let(:attributes) { { y_min: 7, x_min: 4, height: 3, width: width, x: x, y: 8 } }
193
+ let(:x) { 8 }
194
+ let(:width) { 10 }
195
+
196
+ it 'returns the offset index of the cursors x position' do
197
+ area.x_index.must_equal(4)
198
+ end
199
+
200
+ context 'when the area width is 0' do
201
+ let(:width) { 0 }
202
+
203
+ it { area.x_index.must_equal(0) }
204
+ end
205
+
206
+ context 'when the cursor x is less than or equal to the area x_min' do
207
+ let(:x) { 3 }
208
+
209
+ it { area.x_index.must_equal(0) }
210
+ end
211
+
212
+ context 'when the cursor x is more than or equal to the area x_min' do
213
+ let(:x) { 20 }
214
+
215
+ it 'returns the last x coordinate as an index' do
216
+ area.x_index.must_equal(9)
217
+ end
218
+ end
219
+ end
220
+
221
+ describe '#y_position' do
222
+ context 'when the index is less than or equal to 0' do
223
+ it 'returns #y_min' do
224
+
225
+ end
226
+ end
227
+
228
+ context 'when the index is greater than or equal to y_max_index' do
229
+ it 'returns #y_max' do
230
+
231
+ end
232
+ end
233
+
234
+ context 'when the index is in range' do
235
+ it 'returns the associated real position' do
236
+
237
+ end
238
+ end
239
+ end
240
+
241
+ end
242
+ end
@@ -2,7 +2,10 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
  describe Compositor do
5
- before { Terminal.console.stubs(:print) }
5
+ before do
6
+ Interfaces.reset
7
+ Terminal.console.stubs(:print)
8
+ end
6
9
 
7
10
  describe '.render' do
8
11
  it 'raises an exception if the buffer/interface cannot be found' do
@@ -18,10 +21,13 @@ module Vedeu
18
21
  height 3
19
22
  end
20
23
 
24
+ Vedeu.focus('xenon')
25
+
21
26
  Compositor.render('xenon').must_equal([
22
27
  "\e[1;1H \e[1;1H" \
23
28
  "\e[2;1H \e[2;1H" \
24
- "\e[3;1H \e[3;1H"
29
+ "\e[3;1H \e[3;1H" \
30
+ "\e[1;1H\e[?25h"
25
31
  ])
26
32
  end
27
33
  end
@@ -35,6 +41,8 @@ module Vedeu
35
41
  height 3
36
42
  end
37
43
 
44
+ Vedeu.focus('neon')
45
+
38
46
  class MyCompositorView < Vedeu::View
39
47
  def render
40
48
  view 'neon' do
@@ -53,7 +61,8 @@ module Vedeu
53
61
  "\e[3;1H \e[3;1H" \
54
62
  "\e[1;1Hargon" \
55
63
  "\e[2;1Hboron" \
56
- "\e[3;1Hradon"
64
+ "\e[3;1Hradon" \
65
+ "\e[1;1H\e[?25h"
57
66
  ])
58
67
  end
59
68
  end
@@ -2,52 +2,48 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
  describe Render do
5
- before { Buffers.reset }
5
+ before do
6
+ Buffers.reset
7
+ Cursors.reset
8
+ Interfaces.reset
9
+
10
+ Vedeu.interface('fluorine') do
11
+ width 32
12
+ height 3
13
+ line 'this is the first'
14
+ line 'this is the second and it is long'
15
+ line 'this is the third, it is even longer and still truncated'
16
+ line 'this should not render'
17
+ end
18
+ end
6
19
 
7
20
  describe '#initialize' do
8
21
  it 'returns an instance of itself' do
9
- interface = mock('Interface')
22
+ interface = Interface.new
10
23
  Render.new(interface).must_be_instance_of(Render)
11
24
  end
12
25
  end
13
26
 
14
27
  describe '.call' do
28
+ let(:interface) { Vedeu.use('fluorine') }
29
+
30
+ before { interface.stubs(:in_focus?).returns(true) }
31
+
15
32
  it 'returns the content for the interface' do
16
- interface = Interface.new({
17
- name: '.call',
18
- geometry: {
19
- width: 32,
20
- height: 3,
21
- },
22
- lines: [
23
- {
24
- streams: [{ text: 'this is the first' }]
25
- }, {
26
- streams: { text: 'this is the second and it is long' }
27
- }, {
28
- streams: [
29
- { text: 'this is the third, ' },
30
- { text: 'it is even longer ' },
31
- { text: 'and still truncated' }
32
- ]
33
- }, {
34
- streams: [{ text: 'this should not render' }]
35
- }
36
- ]
37
- })
38
33
  Render.call(interface).must_equal(
39
34
  "\e[1;1H \e[1;1H" \
40
35
  "\e[2;1H \e[2;1H" \
41
36
  "\e[3;1H \e[3;1H" \
42
37
  "\e[1;1Hthis is the first" \
43
38
  "\e[2;1Hthis is the second and it is lon" \
44
- "\e[3;1Hthis is the third, it is even lo"
39
+ "\e[3;1Hthis is the third, it is even lo" \
40
+ "\e[1;1H\e[?25h"
45
41
  )
46
42
  end
47
43
 
48
44
  it 'returns a blank interface if there are no streams of text' do
49
45
  interface = Interface.new({
50
- name: '.call',
46
+ name: 'fluorine',
51
47
  geometry: {
52
48
  width: 32,
53
49
  height: 3,
@@ -58,13 +54,14 @@ module Vedeu
58
54
  Render.call(interface).must_equal(
59
55
  "\e[1;1H \e[1;1H" \
60
56
  "\e[2;1H \e[2;1H" \
61
- "\e[3;1H \e[3;1H"
57
+ "\e[3;1H \e[3;1H" \
58
+ "\e[1;1H\e[?25h"
62
59
  )
63
60
  end
64
61
 
65
62
  it 'skips lines which have streams with no content' do
66
63
  interface = Interface.new({
67
- name: '.call',
64
+ name: 'fluorine',
68
65
  geometry: {
69
66
  width: 32,
70
67
  height: 3,
@@ -91,7 +88,8 @@ module Vedeu
91
88
  "\e[3;1H \e[3;1H" \
92
89
  "\e[1;1Hthis is the first" \
93
90
  "\e[2;1H" \
94
- "\e[3;1Hthis is the third, it is even lo"
91
+ "\e[3;1Hthis is the third, it is even lo" \
92
+ "\e[1;1H\e[?25h"
95
93
  )
96
94
  end
97
95
 
@@ -132,16 +130,13 @@ module Vedeu
132
130
  IO.console.stub(:print, nil) do
133
131
  OxygenView.render
134
132
 
135
- Compositor.render('oxygen').must_equal([
136
- "\e[1;1H \e[1;1H" \
137
- "\e[2;1H \e[2;1H" \
138
- "\e[1;1H\e[38;2;255;255;255m\e[48;2;0;0;0m" \
139
- "the grass is \e[38;2;255;255;255m\e[48;2;0;0;0m" \
140
- "\e[38;2;0;255;0mgreen\e[38;2;255;255;255m\e[48;2;0;0;0m" \
141
- " and the sky is \e[38;2;255;255;255m\e[48;2;0;0;0m" \
142
- "\e[38;2;0;0;255mblue\e[38;2;255;255;255m\e[48;2;0;0;0m" \
143
- ".\e[38;2;255;255;255m\e[48;2;0;0;0m"
144
- ])
133
+ Compositor.render('oxygen').must_equal(
134
+ [
135
+ "\e[1;1H \e[1;1H" \
136
+ "\e[2;1H \e[2;1H" \
137
+ "\e[1;1Ht\e[38;2;255;255;255m\e[48;2;0;0;0mh\e[38;2;255;255;255m\e[48;2;0;0;0me\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0mg\e[38;2;255;255;255m\e[48;2;0;0;0mr\e[38;2;255;255;255m\e[48;2;0;0;0ma\e[38;2;255;255;255m\e[48;2;0;0;0ms\e[38;2;255;255;255m\e[48;2;0;0;0ms\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0mi\e[38;2;255;255;255m\e[48;2;0;0;0ms\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;255;0mg\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;255;0mr\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;255;0me\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;255;0me\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;255;0mn\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0ma\e[38;2;255;255;255m\e[48;2;0;0;0mn\e[38;2;255;255;255m\e[48;2;0;0;0md\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0mt\e[38;2;255;255;255m\e[48;2;0;0;0mh\e[38;2;255;255;255m\e[48;2;0;0;0me\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0ms\e[38;2;255;255;255m\e[48;2;0;0;0mk\e[38;2;255;255;255m\e[48;2;0;0;0my\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0mi\e[38;2;255;255;255m\e[48;2;0;0;0ms\e[38;2;255;255;255m\e[48;2;0;0;0m \e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;0;255mb\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;0;255ml\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;0;255mu\e[38;2;255;255;255m\e[48;2;0;0;0m\e[38;2;0;0;255me\e[38;2;255;255;255m\e[48;2;0;0;0m.\e[38;2;255;255;255m\e[48;2;0;0;0m"
138
+ ]
139
+ )
145
140
  end
146
141
  end
147
142
 
@@ -0,0 +1,36 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe Viewport do
6
+
7
+ let(:interface) {
8
+ Interface.new({
9
+ name: 'fluorine',
10
+ geometry: {
11
+ width: 30,
12
+ height: 2,
13
+ },
14
+ lines: [
15
+ { # 53
16
+ streams: [{
17
+ text: 'Something interesting ', # 22
18
+ },{
19
+ text: 'on this line ', # 13
20
+ },{
21
+ text: 'would be cool, eh?' # 18
22
+ }]
23
+ }, { # 49
24
+ streams: [{
25
+ text: 'Maybe a lyric, a little ditty ', # 30
26
+ },{
27
+ text: 'to help you unwind.', # 19
28
+ }]
29
+ }
30
+ ]
31
+ })
32
+ }
33
+
34
+ end
35
+
36
+ end
@@ -3,23 +3,46 @@ require 'test_helper'
3
3
  module Vedeu
4
4
  describe Cursors do
5
5
 
6
- before { Cursors.reset }
6
+ before do
7
+ Cursors.reset
8
+ Registrar.record({ name: 'chromium' })
9
+ end
7
10
 
8
11
  describe '#add' do
9
- it 'raises an exception if the attributes does not have a :name key' do
10
- attributes = { no_name_key: '' }
12
+ let(:attributes) { { name: 'chromium' } }
13
+
14
+ it 'returns a new Cursor after registering' do
15
+ Cursors.add(attributes).must_be_instance_of(Cursor)
16
+ end
17
+
18
+ it 'returns a new Cursor after updating' do
19
+ Cursors.update(attributes).must_be_instance_of(Cursor)
20
+ end
21
+
22
+ context 'when the attributes do not have the :name key' do
23
+ let(:attributes) { { no_name_key: 'some_value' } }
11
24
 
12
- proc { Cursors.add(attributes) }.must_raise(MissingRequired)
25
+ it 'raises an exception' do
26
+ proc { Cursors.update(attributes) }.must_raise(MissingRequired)
27
+ end
28
+
29
+ it 'raises an exception' do
30
+ proc { Cursors.add(attributes) }.must_raise(MissingRequired)
31
+ end
13
32
  end
33
+ end
14
34
 
15
- it 'returns something' do
16
- skip
35
+ describe '#hide' do
36
+ it 'sets the state attribute of the Cursor to :hide' do
37
+ cursor = Cursors.hide
38
+ cursor.state.must_equal(:hide)
17
39
  end
18
40
  end
19
41
 
20
- describe '#use' do
21
- it 'returns something' do
22
- skip
42
+ describe '#show' do
43
+ it 'sets the state attribute of the Cursor to :show' do
44
+ cursor = Cursors.show
45
+ cursor.state.must_equal(:show)
23
46
  end
24
47
  end
25
48
 
@@ -79,6 +79,14 @@ module Vedeu
79
79
  end
80
80
  end
81
81
 
82
+ describe '#refresh' do
83
+ it 'triggers the event to refresh the interface current in focus' do
84
+ Focus.add({ name: 'thallium' })
85
+
86
+ Focus.refresh.must_equal([])
87
+ end
88
+ end
89
+
82
90
  describe '#registered' do
83
91
  it 'returns all the names of the interfaces which can be focussed' do
84
92
  Focus.add({ name: 'thallium' })
@@ -0,0 +1,32 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+ describe Offsets do
5
+
6
+ before { Offsets.reset }
7
+
8
+ describe '#add' do
9
+ it 'raises an exception if a :name attribute is not provided' do
10
+ proc { Offsets.add({ no_name: 'no_name' }) }
11
+ .must_raise(MissingRequired)
12
+ end
13
+
14
+ it 'returns a new instance of Offset once stored' do
15
+ Offsets.add({ name: 'praseodymium' }).must_be_instance_of(Offset)
16
+ end
17
+ end
18
+
19
+ describe '#move' do
20
+ before { Focus.stubs(:current).returns('praseodymium') }
21
+
22
+ it 'returns an instance of Offset' do
23
+ Offsets.move(0, 1).must_be_instance_of(Offset)
24
+ end
25
+
26
+ it 'alters the offset of the interface in focus' do
27
+ Offsets.move(0, 1).x.must_equal(1)
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+ describe Move do
5
+ before do
6
+ Interfaces.reset
7
+ Registrar.record({ name: 'thorium' })
8
+ Terminal.console.stubs(:print)
9
+ end
10
+
11
+ context 'when no interfaces are defined' do
12
+ before { Interfaces.reset }
13
+
14
+ it { proc { Move.down }.must_raise(NoInterfacesDefined) }
15
+
16
+ it { proc { Move.up }.must_raise(NoInterfacesDefined) }
17
+
18
+ it { proc { Move.right }.must_raise(NoInterfacesDefined) }
19
+
20
+ it { proc { Move.left }.must_raise(NoInterfacesDefined) }
21
+ end
22
+
23
+ context 'when there is at least one interface defined' do
24
+ before { Focus.stubs(:current).returns('thorium') }
25
+
26
+ it { Move.down.must_be_instance_of(Array) }
27
+
28
+ it { Move.up.must_be_instance_of(Array) }
29
+
30
+ it { Move.right.must_be_instance_of(Array) }
31
+
32
+ it { Move.left.must_be_instance_of(Array) }
33
+ end
34
+ end
35
+ end
@@ -43,6 +43,12 @@ module Vedeu
43
43
  Buffers.registered?('mendelevium').must_equal(true)
44
44
  end
45
45
 
46
+ it 'sends the attributes to the Offsets repository' do
47
+ Registrar.record(attributes)
48
+
49
+ Offsets.registered?('mendelevium').must_equal(true)
50
+ end
51
+
46
52
  it 'sends the attributes to the Interfaces repository' do
47
53
  Registrar.record(attributes)
48
54
 
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ describe Vedeu do
4
+ # ...
5
+ end
data/vedeu.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.2.3'
7
+ spec.version = '0.2.4'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}