vedeu 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/Guardfile +1 -1
  4. data/README.md +14 -0
  5. data/lib/vedeu.rb +1 -0
  6. data/lib/vedeu/interface/dummy.rb +13 -0
  7. data/lib/vedeu/interface/interface.rb +1 -1
  8. data/lib/vedeu/interface/interfaces.rb +10 -9
  9. data/lib/vedeu/output/colour.rb +2 -0
  10. data/lib/vedeu/output/compositor.rb +3 -23
  11. data/lib/vedeu/output/directive.rb +27 -14
  12. data/lib/vedeu/output/geometry.rb +6 -1
  13. data/lib/vedeu/output/position.rb +8 -3
  14. data/lib/vedeu/output/wordwrap.rb +84 -0
  15. data/lib/vedeu/version.rb +1 -1
  16. data/test/lib/vedeu/application_test.rb +15 -5
  17. data/test/lib/vedeu/interface/dummy_test.rb +5 -5
  18. data/test/lib/vedeu/interface/interface_test.rb +17 -7
  19. data/test/lib/vedeu/interface/interfaces_test.rb +29 -20
  20. data/test/lib/vedeu/output/background_test.rb +40 -3
  21. data/test/lib/vedeu/output/base_test.rb +2 -4
  22. data/test/lib/vedeu/output/colour_test.rb +6 -6
  23. data/test/lib/vedeu/output/compositor_test.rb +15 -15
  24. data/test/lib/vedeu/output/directive_test.rb +36 -35
  25. data/test/lib/vedeu/output/esc_test.rb +9 -9
  26. data/test/lib/vedeu/output/foreground_test.rb +39 -2
  27. data/test/lib/vedeu/output/geometry_test.rb +51 -7
  28. data/test/lib/vedeu/output/position_test.rb +15 -6
  29. data/test/lib/vedeu/output/renderer_test.rb +19 -1
  30. data/test/lib/vedeu/output/style_test.rb +1 -2
  31. data/test/lib/vedeu/output/wordwrap_test.rb +59 -0
  32. data/test/lib/vedeu/process/command_test.rb +8 -8
  33. data/test/lib/vedeu/process/commands_test.rb +27 -7
  34. data/test/lib/vedeu/process/exit_test.rb +1 -1
  35. data/test/lib/vedeu/support/terminal_test.rb +27 -24
  36. data/test/test_helper.rb +1 -1
  37. data/vedeu.gemspec +5 -5
  38. metadata +21 -19
@@ -14,7 +14,9 @@ module Vedeu
14
14
  it { described_instance.must_be_instance_of(Geometry) }
15
15
 
16
16
  describe '#z' do
17
- subject { described_instance.z }
17
+ let(:subject) { described_instance.z }
18
+
19
+ it { subject.must_be_instance_of(Fixnum) }
18
20
 
19
21
  context 'using a value' do
20
22
  let(:values) { { z: 2 } }
@@ -28,7 +30,9 @@ module Vedeu
28
30
  end
29
31
 
30
32
  describe '#y' do
31
- subject { described_instance.y }
33
+ let(:subject) { described_instance.y }
34
+
35
+ it { subject.must_be_instance_of(Fixnum) }
32
36
 
33
37
  context 'using a value' do
34
38
  let(:values) { { y: 17 } }
@@ -42,7 +46,9 @@ module Vedeu
42
46
  end
43
47
 
44
48
  describe '#x' do
45
- subject { described_instance.x }
49
+ let(:subject) { described_instance.x }
50
+
51
+ it { subject.must_be_instance_of(Fixnum) }
46
52
 
47
53
  context 'using a value' do
48
54
  let(:values) { { x: 33 } }
@@ -56,7 +62,9 @@ module Vedeu
56
62
  end
57
63
 
58
64
  describe '#width' do
59
- subject { described_instance.width }
65
+ let(:subject) { described_instance.width }
66
+
67
+ it { subject.must_be_instance_of(Fixnum) }
60
68
 
61
69
  context 'using a value' do
62
70
  let(:values) { { width: 50 } }
@@ -64,13 +72,21 @@ module Vedeu
64
72
  it { subject.must_equal(50) }
65
73
  end
66
74
 
75
+ context 'using :auto' do
76
+ let(:values) { { width: :auto } }
77
+
78
+ it { subject.must_equal(80) }
79
+ end
80
+
67
81
  context 'using the default' do
68
82
  it { subject.must_equal(80) }
69
83
  end
70
84
  end
71
85
 
72
86
  describe '#height' do
73
- subject { described_instance.height }
87
+ let(:subject) { described_instance.height }
88
+
89
+ it { subject.must_be_instance_of(Fixnum) }
74
90
 
75
91
  context 'using a value' do
76
92
  let(:values) { { height: 20 } }
@@ -78,13 +94,21 @@ module Vedeu
78
94
  it { subject.must_equal(20) }
79
95
  end
80
96
 
97
+ context 'using :auto' do
98
+ let(:values) { { height: :auto } }
99
+
100
+ it { subject.must_equal(25) }
101
+ end
102
+
81
103
  context 'using the default' do
82
104
  it { subject.must_equal(25) }
83
105
  end
84
106
  end
85
107
 
86
108
  describe '#dy' do
87
- subject { described_instance.dy }
109
+ let(:subject) { described_instance.dy }
110
+
111
+ it { subject.must_be_instance_of(Fixnum) }
88
112
 
89
113
  context 'when the value is greater than the available terminal size' do
90
114
  it 'clips the value to the terminal size' do
@@ -100,7 +124,9 @@ module Vedeu
100
124
  end
101
125
 
102
126
  describe '#dx' do
103
- subject { described_instance.dx }
127
+ let(:subject) { described_instance.dx }
128
+
129
+ it { subject.must_be_instance_of(Fixnum) }
104
130
 
105
131
  context 'when the value is greater than the available terminal size' do
106
132
  it 'clips the value to the terminal size' do
@@ -111,8 +137,26 @@ module Vedeu
111
137
  context 'when the value is less than the available size' do
112
138
  let(:values) { { x: 17, width: 21 } }
113
139
 
140
+ it { subject.must_be_instance_of(Fixnum) }
141
+
114
142
  it { subject.must_equal(38) }
115
143
  end
116
144
  end
145
+
146
+ describe '#vx' do
147
+ let(:subject) { described_instance.vx }
148
+
149
+ it { subject.must_be_instance_of(Fixnum) }
150
+
151
+ it { subject.must_equal(1) }
152
+ end
153
+
154
+ describe '#vy' do
155
+ let(:subject) { described_instance.vy }
156
+
157
+ it { subject.must_be_instance_of(Fixnum) }
158
+
159
+ it { subject.must_equal(1) }
160
+ end
117
161
  end
118
162
  end
@@ -3,31 +3,40 @@ require_relative '../../../test_helper'
3
3
  module Vedeu
4
4
  describe Position do
5
5
  let(:described_class) { Position }
6
- let(:instance) { described_class.new }
6
+ let(:described_instance) { described_class.new }
7
7
 
8
- it { instance.must_be_instance_of(Position) }
8
+ it { described_instance.must_be_instance_of(Position) }
9
9
 
10
10
  describe '.set' do
11
- subject { described_class.set }
11
+ let(:subject) { described_class.set }
12
12
 
13
13
  it { subject.must_be_instance_of(String) }
14
14
 
15
15
  context 'when no coordinates are provided' do
16
16
  it 'returns a position escape sequence' do
17
- subject.must_equal("\e[1;1H")
17
+ subject.must_equal('')
18
18
  end
19
19
  end
20
20
 
21
21
  context 'when coordinates are provided' do
22
+ let(:subject) { described_class.set(y, x) }
22
23
  let(:y) { 12 }
23
24
  let(:x) { 19 }
24
25
 
25
- subject { described_class.set(y, x) }
26
-
27
26
  it 'returns a position escape sequence' do
28
27
  subject.must_equal("\e[13;20H")
29
28
  end
30
29
  end
31
30
  end
31
+
32
+ describe '.reset' do
33
+ let(:subject) { described_class.reset }
34
+
35
+ it { subject.must_be_instance_of(String) }
36
+
37
+ it 'returns a position escape sequence' do
38
+ subject.must_equal("\e[1;1H")
39
+ end
40
+ end
32
41
  end
33
42
  end
@@ -4,6 +4,24 @@ module Vedeu
4
4
  describe Renderer do
5
5
  let(:described_class) { Renderer }
6
6
  let(:described_instance) { described_class.new(composition) }
7
- let(:composition) {}
7
+ let(:composition) { [] }
8
+
9
+ it { described_instance.must_be_instance_of(Renderer) }
10
+
11
+ describe '.write' do
12
+ let(:subject) { described_class.write(composition) }
13
+
14
+ it { subject.must_be_instance_of(Array) }
15
+
16
+ it { subject.must_equal([]) }
17
+
18
+ context 'capturing i/o' do
19
+ let(:captured) { capture_io { subject }.join }
20
+
21
+ it { captured.must_be_instance_of(String) }
22
+
23
+ it { captured.must_equal("") }
24
+ end
25
+ end
8
26
  end
9
27
  end
@@ -5,10 +5,9 @@ module Vedeu
5
5
  let(:described_class) { Style }
6
6
 
7
7
  describe '.set' do
8
+ let(:subject) { described_class.set(style) }
8
9
  let(:style) {}
9
10
 
10
- subject { described_class.set(style) }
11
-
12
11
  it { subject.must_be_instance_of(String) }
13
12
 
14
13
  it { subject.must_equal('') }
@@ -0,0 +1,59 @@
1
+ require_relative '../../../test_helper'
2
+
3
+ module Vedeu
4
+ describe Wordwrap do
5
+ let(:described_class) { Wordwrap }
6
+ let(:value) {
7
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' \
8
+ "Curabitur aliquet turpis id dui condimentum elementum.\n" \
9
+ 'Pellentesque blandit vulputate imperdiet. Quisque ut arcu ' \
10
+ "dolor. Morbi nec vulputate purus.\n\nQuisque porta feugiat " \
11
+ 'egestas. Aenean ac ipsum varius, lobortis lacus at, mattis ' \
12
+ "est.\nQuisque viverra facilisis tortor, id convallis metus " \
13
+ 'laoreet quis. Curabitur auctor nunc blandit enim volutpat ' \
14
+ 'hendrerit. Phasellus accumsan tempor iaculis. Ut in semper ' \
15
+ "massa. Cras quis viverra elit.\n\nInteger vitae mattis est. " \
16
+ 'Cras id nisl porttitor lectus placerat gravida sit amet ' \
17
+ "quis diam.\n\nDonec mollis, nisi sit amet congue sagittis, " \
18
+ 'sapien magna rhoncus justo, vel molestie metus sapien eget ' \
19
+ "libero.\n\n\n"
20
+ }
21
+ let(:options) { {} }
22
+
23
+ describe '#wordwrap' do
24
+ let(:formatted_value) {
25
+ "Lorem ipsum dolor sit amet, consectetur adipiscing elit. " \
26
+ "Curabitur\naliquet turpis id dui condimentum elementum.\n" \
27
+ "Pellentesque blandit vulputate imperdiet. Quisque ut arcu " \
28
+ "dolor.\nMorbi nec vulputate purus.\n\nQuisque porta " \
29
+ "feugiat egestas. Aenean ac ipsum varius, lobortis\nlacus " \
30
+ "at, mattis est.\nQuisque viverra facilisis tortor, id " \
31
+ "convallis metus laoreet quis.\nCurabitur auctor nunc " \
32
+ "blandit enim volutpat hendrerit. Phasellus\naccumsan " \
33
+ "tempor iaculis. Ut in semper massa. Cras quis viverra " \
34
+ "elit.\n\nInteger vitae mattis est. Cras id nisl porttitor " \
35
+ "lectus placerat\ngravida sit amet quis diam.\n\nDonec " \
36
+ "mollis, nisi sit amet congue sagittis, sapien magna " \
37
+ "rhoncus\njusto, vel molestie metus sapien eget libero."
38
+ }
39
+
40
+ subject { described_class.this(value, options) }
41
+
42
+ it 'returns formatted text' do
43
+ subject.must_equal(formatted_value)
44
+ end
45
+
46
+ context 'when the content should be pruned' do
47
+ let(:options) { { width: 70, prune: true } }
48
+ let(:formatted_value) {
49
+ 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.' \
50
+ " Curabitur a...\e[0m"
51
+ }
52
+
53
+ it 'returns formatted text' do
54
+ subject.must_equal(formatted_value)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -8,14 +8,14 @@ module Vedeu
8
8
  end
