vedeu 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +0 -18
  3. data/lib/vedeu/output/colour.rb +18 -7
  4. data/lib/vedeu/output/compositor.rb +20 -8
  5. data/lib/vedeu/process/process.rb +1 -5
  6. data/lib/vedeu/repository/command.rb +12 -0
  7. data/lib/vedeu/repository/command_repository.rb +10 -2
  8. data/lib/vedeu/repository/dummy_command.rb +2 -0
  9. data/lib/vedeu/repository/dummy_interface.rb +3 -1
  10. data/lib/vedeu/repository/interface.rb +31 -4
  11. data/lib/vedeu/repository/interface_repository.rb +5 -1
  12. data/lib/vedeu/repository/storage.rb +1 -1
  13. data/lib/vedeu/support/terminal.rb +13 -3
  14. data/lib/vedeu/version.rb +1 -1
  15. data/test/lib/vedeu/application_test.rb +6 -2
  16. data/test/lib/vedeu/launcher_test.rb +3 -1
  17. data/test/lib/vedeu/output/background_test.rb +30 -10
  18. data/test/lib/vedeu/output/colour_test.rb +39 -2
  19. data/test/lib/vedeu/output/compositor_test.rb +48 -14
  20. data/test/lib/vedeu/output/directive_test.rb +24 -8
  21. data/test/lib/vedeu/output/esc_test.rb +48 -16
  22. data/test/lib/vedeu/output/foreground_test.rb +30 -10
  23. data/test/lib/vedeu/output/geometry_test.rb +78 -28
  24. data/test/lib/vedeu/output/position_test.rb +9 -3
  25. data/test/lib/vedeu/output/renderer_test.rb +15 -5
  26. data/test/lib/vedeu/output/style_test.rb +30 -10
  27. data/test/lib/vedeu/output/translator_test.rb +3 -1
  28. data/test/lib/vedeu/process/event_loop_test.rb +12 -4
  29. data/test/lib/vedeu/process/exit_test.rb +6 -2
  30. data/test/lib/vedeu/process/input_test.rb +9 -3
  31. data/test/lib/vedeu/process/output_test.rb +12 -4
  32. data/test/lib/vedeu/process/process_test.rb +24 -8
  33. data/test/lib/vedeu/process/queue_test.rb +32 -8
  34. data/test/lib/vedeu/repository/command_repository_test.rb +27 -9
  35. data/test/lib/vedeu/repository/command_test.rb +33 -9
  36. data/test/lib/vedeu/repository/dummy_command_test.rb +9 -3
  37. data/test/lib/vedeu/repository/interface_repository_test.rb +18 -6
  38. data/test/lib/vedeu/repository/interface_test.rb +39 -11
  39. data/test/lib/vedeu/repository/repository_test.rb +24 -8
  40. data/test/lib/vedeu/repository/storage_test.rb +39 -2
  41. data/test/lib/vedeu/support/terminal_test.rb +68 -16
  42. data/test/lib/vedeu/version_test.rb +3 -1
  43. data/test/test_helper.rb +3 -0
  44. data/vedeu.gemspec +13 -12
  45. metadata +45 -30
@@ -3,37 +3,59 @@ require_relative '../../../test_helper'
3
3
  module Vedeu
4
4
  describe Compositor do
5
5
  let(:described_class) { Compositor }
6
- let(:described_instance) { described_class.new(output) }
6
+ let(:described_instance) { described_class.new(output, interface) }
7
+ let(:subject) { described_instance }
7
8
  let(:output) { [[]] }
8
9
  let(:stream) { [] }
9
10
  let(:interface) { 'dummy' }
10
11
 
11
12
  before do
12
- @interface = Interface.create({ name: 'dummy' })
13
+ Interface.create({ name: 'dummy' })
14
+ Interface.create({ name: 'test_interface' })
13
15
  Renderer.stubs(:write).returns(stream)
14
16
  end
15
17
 
16
- it { described_instance.must_be_instance_of(Compositor) }
18
+ after do
19
+ InterfaceRepository.reset
20
+ end
21
+
22
+ it 'returns a Compositor instance' do
23
+ subject.must_be_instance_of(Compositor)
24
+ end
25
+
26
+ it 'sets an instance variable' do
27
+ subject.instance_variable_get("@output").must_equal([[]])
28
+ end
29
+
30
+ it 'sets an instance variable' do
31
+ subject.instance_variable_get("@interface").must_equal("dummy")
32
+ end
17
33
 
18
34
  describe '.arrange' do
19
- let(:subject) { described_class.arrange(output) }
35
+ let(:subject) { described_class.arrange(output, interface) }
20
36
 
21
37
  context 'when empty' do
22
38
  let(:output) { [] }
23
39
 
24
- it { subject.must_be_instance_of(NilClass) }
40
+ it 'returns a NilClass' do
41
+ subject.must_be_instance_of(NilClass)
42
+ end
25
43
  end
26
44
 
27
45
  context 'when an array (single interface)' do
28
46
  let(:output) { [[]] }
29
47
 
30
- it { subject.must_be_instance_of(Array) }
48
+ it 'returns an Array' do
49
+ subject.must_be_instance_of(Array)
50
+ end
31
51
  end
32
52
 
33
53
  context 'when a hash (multiple interfaces)' do
34
- let(:output) { { test_interface: [] } }
54
+ let(:output) { { 'test_interface' => [] } }
35
55
 
36
- it { subject.must_be_instance_of(Array) }
56
+ it 'returns an Array' do
57
+ subject.must_be_instance_of(Array)
58
+ end
37
59
  end
38
60
 
39
61
  context 'when unstyled' do
@@ -41,7 +63,9 @@ module Vedeu
41
63
  let(:output) { [['Some text...']] }
42
64
  let(:stream) { 'Some text...' }
43
65
 
44
- it { subject.must_equal(stream) }
66
+ it 'returns a String' do
67
+ subject.must_equal(stream)
68
+ end
45
69
  end
46
70
 
47
71
  context 'and multi-line' do
@@ -53,7 +77,9 @@ module Vedeu
53
77
  }
54
78
  let(:stream) { "Some text...\nSome more text..." }
55
79
 
56
- it { subject.must_equal(stream) }
80
+ it 'returns a String' do
81
+ subject.must_equal(stream)
82
+ end
57
83
  end
58
84
  end
59
85
 
@@ -67,7 +93,9 @@ module Vedeu
67
93
  }
68
94
  let(:stream) { "\e[38;5;31m\e[48;5;47mSome text..." }
69
95
 
70
- it { subject.must_equal(stream) }
96
+ it 'returns a String' do
97
+ subject.must_equal(stream)
98
+ end
71
99
  end
72
100
 
73
101
  context 'and multi-line' do
@@ -82,7 +110,9 @@ module Vedeu
82
110
  "\e[38;5;34m\e[48;5;43mSome more text..."
83
111
  }
84
112
 
85
- it { subject.must_equal(stream) }
113
+ it 'returns a String' do
114
+ subject.must_equal(stream)
115
+ end
86
116
  end
87
117
  end
88
118
 
@@ -97,7 +127,9 @@ module Vedeu
97
127
  "\e[1mSome text..."
98
128
  }
99
129
 
100
- it { subject.must_equal(stream) }
130
+ it 'returns a String' do
131
+ subject.must_equal(stream)
132
+ end
101
133
  end
102
134
 
103
135
  context 'and multi-line' do
@@ -112,7 +144,9 @@ module Vedeu
112
144
  "\e[4mSome more text..."
113
145
  }
114
146
 
115
- it { subject.must_equal(stream) }
147
+ it 'returns a String' do
148
+ subject.must_equal(stream)
149
+ end
116
150
  end
117
151
  end
118
152
 
@@ -15,41 +15,57 @@ module Vedeu
15
15
  let(:colour) { [] }
16
16
  let(:style) { [] }
17
17
 
18
- it { described_instance.must_be_instance_of(Directive) }
18
+ it 'returns a Directive instance' do
19
+ described_instance.must_be_instance_of(Directive)
20
+ end
19
21
 
20
22
  describe '.enact' do
21
23
  let(:subject) { described_class.enact(directives) }
22
24
 
23
- it { subject.must_be_instance_of(String) }
25
+ it 'returns a String' do
26
+ subject.must_be_instance_of(String)
27
+ end
24
28
 
25
29
  context 'when the position is not set' do
26
- it { subject.must_equal('') }
30
+ it 'returns an empty string' do
31
+ subject.must_equal('')
32
+ end
27
33
  end
28
34
 
29
35
  context 'when the position is set' do
30
36
  let(:position) { [4, 5] }
31
37
 
32
- it { subject.must_equal("\e[4;5H") }
38
+ it 'returns an escape sequence' do
39
+ subject.must_equal("\e[4;5H")
40
+ end
33
41
  end
34
42
 
35
43
  context 'when the colour is not set' do
36
- it { subject.must_equal('') }
44
+ it 'returns an empty string' do
45
+ subject.must_equal('')
46
+ end
37
47
  end
38
48
 
39
49
  context 'when the colour is set' do
40
50
  let(:colour) { [:red, :black] }
41
51
 
42
- it { subject.must_equal("\e[38;5;31m\e[48;5;40m") }
52
+ it 'returns an escape sequence' do
53
+ subject.must_equal("\e[38;5;31m\e[48;5;40m")
54
+ end
43
55
  end
44
56
 
45
57
  context 'when the style is not set' do
46
- it { subject.must_equal('') }
58
+ it 'returns an empty string' do
59
+ subject.must_equal('')
60
+ end
47
61
  end
48
62
 
49
63
  context 'when the style is set' do
50
64
  let(:style) { [:normal, :underline, :normal] }
51
65
 
52
- it { subject.must_equal("\e[0m\e[4m\e[0m") }
66
+ it 'returns an escape sequence' do
67
+ subject.must_equal("\e[0m\e[4m\e[0m")
68
+ end
53
69
  end
54
70
  end
55
71
  end
@@ -7,65 +7,97 @@ module Vedeu
7
7
  describe '.bold' do
8
8
  let(:subject) { described_class.bold }
9
9
 
10
- it { subject.must_be_instance_of(String) }
10
+ it 'returns a String' do
11
+ subject.must_be_instance_of(String)
12
+ end
11
13
 
12
- it { subject.must_equal("\e[1m") }
14
+ it 'returns an escape sequence' do
15
+ subject.must_equal("\e[1m")
16
+ end
13
17
  end
14
18
 
15
19
  describe '.clear' do
16
20
  let(:subject) { described_class.clear }
17
21
 
18
- it { subject.must_be_instance_of(String) }
22
+ it 'returns a String' do
23
+ subject.must_be_instance_of(String)
24
+ end
19
25
 
20
- it { subject.must_equal("\e[2J") }
26
+ it 'returns an escape sequence' do
27
+ subject.must_equal("\e[2J")
28
+ end
21
29
  end
22
30
 
23
31
  describe '.esc' do
24
32
  let(:subject) { described_class.esc }
25
33
 
26
- it { subject.must_be_instance_of(String) }
34
+ it 'returns a String' do
35
+ subject.must_be_instance_of(String)
36
+ end
27
37
 
28
- it { subject.must_equal("\e[") }
38
+ it 'returns an escape sequence' do
39
+ subject.must_equal("\e[")
40
+ end
29
41
  end
30
42
 
31
43
  describe '.hide_cursor' do
32
44
  let(:subject) { described_class.hide_cursor }
33
45
 
34
- it { subject.must_be_instance_of(String) }
46
+ it 'returns a String' do
47
+ subject.must_be_instance_of(String)
48
+ end
35
49
 
36
- it { subject.must_equal("\e[?25l") }
50
+ it 'returns an escape sequence' do
51
+ subject.must_equal("\e[?25l")
52
+ end
37
53
  end
38
54
 
39
55
  describe '.inverse' do
40
56
  let(:subject) { described_class.inverse }
41
57
 
42
- it { subject.must_be_instance_of(String) }
58
+ it 'returns a String' do
59
+ subject.must_be_instance_of(String)
60
+ end
43
61
 
44
- it { subject.must_equal("\e[7m") }
62
+ it 'returns an escape sequence' do
63
+ subject.must_equal("\e[7m")
64
+ end
45
65
  end
46
66
 
47
67
  describe '.reset' do
48
68
  let(:subject) { described_class.reset }
49
69
 
50
- it { subject.must_be_instance_of(String) }
70
+ it 'returns a String' do
71
+ subject.must_be_instance_of(String)
72
+ end
51
73
 
52
- it { subject.must_equal("\e[0m") }
74
+ it 'returns an escape sequence' do
75
+ subject.must_equal("\e[0m")
76
+ end
53
77
  end
54
78
 
55
79
  describe '.show_cursor' do
56
80
  let(:subject) { described_class.show_cursor }
57
81
 
58
- it { subject.must_be_instance_of(String) }
82
+ it 'returns a String' do
83
+ subject.must_be_instance_of(String)
84
+ end
59
85
 
60
- it { subject.must_equal("\e[?25h") }
86
+ it 'returns an escape sequence' do
87
+ subject.must_equal("\e[?25h")
88
+ end
61
89
  end
62
90
 
63
91
  describe '.underline' do
64
92
  let(:subject) { described_class.underline }
65
93
 
66
- it { subject.must_be_instance_of(String) }
94
+ it 'returns a String' do
95
+ subject.must_be_instance_of(String)
96
+ end
67
97
 
68
- it { subject.must_equal("\e[4m") }
98
+ it 'returns an escape sequence' do
99
+ subject.must_equal("\e[4m")
100
+ end
69
101
  end
70
102
  end
71
103
  end
@@ -6,41 +6,61 @@ module Vedeu
6
6
  let(:described_instance) { described_class.new(colour) }
7
7
  let(:colour) {}
8
8
 
9
- it { described_instance.must_be_instance_of(Foreground) }
9
+ it 'returns a Foreground instance' do
10
+ described_instance.must_be_instance_of(Foreground)
11
+ end
10
12
 
11
13
  describe '#escape_sequence' do
12
14
  let(:subject) { described_instance.escape_sequence }
13
15
 
14
- it { subject.must_be_instance_of(String) }
16
+ it 'returns a String' do
17
+ subject.must_be_instance_of(String)
18
+ end
15
19
 
16
20
  context 'with no colour' do
17
- it { subject.must_be_instance_of(String) }
21
+ it 'returns a String' do
22
+ subject.must_be_instance_of(String)
23
+ end
18
24
 
19
- it { subject.must_equal("\e[38;5;39m") }
25
+ it 'returns an escape sequence' do
26
+ subject.must_equal("\e[38;5;39m")
27
+ end
20
28
  end
21
29
 
22
30
  context 'with a named colour' do
23
31
  let(:colour) { :red }
24
32
 
25
- it { subject.must_be_instance_of(String) }
33
+ it 'returns a String' do
34
+ subject.must_be_instance_of(String)
35
+ end
26
36
 
27
- it { subject.must_equal("\e[38;5;31m") }
37
+ it 'returns an escape sequence' do
38
+ subject.must_equal("\e[38;5;31m")
39
+ end
28
40
  end
29
41
 
30
42
  context 'with a html colour' do
31
43
  let(:colour) { '#aadd00' }
32
44
 
33
- it { subject.must_be_instance_of(String) }
45
+ it 'returns a String' do
46
+ subject.must_be_instance_of(String)
47
+ end
34
48
 
35
- it { subject.must_equal("\e[38;5;148m") }
49
+ it 'returns an escape sequence' do
50
+ subject.must_equal("\e[38;5;148m")
51
+ end
36
52
  end
37
53
 
38
54
  context 'with a default colour' do
39
55
  let(:colour) { :undefined }
40
56
 
41
- it { subject.must_be_instance_of(String) }
57
+ it 'returns a String' do
58
+ subject.must_be_instance_of(String)
59
+ end
42
60
 
43
- it { subject.must_equal("\e[38;5;39m") }
61
+ it 'returns an escape sequence' do
62
+ subject.must_equal("\e[38;5;39m")
63
+ end
44
64
  end
45
65
  end
46
66
  end
@@ -11,104 +11,142 @@ module Vedeu
11
11
  Terminal.stubs(:height).returns(25)
12
12
  end
13
13
 
14
- it { described_instance.must_be_instance_of(Geometry) }
14
+ it 'returns a Geometry instance' do
15
+ described_instance.must_be_instance_of(Geometry)
16
+ end
15
17
 
16
18
  describe '#z' do
17
19
  let(:subject) { described_instance.z }
18
20
 
19
- it { subject.must_be_instance_of(Fixnum) }
21
+ it 'returns a Fixnum' do
22
+ subject.must_be_instance_of(Fixnum)
23
+ end
20
24
 
21
25
  context 'using a value' do
22
26
  let(:values) { { z: 2 } }
23
27
 
24
- it { subject.must_equal(2) }
28
+ it 'returns the value' do
29
+ subject.must_equal(2)
30
+ end
25
31
  end
26
32
 
27
33
  context 'using the default' do
28
- it { subject.must_equal(0) }
34
+ it 'returns the default' do
35
+ subject.must_equal(0)
36
+ end
29
37
  end
30
38
  end
31
39
 
32
40
  describe '#y' do
33
41
  let(:subject) { described_instance.y }
34
42
 
35
- it { subject.must_be_instance_of(Fixnum) }
43
+ it 'returns a Fixnum' do
44
+ subject.must_be_instance_of(Fixnum)
45
+ end
36
46
 
37
47
  context 'using a value' do
38
48
  let(:values) { { y: 17 } }
39
49
 
40
- it { subject.must_equal(17) }
50
+ it 'returns the value' do
51
+ subject.must_equal(17)
52
+ end
41
53
  end
42
54
 
43
55
  context 'using the default' do
44
- it { subject.must_equal(1) }
56
+ it 'returns the default' do
57
+ subject.must_equal(1)
58
+ end
45
59
  end
46
60
  end
47
61
 
48
62
  describe '#x' do
49
63
  let(:subject) { described_instance.x }
50
64
 
51
- it { subject.must_be_instance_of(Fixnum) }
65
+ it 'returns a Fixnum' do
66
+ subject.must_be_instance_of(Fixnum)
67
+ end
52
68
 
53
69
  context 'using a value' do
54
70
  let(:values) { { x: 33 } }
55
71
 
56
- it { subject.must_equal(33) }
72
+ it 'returns the value' do
73
+ subject.must_equal(33)
74
+ end
57
75
  end
58
76
 
59
77
  context 'using the default' do
60
- it { subject.must_equal(1) }
78
+ it 'return the default' do
79
+ subject.must_equal(1)
80
+ end
61
81
  end
62
82
  end
63
83
 
64
84
  describe '#width' do
65
85
  let(:subject) { described_instance.width }
66
86
 
67
- it { subject.must_be_instance_of(Fixnum) }
87
+ it 'returns a Fixnum' do
88
+ subject.must_be_instance_of(Fixnum)
89
+ end
68
90
 
69
91
  context 'using a value' do
70
92
  let(:values) { { width: 50 } }
71
93
 
72
- it { subject.must_equal(50) }
94
+ it 'returns the value' do
95
+ subject.must_equal(50)
96
+ end
73
97
  end
74
98
 
75
99
  context 'using :auto' do
76
100
  let(:values) { { width: :auto } }
77
101
 
78
- it { subject.must_equal(80) }
102
+ it 'returns the value' do
103
+ subject.must_equal(80)
104
+ end
79
105
  end
80
106
 
81
107
  context 'using the default' do
82
- it { subject.must_equal(80) }
108
+ it 'returns the default' do
109
+ subject.must_equal(80)
110
+ end
83
111
  end
84
112
  end
85
113
 
86
114
  describe '#height' do
87
115
  let(:subject) { described_instance.height }
88
116
 
89
- it { subject.must_be_instance_of(Fixnum) }
117
+ it 'returns a Fixnum' do
118
+ subject.must_be_instance_of(Fixnum)
119
+ end
90
120
 
91
121
  context 'using a value' do
92
122
  let(:values) { { height: 20 } }
93
123
 
94
- it { subject.must_equal(20) }
124
+ it 'returns the value' do
125
+ subject.must_equal(20)
126
+ end
95
127
  end
96
128
 
97
129
  context 'using :auto' do
98
130
  let(:values) { { height: :auto } }
99
131
 
100
- it { subject.must_equal(25) }
132
+ it 'returns the value' do
133
+ subject.must_equal(25)
134
+ end
101
135
  end
102
136
 
103
137
  context 'using the default' do
104
- it { subject.must_equal(25) }
138
+ it 'returns the default' do
139
+ subject.must_equal(25)
140
+ end
105
141
  end
106
142
  end
107
143
 
108
144
  describe '#dy' do
109
145
  let(:subject) { described_instance.dy }
110
146
 
111
- it { subject.must_be_instance_of(Fixnum) }
147
+ it 'returns a Fixnum' do
148
+ subject.must_be_instance_of(Fixnum)
149
+ end
112
150
 
113
151
  context 'when the value is greater than the available terminal size' do
114
152
  it 'clips the value to the terminal size' do
@@ -119,14 +157,18 @@ module Vedeu
119
157
  context 'when the value is less than the available size' do
120
158
  let(:values) { { y: 20, height: 4 } }
121
159
 
122
- it { subject.must_equal(24) }
160
+ it 'returns the value' do
161
+ subject.must_equal(24)
162
+ end
123
163
  end
124
164
  end
125
165
 
126
166
  describe '#dx' do
127
167
  let(:subject) { described_instance.dx }
128
168
 
129
- it { subject.must_be_instance_of(Fixnum) }
169
+ it 'returns a Fixnum' do
170
+ subject.must_be_instance_of(Fixnum)
171
+ end
130
172
 
131
173
  context 'when the value is greater than the available terminal size' do
132
174
  it 'clips the value to the terminal size' do
@@ -137,26 +179,34 @@ module Vedeu
137
179
  context 'when the value is less than the available size' do
138
180
  let(:values) { { x: 17, width: 21 } }
139
181
 
140
- it { subject.must_be_instance_of(Fixnum) }
141
-
142
- it { subject.must_equal(38) }
182
+ it 'returns the value' do
183
+ subject.must_equal(38)
184
+ end
143
185
  end
144
186
  end
145
187
 
146
188
  describe '#vx' do
147
189
  let(:subject) { described_instance.vx }
148
190
 
149
- it { subject.must_be_instance_of(Fixnum) }
191
+ it 'returns a Fixnum' do
192
+ subject.must_be_instance_of(Fixnum)
193
+ end
150
194
 
151
- it { subject.must_equal(1) }
195
+ it 'returns the value' do
196
+ subject.must_equal(1)
197
+ end
152
198
  end
153
199
 
154
200
  describe '#vy' do
155
201
  let(:subject) { described_instance.vy }
156
202
 
157
- it { subject.must_be_instance_of(Fixnum) }
203
+ it 'returns a Fixnum' do
204
+ subject.must_be_instance_of(Fixnum)
205
+ end
158
206
 
159
- it { subject.must_equal(1) }
207
+ it 'returns the value' do
208
+ subject.must_equal(1)
209
+ end
160
210
  end
161
211
  end
162
212
  end