vedeu 0.8.8 → 0.8.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. checksums.yaml +4 -4
  2. data/docs/dsl/by_method/focus_by_name.md +6 -1
  3. data/docs/dsl/by_method/focus_next.md +7 -0
  4. data/docs/dsl/by_method/focus_previous.md +7 -0
  5. data/docs/events/by_name/mouse_event.md +8 -0
  6. data/lib/vedeu.rb +12 -0
  7. data/lib/vedeu/all.rb +2 -0
  8. data/lib/vedeu/application/controller.rb +2 -6
  9. data/lib/vedeu/buffers/empty.rb +2 -1
  10. data/lib/vedeu/cells/borders/vertices/bottom_left.rb +1 -1
  11. data/lib/vedeu/cells/borders/vertices/bottom_right.rb +1 -1
  12. data/lib/vedeu/cells/borders/vertices/top_left.rb +1 -1
  13. data/lib/vedeu/cells/borders/vertices/top_right.rb +1 -1
  14. data/lib/vedeu/cells/char.rb +2 -6
  15. data/lib/vedeu/cells/cursor.rb +1 -1
  16. data/lib/vedeu/cells/support/html.rb +6 -18
  17. data/lib/vedeu/coercers/all.rb +18 -1
  18. data/lib/vedeu/coercers/chars.rb +29 -0
  19. data/lib/vedeu/coercers/coercer.rb +59 -0
  20. data/lib/vedeu/coercers/colour.rb +15 -33
  21. data/lib/vedeu/coercers/colour_attributes.rb +8 -3
  22. data/lib/vedeu/coercers/editor_line.rb +36 -0
  23. data/lib/vedeu/coercers/editor_lines.rb +36 -0
  24. data/lib/vedeu/coercers/lines.rb +36 -0
  25. data/lib/vedeu/coercers/page.rb +52 -0
  26. data/lib/vedeu/coercers/position.rb +69 -0
  27. data/lib/vedeu/coercers/row.rb +43 -0
  28. data/lib/vedeu/coercers/streams.rb +29 -0
  29. data/lib/vedeu/coercers/style.rb +54 -0
  30. data/lib/vedeu/configuration/api.rb +10 -0
  31. data/lib/vedeu/configuration/configuration.rb +11 -0
  32. data/lib/vedeu/cursors/coordinate.rb +41 -66
  33. data/lib/vedeu/cursors/cursor.rb +4 -4
  34. data/lib/vedeu/cursors/reposition.rb +3 -3
  35. data/lib/vedeu/dsl/border.rb +2 -39
  36. data/lib/vedeu/dsl/elements.rb +5 -6
  37. data/lib/vedeu/dsl/geometry.rb +3 -12
  38. data/lib/vedeu/editor/cropper.rb +2 -1
  39. data/lib/vedeu/error.rb +4 -0
  40. data/lib/vedeu/geometries/position.rb +14 -27
  41. data/lib/vedeu/input/mouse.rb +14 -5
  42. data/lib/vedeu/input/read.rb +1 -11
  43. data/lib/vedeu/interfaces/clear.rb +2 -1
  44. data/lib/vedeu/logging/log.rb +1 -1
  45. data/lib/vedeu/models/page.rb +5 -23
  46. data/lib/vedeu/models/row.rb +5 -14
  47. data/lib/vedeu/models/toggleable.rb +2 -7
  48. data/lib/vedeu/plugins/plugin.rb +1 -0
  49. data/lib/vedeu/presentation/style.rb +4 -20
  50. data/lib/vedeu/renderers/all.rb +24 -10
  51. data/lib/vedeu/repositories/model.rb +2 -8
  52. data/lib/vedeu/repositories/registerable.rb +4 -9
  53. data/lib/vedeu/runtime/application.rb +2 -0
  54. data/lib/vedeu/runtime/flags.rb +2 -0
  55. data/lib/vedeu/runtime/router.rb +2 -0
  56. data/lib/vedeu/support/point.rb +9 -7
  57. data/lib/vedeu/support/x_coordinate.rb +57 -0
  58. data/lib/vedeu/support/y_coordinate.rb +57 -0
  59. data/lib/vedeu/terminal/terminal.rb +2 -0
  60. data/lib/vedeu/version.rb +1 -1
  61. data/lib/vedeu/views/value.rb +3 -12
  62. data/test/lib/vedeu/coercers/chars_test.rb +33 -0
  63. data/test/lib/vedeu/coercers/coercer_test.rb +34 -0
  64. data/test/lib/vedeu/coercers/colour_test.rb +9 -7
  65. data/test/lib/vedeu/coercers/editor_line_test.rb +40 -0
  66. data/test/lib/vedeu/coercers/editor_lines_test.rb +40 -0
  67. data/test/lib/vedeu/coercers/lines_test.rb +40 -0
  68. data/test/lib/vedeu/coercers/page_test.rb +150 -0
  69. data/test/lib/vedeu/coercers/position_test.rb +76 -0
  70. data/test/lib/vedeu/coercers/row_test.rb +64 -0
  71. data/test/lib/vedeu/coercers/streams_test.rb +33 -0
  72. data/test/lib/vedeu/coercers/style_test.rb +62 -0
  73. data/test/lib/vedeu/cursors/coordinate_test.rb +11 -12
  74. data/test/lib/vedeu/geometries/position_test.rb +10 -54
  75. data/test/lib/vedeu/input/capture_test.rb +1 -1
  76. data/test/lib/vedeu/models/page_test.rb +4 -116
  77. data/test/lib/vedeu/models/row_test.rb +1 -31
  78. data/test/lib/vedeu/presentation/style_test.rb +4 -38
  79. data/test/lib/vedeu/renderers/all_test.rb +6 -0
  80. data/test/lib/vedeu/support/point_test.rb +13 -1
  81. data/test/lib/vedeu/support/x_coordinate_test.rb +64 -0
  82. data/test/lib/vedeu/support/y_coordinate_test.rb +64 -0
  83. data/test/support/examples/material_colours_app.rb +1 -0
  84. data/vedeu.gemspec +1 -1
  85. metadata +41 -4
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ module Coercers
8
+
9
+ describe Style do
10
+
11
+ let(:described) { Vedeu::Coercers::Style }
12
+ let(:instance) { described.new(_value) }
13
+ let(:_value) {}
14
+ let(:klass) { Vedeu::Presentation::Style }
15
+
16
+ describe '#initialize' do
17
+ it { instance.must_be_instance_of(described) }
18
+ it { instance.instance_variable_get('@value').must_equal(_value) }
19
+ end
20
+
21
+ describe '.coerce' do
22
+ it { described.must_respond_to(:coerce) }
23
+ end
24
+
25
+ describe '#coerce' do
26
+ subject { instance.coerce }
27
+
28
+ context 'when the value is already the target class' do
29
+ let(:_value) { klass.new }
30
+
31
+ it { subject.must_be_instance_of(klass) }
32
+ it { subject.must_equal(_value) }
33
+ end
34
+
35
+ context 'when the value is nil' do
36
+ let(:_value) { nil }
37
+
38
+ it { subject.must_be_instance_of(klass) }
39
+ end
40
+
41
+ context 'when the value is an Array' do
42
+ let(:_value) { [:bold, :blink] }
43
+
44
+ it { subject.value.must_equal([:bold, :blink]) }
45
+ end
46
+
47
+ context 'when the value is a Hash' do
48
+ let(:_value) {
49
+ {
50
+ style: [:bold, :blink]
51
+ }
52
+ }
53
+
54
+ it { subject.value.must_equal([:bold, :blink]) }
55
+ end
56
+ end
57
+
58
+ end # Style
59
+
60
+ end # Coercers
61
+
62
+ end # Vedeu
@@ -12,25 +12,24 @@ module Vedeu
12
12
  let(:instance) { described.new(attributes) }
