vedeu 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/docs/events.md +6 -0
  3. data/examples/{cursor_app/cursor_app.rb → cursor_app.rb} +1 -1
  4. data/examples/{lines_app/lines_app.rb → lines_app.rb} +1 -1
  5. data/lib/vedeu.rb +48 -28
  6. data/lib/vedeu/api/api.rb +8 -95
  7. data/lib/vedeu/application.rb +6 -2
  8. data/lib/vedeu/{models → colours}/background.rb +1 -1
  9. data/lib/vedeu/{models → colours}/colour.rb +0 -0
  10. data/lib/vedeu/{models → colours}/foreground.rb +2 -2
  11. data/lib/vedeu/{support/colour_translator.rb → colours/translator.rb} +7 -7
  12. data/lib/vedeu/input/input.rb +13 -5
  13. data/lib/vedeu/models/geometry.rb +30 -2
  14. data/lib/vedeu/models/key.rb +39 -0
  15. data/lib/vedeu/output/compositor.rb +30 -76
  16. data/lib/vedeu/output/output.rb +74 -0
  17. data/lib/vedeu/output/viewport.rb +36 -44
  18. data/lib/vedeu/repositories/buffers.rb +5 -18
  19. data/lib/vedeu/repositories/cursors.rb +16 -8
  20. data/lib/vedeu/repositories/events.rb +96 -9
  21. data/lib/vedeu/repositories/focus.rb +21 -20
  22. data/lib/vedeu/repositories/groups.rb +3 -11
  23. data/lib/vedeu/repositories/interfaces.rb +6 -9
  24. data/lib/vedeu/repositories/keymaps.rb +8 -3
  25. data/lib/vedeu/repositories/menus.rb +6 -21
  26. data/lib/vedeu/{models → repositories/models}/buffer.rb +62 -28
  27. data/lib/vedeu/{models → repositories/models}/cursor.rb +8 -2
  28. data/lib/vedeu/{models → repositories/models}/event.rb +7 -0
  29. data/lib/vedeu/repositories/models/group.rb +56 -0
  30. data/lib/vedeu/{models → repositories/models}/interface.rb +6 -0
  31. data/lib/vedeu/{models → repositories/models}/keymap.rb +7 -1
  32. data/lib/vedeu/{models → repositories/models}/menu.rb +9 -0
  33. data/lib/vedeu/{models → repositories/models}/offset.rb +8 -1
  34. data/lib/vedeu/repositories/offsets.rb +17 -12
  35. data/lib/vedeu/support/bounding_area.rb +127 -0
  36. data/lib/vedeu/support/common.rb +8 -0
  37. data/lib/vedeu/support/exceptions.rb +2 -12
  38. data/lib/vedeu/support/model.rb +14 -0
  39. data/lib/vedeu/support/refresh.rb +8 -7
  40. data/lib/vedeu/support/registrar.rb +7 -1
  41. data/lib/vedeu/support/repository.rb +31 -10
  42. data/lib/vedeu/support/sentence.rb +67 -0
  43. data/lib/vedeu/support/terminal.rb +19 -0
  44. data/lib/vedeu/support/trace.rb +2 -5
  45. data/test/integration/api/api_test.rb +97 -0
  46. data/test/integration/api_dsl/dsl_api_test.rb +4 -0
  47. data/test/integration/api_dsl/dsl_composition_test.rb +4 -0
  48. data/test/integration/api_dsl/dsl_defined_test.rb +4 -0
  49. data/test/integration/api_dsl/dsl_helpers_test.rb +4 -0
  50. data/test/integration/api_dsl/dsl_interface_test.rb +4 -0
  51. data/test/integration/api_dsl/dsl_keymap.rb +4 -0
  52. data/test/integration/api_dsl/dsl_line_test.rb +4 -0
  53. data/test/integration/api_dsl/dsl_menu_test.rb +4 -0
  54. data/test/integration/api_dsl/dsl_stream_test.rb +138 -0
  55. data/test/lib/vedeu/api/api_test.rb +1 -25
  56. data/test/lib/vedeu/api/helpers_test.rb +0 -10
  57. data/test/lib/vedeu/{models → colours}/background_test.rb +0 -0
  58. data/test/lib/vedeu/{models → colours}/colour_test.rb +0 -0
  59. data/test/lib/vedeu/{models → colours}/foreground_test.rb +0 -0
  60. data/test/lib/vedeu/{support/colour_translator_test.rb → colours/translator_test.rb} +3 -3
  61. data/test/lib/vedeu/input/input_test.rb +16 -47
  62. data/test/lib/vedeu/models/geometry_test.rb +46 -0
  63. data/test/lib/vedeu/models/group_test.rb +99 -0
  64. data/test/lib/vedeu/models/key_test.rb +41 -0
  65. data/test/lib/vedeu/output/compositor_test.rb +25 -101
  66. data/test/lib/vedeu/output/output_test.rb +108 -0
  67. data/test/lib/vedeu/repositories/buffers_test.rb +0 -8
  68. data/test/lib/vedeu/repositories/cursors_test.rb +34 -0
  69. data/test/lib/vedeu/repositories/focus_test.rb +37 -28
  70. data/test/lib/vedeu/repositories/interfaces_test.rb +1 -1
  71. data/test/lib/vedeu/repositories/keymaps_test.rb +6 -20
  72. data/test/lib/vedeu/repositories/menus_test.rb +0 -6
  73. data/test/lib/vedeu/{models → repositories/models}/buffer_test.rb +24 -27
  74. data/test/lib/vedeu/{models → repositories/models}/cursor_test.rb +0 -0
  75. data/test/lib/vedeu/{models → repositories/models}/event_test.rb +0 -0
  76. data/test/lib/vedeu/{models → repositories/models}/interface_test.rb +0 -0
  77. data/test/lib/vedeu/{models → repositories/models}/keymap_test.rb +0 -0
  78. data/test/lib/vedeu/{models → repositories/models}/menu_test.rb +0 -0
  79. data/test/lib/vedeu/{models → repositories/models}/offset_test.rb +0 -0
  80. data/test/lib/vedeu/support/bounding_area_test.rb +139 -0
  81. data/test/lib/vedeu/support/coercions_test.rb +6 -17
  82. data/test/lib/vedeu/support/grid_test.rb +1 -1
  83. data/test/lib/vedeu/support/model_test.rb +23 -0
  84. data/test/lib/vedeu/support/presentation_test.rb +0 -10
  85. data/test/lib/vedeu/support/refresh_test.rb +2 -2
  86. data/test/lib/vedeu/support/repository_test.rb +63 -64
  87. data/test/lib/vedeu/support/sentence_test.rb +48 -0
  88. data/test/lib/vedeu/support/terminal_test.rb +86 -6
  89. data/test/support/test_classes/all.rb +5 -0
  90. data/test/support/test_classes/coercions.rb +16 -0
  91. data/test/support/test_classes/helpers.rb +19 -0
  92. data/test/support/test_classes/model.rb +23 -0
  93. data/test/support/test_classes/presentation.rb +16 -0
  94. data/test/support/test_classes/repositories.rb +26 -0
  95. data/test/support/test_modules/all.rb +1 -0
  96. data/test/support/test_modules/repository.rb +16 -0
  97. data/test/test_helper.rb +4 -0
  98. data/vedeu.gemspec +3 -3
  99. metadata +95 -50
  100. data/lib/vedeu/output/clear.rb +0 -88
  101. data/lib/vedeu/output/render.rb +0 -50
  102. data/lib/vedeu/repositories/positional.rb +0 -23
  103. data/test/lib/vedeu/output/clear_test.rb +0 -56
  104. data/test/lib/vedeu/output/render_test.rb +0 -100
  105. data/test/lib/vedeu/repositories/positional_test.rb +0 -50
