vedeu 0.6.57 → 0.6.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/vedeu/geometry/all.rb +1 -0
- data/lib/vedeu/geometry/geometry.rb +2 -77
- data/lib/vedeu/geometry/move.rb +223 -0
- data/lib/vedeu/geometry/repository.rb +6 -6
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/geometry/geometry_test.rb +0 -115
- data/test/lib/vedeu/geometry/move_test.rb +176 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d33a3d7e8cd6ab472659549aafd770caeadce867
|
|
4
|
+
data.tar.gz: 7c8de69994fd536b0d42db2d95d09a51610b3eaa
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eebb2b6fecc5b82b8f936d5f57732729db7ec0698eace850ab92e9d048e5aea66196757d3c1a65d5a932f4ee15dd2feae3ee63d24f4ad68a5168969f69d4d1a9
|
|
7
|
+
data.tar.gz: 3e11185cf8ae5e7862f4f072ddad207cffc17197b086aae08d403afb02eaa281bf8ca92a5df6c3abc61e0144d7e942780831431e0a0e07ec4c2b085ade3e5863
|
data/lib/vedeu/geometry/all.rb
CHANGED
|
@@ -26,6 +26,7 @@ require 'vedeu/geometry/dsl'
|
|
|
26
26
|
require 'vedeu/geometry/coordinate'
|
|
27
27
|
require 'vedeu/geometry/geometry'
|
|
28
28
|
require 'vedeu/geometry/grid'
|
|
29
|
+
require 'vedeu/geometry/move'
|
|
29
30
|
require 'vedeu/geometry/null'
|
|
30
31
|
require 'vedeu/geometry/position'
|
|
31
32
|
require 'vedeu/geometry/repository'
|
|
@@ -84,8 +84,8 @@ module Vedeu
|
|
|
84
84
|
|
|
85
85
|
# @param (see #initialize)
|
|
86
86
|
# @return (see #initialize)
|
|
87
|
-
def self.store(attributes)
|
|
88
|
-
new(attributes).store
|
|
87
|
+
def self.store(attributes, &block)
|
|
88
|
+
new(attributes).store(&block)
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
# Returns a new instance of Vedeu::Geometry::Geometry.
|
|
@@ -169,51 +169,6 @@ module Vedeu
|
|
|
169
169
|
end
|
|
170
170
|
end
|
|
171
171
|
|
|
172
|
-
# Moves the geometry down by one row.
|
|
173
|
-
#
|
|
174
|
-
# @return [Vedeu::Geometry::Geometry]
|
|
175
|
-
def move_down
|
|
176
|
-
return self if yn + 1 > Vedeu.height
|
|
177
|
-
|
|
178
|
-
move(y: y + 1, yn: yn + 1) { Vedeu.trigger(:_cursor_down_, name) }
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
# Moves the geometry left by one column.
|
|
182
|
-
#
|
|
183
|
-
# @return [Vedeu::Geometry::Geometry]
|
|
184
|
-
def move_left
|
|
185
|
-
return self if x - 1 < 1
|
|
186
|
-
|
|
187
|
-
move(x: x - 1, xn: xn - 1) { Vedeu.trigger(:_cursor_left_, name) }
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
# Moves the geometry to the top left of the terminal.
|
|
191
|
-
#
|
|
192
|
-
# @return [Vedeu::Geometry::Geometry]
|
|
193
|
-
def move_origin
|
|
194
|
-
move(x: 1, xn: (xn - x + 1), y: 1, yn: (yn - y + 1)) do
|
|
195
|
-
Vedeu.trigger(:_cursor_origin_, name)
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
|
|
199
|
-
# Moves the geometry right by one column.
|
|
200
|
-
#
|
|
201
|
-
# @return [Vedeu::Geometry::Geometry]
|
|
202
|
-
def move_right
|
|
203
|
-
return self if xn + 1 > Vedeu.width
|
|
204
|
-
|
|
205
|
-
move(x: x + 1, xn: xn + 1) { Vedeu.trigger(:_cursor_right_, name) }
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
# Moves the geometry up by one column.
|
|
209
|
-
#
|
|
210
|
-
# @return [Vedeu::Geometry::Geometry]
|
|
211
|
-
def move_up
|
|
212
|
-
return self if y - 1 < 1
|
|
213
|
-
|
|
214
|
-
move(y: y - 1, yn: yn - 1) { Vedeu.trigger(:_cursor_up_, name) }
|
|
215
|
-
end
|
|
216
|
-
|
|
217
172
|
# Will unmaximise the named interface geometry. Previously, when
|
|
218
173
|
# a geometry was maximised, then triggering the unmaximise event
|
|
219
174
|
# will return it to its usual defined size (terminal size
|
|
@@ -259,36 +214,6 @@ module Vedeu
|
|
|
259
214
|
}
|
|
260
215
|
end
|
|
261
216
|
|
|
262
|
-
# When moving an interface;
|
|
263
|
-
# 1) Reset the alignment and maximised states to false;
|
|
264
|
-
# it wont be aligned to a side if moved, and cannot be moved
|
|
265
|
-
# if maximised.
|
|
266
|
-
# 2) Get the current coordinates of the interface, then:
|
|
267
|
-
# 3) Override the attributes with the new coordinates for
|
|
268
|
-
# desired movement; these are usually +/- 1 of the current
|
|
269
|
-
# state, depending on direction.
|
|
270
|
-
#
|
|
271
|
-
# @param coordinates [Hash<Symbol => Fixnum>]
|
|
272
|
-
# @option coordinates x [Fixnum] The starting column/character
|
|
273
|
-
# position.
|
|
274
|
-
# @option coordinates xn [Fixnum] The ending column/character
|
|
275
|
-
# position.
|
|
276
|
-
# @option coordinates y [Fixnum] The starting row/line position.
|
|
277
|
-
# @option coordinates yn [Fixnum] The ending row/line position.
|
|
278
|
-
# @return [Hash<Symbol => Boolean, Fixnum>]
|
|
279
|
-
def move(coordinates = {})
|
|
280
|
-
attrs = attributes.merge!(horizontal_alignment: :none,
|
|
281
|
-
maximised: false,
|
|
282
|
-
vertical_alignment: :none)
|
|
283
|
-
.merge!(coordinates)
|
|
284
|
-
|
|
285
|
-
geometry = Vedeu::Geometry::Geometry.store(attrs)
|
|
286
|
-
|
|
287
|
-
yield if block_given?
|
|
288
|
-
|
|
289
|
-
geometry
|
|
290
|
-
end
|
|
291
|
-
|
|
292
217
|
# Returns the default options/attributes for this class.
|
|
293
218
|
#
|
|
294
219
|
# @return [Hash<Symbol => Boolean|Fixnum|NilClass|String|Symbol|
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
module Vedeu
|
|
2
|
+
|
|
3
|
+
module Geometry
|
|
4
|
+
|
|
5
|
+
# Move an interface/view via changing its geometry.
|
|
6
|
+
#
|
|
7
|
+
# When moving an interface/view;
|
|
8
|
+
#
|
|
9
|
+
# 1) Reset the alignment and maximised states to false;
|
|
10
|
+
# it wont be aligned to a side if moved, and cannot be moved
|
|
11
|
+
# if maximised.
|
|
12
|
+
# 2) Get the current coordinates of the interface, then:
|
|
13
|
+
# 3) Override the attributes with the new coordinates for
|
|
14
|
+
# desired movement; these are usually +/- 1 of the current
|
|
15
|
+
# state, depending on direction.
|
|
16
|
+
#
|
|
17
|
+
# @api private
|
|
18
|
+
#
|
|
19
|
+
class Move
|
|
20
|
+
|
|
21
|
+
extend Forwardable
|
|
22
|
+
|
|
23
|
+
def_delegators :geometry,
|
|
24
|
+
:x,
|
|
25
|
+
:xn,
|
|
26
|
+
:y,
|
|
27
|
+
:yn
|
|
28
|
+
|
|
29
|
+
# @param attributes See #initialize
|
|
30
|
+
# @return See #move
|
|
31
|
+
def self.move(attributes = {})
|
|
32
|
+
new(attributes).move
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Returns a new instance of Vedeu::Geometry::Move.
|
|
36
|
+
#
|
|
37
|
+
# @param attributes [Hash<Symbol => Boolean|Fixnum|String|
|
|
38
|
+
# Symbol|Vedeu::Geometry::Repository]
|
|
39
|
+
# @option attributes name [String|Symbol] The name of the
|
|
40
|
+
# interface/view.
|
|
41
|
+
# @option attributes direction [Symbol] The direction to move;
|
|
42
|
+
# one of: :down, :left, :origin, :right, :up.
|
|
43
|
+
# @option attributes offset [Fixnum] The number of columns or
|
|
44
|
+
# rows to move by.
|
|
45
|
+
# @return [Vedeu::Geometry::Move]
|
|
46
|
+
def initialize(attributes = {})
|
|
47
|
+
defaults.merge!(attributes).each do |key, value|
|
|
48
|
+
instance_variable_set("@#{key}", value || defaults.fetch(key))
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [FalseClass|Vedeu::Geometry::Geometry]
|
|
53
|
+
def move
|
|
54
|
+
return false unless valid?
|
|
55
|
+
|
|
56
|
+
Vedeu::Geometry::Geometry.store(new_attributes) do
|
|
57
|
+
update_cursor!
|
|
58
|
+
refresh!
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
protected
|
|
63
|
+
|
|
64
|
+
# @!attribute [r] direction
|
|
65
|
+
# @return [Symbol]
|
|
66
|
+
attr_reader :direction
|
|
67
|
+
|
|
68
|
+
# @!attribute [r] name
|
|
69
|
+
# @return [String|Symbol]
|
|
70
|
+
attr_reader :name
|
|
71
|
+
|
|
72
|
+
# @!attribute [r] offset
|
|
73
|
+
# @return [Symbol]
|
|
74
|
+
attr_reader :offset
|
|
75
|
+
|
|
76
|
+
private
|
|
77
|
+
|
|
78
|
+
# @return [Hash<Symbol => Fixnum|String|Symbol>]
|
|
79
|
+
def defaults
|
|
80
|
+
{
|
|
81
|
+
direction: :none,
|
|
82
|
+
name: '',
|
|
83
|
+
offset: 1,
|
|
84
|
+
}
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# @return [Boolean]
|
|
88
|
+
def direction?
|
|
89
|
+
direction != :none
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Moves the geometry down by the offset.
|
|
93
|
+
#
|
|
94
|
+
# @return [Hash<Symbol => Fixnum]
|
|
95
|
+
def down
|
|
96
|
+
{
|
|
97
|
+
y: y + offset,
|
|
98
|
+
yn: yn + offset,
|
|
99
|
+
}
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# @return [Hash<Symbol => Symbol>]
|
|
103
|
+
def event
|
|
104
|
+
{
|
|
105
|
+
down: :_cursor_down_,
|
|
106
|
+
left: :_cursor_left_,
|
|
107
|
+
origin: :_cursor_origin_,
|
|
108
|
+
right: :_cursor_right_,
|
|
109
|
+
up: :_cursor_up_,
|
|
110
|
+
}[direction]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
# @return [Vedeu::Geometry::Geometry]
|
|
114
|
+
def geometry
|
|
115
|
+
Vedeu.geometries.by_name(name)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Moves the geometry left by the offset.
|
|
119
|
+
#
|
|
120
|
+
# @return [Hash<Symbol => Fixnum]
|
|
121
|
+
def left
|
|
122
|
+
{
|
|
123
|
+
x: x - offset,
|
|
124
|
+
xn: xn - offset,
|
|
125
|
+
}
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# @return [Hash<Symbol => Boolean|String|Symbol>]
|
|
129
|
+
def new_attributes
|
|
130
|
+
geometry.attributes.merge!(unalign_unmaximise).merge!(send(direction))
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Moves the geometry to the top left of the terminal.
|
|
134
|
+
#
|
|
135
|
+
# @return [Hash<Symbol => Fixnum]
|
|
136
|
+
def origin
|
|
137
|
+
{
|
|
138
|
+
x: 1,
|
|
139
|
+
xn: (xn - x + 1),
|
|
140
|
+
y: 1,
|
|
141
|
+
yn: (yn - y + 1),
|
|
142
|
+
}
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Refresh the screen after moving.
|
|
146
|
+
#
|
|
147
|
+
# @return [void]
|
|
148
|
+
def refresh!
|
|
149
|
+
Vedeu.trigger(:_movement_refresh_, name)
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
# Moves the geometry right by the offset.
|
|
153
|
+
#
|
|
154
|
+
# @return [Hash<Symbol => Fixnum]
|
|
155
|
+
def right
|
|
156
|
+
{
|
|
157
|
+
x: x + offset,
|
|
158
|
+
xn: xn + offset,
|
|
159
|
+
}
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# @return [Hash<Symbol => Boolean|Symbol]
|
|
163
|
+
def unalign_unmaximise
|
|
164
|
+
{
|
|
165
|
+
horizontal_alignment: :none,
|
|
166
|
+
maximised: false,
|
|
167
|
+
vertical_alignment: :none,
|
|
168
|
+
}
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
# Moves the geometry up by the offset.
|
|
172
|
+
#
|
|
173
|
+
# @return [Hash<Symbol => Fixnum]
|
|
174
|
+
def up
|
|
175
|
+
{
|
|
176
|
+
y: y - offset,
|
|
177
|
+
yn: yn - offset,
|
|
178
|
+
}
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Refresh the cursor after moving.
|
|
182
|
+
#
|
|
183
|
+
# @return [void]
|
|
184
|
+
def update_cursor!
|
|
185
|
+
Vedeu.trigger(event, name)
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
# @return [Boolean]
|
|
189
|
+
def valid?
|
|
190
|
+
{
|
|
191
|
+
down: valid_down?,
|
|
192
|
+
left: valid_left?,
|
|
193
|
+
origin: true,
|
|
194
|
+
right: valid_right?,
|
|
195
|
+
up: valid_up?,
|
|
196
|
+
}.fetch(direction, false)
|
|
197
|
+
end
|
|
198
|
+
|
|
199
|
+
# @return [Boolean]
|
|
200
|
+
def valid_down?
|
|
201
|
+
yn + offset <= Vedeu.height
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
# @return [Boolean]
|
|
205
|
+
def valid_left?
|
|
206
|
+
x - offset >= 1
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
# @return [Boolean]
|
|
210
|
+
def valid_right?
|
|
211
|
+
xn + offset <= Vedeu.width
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
# @return [Boolean]
|
|
215
|
+
def valid_up?
|
|
216
|
+
y - offset >= 1
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
end # Move
|
|
220
|
+
|
|
221
|
+
end # Geometry
|
|
222
|
+
|
|
223
|
+
end # Vedeu
|
|
@@ -46,15 +46,15 @@ module Vedeu
|
|
|
46
46
|
Vedeu.geometries.by_name(name).unmaximise
|
|
47
47
|
end
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
Vedeu.bind(:"_view_#{direction}_") do |name|
|
|
51
|
-
Vedeu.
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
[:down, :left, :right, :up].each do |direction|
|
|
50
|
+
Vedeu.bind(:"_view_#{direction}_") do |name, offset|
|
|
51
|
+
Vedeu::Geometry::Move.move(direction: direction,
|
|
52
|
+
name: name,
|
|
53
|
+
offset: offset)
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
[:down, :left, :right, :up].each do |direction|
|
|
58
58
|
Vedeu.bind_alias(:"_geometry_#{direction}_", :"_view_#{direction}_")
|
|
59
59
|
end
|
|
60
60
|
|
data/lib/vedeu/version.rb
CHANGED
|
@@ -132,121 +132,6 @@ module Vedeu
|
|
|
132
132
|
it { subject.maximised.must_equal(true) }
|
|
133
133
|
end
|
|
134
134
|
|
|
135
|
-
describe '#move_down' do
|
|
136
|
-
let(:x) { 15 }
|
|
137
|
-
let(:xn) { 25 }
|
|
138
|
-
let(:y) { 4 }
|
|
139
|
-
let(:yn) { 8 }
|
|
140
|
-
|
|
141
|
-
subject { instance.move_down }
|
|
142
|
-
|
|
143
|
-
it { subject.must_be_instance_of(described) }
|
|
144
|
-
|
|
145
|
-
it { subject.y.must_equal(5) }
|
|
146
|
-
it { subject.yn.must_equal(9) }
|
|
147
|
-
|
|
148
|
-
context 'when the move will make the geometry out of bounds' do
|
|
149
|
-
let(:x) { 15 }
|
|
150
|
-
let(:xn) { 25 }
|
|
151
|
-
let(:y) { 8 }
|
|
152
|
-
let(:yn) { 12 }
|
|
153
|
-
|
|
154
|
-
it { subject.y.must_equal(8) }
|
|
155
|
-
it { subject.yn.must_equal(12) }
|
|
156
|
-
end
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
describe '#move_left' do
|
|
160
|
-
let(:x) { 15 }
|
|
161
|
-
let(:xn) { 25 }
|
|
162
|
-
let(:y) { 4 }
|
|
163
|
-
let(:yn) { 8 }
|
|
164
|
-
|
|
165
|
-
subject { instance.move_left }
|
|
166
|
-
|
|
167
|
-
it { subject.must_be_instance_of(described) }
|
|
168
|
-
|
|
169
|
-
it { subject.x.must_equal(14) }
|
|
170
|
-
it { subject.xn.must_equal(24) }
|
|
171
|
-
|
|
172
|
-
context 'when the move will make the geometry out of bounds' do
|
|
173
|
-
let(:x) { 1 }
|
|
174
|
-
let(:xn) { 11 }
|
|
175
|
-
let(:y) { 4 }
|
|
176
|
-
let(:yn) { 8 }
|
|
177
|
-
|
|
178
|
-
it { subject.x.must_equal(1) }
|
|
179
|
-
it { subject.xn.must_equal(11) }
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
describe '#move_origin' do
|
|
184
|
-
let(:x) { 15 }
|
|
185
|
-
let(:xn) { 25 }
|
|
186
|
-
let(:y) { 4 }
|
|
187
|
-
let(:yn) { 8 }
|
|
188
|
-
|
|
189
|
-
before do
|
|
190
|
-
Vedeu.stubs(:trigger)
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
subject { instance.move_origin }
|
|
194
|
-
|
|
195
|
-
it { subject.must_be_instance_of(described) }
|
|
196
|
-
it { subject.x.must_equal(1) }
|
|
197
|
-
it { subject.xn.must_equal(11) }
|
|
198
|
-
it { subject.y.must_equal(1) }
|
|
199
|
-
it { subject.yn.must_equal(5) }
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
describe '#move_right' do
|
|
203
|
-
let(:x) { 15 }
|
|
204
|
-
let(:xn) { 25 }
|
|
205
|
-
let(:y) { 4 }
|
|
206
|
-
let(:yn) { 8 }
|
|
207
|
-
|
|
208
|
-
subject { instance.move_right }
|
|
209
|
-
|
|
210
|
-
it { subject.must_be_instance_of(described) }
|
|
211
|
-
|
|
212
|
-
it { subject.x.must_equal(16) }
|
|
213
|
-
it { subject.xn.must_equal(26) }
|
|
214
|
-
|
|
215
|
-
context 'when the move will make the geometry out of bounds' do
|
|
216
|
-
let(:x) { 30 }
|
|
217
|
-
let(:xn) { 40 }
|
|
218
|
-
let(:y) { 4 }
|
|
219
|
-
let(:yn) { 8 }
|
|
220
|
-
|
|
221
|
-
it { subject.x.must_equal(30) }
|
|
222
|
-
it { subject.xn.must_equal(40) }
|
|
223
|
-
end
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
describe '#move_up' do
|
|
227
|
-
let(:x) { 15 }
|
|
228
|
-
let(:xn) { 25 }
|
|
229
|
-
let(:y) { 4 }
|
|
230
|
-
let(:yn) { 8 }
|
|
231
|
-
|
|
232
|
-
subject { instance.move_up }
|
|
233
|
-
|
|
234
|
-
it { subject.must_be_instance_of(described) }
|
|
235
|
-
|
|
236
|
-
it { subject.y.must_equal(3) }
|
|
237
|
-
it { subject.yn.must_equal(7) }
|
|
238
|
-
|
|
239
|
-
context 'when the move will make the geometry out of bounds' do
|
|
240
|
-
let(:x) { 15 }
|
|
241
|
-
let(:xn) { 25 }
|
|
242
|
-
let(:y) { 1 }
|
|
243
|
-
let(:yn) { 5 }
|
|
244
|
-
|
|
245
|
-
it { subject.y.must_equal(1) }
|
|
246
|
-
it { subject.yn.must_equal(5) }
|
|
247
|
-
end
|
|
248
|
-
end
|
|
249
|
-
|
|
250
135
|
describe '#unmaximise' do
|
|
251
136
|
let(:attributes) {
|
|
252
137
|
{
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
module Vedeu
|
|
4
|
+
|
|
5
|
+
module Geometry
|
|
6
|
+
|
|
7
|
+
describe Move do
|
|
8
|
+
|
|
9
|
+
let(:described) { Vedeu::Geometry::Move }
|
|
10
|
+
let(:instance) { described.new(attributes) }
|
|
11
|
+
let(:direction) {}
|
|
12
|
+
let(:_name) { 'Vedeu::Geometry::Move' }
|
|
13
|
+
let(:offset) {}
|
|
14
|
+
let(:attributes) {
|
|
15
|
+
{
|
|
16
|
+
direction: direction,
|
|
17
|
+
name: _name,
|
|
18
|
+
offset: offset,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
let(:geometry) {
|
|
22
|
+
Vedeu::Geometry::Geometry.new(name: _name, x: 2, xn: 8, y: 2, yn: 8)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe '#initialize' do
|
|
26
|
+
it { instance.must_be_instance_of(described) }
|
|
27
|
+
|
|
28
|
+
context 'when a direction is given' do
|
|
29
|
+
let(:direction) { :left }
|
|
30
|
+
|
|
31
|
+
it {
|
|
32
|
+
instance.instance_variable_get('@direction').must_equal(direction)
|
|
33
|
+
}
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when a direction is not given' do
|
|
37
|
+
it { instance.instance_variable_get('@direction').must_equal(:none) }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context 'when a name is given' do
|
|
41
|
+
it { instance.instance_variable_get('@name').must_equal(_name) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context 'when a name is not given' do
|
|
45
|
+
let(:_name) {}
|
|
46
|
+
|
|
47
|
+
it { instance.instance_variable_get('@name').must_equal('') }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
context 'when an offset is given' do
|
|
51
|
+
let(:offset) { 2 }
|
|
52
|
+
|
|
53
|
+
it { instance.instance_variable_get('@offset').must_equal(offset) }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
context 'when an offset is not given' do
|
|
57
|
+
it { instance.instance_variable_get('@offset').must_equal(1) }
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
describe '.move' do
|
|
62
|
+
before do
|
|
63
|
+
Vedeu.geometries.stubs(:by_name).with(_name).returns(geometry)
|
|
64
|
+
Vedeu.stubs(:trigger)
|
|
65
|
+
Vedeu.stubs(:height).returns(10)
|
|
66
|
+
Vedeu.stubs(:width).returns(10)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
subject { described.move(attributes) }
|
|
70
|
+
|
|
71
|
+
context 'when the direction is :down' do
|
|
72
|
+
let(:direction) { :down }
|
|
73
|
+
|
|
74
|
+
context 'when y + offset > terminal height' do
|
|
75
|
+
let(:offset) { 3 }
|
|
76
|
+
|
|
77
|
+
it { subject.must_equal(false) }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
context 'when y + offset <= terminal height' do
|
|
81
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
|
|
82
|
+
it { subject.x.must_equal(2) }
|
|
83
|
+
it { subject.xn.must_equal(8) }
|
|
84
|
+
it { subject.y.must_equal(3) }
|
|
85
|
+
it { subject.yn.must_equal(9) }
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context 'when the direction is :left' do
|
|
90
|
+
let(:direction) { :left }
|
|
91
|
+
|
|
92
|
+
context 'when x - offset < 1' do
|
|
93
|
+
let(:offset) { 3 }
|
|
94
|
+
|
|
95
|
+
it { subject.must_equal(false) }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context 'when x - offset >= 1' do
|
|
99
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
|
|
100
|
+
it { subject.x.must_equal(1) }
|
|
101
|
+
it { subject.xn.must_equal(7) }
|
|
102
|
+
it { subject.y.must_equal(2) }
|
|
103
|
+
it { subject.yn.must_equal(8) }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
context 'when the direction is :none' do
|
|
108
|
+
let(:direction) { :none }
|
|
109
|
+
let(:offset) { 1 }
|
|
110
|
+
|
|
111
|
+
it { subject.must_equal(false) }
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
context 'when the direction is :origin' do
|
|
115
|
+
let(:direction) { :origin }
|
|
116
|
+
|
|
117
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
|
|
118
|
+
it { subject.x.must_equal(1) }
|
|
119
|
+
it { subject.xn.must_equal(7) }
|
|
120
|
+
it { subject.y.must_equal(1) }
|
|
121
|
+
it { subject.yn.must_equal(7) }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
context 'when the direction is :right' do
|
|
125
|
+
let(:direction) { :right }
|
|
126
|
+
|
|
127
|
+
context 'when xn + offset > terminal width' do
|
|
128
|
+
let(:offset) { 3 }
|
|
129
|
+
|
|
130
|
+
it { subject.must_equal(false) }
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
context 'when xn + offset <= terminal width' do
|
|
134
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
|
|
135
|
+
it { subject.x.must_equal(3) }
|
|
136
|
+
it { subject.xn.must_equal(9) }
|
|
137
|
+
it { subject.y.must_equal(2) }
|
|
138
|
+
it { subject.yn.must_equal(8) }
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
context 'when the direction is :up' do
|
|
143
|
+
let(:direction) { :up }
|
|
144
|
+
|
|
145
|
+
context 'when y - offset < 1' do
|
|
146
|
+
let(:offset) { 3 }
|
|
147
|
+
|
|
148
|
+
it { subject.must_equal(false) }
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
context 'when y - offset >= 1' do
|
|
152
|
+
it { subject.must_be_instance_of(Vedeu::Geometry::Geometry) }
|
|
153
|
+
it { subject.x.must_equal(2) }
|
|
154
|
+
it { subject.xn.must_equal(8) }
|
|
155
|
+
it { subject.y.must_equal(1) }
|
|
156
|
+
it { subject.yn.must_equal(7) }
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
context 'when the direction is invalid' do
|
|
161
|
+
let(:direction) { :invalid }
|
|
162
|
+
let(:offset) { 1 }
|
|
163
|
+
|
|
164
|
+
it { subject.must_equal(false) }
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
describe '#move' do
|
|
169
|
+
it { instance.must_respond_to(:move) }
|
|
170
|
+
end
|
|
171
|
+
|
|
172
|
+
end # Move
|
|
173
|
+
|
|
174
|
+
end # Geometry
|
|
175
|
+
|
|
176
|
+
end # Vedeu
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: vedeu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.58
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gavin Laking
|
|
@@ -420,6 +420,7 @@ files:
|
|
|
420
420
|
- lib/vedeu/geometry/geometry.rb
|
|
421
421
|
- lib/vedeu/geometry/grid.rb
|
|
422
422
|
- lib/vedeu/geometry/horizontal_alignment.rb
|
|
423
|
+
- lib/vedeu/geometry/move.rb
|
|
423
424
|
- lib/vedeu/geometry/null.rb
|
|
424
425
|
- lib/vedeu/geometry/position.rb
|
|
425
426
|
- lib/vedeu/geometry/repository.rb
|
|
@@ -605,6 +606,7 @@ files:
|
|
|
605
606
|
- test/lib/vedeu/geometry/geometry_test.rb
|
|
606
607
|
- test/lib/vedeu/geometry/grid_test.rb
|
|
607
608
|
- test/lib/vedeu/geometry/horizontal_alignment_test.rb
|
|
609
|
+
- test/lib/vedeu/geometry/move_test.rb
|
|
608
610
|
- test/lib/vedeu/geometry/null_test.rb
|
|
609
611
|
- test/lib/vedeu/geometry/position_test.rb
|
|
610
612
|
- test/lib/vedeu/geometry/repository_test.rb
|
|
@@ -817,6 +819,7 @@ test_files:
|
|
|
817
819
|
- test/lib/vedeu/geometry/geometry_test.rb
|
|
818
820
|
- test/lib/vedeu/geometry/grid_test.rb
|
|
819
821
|
- test/lib/vedeu/geometry/horizontal_alignment_test.rb
|
|
822
|
+
- test/lib/vedeu/geometry/move_test.rb
|
|
820
823
|
- test/lib/vedeu/geometry/null_test.rb
|
|
821
824
|
- test/lib/vedeu/geometry/position_test.rb
|
|
822
825
|
- test/lib/vedeu/geometry/repository_test.rb
|