13
13
  let(:attributes) {
14
14
  {
15
- name: _name,
16
- offset: offset,
17
- type: type,
15
+ geometry: geometry,
16
+ offset: offset,
17
+ type: type,
18
18
  }
19
19
  }
20
- let(:_name) {}
21
- let(:offset) {}
22
- let(:type) {}
23
20
  let(:geometry) {
24
- Vedeu::Geometries::Geometry.new(name: _name, x: 2, y: 3, xn: 10, yn: 6)
21
+ Vedeu::Geometries::Geometry.new(name: :vedeu_cursors_coordinate,
22
+ x: 2,
23
+ y: 3,
24
+ xn: 10,
25
+ yn: 6)
25
26
  }
26
-
27
- before do
28
- Vedeu.geometries.stubs(:by_name).returns(geometry)
29
- end
27
+ let(:offset) {}
28
+ let(:type) {}
30
29
 
31
30
  describe '#initialize' do
32
31
  it { instance.must_be_instance_of(described) }
33
- it { instance.instance_variable_get('@name').must_equal(_name) }
32
+ it { instance.instance_variable_get('@geometry').must_equal(geometry) }
34
33
  it { instance.instance_variable_get('@offset').must_equal(offset) }
35
34
  it { instance.instance_variable_get('@type').must_equal(type) }
