vedeu 0.2.2 → 0.2.3
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/docs/api.md +1 -1
- data/docs/events.md +11 -8
- data/lib/vedeu/api/api.rb +19 -43
- data/lib/vedeu/api/composition.rb +13 -8
- data/lib/vedeu/api/defined.rb +14 -4
- data/lib/vedeu/api/helpers.rb +8 -5
- data/lib/vedeu/api/interface.rb +15 -21
- data/lib/vedeu/api/keymap.rb +11 -5
- data/lib/vedeu/api/line.rb +6 -7
- data/lib/vedeu/api/menu.rb +9 -17
- data/lib/vedeu/api/stream.rb +8 -6
- data/lib/vedeu/application.rb +14 -12
- data/lib/vedeu/configuration/api.rb +33 -3
- data/lib/vedeu/configuration/cli.rb +23 -3
- data/lib/vedeu/configuration/configuration.rb +3 -2
- data/lib/vedeu/input/input.rb +6 -2
- data/lib/vedeu/launcher.rb +5 -2
- data/lib/vedeu/models/attributes/background.rb +3 -2
- data/lib/vedeu/models/attributes/coercions.rb +3 -2
- data/lib/vedeu/models/attributes/colour_translator.rb +11 -4
- data/lib/vedeu/models/attributes/foreground.rb +3 -2
- data/lib/vedeu/models/attributes/presentation.rb +3 -2
- data/lib/vedeu/models/colour.rb +3 -2
- data/lib/vedeu/models/composition.rb +5 -2
- data/lib/vedeu/models/cursor.rb +3 -2
- data/lib/vedeu/models/geometry.rb +48 -6
- data/lib/vedeu/models/interface.rb +12 -2
- data/lib/vedeu/models/keymap.rb +4 -2
- data/lib/vedeu/models/line.rb +5 -2
- data/lib/vedeu/models/stream.rb +12 -2
- data/lib/vedeu/models/style.rb +3 -2
- data/lib/vedeu/output/clear.rb +5 -2
- data/lib/vedeu/output/compositor.rb +4 -2
- data/lib/vedeu/output/refresh.rb +4 -6
- data/lib/vedeu/output/render.rb +17 -14
- data/lib/vedeu/output/view.rb +5 -2
- data/lib/vedeu/repositories/buffers.rb +16 -47
- data/lib/vedeu/repositories/cursors.rb +26 -28
- data/lib/vedeu/repositories/events.rb +33 -48
- data/lib/vedeu/repositories/focus.rb +24 -20
- data/lib/vedeu/repositories/groups.rb +17 -52
- data/lib/vedeu/repositories/interfaces.rb +21 -42
- data/lib/vedeu/repositories/keymaps.rb +9 -57
- data/lib/vedeu/repositories/menus.rb +15 -55
- data/lib/vedeu/support/common.rb +2 -2
- data/lib/vedeu/support/esc.rb +35 -2
- data/lib/vedeu/support/event.rb +7 -8
- data/lib/vedeu/support/exceptions.rb +47 -0
- data/lib/vedeu/support/grid.rb +11 -4
- data/lib/vedeu/support/keymap_validator.rb +9 -14
- data/lib/vedeu/support/log.rb +13 -3
- data/lib/vedeu/support/menu.rb +3 -2
- data/lib/vedeu/support/position.rb +3 -2
- data/lib/vedeu/support/registrar.rb +2 -23
- data/lib/vedeu/support/repository.rb +77 -0
- data/lib/vedeu/support/terminal.rb +12 -2
- data/lib/vedeu/support/trace.rb +127 -20
- data/lib/vedeu.rb +11 -46
- data/test/lib/vedeu/api/api_test.rb +14 -18
- data/test/lib/vedeu/api/defined_test.rb +16 -6
- data/test/lib/vedeu/api/interface_test.rb +5 -20
- data/test/lib/vedeu/api/menu_test.rb +1 -1
- data/test/lib/vedeu/models/geometry_test.rb +41 -0
- data/test/lib/vedeu/models/interface_test.rb +14 -0
- data/test/lib/vedeu/repositories/buffers_test.rb +6 -32
- data/test/lib/vedeu/repositories/cursors_test.rb +14 -0
- data/test/lib/vedeu/repositories/events_test.rb +18 -47
- data/test/lib/vedeu/repositories/focus_test.rb +18 -5
- data/test/lib/vedeu/repositories/groups_test.rb +3 -62
- data/test/lib/vedeu/repositories/interfaces_test.rb +13 -49
- data/test/lib/vedeu/repositories/keymaps_test.rb +0 -23
- data/test/lib/vedeu/repositories/menus_test.rb +3 -62
- data/test/lib/vedeu/support/esc_test.rb +24 -0
- data/test/lib/vedeu/support/keymap_validator_test.rb +19 -38
- data/test/lib/vedeu/support/repository_test.rb +70 -0
- data/test/test_helper.rb +2 -0
- data/vedeu.gemspec +3 -3
- metadata +10 -6
@@ -10,6 +10,12 @@ module Vedeu
|
|
10
10
|
Buffers.add({ name: 'molybdenum' }).must_equal('molybdenum')
|
11
11
|
end
|
12
12
|
|
13
|
+
it 'raises an exception if the attributes does not have a :name key' do
|
14
|
+
attributes = { no_name_key: '' }
|
15
|
+
|
16
|
+
proc { Buffers.add(attributes) }.must_raise(MissingRequired)
|
17
|
+
end
|
18
|
+
|
13
19
|
context 'when the buffer is already registered' do
|
14
20
|
it 'retrieves the buffer in storage, and adds the attributes to the ' \
|
15
21
|
'back buffer, preserving the front which may already have content' do
|
@@ -25,20 +31,6 @@ module Vedeu
|
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
28
|
-
describe '.find' do
|
29
|
-
context 'when the buffer does not exist by this name' do
|
30
|
-
it '' do
|
31
|
-
skip
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context 'when the buffer can be found by name' do
|
36
|
-
it '' do
|
37
|
-
skip
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
34
|
describe '.latest' do
|
43
35
|
context 'when the buffer does not exist by this name' do
|
44
36
|
it '' do
|
@@ -53,23 +45,5 @@ module Vedeu
|
|
53
45
|
end
|
54
46
|
end
|
55
47
|
|
56
|
-
describe '.registered' do
|
57
|
-
it '' do
|
58
|
-
skip
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe '.registered>' do
|
63
|
-
it '' do
|
64
|
-
skip
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
describe '.reset' do
|
69
|
-
it '' do
|
70
|
-
skip
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
48
|
end
|
75
49
|
end
|
@@ -3,7 +3,21 @@ require 'test_helper'
|
|
3
3
|
module Vedeu
|
4
4
|
describe Cursors do
|
5
5
|
|
6
|
+
before { Cursors.reset }
|
7
|
+
|
6
8
|
describe '#add' do
|
9
|
+
it 'raises an exception if the attributes does not have a :name key' do
|
10
|
+
attributes = { no_name_key: '' }
|
11
|
+
|
12
|
+
proc { Cursors.add(attributes) }.must_raise(MissingRequired)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'returns something' do
|
16
|
+
skip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#use' do
|
7
21
|
it 'returns something' do
|
8
22
|
skip
|
9
23
|
end
|
@@ -2,68 +2,39 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Events do
|
5
|
-
describe '#
|
6
|
-
it 'adds the event
|
7
|
-
|
8
|
-
|
9
|
-
events.registered.must_equal([:sulphur])
|
5
|
+
describe '#add' do
|
6
|
+
it 'adds the event' do
|
7
|
+
Events.add(:sulphur) { proc { |x| x } }
|
8
|
+
Events.registered.must_include(:sulphur)
|
10
9
|
end
|
11
10
|
end
|
12
11
|
|
13
|
-
describe '#
|
12
|
+
describe '#remove' do
|
14
13
|
it 'removes the event by name' do
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
events.registered.must_equal([:argon])
|
14
|
+
Events.add(:chlorine) { proc { |x| x } }
|
15
|
+
Events.add(:argon) { proc { |y| y } }
|
16
|
+
Events.remove(:chlorine)
|
17
|
+
Events.registered.wont_include(:chlorine)
|
20
18
|
end
|
21
19
|
|
22
20
|
it 'removes the event by name only if the name exists' do
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
events.unevent(:potassium)
|
27
|
-
events.registered.must_equal([:chlorine, :argon])
|
21
|
+
Events.add(:chlorine) { proc { |x| x } }
|
22
|
+
Events.add(:argon) { proc { |y| y } }
|
23
|
+
Events.remove(:potassium).must_equal(false)
|
28
24
|
end
|
29
25
|
end
|
30
26
|
|
31
|
-
describe '#
|
32
|
-
it 'returns
|
33
|
-
|
34
|
-
event(:some_event) { proc { |x| x } }
|
35
|
-
end
|
36
|
-
events.registered.must_equal([:some_event])
|
37
|
-
end
|
38
|
-
end
|
27
|
+
describe '#trigger' do
|
28
|
+
it 'returns the result of triggering the event' do
|
29
|
+
NastyException = Class.new(StandardError)
|
39
30
|
|
40
|
-
|
41
|
-
it '' do
|
42
|
-
skip
|
43
|
-
end
|
44
|
-
end
|
31
|
+
Events.add(:_nasty_exception_) { fail NastyException }
|
45
32
|
|
46
|
-
|
47
|
-
it 'returns a collection containing the event when the event is ' \
|
48
|
-
'pre-registered' do
|
49
|
-
events = Events.new do
|
50
|
-
event(:_exit_) { fail StopIteration }
|
51
|
-
end
|
52
|
-
proc { events.trigger(:_exit_) }.must_raise(StopIteration)
|
33
|
+
proc { Events.use(:_nasty_exception_) }.must_raise(NastyException)
|
53
34
|
end
|
54
35
|
|
55
36
|
it 'returns an empty collection when the event has not been registered' do
|
56
|
-
|
57
|
-
events.trigger(:_not_found_).must_be_empty
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe '#reset' do
|
62
|
-
it 'removes all events registered' do
|
63
|
-
events = Events.new do
|
64
|
-
event(:potassium) { proc { |x| x } }
|
65
|
-
end
|
66
|
-
events.reset.must_equal({})
|
37
|
+
Events.use(:_not_found_).must_be_empty
|
67
38
|
end
|
68
39
|
end
|
69
40
|
end
|
@@ -15,6 +15,12 @@ module Vedeu
|
|
15
15
|
Focus.add({ name: 'thallium' })
|
16
16
|
Focus.registered.must_equal(['thallium'])
|
17
17
|
end
|
18
|
+
|
19
|
+
it 'raises an exception if the attributes does not have a :name key' do
|
20
|
+
attributes = { no_name_key: '' }
|
21
|
+
|
22
|
+
proc { Focus.add(attributes) }.must_raise(MissingRequired)
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
26
|
describe '#by_name' do
|
@@ -43,6 +49,18 @@ module Vedeu
|
|
43
49
|
end
|
44
50
|
end
|
45
51
|
|
52
|
+
describe '#current?' do
|
53
|
+
before { Focus.stubs(:current).returns('lead') }
|
54
|
+
|
55
|
+
context 'when the interface is currently in focus' do
|
56
|
+
it { Focus.current?('lead').must_equal(true) }
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when the interface is not currently in focus' do
|
60
|
+
it { Focus.current?('bismuth').must_equal(false) }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
46
64
|
describe '#next_item' do
|
47
65
|
it 'the next interface is focussed when the method is called' do
|
48
66
|
Focus.add({ name: 'thallium' })
|
@@ -87,10 +105,5 @@ module Vedeu
|
|
87
105
|
end
|
88
106
|
end
|
89
107
|
|
90
|
-
describe '.reset' do
|
91
|
-
it 'returns an empty collection with no focussed interfaces stored' do
|
92
|
-
Focus.reset.must_equal([])
|
93
|
-
end
|
94
|
-
end
|
95
108
|
end
|
96
109
|
end
|
@@ -13,72 +13,13 @@ module Vedeu
|
|
13
13
|
Groups.add({ group: 'elements', name: 'germanium', delay: 0.0 })
|
14
14
|
Groups.all.must_equal({ 'elements' => Set['germanium'] })
|
15
15
|
end
|
16
|
-
end
|
17
|
-
|
18
|
-
describe '#all' do
|
19
|
-
before do
|
20
|
-
Groups.reset
|
21
|
-
Groups.add({ group: 'elements', name: 'cobalt', delay: 0.0 })
|
22
|
-
Groups.add({ group: 'elements', name: 'nickel', delay: 0.0 })
|
23
|
-
Groups.add({ group: 'elements', name: 'copper', delay: 0.0 })
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'returns all the groups from storage' do
|
27
|
-
Groups.all.must_equal({
|
28
|
-
"elements" => Set["cobalt", "nickel", "copper"]
|
29
|
-
})
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
describe '#find' do
|
34
|
-
before do
|
35
|
-
Groups.reset
|
36
|
-
Groups.add({ group: 'elements', name: 'zinc', delay: 0.0 })
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'raises an exception if the group cannot be found' do
|
40
|
-
proc { Groups.find('not_found') }.must_raise(GroupNotFound)
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'returns a collection of interface names belonging to the group' do
|
44
|
-
Groups.find('elements').must_equal(Set['zinc'])
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe '#registered' do
|
49
|
-
before do
|
50
|
-
Groups.reset
|
51
|
-
Groups.add({ group: 'elements', name: 'cobalt', delay: 0.0 })
|
52
|
-
Groups.add({ group: 'minerals', name: 'ruby', delay: 0.0 })
|
53
|
-
Groups.add({ group: 'elements', name: 'copper', delay: 0.0 })
|
54
|
-
Groups.add({ group: 'minerals', name: 'diamond', delay: 0.0 })
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns all the groups from storage' do
|
58
|
-
Groups.registered.must_equal(['elements', 'minerals'])
|
59
|
-
end
|
60
|
-
end
|
61
16
|
|
62
|
-
|
63
|
-
|
64
|
-
Groups.add({ group: 'registered' })
|
17
|
+
it 'raises an exception if the attributes does not have a :name key' do
|
18
|
+
attributes = { no_name_key: '' }
|
65
19
|
|
66
|
-
Groups.
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns false when the group is not registered' do
|
70
|
-
Groups.registered?('not_registered').must_equal(false)
|
20
|
+
proc { Groups.add(attributes) }.must_raise(MissingRequired)
|
71
21
|
end
|
72
22
|
end
|
73
23
|
|
74
|
-
describe '#reset' do
|
75
|
-
before { Groups.reset }
|
76
|
-
|
77
|
-
it 'removes all known groups from the storage' do
|
78
|
-
Groups.add({ group: 'elements', name: 'bromine', delay: 0.0 })
|
79
|
-
Groups.all.must_equal({ 'elements' => Set['bromine'] })
|
80
|
-
Groups.reset.must_be_empty
|
81
|
-
end
|
82
|
-
end
|
83
24
|
end
|
84
25
|
end
|
@@ -6,68 +6,32 @@ module Vedeu
|
|
6
6
|
describe '#add' do
|
7
7
|
before { Interfaces.reset }
|
8
8
|
|
9
|
-
it 'returns false if the interface name is empty' do
|
10
|
-
Interfaces.add({ name: '' }).must_equal(false)
|
11
|
-
end
|
12
|
-
|
13
9
|
it 'adds the interface to the storage' do
|
14
10
|
Interfaces.add({ name: 'germanium' })
|
15
11
|
Interfaces.all.must_equal({ 'germanium' => { name: 'germanium' } })
|
16
12
|
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#all' do
|
20
|
-
before do
|
21
|
-
Interfaces.reset
|
22
|
-
Interfaces.add({ name: 'cobalt' })
|
23
|
-
Interfaces.add({ name: 'nickel' })
|
24
|
-
Interfaces.add({ name: 'copper' })
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'returns the storage' do
|
28
|
-
Interfaces.all.must_equal(
|
29
|
-
{
|
30
|
-
'cobalt' => { name: 'cobalt' },
|
31
|
-
'nickel' => { name: 'nickel' },
|
32
|
-
'copper' => { name: 'copper' }
|
33
|
-
}
|
34
|
-
)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
describe '#find' do
|
39
|
-
before { Interfaces.add({ name: 'zinc' }) }
|
40
13
|
|
41
|
-
it 'raises an exception if the
|
42
|
-
|
43
|
-
end
|
14
|
+
it 'raises an exception if the attributes does not have a :name key' do
|
15
|
+
attributes = { no_name_key: '' }
|
44
16
|
|
45
|
-
|
46
|
-
Interfaces.find('zinc').must_equal({ name: 'zinc' })
|
17
|
+
proc { Interfaces.add(attributes) }.must_raise(MissingRequired)
|
47
18
|
end
|
48
19
|
end
|
49
20
|
|
50
|
-
describe '#
|
51
|
-
|
52
|
-
Interfaces.reset
|
53
|
-
Interfaces.add({ name: 'cobalt' })
|
54
|
-
Interfaces.add({ name: 'ruby' })
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns all the registered interfaces from storage' do
|
58
|
-
Interfaces.registered.must_equal(['cobalt', 'ruby'])
|
59
|
-
end
|
60
|
-
end
|
21
|
+
describe '#build' do
|
22
|
+
let(:attributes) { { name: 'rhenium' } }
|
61
23
|
|
62
|
-
|
63
|
-
|
64
|
-
Interfaces.add({ name: 'registered' })
|
24
|
+
before { Interfaces.add(attributes) }
|
25
|
+
after { Interfaces.reset }
|
65
26
|
|
66
|
-
|
27
|
+
it 'returns a new instance of Interface based on the stored attributes' do
|
28
|
+
Interfaces.build('rhenium').must_be_instance_of(Interface)
|
67
29
|
end
|
68
30
|
|
69
|
-
|
70
|
-
|
31
|
+
context 'when the interface cannot be found' do
|
32
|
+
it 'raises an exception' do
|
33
|
+
proc { Interfaces.build('manganese') }.must_raise(InterfaceNotFound)
|
34
|
+
end
|
71
35
|
end
|
72
36
|
end
|
73
37
|
|
@@ -19,14 +19,6 @@ module Vedeu
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
-
describe '#all' do
|
23
|
-
before { Keymaps.reset }
|
24
|
-
|
25
|
-
it 'returns all stored keymaps' do
|
26
|
-
Keymaps.all.must_equal({ '_global_keymap_' => {} })
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
22
|
describe '#find' do
|
31
23
|
let(:attributes) {
|
32
24
|
{
|
@@ -157,15 +149,6 @@ module Vedeu
|
|
157
149
|
end
|
158
150
|
end
|
159
151
|
|
160
|
-
describe '#registered' do
|
161
|
-
before { Keymaps.reset }
|
162
|
-
|
163
|
-
it 'returns a collection of the interface names of all registered ' \
|
164
|
-
'keymaps' do
|
165
|
-
Keymaps.registered.must_equal(['_global_keymap_'])
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
152
|
describe '#registered?' do
|
170
153
|
it 'returns false when the named keymap is not registered' do
|
171
154
|
Keymaps.registered?('vanadium').must_equal(false)
|
@@ -176,12 +159,6 @@ module Vedeu
|
|
176
159
|
end
|
177
160
|
end
|
178
161
|
|
179
|
-
describe '#reset' do
|
180
|
-
it 'removes all stored keymaps' do
|
181
|
-
Keymaps.reset.must_equal({ '_global_keymap_' => {} })
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
162
|
describe '#system_key?' do
|
186
163
|
it 'returns false when the key is not registered as a system key' do
|
187
164
|
Keymaps.system_key?('r').must_equal(false)
|
@@ -4,7 +4,7 @@ module Vedeu
|
|
4
4
|
|
5
5
|
describe Menus do
|
6
6
|
|
7
|
-
describe '
|
7
|
+
describe ' system events defined by Menus' do
|
8
8
|
let(:collection) { [:sulphur, :gold, :tin, :helium] }
|
9
9
|
let(:instance) { Vedeu::Menu.new(collection) }
|
10
10
|
|
@@ -139,8 +139,8 @@ module Vedeu
|
|
139
139
|
Vedeu::Menu.stubs(:new).returns(instance)
|
140
140
|
end
|
141
141
|
|
142
|
-
it '
|
143
|
-
Menus.add({ name: '' }).
|
142
|
+
it 'raises an exception if menu name is empty' do
|
143
|
+
proc { Menus.add({ name: '' }) }.must_raise(MissingRequired)
|
144
144
|
end
|
145
145
|
|
146
146
|
it 'adds the menu to the storage' do
|
@@ -153,55 +153,6 @@ module Vedeu
|
|
153
153
|
end
|
154
154
|
end
|
155
155
|
|
156
|
-
describe '#all' do
|
157
|
-
before do
|
158
|
-
Menus.reset
|
159
|
-
Menus.add({ name: 'barium' })
|
160
|
-
Menus.add({ name: 'lanthanum' })
|
161
|
-
Menus.add({ name: 'cerium' })
|
162
|
-
end
|
163
|
-
|
164
|
-
it 'returns the storage' do
|
165
|
-
Menus.all.keys.must_equal(['barium', 'lanthanum', 'cerium'])
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
describe '#find' do
|
170
|
-
before { Menus.add({ name: 'erbium' }) }
|
171
|
-
|
172
|
-
it 'raises an exception if the menu cannot be found' do
|
173
|
-
proc { Menus.find('not_found') }.must_raise(MenuNotFound)
|
174
|
-
end
|
175
|
-
|
176
|
-
it 'returns the attributes of the named menu' do
|
177
|
-
Menus.find('erbium').must_be_instance_of(Hash)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
describe '#registered' do
|
182
|
-
before do
|
183
|
-
Menus.reset
|
184
|
-
Menus.add({ name: 'barium' })
|
185
|
-
Menus.add({ name: 'caesium' })
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'returns all the registered menus from storage' do
|
189
|
-
Menus.registered.must_equal(['barium', 'caesium'])
|
190
|
-
end
|
191
|
-
end
|
192
|
-
|
193
|
-
describe '#registered?' do
|
194
|
-
it 'returns true when the menu is registered' do
|
195
|
-
Menus.add({ name: 'registered' })
|
196
|
-
|
197
|
-
Menus.registered?('registered').must_equal(true)
|
198
|
-
end
|
199
|
-
|
200
|
-
it 'returns false when the menu is not registered' do
|
201
|
-
Menus.registered?('not_registered').must_equal(false)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
156
|
describe '#remove' do
|
206
157
|
it 'returns false when the menu is not registered' do
|
207
158
|
Menus.remove('not_registered').must_equal(false)
|
@@ -221,16 +172,6 @@ module Vedeu
|
|
221
172
|
end
|
222
173
|
end
|
223
174
|
|
224
|
-
describe '#reset' do
|
225
|
-
before { Menus.reset }
|
226
|
-
|
227
|
-
it 'removes all known menus from the storage' do
|
228
|
-
Menus.add({ name: 'uranium' })
|
229
|
-
Menus.all.wont_be_empty
|
230
|
-
Menus.reset.must_be_empty
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
175
|
describe '#use' do
|
235
176
|
let(:collection) { [:calcium, :fermium, :nitrogen, :palladium] }
|
236
177
|
let(:instance) { Vedeu::Menu.new(collection) }
|
@@ -2,6 +2,30 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
module Vedeu
|
4
4
|
describe Esc do
|
5
|
+
describe 'colours defined via define_method' do
|
6
|
+
it 'returns an escape sequence for the foreground colour' do
|
7
|
+
Esc.magenta.must_equal("\e[35m")
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'returns an escape sequence for the foreground colour and resets ' \
|
11
|
+
'after calling the block' do
|
12
|
+
Esc.cyan do
|
13
|
+
'ununpentium'
|
14
|
+
end.must_equal("\e[36mununpentium\e[39m")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'returns an escape sequence for the background colour' do
|
18
|
+
Esc.on_yellow.must_equal("\e[43m")
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'returns an escape sequence for the background colour and resets ' \
|
22
|
+
'after calling the block' do
|
23
|
+
Esc.on_red do
|
24
|
+
'livermorium'
|
25
|
+
end.must_equal("\e[41mlivermorium\e[49m")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
5
29
|
describe '.string' do
|
6
30
|
it 'returns an empty string when the style is not provided' do
|
7
31
|
Esc.string.must_equal('')
|
@@ -16,53 +16,34 @@ module Vedeu
|
|
16
16
|
let(:interface) { 'dubnium' }
|
17
17
|
|
18
18
|
describe '.check' do
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
result.last.must_match(/by the system/)
|
24
|
-
end
|
19
|
+
it 'raises an exception when already in use as a system key' do
|
20
|
+
proc {
|
21
|
+
KeymapValidator.check(storage, :shift_tab, interface)
|
22
|
+
}.must_raise(KeyInUse)
|
25
23
|
end
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
result.last.must_match(/as a global key/)
|
32
|
-
end
|
25
|
+
it 'raises an exception when already in use as a global key' do
|
26
|
+
proc {
|
27
|
+
KeymapValidator.check(storage, 'g', interface)
|
28
|
+
}.must_raise(KeyInUse)
|
33
29
|
end
|
34
30
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
result.last.must_match(/by this interface/)
|
40
|
-
end
|
31
|
+
it 'raises an exception when already in use by the interface' do
|
32
|
+
proc {
|
33
|
+
KeymapValidator.check(storage, 'a', interface)
|
34
|
+
}.must_raise(KeyInUse)
|
41
35
|
end
|
42
36
|
|
43
|
-
|
44
|
-
|
45
|
-
it 'returns false with a message' do
|
46
|
-
result = KeymapValidator.check(storage, 'a', '')
|
47
|
-
result.must_include(false)
|
48
|
-
result.last.must_match(/therefore cannot be global/)
|
49
|
-
end
|
37
|
+
it 'raises an exception when already in use' do
|
38
|
+
proc { KeymapValidator.check(storage, 'a', '') }.must_raise(KeyInUse)
|
50
39
|
end
|
51
40
|
|
52
|
-
|
53
|
-
|
54
|
-
result = KeymapValidator.check(storage, 'h', '')
|
55
|
-
result.must_include(true)
|
56
|
-
result.last.must_match(/can be registered/)
|
57
|
-
end
|
41
|
+
it 'returns true when valid as a global key' do
|
42
|
+
KeymapValidator.check(storage, 'h', '').must_equal(true)
|
58
43
|
end
|
59
44
|
|
60
|
-
|
61
|
-
|
62
|
-
result = KeymapValidator.check(storage, 'b', 'dubnium')
|
63
|
-
result.must_include(true)
|
64
|
-
result.last.must_match(/can be registered/)
|
65
|
-
end
|
45
|
+
it 'returns true when valid as an interface key' do
|
46
|
+
KeymapValidator.check(storage, 'b', 'dubnium').must_equal(true)
|
66
47
|
end
|
67
48
|
end
|
68
49
|
|
@@ -73,7 +54,7 @@ module Vedeu
|
|
73
54
|
interface = ''
|
74
55
|
|
75
56
|
KeymapValidator.new(storage, key, interface)
|
76
|
-
|
57
|
+
.must_be_instance_of(KeymapValidator)
|
77
58
|
end
|
78
59
|
end
|
79
60
|
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Vedeu
|
4
|
+
EntityNotFound = Class.new(StandardError)
|
5
|
+
|
6
|
+
class RepositoryTestClass
|
7
|
+
include Repository
|
8
|
+
|
9
|
+
def in_memory
|
10
|
+
{}
|
11
|
+
end
|
12
|
+
alias_method :storage, :in_memory
|
13
|
+
|
14
|
+
def not_found(name)
|
15
|
+
fail EntityNotFound
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe Repository do
|
20
|
+
|
21
|
+
describe '#all' do
|
22
|
+
it 'returns a Hash' do
|
23
|
+
RepositoryTestClass.new.all.must_be_instance_of(Hash)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns the whole repository' do
|
27
|
+
RepositoryTestClass.new.all.must_equal({})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#find' do
|
32
|
+
it 'raises an exception when the entity cannot be found' do
|
33
|
+
proc { RepositoryTestClass.new.find('terbium') }
|
34
|
+
.must_raise(EntityNotFound)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#registered' do
|
39
|
+
it 'returns an Array' do
|
40
|
+
RepositoryTestClass.new.registered.must_be_instance_of(Array)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns a collection of the names of all the registered entities' do
|
44
|
+
RepositoryTestClass.new.registered.must_equal([])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe '#registered?' do
|
49
|
+
it 'returns a FalseClass' do
|
50
|
+
RepositoryTestClass.new.registered?('terbium')
|
51
|
+
.must_be_instance_of(FalseClass)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'returns false when the entity is not registered' do
|
55
|
+
RepositoryTestClass.new.registered?('terbium').must_equal(false)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#reset' do
|
60
|
+
it 'returns a Hash' do
|
61
|
+
RepositoryTestClass.new.reset.must_be_instance_of(Hash)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'resets the repository' do
|
65
|
+
RepositoryTestClass.new.reset.must_equal({})
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|