9
9
 
10
10
  describe Command do
11
- let(:described_class) { Command }
12
- let(:instance) { described_class.new(cmd_name, cmd_klass, cmd_args, cmd_options) }
13
- let(:cmd_name) { "dummy" }
14
- let(:cmd_klass) { DummyCommand }
15
- let(:cmd_args) { [] }
16
- let(:cmd_options) { {} }
17
-
18
- it { instance.must_be_instance_of(Command) }
11
+ let(:described_class) { Command }
12
+ let(:described_instance) { described_class.new(cmd_name, cmd_klass, cmd_args, cmd_options) }
13
+ let(:cmd_name) { "dummy" }
14
+ let(:cmd_klass) { DummyCommand }
15
+ let(:cmd_args) { [] }
16
+ let(:cmd_options) { {} }
17
+
18
+ it { described_instance.must_be_instance_of(Command) }
19
19
 
20
20
  describe '#define' do
21
21
  subject do
@@ -11,31 +11,51 @@ module Vedeu
11
11
  let(:described_class) { Commands }
12
12
 
13
13
  describe '.define' do
14
- subject { described_class.define }
14
+ let(:subject) { described_class.define }
15
15
 
16
- it { skip }
16
+ context 'when a block is given' do
17
+ let(:subject) { described_class.define { :nil } }
18
+
19
+ it 'yields the block' do
20
+ subject.must_be_instance_of(Symbol)
21
+ end
22
+ end
23
+
24
+ context 'when a block is not given' do
25
+ it { subject.must_be_instance_of(Module) }
26
+ end
17
27
  end
18
28
 
19
29
  describe '.execute' do
20
- subject { described_class.execute }
30
+ let(:subject) { described_class.execute(command) }
31
+ let(:command) {}
32
+
33
+ context 'when the command does not exist' do
34
+ it { subject.must_be_instance_of(NilClass) }
35
+ end
21
36
 
22
- it { skip }
37
+ context 'when the command exists' do
38
+ let(:command) { 'exit' }
39
+
40
+ before { Exit.stubs(:dispatch).returns(true) }
41
+
42
+ it { subject.must_be_instance_of(TrueClass) }
43
+ end
23
44
  end
24
45
 
25
46
  describe '.list' do
26
- subject { described_class.list }
47
+ let(:subject) { described_class.list }
27
48
 
28
49
  it { subject.must_be_instance_of(String) }
29
50
  end
30
51
 
31
52
  describe '.add' do
53
+ let(:subject) { described_class.add(command_name, command_klass, args, options) }
32
54
  let(:command_name) { "some_name" }
33
55
  let(:command_klass) { DummyCommand }
34
56
  let(:args) { [] }
35
57
  let(:options) { {} }
36
58
 
37
- subject { described_class.add(command_name, command_klass, args, options) }
38
-
39
59
  it { subject.must_be_instance_of(Hash) }
40
60
  end
41
61
  end
@@ -5,7 +5,7 @@ module Vedeu
5
5
  let(:described_class) { Exit }
6
6
 
7
7
  describe '.dispatch' do
8
- subject { described_class.dispatch }
8
+ let(:subject) { described_class.dispatch }
9
9
 
10
10
  it { subject.must_be_instance_of(Symbol) }
11
11
 
@@ -12,23 +12,25 @@ module Vedeu
12
12
  end
13
13
 
14
14
  describe '.input' do
15
- before { console.stubs(:gets).returns("test") }
15
+ let(:subject) { described_class.input }
16
16
 
17
- subject { described_class.input }
17
+ before { console.stubs(:gets).returns("test\n") }
18
18
 
19
19
  it { subject.must_be_instance_of(String) }
20
+
21
+ it { subject.must_equal("test") }
20
22
  end
21
23
 
22
24
  describe '.output' do
23
- before { console.stubs(:print).returns("test") }
25
+ let(:subject) { described_class.output }
24
26
 
25
- subject { described_class.output }
27
+ before { console.stubs(:print).returns("test") }
26
28
 