36
35
  end
@@ -60,82 +60,38 @@ module Vedeu
60
60
  describe '.[]' do
61
61
  subject { described.[](y, x) }
62
62
 
63
- it { instance.must_be_instance_of(described) }
63
+ it { subject.must_be_instance_of(described) }
64
64
 
65
65
  context 'when the x and y coordinates are given' do
66
- it { instance.y.must_equal(12) }
67
- it { instance.x.must_equal(19) }
66
+ it { subject.y.must_equal(12) }
67
+ it { subject.x.must_equal(19) }
68
68
  end
69
69
 
70
70
  context 'when the x coordinate is not given' do
71
71
  let(:x) {}
72
72
 
73
- it { instance.y.must_equal(12) }
74
- it { instance.x.must_equal(1) }
73
+ it { subject.y.must_equal(12) }
74
+ it { subject.x.must_equal(1) }
75
75
  end
76
76
 
77
77
  context 'when the y coordinate is not given' do
78
78
  let(:y) {}
79
79
 
80
- it { instance.y.must_equal(1) }
81
- it { instance.x.must_equal(19) }
80
+ it { subject.y.must_equal(1) }
81
+ it { subject.x.must_equal(19) }
82
82
  end
83
83
 
84
84
  context 'when the x and y coordinates are not given' do
85
85
  let(:x) {}
86
86
  let(:y) {}
87
87
 
88
- it { instance.y.must_equal(1) }
89
- it { instance.x.must_equal(1) }
88
+ it { subject.y.must_equal(1) }
89
+ it { subject.x.must_equal(1) }
90
90
  end
91
91
  end
92
92
 
93
93
  describe '.coerce' do
94
- let(:_value) {}
95
-
96
- subject { described.coerce(_value) }
97
-
98
- context 'when the value is already a Position' do
99
- let(:_value) { instance }
100
-
101
- it { subject.must_equal(instance) }
102
- end
103
-
104
- context 'when the value is an Array' do
105
- let(:_value) { [2, 8] }
106
-
107
- it { subject.must_be_instance_of(described) }
108
- it { subject.y.must_equal(2) }
109
- it { subject.x.must_equal(8) }
110
- end
111
-
112
- context 'when the value is an Fixnum' do
113
- let(:_value) { 2 }
114
-
115
- it { subject.must_be_instance_of(described) }
116
- it { subject.y.must_equal(2) }
117
- it { subject.x.must_equal(1) }
118
- end
119
-
120
- context 'when the value is a Hash' do
121
- let(:_value) { { y: 3, x: 9 } }
122
-
123
- it { subject.must_be_instance_of(described) }
124
- it { subject.y.must_equal(3) }
125
- it { subject.x.must_equal(9) }
126
- end
127
-
128
- context 'when the value is a NilClass' do
129
- let(:_value) {}
130
-
131
- it { subject.must_be_instance_of(NilClass) }
132
- end
133
-
134
- context 'when the value is something unhandled' do
135
- let(:_value) { :invalid }
136
-
137
- it { subject.must_be_instance_of(NilClass) }
138
- end
94
+ it { described.must_respond_to(:coerce) }
139
95
  end
140
96
 
141
97
  describe '#<=>' do
@@ -40,7 +40,7 @@ module Vedeu
40
40
 
41
41
  subject { described.read }
42
42
 
43
- it 'appends "Waiting for user input..." to the log' do
43
+ it 'writes to the log file' do
44
44
  Vedeu.expects(:log)
45
45
  subject
46
46
  end
@@ -32,124 +32,12 @@ module Vedeu
32
32
  end