@@ -31,7 +31,7 @@ module Vedeu
31
31
 
32
32
  context 'when the interface cannot be found' do
33
33
  it 'raises an exception' do
34
- proc { Interfaces.build('manganese') }.must_raise(InterfaceNotFound)
34
+ proc { Interfaces.build('manganese') }.must_raise(ModelNotFound)
35
35
  end
36
36
  end
37
37
  end
@@ -4,9 +4,9 @@ module Vedeu
4
4
 
5
5
  describe Keymaps do
6
6
 
7
- describe '#add' do
8
- before { Keymaps.reset }
7
+ before { Keymaps.reset }
9
8
 
9
+ describe '#add' do
10
10
  it 'returns false when there are no keys defined' do
11
11
  attributes = {}
12
12
 
@@ -28,10 +28,7 @@ module Vedeu
28
28
  }
29
29
  }
30
30
 
31
- before do
32
- Keymaps.reset
33
- Keymaps.add(attributes)
34
- end
31
+ before { Keymaps.add(attributes) }
35
32
 
36
33
  it 'returns false when the named keymap cannot be found' do
37
34
  Keymaps.find('vanadium').must_equal({})
@@ -43,10 +40,7 @@ module Vedeu
43
40
  end
44
41
 
45
42
  describe '#global_key?' do