27
29
  it { subject.must_be_instance_of(String) }
28
30
  end
29
31
 
30
32
  describe '.width' do
31
- subject { described_class.width }
33
+ let(:subject) { described_class.width }
32
34
 
33
35
  it { subject.must_be_instance_of(Fixnum) }
34
36
 
@@ -38,7 +40,7 @@ module Vedeu
38
40
  end
39
41
 
40
42
  describe '.height' do
41
- subject { described_class.height }
43
+ let(:subject) { described_class.height }
42
44
 
43
45
  it { subject.must_be_instance_of(Fixnum) }
44
46
 
@@ -48,7 +50,7 @@ module Vedeu
48
50
  end
49
51
 
50
52
  describe '.size' do
51
- subject { described_class.size }
53
+ let(:subject) { described_class.size }
52
54
 
53
55
  it { subject.must_be_instance_of(Array) }
54
56
 
@@ -58,39 +60,39 @@ module Vedeu
58
60
  end
59
61
 
60
62
  describe '.open' do
61
- subject { described_class.open }
63
+ let(:subject) { described_class.open }
62
64
 
63
65
  it { skip }
64
66
  end
65
67
 
66
68
  describe '.close' do
67
- subject { described_class.close }
69
+ let(:subject) { described_class.close }
68
70
 
69
71
  it { skip }
70
72
  end
71
73
 
72
74
  describe '.cooked' do
73
- subject { described_class.cooked }
75
+ let(:subject) { described_class.cooked }
74
76
 
75
77
  it { skip }
76
78
  end
77
79
 
78
80
  describe '.raw' do
79
- subject { described_class.raw }
81
+ let(:subject) { described_class.raw }
80
82
 
81
83
  it { skip }
82
84
  end
83
85
 
84
86
  describe '.console' do
85
- subject { described_class.console }
87
+ let(:subject) { described_class.console }
86
88
 
87
89
  it { skip }
88
90
  end
89
91
 
90
92
  describe '.clear_screen' do
91
- before { Esc.stubs(:clear).returns('') }
93
+ let(:subject) { described_class.clear_screen }
92
94
 
93
- subject { described_class.clear_screen }
95
+ before { Esc.stubs(:clear).returns('') }
94
96
 
95
97
  it { subject.must_be_instance_of(NilClass) }
96
98
 
@@ -102,13 +104,14 @@ module Vedeu
102
104
  end
103
105
 
104
106
  describe '.clear_line' do
105
- subject { described_class.clear_line }
107
+ let(:subject) { described_class.clear_line(index) }
108
+ let(:index) { 0 }
106
109
 
107
- it { skip }
110
+ it { subject.must_be_instance_of(NilClass) }
108
111
  end
109
112
 
110
113
  describe '.show_cursor' do
111
- subject { described_class.show_cursor }
114
+ let(:subject) { described_class.show_cursor }
112
115
 
113
116
  it { subject.must_be_instance_of(NilClass) }
114
117
 
@@ -120,7 +123,7 @@ module Vedeu
120
123
  end
121
124
 
122
125
  describe '.hide_cursor' do
123
- subject { described_class.hide_cursor }
126
+ let(:subject) { described_class.hide_cursor }
124
127
 
125
128
  it { subject.must_be_instance_of(NilClass) }
126
129
 
@@ -132,21 +135,21 @@ module Vedeu
132
135
  end
133
136
 
134
137
  describe '#initialize' do
135
- subject { described_class.new }
138
+ let(:subject) { described_class.new }
136
139
 
137
- it { skip }
140
+ it { subject.must_be_instance_of(Terminal) }
138
141
  end
139
142
 
140
143
  describe '#open' do
141
- subject { described_class.new.open }
144
+ let(:subject) { described_class.new.open }
142
145
 
143
- it { skip }
146
+ it { subject.must_be_instance_of(NilClass) }
144
147
  end
145
148
 
146
149
  describe '#initial_setup!' do
147
- subject { described_class.new.initial_setup! }
150
+ let(:subject) { described_class.new.initial_setup! }
148
151
 
149
- it { skip }
152
+ it { subject.must_be_instance_of(NilClass) }
150
153
  end
151
154
  end
152
155
  end