33
33
  end
34
34
 
35
- describe '#rows' do
36
- it { instance.must_respond_to(:rows) }
37
- end
38
-
39
35
  describe '.coerce' do
40
- let(:_value) {}
41
-
42
- subject { described.coerce(_value) }
43
-
44
- it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
45
-
46
- context 'when the value is a Vedeu::Models::Page' do
47
- let(:_value) { described.new }
48
-
49
- it { subject.must_equal(_value) }
50
- end
51
-
52
- context 'when the value is a Vedeu::Models::Row' do
53
- let(:_value) { Vedeu::Models::Row.new }
54
- let(:expected) { described.new([_value]) }
55
-
56
- it { subject.must_equal(expected) }
57
- end
58
-
59
- context 'when the value is an Array' do
60
- context 'and the value is empty' do
61
- let(:_value) { [] }
62
- let(:expected) {
63
- described.coerce(Vedeu::Models::Row.coerce(_value))
64
- }
65
-
66
- it { subject.must_be_instance_of(described) }
67
- it { subject.must_equal(expected) }
68
- end
69
-
70
- context 'and the value is not empty, the content is' do
71
- context 'is an empty Array' do
72
- let(:_value) { [[]] }
73
- let(:expected) { described.coerce(Vedeu::Models::Row.coerce([])) }
74
-
75
- it { subject.must_be_instance_of(described) }
76
- it { subject.must_equal(expected) }
77
- end
78
-
79
- context 'an array of Vedeu::Models::Row objects' do
80
- let(:_value) {
81
- [
82
- Vedeu::Models::Row.new([:hydrogen, :helium]),
83
- Vedeu::Models::Row.new([:lithium, :beryllium]),
84
- ]
85
- }
86
- let(:expected) { described.new(_value) }
87
-
88
- it { subject.must_equal(expected) }
89
- end
90
-
91
- context 'a mix of Vedeu::Models::Row objects and other objects' do
92
- let(:_value) {
93
- [
94
- Vedeu::Models::Row.new([:hydrogen, :helium]),
95
- [:lithium],
96
- Vedeu::Models::Row.new([:beryllium, :boron]),
97
- ]
98
- }
99
- let(:expected) {
100
- described.new([
101
- Vedeu::Models::Row.new([:hydrogen, :helium]),
102
- Vedeu::Models::Row.new([:lithium]),
103
- Vedeu::Models::Row.new([:beryllium, :boron]),
104
- ])
105
- }
106
-
107
- it { subject.must_equal(expected) }
108
- end
109
-
110
- context 'a mix of Vedeu::Models::Row objects, other objects and ' \
111
- 'nils' do
112
- let(:_value) {
113
- [
114
- Vedeu::Models::Row.new([:hydrogen, :helium]),
115
- nil,
116
- [:lithium],
117
- Vedeu::Models::Row.new([:beryllium]),
118
- [
119
- Vedeu::Cells::Char.new(value: 'b'),
120
- Vedeu::Cells::Char.new(value: 'o'),
121
- Vedeu::Cells::Char.new(value: 'r'),
122
- Vedeu::Cells::Char.new(value: 'o'),
123
- Vedeu::Cells::Char.new(value: 'n'),
124
- ],
125
- [nil, :carbon],
126
- :nitrogen,
127
- ]
128
- }
129
- let(:expected) {
130
- described.new([
131
- Vedeu::Models::Row.new([:hydrogen, :helium]),
132
- Vedeu::Models::Row.new([]),
133
- Vedeu::Models::Row.new([:lithium]),
134
- Vedeu::Models::Row.new([:beryllium]),
135
- Vedeu::Models::Row.new([
136
- Vedeu::Cells::Char.new(value: 'b'),
137
- Vedeu::Cells::Char.new(value: 'o'),
138
- Vedeu::Cells::Char.new(value: 'r'),
139
- Vedeu::Cells::Char.new(value: 'o'),
140
- Vedeu::Cells::Char.new(value: 'n'),
141
- ]),
142
- Vedeu::Models::Row.new([:carbon]),
143
- Vedeu::Models::Row.new([:nitrogen]),
144
- ])
145
- }
146
-
147
- it { subject.must_equal(expected) }
148
- end
149
-
150
- end
36
+ it { described.must_respond_to(:coerce) }
37
+ end
151
38
 