46
- before do
47
- Keymaps.reset
48
- Keymaps.stubs(:global_keys).returns(['i', 'j'])
49
- end
43
+ before { Keymaps.stubs(:global_keys).returns(['i', 'j']) }
50
44
 
51
45
  it 'returns false when the key is not registered as a global key' do
52
46
  Keymaps.global_key?('h').must_equal(false)
@@ -72,10 +66,7 @@ module Vedeu
72
66
  }
73
67
  }
74
68
 
75
- before do
76
- Keymaps.reset
77
- Keymaps.add(attributes)
78
- end
69
+ before { Keymaps.add(attributes) }
79
70
 
80
71
  it 'returns the defined global keys' do
81
72
  Keymaps.global_keys.must_equal(['a', 'b', 'c'])
@@ -83,10 +74,7 @@ module Vedeu
83
74
  end
84
75
 
85
76
  describe '#interface_key?' do
86
- before do
87
- Keymaps.reset
88
- Keymaps.stubs(:interface_keys).returns(['g', 'h'])
89
- end
77
+ before { Keymaps.stubs(:interface_keys).returns(['g', 'h']) }
90
78
 
91
79
  it 'returns false when the key is not registered with an interface' do
92
80
  Keymaps.interface_key?('f').must_equal(false)
@@ -140,7 +128,6 @@ module Vedeu
140
128
  }
141
129
 
142
130
  before do
143
- Keymaps.reset
144
131
  Keymaps.add(rhodium_attributes)
145
132
  Keymaps.add(magnesium_attributes)
146
133
  end
@@ -198,7 +185,6 @@ module Vedeu
198
185
  }
199
186
 
200
187
  before do
201
- Keymaps.reset
202
188
  Keymaps.add(meitnerium_attributes)
203
189
  Keymaps.add(global_attributes)
204
190
  Vedeu::Focus.stubs(:current).returns('meitnerium')
@@ -15,12 +15,6 @@ module Vedeu
15
15
  Vedeu::Menu.stubs(:new).returns(instance)
16
16
  end
17
17
 
18
- it 'raises an exception when triggered with an unregistered name' do
19
- proc {
20
- Vedeu.trigger(:_menu_current_, 'unknown')
21
- }.must_raise(MenuNotFound)
22
- end
23
-
24
18
  it '_menu_current_' do
25
19
  Vedeu.trigger(:_menu_current_, 'elements').must_equal(:sulphur)
26
20
  end
@@ -52,71 +52,68 @@ module Vedeu
52
52
  it { subject.must_be_instance_of(Hash) }
53
53
  end
54
54
 
55
- describe '#back?' do
56
- subject { Buffer.new(attributes).back? }
55
+ describe '#content' do
56
+ subject { Buffer.new(attributes).content }
57
57
 
58
58
  context 'when there is content on the back buffer' do
59
59
  let(:back) { { lines: [{ streams: [{ text: 'back' }] }] } }
60
+ let(:buffer) { :back }
60
61
 
61
- it { subject.must_equal(true) }
62
+ it { subject.must_equal([{}, back]) }
62
63
  end
63
64
 
64
65
  context 'when there is no content on the back buffer' do
65
- it { subject.must_equal(false) }
66
+ let(:buffer) { :back }
67
+
68
+ it { subject.must_equal([{}]) }
66
69
  end
67
70
 
68
71
  context 'when there is no content on the back buffer' do
69
72
  let(:back) { { lines: [] } }
73
+ let(:buffer) { :back }
70
74
 
71
- it { subject.must_equal(false) }
75
+ it { subject.must_equal([{}]) }
72
76
  end
73
- end
74
-
75
- describe '#front?' do
76
- subject { Buffer.new(attributes).front? }
77
77
 
78
78
  context 'when there is content on the front buffer' do
79
+ let(:buffer) { :front }
79
80
  let(:front) { { lines: [{ streams: [{ text: 'front' }] }] } }
80
81
 
81
- it { subject.must_equal(true) }
82
+ it { subject.must_equal([front]) }
82
83
  end
83
84
 
84
85
  context 'when there is no content on the front buffer' do
85
- it { subject.must_equal(false) }
86
+ let(:buffer) { :front }
87
+
88
+ it { subject.must_equal([{}]) }
86
89
  end
87
90
 
88
91
  context 'when there is no content on the front buffer' do
89
- let(:front) { { lines: [] } }
90
-
91
- it { subject.must_equal(false) }
92
- end
92
+ let(:buffer) { :front }
93
93
 
94
- context 'alias method: #current?' do
95
- subject { Buffer.new(attributes).current? }
94
+ let(:front) { { lines: [] } }
96
95
 
97
- context 'when there is no content on the front buffer' do
98
- it { subject.must_equal(false) }
99
- end
96
+ it { subject.must_equal([{}]) }
100
97
  end
101
- end
102
-
103
- describe '#previous?' do
104
- subject { Buffer.new(attributes).previous? }
105
98
 
106
99
  context 'when there is content on the previous buffer' do
100
+ let(:buffer) { :previous }
107
101
  let(:previous) { { lines: [{ streams: [{ text: 'previous' }] }] } }
108
102
 
109
- it { subject.must_equal(true) }
103
+ it { subject.must_equal([previous]) }
110
104
  end
111
105
 
112
106
  context 'when there is no content on the previous buffer' do
113
- it { subject.must_equal(false) }
107
+ let(:buffer) { :previous }
108
+
109
+ it { subject.must_equal([{}]) }
114
110
  end
115
111
 
116
112
  context 'when there is no content on the previous buffer' do
113
+ let(:buffer) { :previous }
117
114
  let(:previous) { { lines: [] } }
118
115
 
119
- it { subject.must_equal(false) }
116
+ it { subject.must_equal([{}]) }
120
117
  end
121
118
  end
122
119
 
@@ -0,0 +1,139 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe BoundingArea do
6
+
7
+ let(:height) { 15 }
8
+ let(:width) { 40 }
9
+ let(:described_instance) { BoundingArea.new(height, width) }
10
+
11
+ describe '#initialize' do
12
+ it 'returns an instance of itself' do
13
+ described_instance.must_be_instance_of(BoundingArea)
14
+ end
15
+
16
+ it 'assigns the height' do
17
+ described_instance.instance_variable_get("@height").must_equal(height)
18
+ end
19
+
20
+ it 'assigns the width' do
21
+ described_instance.instance_variable_get("@width").must_equal(width)
22
+ end
23
+ end
24
+
25
+ describe '#height' do
26
+ it 'returns the height' do
27
+ described_instance.height.must_equal(height)
28
+ end
29
+ end
30
+
31
+ describe '#width' do
32
+ it 'returns the width' do
33
+ described_instance.width.must_equal(width)
34
+ end
35
+ end
36
+
37
+ describe '#top' do
38
+ context 'when an offset is provided' do
39
+ it 'returns the new top with the offset applied' do
40
+ described_instance.top(5).must_equal(6)
41
+ end
42
+
43
+ context 'when the offset is greater or equal to the height' do
44
+ it 'returns the height' do
45
+ described_instance.top(20).must_equal(15)
46
+ end
47
+ end
48
+
49
+ context 'when the offset is less than or equal to 1' do
50
+ it { described_instance.top(-1).must_equal(1) }
51
+ end
52
+ end
53
+
54
+ context 'when an offset is not provided' do
55
+ it { described_instance.top.must_equal(1) }
56
+ end
57
+
58
+ context 'alias_method #y' do
59
+ it { described_instance.y.must_equal(1) }
60
+ end
61
+ end
62
+
63
+ describe '#bottom' do
64
+ context 'when an offset is provided' do
65
+ it 'returns the new bottom with the offset applied' do
66
+ described_instance.bottom(5).must_equal(10)
67
+ end
68
+
69
+ context 'when the offset is greater or equal to the height' do
70
+ it { described_instance.bottom(30).must_equal(1) }
71
+ end
72
+
73
+ context 'when the offset is less than 0' do
74
+ it { described_instance.bottom(-1).must_equal(height) }
75
+ end
76
+ end
77
+
78
+ context 'when an offset is not provided' do
79
+ it { described_instance.bottom.must_equal(15) }
80
+ end
81
+
82
+ context 'alias_method #yn' do
83
+ it { described_instance.yn.must_equal(15) }
84
+ end
85
+ end
86
+
87
+ describe '#left' do
88
+ context 'when an offset is provided' do
89
+ it 'returns the new left with the offset applied' do
90
+ described_instance.left(5).must_equal(6)
91
+ end
92
+
93
+ context 'when the offset is greater or equal to the width' do
94
+ it 'returns the width' do
95
+ described_instance.left(50).must_equal(40)
96
+ end
97
+ end
98
+
99
+ context 'when the offset is less than or equal to 1' do
100
+ it { described_instance.left(-1).must_equal(1) }
101
+ end
102
+ end
103
+
104
+ context 'when an offset is not provided' do
105
+ it { described_instance.left.must_equal(1) }
106
+ end
107
+
108
+ context 'alias_method #x' do
109
+ it { described_instance.x.must_equal(1) }
110
+ end
111
+ end
112
+
113
+ describe '#right' do
114
+ context 'when an offset is provided' do
115
+ it 'returns the new right with the offset applied' do
116
+ described_instance.right(5).must_equal(35)
117
+ end
118
+
119
+ context 'when the offset is greater or equal to the width' do
120
+ it { described_instance.right(50).must_equal(1) }
121
+ end
122
+
123
+ context 'when the offset is less than 0' do
124
+ it { described_instance.right(-1).must_equal(40) }
125
+ end
126
+ end
127
+
128
+ context 'when an offset is not provided' do
129
+ it { described_instance.right.must_equal(40) }
130
+ end
131
+
132
+ context 'alias_method #xn' do
133
+ it { described_instance.xn.must_equal(40) }
134
+ end
135
+ end
136
+
137
+ end # BoundingArea
138
+
139
+ end # Vedeu
@@ -2,40 +2,29 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- class TestClass
6
- include Coercions
7
-
8
- attr_reader :attributes
9
-
10
- def initialize(attributes = {})
11
- @attributes = attributes
12
- @name = attributes[:name]
13
- end
14
- end # TestClass
15
-
16
5
  describe Coercions do
