vedeu 0.0.30 → 0.0.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +4 -4
  3. data/lib/vedeu/configuration.rb +2 -2
  4. data/lib/vedeu/launcher.rb +2 -2
  5. data/lib/vedeu/models/command.rb +1 -1
  6. data/lib/vedeu/models/interface.rb +4 -0
  7. data/lib/vedeu/output/interface_renderer.rb +1 -1
  8. data/lib/vedeu/output/template.rb +23 -0
  9. data/lib/vedeu/output/text_adaptor.rb +1 -1
  10. data/lib/vedeu/process/process.rb +5 -1
  11. data/lib/vedeu/repository/command_repository.rb +3 -5
  12. data/lib/vedeu/repository/event_repository.rb +27 -0
  13. data/lib/vedeu/repository/interface_repository.rb +8 -6
  14. data/lib/vedeu/repository/storage.rb +2 -0
  15. data/lib/vedeu/support/esc.rb +2 -1
  16. data/lib/vedeu/support/geometry.rb +11 -23
  17. data/lib/vedeu/support/parser.rb +1 -1
  18. data/lib/vedeu/support/queue.rb +3 -1
  19. data/lib/vedeu.rb +18 -1
  20. data/test/example_app/bin/app +9 -0
  21. data/test/example_app/lib/app.rb +63 -0
  22. data/test/lib/vedeu/application_test.rb +6 -36
  23. data/test/lib/vedeu/configuration_test.rb +5 -31
  24. data/test/lib/vedeu/input/input_test.rb +4 -16
  25. data/test/lib/vedeu/launcher_test.rb +6 -15
  26. data/test/lib/vedeu/models/background_test.rb +5 -21
  27. data/test/lib/vedeu/models/colour_test.rb +18 -49
  28. data/test/lib/vedeu/models/command_test.rb +19 -83
  29. data/test/lib/vedeu/models/composition_test.rb +78 -175
  30. data/test/lib/vedeu/models/foreground_test.rb +4 -21
  31. data/test/lib/vedeu/models/interface_collection_test.rb +13 -45
  32. data/test/lib/vedeu/models/interface_test.rb +71 -195
  33. data/test/lib/vedeu/models/line_collection_test.rb +13 -52
  34. data/test/lib/vedeu/models/line_test.rb +17 -61
  35. data/test/lib/vedeu/models/presentation_test.rb +6 -19
  36. data/test/lib/vedeu/models/stream_collection_test.rb +10 -42
  37. data/test/lib/vedeu/models/stream_test.rb +16 -54
  38. data/test/lib/vedeu/models/style_collection_test.rb +1 -10
  39. data/test/lib/vedeu/output/interface_renderer_test.rb +7 -38
  40. data/test/lib/vedeu/output/output_test.rb +1 -18
  41. data/test/lib/vedeu/output/template.rb +20 -0
  42. data/test/lib/vedeu/output/text_adaptor_test.rb +9 -46
  43. data/test/lib/vedeu/process/process_test.rb +36 -38
  44. data/test/lib/vedeu/repository/command_repository_test.rb +16 -45
  45. data/test/lib/vedeu/repository/interface_repository_test.rb +36 -74
  46. data/test/lib/vedeu/repository/repository_test.rb +9 -33
  47. data/test/lib/vedeu/repository/storage_test.rb +7 -42
  48. data/test/lib/vedeu/support/esc_test.rb +46 -130
  49. data/test/lib/vedeu/support/event_repository_test.rb +31 -0
  50. data/test/lib/vedeu/support/exit_test.rb +1 -9
  51. data/test/lib/vedeu/support/geometry_test.rb +81 -105
  52. data/test/lib/vedeu/support/parser_test.rb +10 -54
  53. data/test/lib/vedeu/support/parsing/hash_parser_test.rb +18 -33
  54. data/test/lib/vedeu/support/parsing/json_parser_test.rb +4 -23
  55. data/test/lib/vedeu/support/queue_test.rb +33 -57
  56. data/test/lib/vedeu/support/terminal_test.rb +21 -52
  57. data/test/lib/vedeu/support/translator_test.rb +16 -33
  58. data/test/lib/vedeu/support/wordwrap_test.rb +29 -46
  59. data/test/lib/vedeu_test.rb +3 -5
  60. data/test/support/template.erb +3 -0
  61. data/test/test_helper.rb +1 -12
  62. data/vedeu.gemspec +8 -10
  63. metadata +26 -38
  64. data/lib/vedeu/support/events.rb +0 -21
  65. data/lib/vedeu/version.rb +0 -3
  66. data/test/lib/vedeu/support/events_test.rb +0 -45
  67. data/test/lib/vedeu/version_test.rb +0 -12
  68. data/test/support/output_1.json +0 -9
  69. data/test/support/output_1.rb +0 -14
@@ -17,66 +17,42 @@ module Vedeu
17
17
  end
18
18
 
19
19
  describe Repository do
20
- let(:described_class) { DummyRepository }
21
-
22
- before do
23
- @dummy = DummyRepository.create(Dummy.new)
24
- end
25
-
26
- after do
27
- DummyRepository.reset
28
- end
29
-
30
20
  describe '#adaptor' do
31
- let(:subject) { described_class.adaptor }
32
-
33
21
  it 'returns a Storage' do
34
- subject.must_be_instance_of(Storage)
22
+ DummyRepository.adaptor.must_be_instance_of(Storage)
35
23
  end
36
24
  end
37
25
 
38
26
  describe '#find' do
39
- let(:subject) { described_class.find(record_name) }
40
- let(:record_name) { @dummy.name }
41
-
42
27
  it 'returns a Dummy' do
43
- subject.must_be_instance_of(Dummy)
28
+ dummy = DummyRepository.create(Dummy.new)
29
+ DummyRepository.find(dummy.name).must_be_instance_of(Dummy)
44
30
  end
45
31
  end
46
32
 
47
33
  describe '#all' do
48
- let(:subject) { described_class.all }
49
-
50
34
  it 'returns all the stored items' do
51
- subject.must_be_instance_of(Array)
35
+ DummyRepository.all.must_be_instance_of(Array)
52
36
  end
53
37
  end
54
38
 
55
39
  describe '#query' do
56
- let(:subject) { described_class.query(entity, attribute, value) }
57
- let(:entity) { Dummy }
58
- let(:attribute) { :name }
59
- let(:value) { 'dummy' }
60
-
61
40
  it 'returns a Dummy' do
62
- subject.must_be_instance_of(Dummy)
41
+ dummy = DummyRepository.create(Dummy.new)
42
+ DummyRepository.query(Dummy, :name, 'dummy').must_be_instance_of(Dummy)
63
43
  end
64
44
  end
65
45
 
66
46
  describe '#create' do
67
- let(:subject) { described_class.create(model) }
68
- let(:model) { @dummy }
69
-
70
47
  it 'returns a Dummy' do
71
- subject.must_be_instance_of(Dummy)
48
+ dummy = DummyRepository.create(Dummy.new)
49
+ DummyRepository.create(dummy).must_be_instance_of(Dummy)
72
50
  end
73
51
  end
74
52
 
75
53
  describe '#reset' do
76
- let(:subject) { described_class.reset }
77
-
78
54
  it 'returns an Array' do
79
- subject.must_be_instance_of(Array)
55
+ DummyRepository.reset.must_be_instance_of(Array)
80
56
  end
81
57
  end
82
58
  end
@@ -2,76 +2,41 @@ require_relative '../../../test_helper'
2
2
  require_relative '../../../support/dummy_command'
3
3
  require_relative '../../../../lib/vedeu/repository/storage'
4
4
 
5
-
6
5
  module Vedeu
7
6
  describe Storage do
8
- let(:described_class) { Storage }
9
- let(:subject) { described_class.new }
10
- let(:record) { DummyCommand.new }
11
- let(:entity) {}
12
-
13
- describe '#initialize' do
14
- let(:subject) { described_class.new }
15
-
16
- it 'returns a Storage instance' do
17
- subject.must_be_instance_of(Storage)
18
- end
19
-
20
- it 'sets an instance variable' do
21
- subject.instance_variable_get('@map').must_equal({})
22
- end
23
- end
24
-
25
7
  describe '#create' do
26
- let(:subject) { described_class.new.create(record) }
27
-
28
8
  it 'returns the stored record' do
29
- subject.must_be_instance_of(DummyCommand)
9
+ Storage.new.create(DummyCommand.new).must_be_instance_of(DummyCommand)
30
10
  end
31
11
  end
32
12
 
33
13
  describe '#delete' do
34
- let(:subject) { described_class.new.delete(record) }
35
-
36
14
  it 'returns a NilClass' do
37
- subject.must_be_instance_of(NilClass)
15
+ Storage.new.delete(DummyCommand.new).must_be_instance_of(NilClass)
38
16
  end
39
17
  end
40
18
 
41
19
  describe '#reset' do
42
- let(:subject) { described_class.new.reset(entity) }
43
-
44
20
  it 'returns an Array' do
45
- subject.must_be_instance_of(Array)
21
+ Storage.new.reset(nil).must_be_instance_of(Array)
46
22
  end
47
23
  end
48
24
 
49
25
  describe '#find' do
50
- let(:subject) { described_class.new.find(entity, record_name) }
51
- let(:record_name) { 'dummy' }
52
-
53
26
  it 'returns a NilClass' do
54
- subject.must_be_instance_of(NilClass)
27
+ Storage.new.find(nil, 'dummy').must_be_instance_of(NilClass)
55
28
  end
56
29
  end
57
30
 
58
31
  describe '#all' do
59
- let(:subject) { described_class.new.all(entity) }
60
-
61
32
  it 'returns an Array' do
62
- subject.must_be_instance_of(Array)
33
+ Storage.new.all(nil).must_be_instance_of(Array)
63
34
  end
64
35
  end
65
36
 
66
37
  describe '#query' do
67
- let(:subject) { described_class.new.query(entity, attribute, value) }
68
- let(:attribute) {}
69
- let(:value) {}
70
-
71
- context 'when the item cannot be found' do
72
- it 'returns a NilClass' do
73
- subject.must_be_instance_of(NilClass)
74
- end
38
+ it 'returns a FalseClass when the item cannot be found' do
39
+ Storage.new.query(nil, nil, nil).must_be_instance_of(FalseClass)
75
40
  end
76
41
  end
77
42
  end
@@ -3,189 +3,105 @@ require_relative '../../../../lib/vedeu/support/esc'
3
3
 
4
4
  module Vedeu
5
5
  describe Esc do
6
- let(:described_class) { Esc }
7
-
8
6
  describe '.background_colour' do
9
- let(:subject) { described_class.background_colour }
10
-
11
- it 'returns a String' do
12
- subject.must_be_instance_of(String)
13
- end
14
-
15
7
  it 'returns an escape sequence' do
16
- subject.must_equal("\e[48;5;16m")
8
+ Esc.background_colour.must_equal("\e[48;5;16m")
17
9
  end
18
10
  end
19
11
 
20
12
  describe '.clear_line' do
21
- let(:subject) { described_class.clear_line }
22
-
23
- it 'returns a String' do
24
- subject.must_be_instance_of(String)
25
- end
26
-
27
13
  it 'returns an escape sequence' do
28
- subject.must_equal("\e[2K")
14
+ Esc.clear_line.must_equal("\e[2K")
29
15
  end
30
16
  end
31
17
 
32
- describe '.foreground_colour' do
33
- let(:subject) { described_class.foreground_colour }
34
-
35
- it 'returns a String' do
36
- subject.must_be_instance_of(String)
18
+ describe '.clear_last_line' do
19
+ it 'returns an escape sequence to clear the last line' do
20
+ IO.console.stub :winsize, [25, 25] do
21
+ Esc.clear_last_line.must_equal("\e[24;1H\e[2K")
22
+ end
37
23
  end
24
+ end
38
25
 
26
+ describe '.foreground_colour' do
39
27
  it 'returns an escape sequence' do
40
- subject.must_equal("\e[38;5;231m")
28
+ Esc.foreground_colour.must_equal("\e[38;5;231m")
41
29
  end
42
30
  end
43
31
 
44
32
  describe '.set_position' do
45
- let(:subject) { described_class.set_position(y, x) }
46
- let(:y) {}
47
- let(:x) {}
48
-
49
- context 'when no coordinates are provided' do
50
- it 'returns a position escape sequence' do
51
- subject.must_equal("\e[1;1H")
52
- end
33
+ it 'returns a position escape sequence when no coordinates are provided' do
34
+ Esc.set_position.must_equal("\e[1;1H")
53
35
  end
54
36
 
55
- context 'when coordinates are provided' do
56
- let(:y) { 12 }
57
- let(:x) { 19 }
58
-
59
- it 'returns a position escape sequence' do
60
- subject.must_equal("\e[12;19H")
61
- end
37
+ it 'returns a position escape sequence when coordinates are provided' do
38
+ Esc.set_position(12, 19).must_equal("\e[12;19H")
62
39
  end
63
40
  end
64
41
 
65
42
  describe '.string' do
66
- let(:subject) { described_class.string(style) }
67
- let(:style) {}
68
-
69
- it 'returns a String' do
70
- subject.must_be_instance_of(String)
43
+ it 'returns an empty string when the style is not provided' do
44
+ Esc.string.must_equal('')
71
45
  end
72
46
 
73
- context 'when the style is not provided' do
74
- it 'returns an empty string' do
75
- subject.must_equal('')
76
- end
47
+ it 'returns an escape sequence when the style is blink' do
48
+ Esc.string('blink').must_equal("\e[5m")
77
49
  end
78
50
 
79
- context 'when the style is blink' do
80
- let(:style) { 'blink' }
81
-
82
- it 'returns an escape sequence' do
83
- subject.must_equal("\e[5m")
84
- end
51
+ it 'returns an escape sequence when the style is blink off' do
52
+ Esc.string('blink_off').must_equal("\e[25m")
85
53
  end
86
54
 
87
- context 'when the style is blink off' do
88
- let(:style) { 'blink_off' }
89
-
90
- it 'returns an escape sequence' do
91
- subject.must_equal("\e[25m")
92
- end
55
+ it 'returns an escape sequence when the style is bold' do
56
+ Esc.string('bold').must_equal("\e[1m")
93
57
  end
94
58
 
95
- context 'when the style is bold' do
96
- let(:style) { 'bold' }
97
-
98
- it 'returns an escape sequence' do
99
- subject.must_equal("\e[1m")
100
- end
59
+ it 'returns an escape sequence when the style is bold off' do
60
+ Esc.string('bold_off').must_equal("\e[21m")
101
61
  end
102
62
 
103
- context 'when the style is bold off' do
104
- let(:style) { 'bold_off' }
105
-
106
- it 'returns an escape sequence' do
107
- subject.must_equal("\e[21m")
108
- end
63
+ it 'returns an escape sequence when the style is clear' do
64
+ Esc.string('clear').must_equal("\e[2J")
109
65
  end
110
66
 
111
- context 'when the style is clear' do
112
- let(:style) { 'clear' }
113
-
114
- it 'returns an escape sequence' do
115
- subject.must_equal("\e[2J")
116
- end
67
+ it 'returns an escape sequence when the style is colour_reset' do
68
+ Esc.string('colour_reset').must_equal("\e[38;2;39m\e[48;2;49m")
117
69
  end
118
70
 
119
- context 'when the style is hide_cursor' do
120
- let(:style) { 'hide_cursor' }
121
-
122
- it 'returns an escape sequence' do
123
- subject.must_equal("\e[?25l")
124
- end
71
+ it 'returns an escape sequence when the style is hide_cursor' do
72
+ Esc.string('hide_cursor').must_equal("\e[?25l")
125
73
  end
126
74
 
127
- context 'when the style is negative' do
128
- let(:style) { 'negative' }
129
-
130
- it 'returns an escape sequence' do
131
- subject.must_equal("\e[7m")
132
- end
75
+ it 'returns an escape sequence when the style is negative' do
76
+ Esc.string('negative').must_equal("\e[7m")
133
77
  end
134
78
 
135
- context 'when the style is positive' do
136
- let(:style) { 'positive' }
137
-
138
- it 'returns an escape sequence' do
139
- subject.must_equal("\e[27m")
140
- end
79
+ it 'returns an escape sequence when the style is positive' do
80
+ Esc.string('positive').must_equal("\e[27m")
141
81
  end
142
82
 
143
- context 'when the style is reset' do
144
- let(:style) { 'reset' }
145
-
146
- it 'returns an escape sequence' do
147
- subject.must_equal("\e[0m")
148
- end
83
+ it 'returns an escape sequence when the style is reset' do
84
+ Esc.string('reset').must_equal("\e[0m")
149
85
  end
150
86
 
151
- context 'when the style is normal' do
152
- let(:style) { 'normal' }
153
-
154
- it 'returns an escape sequence' do
155
- subject.must_equal("\e[24m\e[21m\e[27m")
156
- end
87
+ it 'returns an escape sequence when the style is normal' do
88
+ Esc.string('normal').must_equal("\e[24m\e[21m\e[27m")
157
89
  end
158
90
 
159
- context 'when the style is dim' do
160
- let(:style) { 'dim' }
161
-
162
- it 'returns an escape sequence' do
163
- subject.must_equal("\e[2m")
164
- end
91
+ it 'returns an escape sequence when the style is dim' do
92
+ Esc.string('dim').must_equal("\e[2m")
165
93
  end
166
94
 
167
- context 'when the style is show_cursor' do
168
- let(:style) { 'show_cursor' }
169
-
170
- it 'returns an escape sequence' do
171
- subject.must_equal("\e[?25h")
172
- end
95
+ it 'returns an escape sequence when the style is show_cursor' do
96
+ Esc.string('show_cursor').must_equal("\e[?25h")
173
97
  end
174
98
 
175
- context 'when the style is underline' do
176
- let(:style) { 'underline' }
177
-
178
- it 'returns an escape sequence' do
179
- subject.must_equal("\e[4m")
180
- end
99
+ it 'returns an escape sequence when the style is underline' do
100
+ Esc.string('underline').must_equal("\e[4m")
181
101
  end
182
102
 
183
- context 'when the style is underline off' do
184
- let(:style) { 'underline_off' }
185
-
186
- it 'returns an escape sequence' do
187
- subject.must_equal("\e[24m")
188
- end
103
+ it 'returns an escape sequence when the style is underline off' do
104
+ Esc.string('underline_off').must_equal("\e[24m")
189
105
  end
190
106
  end
191
107
  end
@@ -0,0 +1,31 @@
1
+ require_relative '../../../test_helper'
2
+ require_relative '../../../../lib/vedeu/repository/event_repository'
3
+
4
+ module Vedeu
5
+ describe EventRepository do
6
+ describe '#handlers' do
7
+ it 'returns a Hash' do
8
+ EventRepository.handlers.must_be_instance_of(Hash)
9
+ end
10
+ end
11
+
12
+ describe '#register' do
13
+ it 'returns an Array' do
14
+ EventRepository.register(:some_event) { proc { |x| x } }
15
+ .must_be_instance_of(Array)
16
+ end
17
+ end
18
+
19
+ describe '#trigger' do
20
+ it 'returns a collection containing the event when the event is pre-registered' do
21
+ EventRepository.register(:some_event) { proc { |x| x } }
22
+ EventRepository.trigger(:_exit_, []).first.call
23
+ .must_equal(:exit)
24
+ end
25
+
26
+ it 'returns an empty collection when the event has not been registered' do
27
+ EventRepository.trigger(:_not_found_, []).must_be_empty
28
+ end
29
+ end
30
+ end
31
+ end
@@ -3,17 +3,9 @@ require_relative '../../../../lib/vedeu/support/exit'
3
3
 
4
4
  module Vedeu
5
5
  describe Exit do
6
- let(:described_class) { Exit }
7
-
8
6
  describe '.dispatch' do
9
- let(:subject) { described_class.dispatch }
10
-
11
- it 'returns a Symbol' do
12
- subject.must_be_instance_of(Symbol)
13
- end
14
-
15
7
  it 'returns the symbol :stop' do
16
- subject.must_equal(:stop)
8
+ Exit.dispatch.must_equal(:stop)
17
9
  end
18
10
  end
19
11
  end
@@ -4,127 +4,103 @@ require_relative '../../../../lib/vedeu/models/interface'
4
4
 
5
5
  module Vedeu
6
6
  describe Geometry do
7
- let(:described_class) { Geometry }
8
- let(:described_instance) { described_class.new(interface, index) }
9
- let(:interface) { Interface.new(attributes) }
10
- let(:attributes) {
11
- {
12
- name: 'dummy',
13
- lines: [],
14
- colour: {
15
- foreground: '#ff0000',
16
- background: '#000000'
17
- },
18
- width: 7,
19
- height: 3
20
- }
21
- }
22
- let(:index) { 0 }
23
-
24
- before do
25
- Terminal.stubs(:width).returns(40)
26
- Terminal.stubs(:height).returns(25)
27
- end
28
-
29
7
  describe '#origin' do
30
- it 'returns a String' do
31
- described_instance.origin.must_be_instance_of(String)
32
- end
33
-
34
8
  it 'returns the origin for the interface' do
35
- described_instance.origin.must_equal("\e[1;1H")
9
+ interface = Interface.new({
10
+ name: 'dummy',
11
+ width: 5,
12
+ height: 5,
13
+ x: 1,
14
+ y: 1,
15
+ z: 1
16
+ })
17
+ Geometry.new(interface).origin.must_equal("\e[1;1H")
36
18
  end
37
19
 
38
- context 'when the index is provided' do
39
- let(:index) { 3 }
40
-
41
- it 'returns the line position relative to the origin' do
42
- described_instance.origin.must_equal("\e[4;1H")
43
- end
20
+ it 'returns the line position relative to the origin' do
21
+ interface = Interface.new({
22
+ name: 'dummy',
23
+ width: 5,
24
+ height: 5,
25
+ x: 1,
26
+ y: 1,
27
+ z: 1
28
+ })
29
+ Geometry.new(interface).origin(3).must_equal("\e[4;1H")
44
30
  end
45
31
 
46
- context 'when the interface is at a custom position' do
47
- let(:attributes) { { y: 6, x: 3 }}
48
-
49
- it 'returns the origin for the interface' do
50
- described_instance.origin.must_equal("\e[6;3H")
51
- end
52
-
53
- context 'when the index is provided' do
54
- let(:index) { 3 }
55
-
56
- it 'returns the line position relative to the origin' do
57
- described_instance.origin.must_equal("\e[9;3H")
58
- end
59
- end
32
+ it 'returns the origin for the interface when the interface is at a custom position' do
33
+ interface = Interface.new({
34
+ name: 'dummy',
35
+ width: 5,
36
+ height: 5,
37
+ x: 3,
38
+ y: 6,
39
+ z: 1
40
+ })
41
+ Geometry.new(interface).origin.must_equal("\e[6;3H")
60
42
  end
61
- end
62
43
 
63
- describe '#max_y' do
64
- let(:subject) { described_instance.max_y }
65
-
66
- it 'returns a Fixnum' do
67
- subject.must_be_instance_of(Fixnum)
44
+ it 'returns the line position relative to the origin when the interface is at a custom position' do
45
+ interface = Interface.new({
46
+ name: 'dummy',
47
+ width: 5,
48
+ height: 5,
49
+ x: 3,
50
+ y: 6,
51
+ z: 1
52
+ })
53
+ Geometry.new(interface).origin(3).must_equal("\e[9;3H")
68
54
  end
69
55
 
70
- context 'when the value is greater than the available terminal size' do
71
- it 'clips the value to the terminal size' do
72
- subject.must_equal(4)
73
- end
56
+ it 'clips the maximum height to the terminal height when the height is more than the terminal height' do
57
+ skip
58
+ interface = Interface.new({
59
+ name: 'dummy',
60
+ width: 5,
61
+ height: 6,
62
+ x: 1,
63
+ y: 20,
64
+ z: 1
65
+ })
66
+ Geometry.new(interface).origin.must_equal("\e[1;1H")
74
67
  end
75
68
 
76
- context 'when the value is less than the available size' do
77
- let(:attributes) { { y: 20, height: 4 } }
78
-
79
- it 'returns the value' do
80
- subject.must_equal(24)
81
- end
69
+ it 'returns the value when the height is less than the terminal height' do
70
+ skip
71
+ interface = Interface.new({
72
+ name: 'dummy',
73
+ width: 5,
74
+ height: 2,
75
+ x: 1,
76
+ y: 20,
77
+ z: 1
78
+ })
79
+ Geometry.new(interface).origin.must_equal("\e[1;1H")
82
80
  end
83
- end
84
-
85
- describe '#max_x' do
86
- let(:subject) { described_instance.max_x }
87
-
88
- it 'returns a Fixnum' do
89
- subject.must_be_instance_of(Fixnum)
90
- end
91
-
92
- context 'when the value is greater than the available terminal size' do
93
- it 'clips the value to the terminal size' do
94
- subject.must_equal(8)
95
- end
96
- end
97
-
98
- context 'when the value is less than the available size' do
99
- let(:attributes) { { x: 17, width: 21 } }
100
-
101
- it 'returns the value' do
102
- subject.must_equal(38)
103
- end
104
- end
105
- end
106
-
107
- describe '#virtual_x' do
108
- let(:subject) { described_instance.virtual_x }
109
-
110
- it 'returns a Fixnum' do
111
- subject.must_be_instance_of(Fixnum)
112
- end
113
-
114
- it 'returns the value' do
115
- subject.must_equal(1)
116
- end
117
- end
118
-
119
- describe '#virtual_y' do
120
- let(:subject) { described_instance.virtual_y }
121
81
 
122
- it 'returns a Fixnum' do
123
- subject.must_be_instance_of(Fixnum)
82
+ it 'clips the maximum width to the terminal width when the width is more than the terminal width' do
83
+ interface = Interface.new({
84
+ name: 'dummy',
85
+ width: 20,
86
+ height: 5,
87
+ x: 30,
88
+ y: 1,
89
+ z: 1
90
+ })
91
+ Geometry.new(interface).origin.must_equal("\e[1;30H")
124
92
  end
125
93
 
126
- it 'returns the value' do
127
- subject.must_equal(1)
94
+ it 'returns the value when the width is less than the terminal width' do
95
+ interface = Interface.new({
96
+ name: 'dummy',
97
+ width: 20,
98
+ height: 5,
99
+ x: 15,
100
+ y: 1,
101
+ z: 1
102
+ })
103
+ Geometry.new(interface).origin.must_equal("\e[1;15H")
128
104
  end
129
105
  end
130
106
  end