vedeu 0.2.11 → 0.2.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/examples/borders_app.rb +171 -0
  3. data/lib/vedeu.rb +1 -1
  4. data/lib/vedeu/api/interface.rb +12 -0
  5. data/lib/vedeu/api/menu.rb +1 -1
  6. data/lib/vedeu/colours/colour.rb +1 -1
  7. data/lib/vedeu/models/border.rb +238 -0
  8. data/lib/vedeu/models/char.rb +1 -1
  9. data/lib/vedeu/models/composition.rb +1 -1
  10. data/lib/vedeu/models/geometry.rb +1 -1
  11. data/lib/vedeu/models/line.rb +1 -1
  12. data/lib/vedeu/models/stream.rb +1 -1
  13. data/lib/vedeu/output/output.rb +1 -1
  14. data/lib/vedeu/output/viewport.rb +34 -3
  15. data/lib/vedeu/repositories/models/cursor.rb +34 -7
  16. data/lib/vedeu/repositories/models/event.rb +1 -1
  17. data/lib/vedeu/repositories/models/group.rb +1 -1
  18. data/lib/vedeu/repositories/models/interface.rb +14 -6
  19. data/lib/vedeu/repositories/models/keymap.rb +1 -1
  20. data/lib/vedeu/repositories/models/offset.rb +1 -1
  21. data/lib/vedeu/support/trace.rb +1 -1
  22. data/test/integration/views/basic_view_test.rb +19 -0
  23. data/test/lib/vedeu/api/api_test.rb +6 -5
  24. data/test/lib/vedeu/api/helpers_test.rb +2 -6
  25. data/test/lib/vedeu/api/interface_test.rb +53 -45
  26. data/test/lib/vedeu/api/menu_test.rb +6 -0
  27. data/test/lib/vedeu/api/stream_test.rb +1 -3
  28. data/test/lib/vedeu/application_test.rb +6 -12
  29. data/test/lib/vedeu/colours/colour_test.rb +16 -5
  30. data/test/lib/vedeu/colours/translator_test.rb +7 -2
  31. data/test/lib/vedeu/configuration/cli_test.rb +9 -0
  32. data/test/lib/vedeu/input/input_test.rb +5 -5
  33. data/test/lib/vedeu/launcher_test.rb +9 -3
  34. data/test/lib/vedeu/models/border_test.rb +197 -0
  35. data/test/lib/vedeu/models/char_test.rb +18 -15
  36. data/test/lib/vedeu/models/composition_test.rb +6 -7
  37. data/test/lib/vedeu/models/geometry_test.rb +43 -49
  38. data/test/lib/vedeu/models/key_test.rb +7 -5
  39. data/test/lib/vedeu/models/line_test.rb +12 -16
  40. data/test/lib/vedeu/models/stream_test.rb +20 -10
  41. data/test/lib/vedeu/models/style_test.rb +9 -10
  42. data/test/lib/vedeu/output/compositor_test.rb +7 -22
  43. data/test/lib/vedeu/output/output_test.rb +34 -33
  44. data/test/lib/vedeu/output/viewport_test.rb +6 -6
  45. data/test/lib/vedeu/repositories/models/buffer_test.rb +13 -18
  46. data/test/lib/vedeu/repositories/models/cursor_test.rb +21 -21
  47. data/test/lib/vedeu/repositories/models/event_test.rb +10 -4
  48. data/test/lib/vedeu/{models → repositories/models}/group_test.rb +8 -9
  49. data/test/lib/vedeu/repositories/models/interface_test.rb +37 -17
  50. data/test/lib/vedeu/repositories/models/keymap_test.rb +6 -6
  51. data/test/lib/vedeu/repositories/models/menu_test.rb +6 -3
  52. data/test/lib/vedeu/repositories/models/offset_test.rb +6 -3
  53. data/test/lib/vedeu/support/bounding_area_test.rb +28 -36
  54. data/test/lib/vedeu/support/grid_test.rb +8 -0
  55. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -8
  56. data/test/lib/vedeu/support/position_test.rb +3 -3
  57. data/test/lib/vedeu/support/registrar_test.rb +13 -7
  58. data/test/lib/vedeu/support/sentence_test.rb +9 -2
  59. data/test/lib/vedeu/support/trace_test.rb +5 -3
  60. data/test/test_helper.rb +12 -0
  61. data/vedeu.gemspec +1 -1
  62. metadata +8 -7
  63. data/lib/vedeu/output/view.rb +0 -64
  64. data/test/lib/vedeu/output/view_test.rb +0 -21
@@ -3,34 +3,36 @@ require 'test_helper'
3
3
  module Vedeu
4
4
 
5
5
  describe Output do
6
- # let(:interface) {
7
- # Interface.new({
8
- # name: 'flourine',
9
- # geometry: {
10
- # width: 32,
11
- # height: 3,
12
- # },
13
- # lines: lines,
14
- # colour: colour
15
- # })
16
- # }
17
- # let(:lines) {
18
- # [
19
- # {
20
- # streams: [{ text: 'this is the first' }]
21
- # },
22
- # {
23
- # streams: [{ text: 'this is the second and it is long' }]
24
- # },
25
- # {
26
- # streams: [{ text: 'this is the third, it is even longer and still truncated' }]
27
- # },
28
- # {
29
- # streams: [{ text: 'this should not render' }]
30
- # }
31
- # ]
32
- # }
33
- # let(:colour) { {} }
6
+
7
+ let(:described) { Output.new(interface) }
8
+ let(:interface) {
9
+ Interface.new({
10
+ name: 'flourine',
11
+ geometry: {
12
+ width: 32,
13
+ height: 3,
14
+ },
15
+ lines: lines,
16
+ colour: colour
17
+ })
18
+ }
19
+ let(:lines) {
20
+ [
21
+ {
22
+ streams: [{ text: 'this is the first' }]
23
+ },
24
+ {
25
+ streams: [{ text: 'this is the second and it is long' }]
26
+ },
27
+ {
28
+ streams: [{ text: 'this is the third, it is even longer and still truncated' }]
29
+ },
30
+ {
31
+ streams: [{ text: 'this should not render' }]
32
+ }
33
+ ]
34
+ }
35
+ let(:colour) { {} }
34
36
 
35
37
  # before do
36
38
  # Buffers.reset
@@ -41,11 +43,10 @@ module Vedeu
41
43
  # Terminal.console.stubs(:print)
42
44
  # end
43
45
 
44
- # describe '#initialize' do
45
- # it 'returns an instance of itself' do
46
- # Output.new(interface).must_be_instance_of(Output)
47
- # end
48
- # end
46
+ describe '#initialize' do
47
+ it { return_type_for(described, Output) }
48
+ it { assigns(described, '@interface', interface) }
49
+ end
49
50
 
50
51
  # describe '.render' do
51
52
  # it 'returns the content for the interface' do
@@ -4,6 +4,7 @@ module Vedeu
4
4
 
5
5
  describe Viewport do
6
6
 
7
+ let(:described) { Viewport.new(interface) }
7
8
  let(:interface) {
8
9
  Interface.new({
9
10
  name: 'fluorine',
@@ -32,15 +33,14 @@ module Vedeu
32
33
  }
33
34
 
34
35
  describe '#initialize' do
35
- it 'returns an instance of itself' do
36
- Viewport.new(interface).must_be_instance_of(Viewport)
37
- end
36
+ it { return_type_for(described, Viewport) }
37
+ it { assigns(described, '@interface', interface) }
38
+ it { assigns(described, '@top', 0) }
39
+ it { assigns(described, '@left', 0) }
38
40
  end
39
41
 
40
42
  describe '.show' do
41
- it 'returns an Array' do
42
- Viewport.show(interface).must_be_instance_of(Array)
43
- end
43
+ it { return_type_for(Viewport.show(interface), Array) }
44
44
 
45
45
  context 'when there is no content' do
46
46
  before { interface.stubs(:content).returns([]) }
@@ -4,6 +4,7 @@ module Vedeu
4
4
 
5
5
  describe Buffer do
6
6
 
7
+ let(:described) { Buffer.new(attributes) }
7
8
  let(:attributes) {
8
9
  {
9
10
  name: '',
@@ -17,42 +18,36 @@ module Vedeu
17
18
  let(:previous) { {} }
18
19
 
19
20
  describe '#initialize' do
20
- it 'returns an instance of Buffer' do
21
- Buffer.new(attributes).must_be_instance_of(Buffer)
22
- end
21
+ it { return_type_for(described, Buffer) }
22
+ it { assigns(described, '@name', '') }
23
+ it { assigns(described, '@back', {}) }
24
+ it { assigns(described, '@front', {}) }
25
+ it { assigns(described, '@previous', {}) }
23
26
  end
24
27
 
25
28
  describe '#back' do
26
- subject { Buffer.new(attributes).back }
27
-
28
- it { subject.must_be_instance_of(Hash) }
29
+ it { return_type_for(described.back, Hash) }
29
30
  end
30
31
 
31
32
  describe '#front' do
32
- subject { Buffer.new(attributes).front }
33
-
34
- it { subject.must_be_instance_of(Hash) }
33
+ it { return_type_for(described.front, Hash) }
35
34
 
36
35
  context 'alias method: #current' do
37
- subject { Buffer.new(attributes).current }
38
-
39
- it { subject.must_be_instance_of(Hash) }
36
+ it { return_type_for(described.current, Hash) }
40
37
  end
41
38
  end
42
39
 
43
40
  describe '#name' do
44
- subject { Buffer.new(attributes).name }
45
-
46
- it { subject.must_be_instance_of(String) }
41
+ it { return_type_for(described.name, String) }
47
42
  end
48
43
 
49
44
  describe '#previous' do
50
- subject { Buffer.new(attributes).previous }
51
-
52
- it { subject.must_be_instance_of(Hash) }
45
+ it { return_type_for(described.previous, Hash) }
53
46
  end
54
47
 
55
48
  describe '#content' do
49
+ it { return_type_for(described.content, Array) }
50
+
56
51
  subject { Buffer.new(attributes).content }
57
52
 
58
53
  context 'when there is content on the back buffer' do
@@ -4,6 +4,7 @@ module Vedeu
4
4
 
5
5
  describe Cursor do
6
6
 
7
+ let(:described) { Cursor.new(attributes) }
7
8
  let(:attributes) {
8
9
  {
9
10
  name: 'silver',
@@ -25,23 +26,24 @@ module Vedeu
25
26
  end
26
27
 
27
28
  describe '#initialize' do
28
- it 'returns an instance of itself' do
29
- Cursor.new(attributes).must_be_instance_of(Cursor)
30
- end
29
+ it { return_type_for(described, Cursor) }
30
+ it { assigns(described, '@attributes', attributes) }
31
+ it { assigns(described, '@name', 'silver') }
32
+ it { assigns(described, '@state', :show) }
33
+ it { assigns(described, '@x', 19) }
34
+ it { assigns(described, '@y', 8) }
31
35
  end
32
36
 
33
37
  describe '#attributes' do
34
38
  it 'returns a hash containing the attributes of the instance' do
35
- Cursor.new(attributes).attributes.must_equal(
39
+ described.attributes.must_equal(
36
40
  { name: 'silver', state: :show, x: 19, y: 8 }
37
41
  )
38
42
  end
39
43
  end
40
44
 
41
45
  describe '#x' do
42
- it 'returns a Fixnum' do
43
- Cursor.new(attributes).x.must_be_instance_of(Fixnum)
44
- end
46
+ it { return_type_for(described.x, Fixnum) }
45
47
 
46
48
  context 'when the cursors position is outside the interface' do
47
49
  let(:attributes) { { name: 'silver', state: :show, x: 10, y: 8 } }
@@ -58,22 +60,20 @@ module Vedeu
58
60
 
59
61
  it 'repositions the cursor at the end of the line' do
60
62
  Cursor.new(attributes).attributes.must_equal(
61
- { name: 'silver', state: :show, x: 21, y: 8 }
63
+ { name: 'silver', state: :show, x: 22, y: 8 }
62
64
  )
63
65
  end
64
66
  end
65
67
  end
66
68
 
67
69
  describe '#y' do
68
- it 'returns a Fixnum' do
69
- Cursor.new(attributes).y.must_be_instance_of(Fixnum)
70
- end
70
+ it { return_type_for(described.y, Fixnum) }
71
71
 
72
72
  context 'when the cursors position is outside the interface' do
73
73
  let(:attributes) { { name: 'silver', state: :show, x: 19, y: 3 } }
74
74
 
75
75
  it 'repositions the cursor at the start of the line' do
76
- Cursor.new(attributes).attributes.must_equal(
76
+ described.attributes.must_equal(
77
77
  { name: 'silver', state: :show, x: 19, y: 5 }
78
78
  )
79
79
  end
@@ -83,8 +83,8 @@ module Vedeu
83
83
  let(:attributes) { { name: 'silver', state: :show, x: 19, y: 12 } }
84
84
 
85
85
  it 'repositions the cursor at the end of the line' do
86
- Cursor.new(attributes).attributes.must_equal(
87
- { name: 'silver', state: :show, x: 19, y: 8 }
86
+ described.attributes.must_equal(
87
+ { name: 'silver', state: :show, x: 19, y: 9 }
88
88
  )
89
89
  end
90
90
  end
@@ -92,7 +92,7 @@ module Vedeu
92
92
 
93
93
  describe '#refresh' do
94
94
  it 'returns a hash containing the attributes of the instance' do
95
- Cursor.new(attributes).refresh.must_equal(
95
+ described.refresh.must_equal(
96
96
  { name: 'silver', state: :show, x: 19, y: 8 }
97
97
  )
98
98
  end
@@ -100,7 +100,7 @@ module Vedeu
100
100
 
101
101
  describe '#show' do
102
102
  it 'sets the state attribute to :show' do
103
- cursor = Cursor.new(attributes)
103
+ cursor = described
104
104
  cursor.hide
105
105
  cursor.attributes.must_equal(
106
106
  { name: 'silver', state: :hide, x: 19, y: 8 }
@@ -114,7 +114,7 @@ module Vedeu
114
114
 
115
115
  describe '#hide' do
116
116
  it 'sets the state attribute to :hide' do
117
- cursor = Cursor.new(attributes)
117
+ cursor = described
118
118
  cursor.hide
119
119
  cursor.attributes.must_equal(
120
120
  { name: 'silver', state: :hide, x: 19, y: 8 }
@@ -126,7 +126,7 @@ module Vedeu
126
126
  describe '#to_s' do
127
127
  context 'when the cursor state is :show' do
128
128
  it 'returns an escape sequence for showing the cursor (and position)' do
129
- cursor = Cursor.new(attributes)
129
+ cursor = described
130
130
  cursor.show
131
131
  cursor.to_s.must_equal("\e[8;19H\e[?25h")
132
132
  end
@@ -134,7 +134,7 @@ module Vedeu
134
134
 
135
135
  context 'when the cursor state is :hide' do
136
136
  it 'returns an escape sequence for hiding the cursor (and position)' do
137
- cursor = Cursor.new(attributes)
137
+ cursor = described
138
138
  cursor.hide
139
139
  cursor.to_s.must_equal("\e[8;19H\e[?25l")
140
140
  end
@@ -142,12 +142,12 @@ module Vedeu
142
142
 
143
143
  it 'returns the escape sequence to position and set the visibility of ' \
144
144
  'the cursor' do
145
- Cursor.new(attributes).to_s.must_equal("\e[8;19H\e[?25h")
145
+ described.to_s.must_equal("\e[8;19H\e[?25h")
146
146
  end
147
147
 
148
148
  it 'returns the escape sequence to position and set the visibility of ' \
149
149
  'the cursor and returns to that position after yielding the block' do
150
- Cursor.new(attributes).to_s do
150
+ described.to_s do
151
151
  # ...
152
152
  end.must_equal("\e[8;19H\e[?25h\e[8;19H\e[?25h")
153
153
  end
@@ -4,15 +4,21 @@ module Vedeu
4
4
 
5
5
  describe Event do
6
6
 
7
+ let(:described) { Event.new(event_name, options, closure) }
7
8
  let(:event_name) { :some_event }
8
9
  let(:options) { {} }
9
10
  let(:closure) { proc { :event_triggered } }
10
11
 
11
-
12
12
  describe '#initialize' do
13
- it 'returns an instance of itself' do
14
- Event.new(event_name, options, closure).must_be_instance_of(Event)
15
- end
13
+ it { return_type_for(described, Event) }
14
+ it { assigns(described, '@name', :some_event) }
15
+ it { assigns(described, '@options', options) }
16
+
17
+ it { skip; assigns(described, '@closure', closure) }
18
+
19
+ it { assigns(described, '@deadline', 0) }
20
+ it { assigns(described, '@executed_at', 0) }
21
+ it { assigns(described, '@now', 0) }
16
22
  end
17
23
 
18
24
  describe '#trigger' do
@@ -4,10 +4,13 @@ module Vedeu
4
4
 
5
5
  describe Group do
6
6
 
7
+ let(:described) { Group.new('organics', *members) }
8
+ let(:members) { ['carbon', 'nitrogen', 'oxygen'] }
9
+
7
10
  describe '#initialize' do
8
- it 'returns a Group' do
9
- Group.new('organics').must_be_instance_of(Group)
10
- end
11
+ it { return_type_for(described, Group) }
12
+ it { assigns(described, '@members', members.to_set) }
13
+ it { assigns(described, '@name', 'organics') }
11
14
  end
12
15
 
13
16
  describe '#add' do
@@ -33,9 +36,7 @@ module Vedeu
33
36
  end
34
37
 
35
38
  describe '#members' do
36
- it 'returns an instance of Array' do
37
- Group.new('organics').members.must_be_instance_of(Array)
38
- end
39
+ it { return_type_for(described.members, Array) }
39
40
 
40
41
  context 'when the group has no members' do
41
42
  it 'returns an empty Set' do
@@ -83,9 +84,7 @@ module Vedeu
83
84
  end
84
85
 
85
86
  describe '#reset' do
86
- it 'returns a Group' do
87
- Group.new('organics').reset.must_be_instance_of(Group)
88
- end
87
+ it { return_type_for(described.reset, Group) }
89
88
 
90
89
  it 'returns a Group with no members' do
91
90
  group = Group.new('organics', 'nitrogen', 'carbon')
@@ -3,6 +3,9 @@ require 'test_helper'
3
3
  module Vedeu
4
4
 
5
5
  describe Interface do
6
+ let(:described) { Interface.new(attributes) }
7
+ let(:attributes) { {} }
8
+
6
9
  let(:interface) { Vedeu.use('#initialize') }
7
10
 
8
11
  before do
@@ -18,41 +21,60 @@ module Vedeu
18
21
  end
19
22
 
20
23
  describe '#initialize' do
21
- it 'returns an instance of itself' do
22
- interface.must_be_instance_of(Interface)
23
- end
24
+ it { return_type_for(described, Interface) }
25
+ it { assigns(described, '@attributes', {
26
+ border: {},
27
+ colour: {},
28
+ cursor: :hide,
29
+ delay: 0.0,
30
+ geometry: {},
31
+ group: '',
32
+ lines: [],
33
+ name: '',
34
+ parent: nil,
35
+ style: ''
36
+ })
37
+ }
38
+ it { assigns(described, '@cursor', :hide) }
39
+ it { assigns(described, '@delay', 0.0) }
40
+ it { assigns(described, '@group', '') }
41
+ it { assigns(described, '@name', '') }
42
+ it { assigns(described, '@parent', nil) }
24
43
  end
25
44
 
26
45
  describe '#attributes' do
27
46
  it 'returns the value' do
28
47
  interface.attributes.must_equal(
29
48
  {
30
- cursor: :hide,
31
- name: '#initialize',
32
- group: 'my_group',
33
- lines: [],
49
+ border: {},
34
50
  colour: {
35
51
  foreground: '#ff0000',
36
52
  background: '#000000'
37
53
  },
38
- style: '',
54
+ cursor: :hide,
55
+ delay: 0.0,
39
56
  geometry: {
40
57
  y: 3,
41
58
  x: 5,
42
59
  width: 10,
43
- height: 15
60
+ height: 15,
44
61
  },
45
- delay: 0.0,
46
- parent: nil
62
+ group: 'my_group',
63
+ lines: [],
64
+ name: '#initialize',
65
+ parent: nil,
66
+ style: '',
47
67
  }
48
68
  )
49
69
  end
50
70
  end
51
71
 
72
+ describe '#border' do
73
+ it { return_type_for(described.border, Border) }
74
+ end
75
+
52
76
  describe '#cursor' do
53
- it 'returns a Cursor' do
54
- interface.cursor.must_be_instance_of(Cursor)
55
- end
77
+ it { return_type_for(described.cursor, Cursor) }
56
78
  end
57
79
 
58
80
  describe '#name' do
@@ -88,9 +110,7 @@ module Vedeu
88
110
  end
89
111
 
90
112
  describe '#geometry' do
91
- it 'returns the value' do
92
- interface.geometry.must_be_instance_of(Geometry)
93
- end
113
+ it { return_type_for(described.geometry, Geometry) }
94
114
  end
95
115
 
96
116
  describe '#delay' do