17
6
 
18
7
  describe '.coercer' do
19
8
  [nil, [], {}].each do |empty_value|
20
9
  it 'returns an empty collection when nil or empty' do
21
- TestClass.coercer(empty_value).must_equal([])
10
+ CoercionsTestClass.coercer(empty_value).must_equal([])
22
11
  end
23
12
  end
24
13
 
25
14
  it 'returns when an object' do
26
- klass = TestClass.new
15
+ klass = CoercionsTestClass.new
27
16
 
28
- TestClass.coercer([klass]).must_equal([klass])
17
+ CoercionsTestClass.coercer([klass]).must_equal([klass])
29
18
  end
30
19
 
31
20
  it 'returns a collection of models when a single hash' do
32
- coerced = TestClass.coercer({ :name => 'test1' })
21
+ coerced = CoercionsTestClass.coercer({ :name => 'test1' })
33
22
  coerced.must_be_instance_of(Array)
34
23
  coerced.first.attributes.must_equal({ name: "test1" })
35
24
  end
36
25
 
37
26
  it 'returns a collection of models when multiple hashes' do
38
- coerced = TestClass.coercer([
27
+ coerced = CoercionsTestClass.coercer([
39
28
  { :name => 'test1' }, { :name => 'test2' }
40
29
  ])
41
30
  coerced.size.must_equal(2)
@@ -45,7 +34,7 @@ module Vedeu
45
34
  end
46
35
 
47
36
  it 'returns a collection of models when a single array' do
48
- coerced = TestClass.coercer([{ :name => 'test3' }])
37
+ coerced = CoercionsTestClass.coercer([{ :name => 'test3' }])
49
38
  coerced.size.must_equal(1)
50
39
  coerced.first.attributes.must_equal({ name: "test3" })
51
40
  end
@@ -34,4 +34,4 @@ module Vedeu
34
34
 
35
35
  end # Grid
36
36
 
37
- end # Vedeu
37
+ end # Vedeu
@@ -0,0 +1,23 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe Model do
6
+
7
+ describe '#store' do
8
+ let(:attributes) {
9
+ {
10
+ name: 'hydrogen'
11
+ }
12
+ }
13
+
14
+ subject { ModelTestClass.new(attributes).store }
15
+
16
+ it 'returns the model' do
17
+ subject.must_be_instance_of(ModelTestClass)
18
+ end
19
+ end
20
+
21
+ end # Model
22
+
23
+ end # Vedeu
@@ -1,16 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
3
  module Vedeu
4
- class PresentationTestClass
5
- include Presentation
6
-
7
- def attributes
8
- {
9
- colour: { background: '#000033', foreground: '#aadd00' },
10
- style: ['bold']
11
- }
12
- end
13
- end # PresentationTestClass
14
4
 
15
5
  describe Presentation do
16
6