152
- end
39
+ describe '#rows' do
40
+ it { instance.must_respond_to(:rows) }
153
41
  end
154
42
 
155
43
  describe '#cell' do
@@ -33,37 +33,7 @@ module Vedeu
33
33
  end
34
34
 
35
35
  describe '.coerce' do
36
- subject { described.coerce(_value) }
37
-
38
- context 'when the value is a Vedeu::Models::Row' do
39
- let(:_value) { described.new }
40
-
41
- it { subject.must_equal(_value) }
42
- end
43
-
44
- context 'when the value is an Array' do
45
- let(:_value) { [:hydrogen, :helium, :lithium] }
46
-
47
- it { subject.must_equal(described.new(_value)) }
48
- end
49
-
50
- context 'when the value is an Array containing nil objects' do
51
- let(:_value) { [:hydrogen, nil, :lithium] }
52
-
53
- it { subject.must_equal(described.new([:hydrogen, :lithium])) }
54
- end
55
-
56
- context 'when the value is nil' do
57
- let(:_value) {}
58
-
59
- it { subject.must_equal(described.new) }
60
- end
61
-
62
- context 'when the value is anything else' do
63
- let(:_value) { :beryllium }
64
-
65
- it { subject.must_equal(described.new([_value])) }
66
- end
36
+ it { described.must_respond_to(:coerce) }
67
37
  end
68
38
 
69
39
  describe '#cell' do
@@ -17,6 +17,10 @@ module Vedeu
17
17
  it { instance.instance_variable_get('@value').must_equal('bold') }
18
18
  end
19
19
 
20
+ describe '.coerce' do
21
+ it { described.must_respond_to(:coerce) }
22
+ end
23
+
20
24
  describe '#escape_sequences' do
21
25
  it { instance.must_respond_to(:escape_sequences) }
22
26
  end
@@ -29,44 +33,6 @@ module Vedeu
29
33
  it { instance.must_respond_to(:value=) }
30
34
  end
31
35
 
32
- describe '.coerce' do
33
- let(:_value) { 'bold' }
34
-
35
- subject { described.coerce(_value) }
36
-
37
- it { subject.must_be_instance_of(described) }
38
-
39
- context 'when the value is nil' do
40
- let(:_value) { nil }
41
-
42
- it { subject.must_be_instance_of(described) }
43
- end
44
-
45
- context 'when the value is a Style already' do
46
- let(:_value) { Vedeu::Presentation::Style.new('bold') }
47
-
48
- it 'returns the value' do
49
- subject.must_equal(_value)
50
- end
51
- end
52
-
53
- context 'when the value is an Array' do
54
- let(:_value) { [:bold, :blink] }
55
-
56
- it { subject.value.must_equal([:bold, :blink]) }
57
- end
58
-
59
- context 'when the value is a Hash' do
60
- let(:_value) {
61
- {
62
- style: [:bold, :blink]
63
- }
64
- }
65
-
66
- it { subject.value.must_equal([:bold, :blink]) }
67
- end
68
- end
69
-
70
36
  describe '#attributes' do
71
37
  subject { instance.attributes }
72
38
 
@@ -27,6 +27,12 @@ module Vedeu
27
27
  }
28
28
  after { Vedeu::Renderers.reset }
29
29
 
30
+ describe '.clear' do
31
+ subject { described.clear }
32
+
33
+ it { described.must_respond_to(:clear) }
34
+ end
35
+
30
36
  describe '.renderers' do
31
37
  subject { described.renderers }
32
38
 
@@ -26,7 +26,19 @@ module Vedeu
26
26
  it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
27
27
  end
28
28
 
29
- context 'when :max is not a Fixnum' do
29
+ context 'when :min is not given' do
30
+ subject { described.coerce(value: _value, max: max) }
31
+
32
+ it { subject.must_be_instance_of(Vedeu::Point) }
33
+ end
34
+
35
+ context 'when :max is not given' do
36
+ subject { described.coerce(value: _value, min: min) }
37
+
38
+ it { subject.must_be_instance_of(Vedeu::Point) }
39
+ end
40
+
41
+ context 'when :max is not a Fixnum or Float::INFINITY' do
30
42
  let(:max) { :invalid }
31
43
 
32
44
  it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }