vedeu 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/bin/vedeu +0 -3
  3. data/examples/borders_app.rb +0 -3
  4. data/examples/colours_app.rb +0 -3
  5. data/examples/configuration_app.rb +0 -3
  6. data/examples/cursor_app.rb +0 -3
  7. data/examples/focus_app.rb +0 -3
  8. data/examples/geometry_app.rb +0 -3
  9. data/examples/lines_app.rb +0 -3
  10. data/examples/view_templates_app/template.erb +1 -0
  11. data/examples/view_templates_app/view_templates_app.rb +82 -0
  12. data/lib/vedeu/all.rb +0 -1
  13. data/lib/vedeu/application.rb +7 -6
  14. data/lib/vedeu/bindings.rb +8 -8
  15. data/lib/vedeu/buffers/buffer.rb +14 -4
  16. data/lib/vedeu/buffers/display_buffer.rb +2 -2
  17. data/lib/vedeu/configuration/cli.rb +7 -1
  18. data/lib/vedeu/configuration/configuration.rb +4 -2
  19. data/lib/vedeu/cursor/all.rb +1 -1
  20. data/lib/vedeu/cursor/cursor.rb +29 -2
  21. data/lib/vedeu/cursor/move_cursor.rb +20 -6
  22. data/lib/vedeu/cursor/toggle_cursor.rb +2 -0
  23. data/lib/vedeu/distributed/client.rb +2 -0
  24. data/lib/vedeu/distributed/server.rb +3 -1
  25. data/lib/vedeu/distributed/subprocess.rb +6 -1
  26. data/lib/vedeu/distributed/test_application.rb +32 -9
  27. data/lib/vedeu/distributed/uri.rb +7 -1
  28. data/lib/vedeu/dsl/components/border.rb +2 -0
  29. data/lib/vedeu/dsl/components/geometry.rb +2 -0
  30. data/lib/vedeu/dsl/components/keymap.rb +2 -0
  31. data/lib/vedeu/dsl/components/menu.rb +3 -1
  32. data/lib/vedeu/dsl/composition.rb +31 -2
  33. data/lib/vedeu/dsl/group.rb +2 -0
  34. data/lib/vedeu/dsl/interface.rb +3 -1
  35. data/lib/vedeu/dsl/line.rb +2 -0
  36. data/lib/vedeu/dsl/shared/style.rb +1 -1
  37. data/lib/vedeu/dsl/shared/text.rb +1 -2
  38. data/lib/vedeu/dsl/stream.rb +2 -0
  39. data/lib/vedeu/dsl/view.rb +1 -1
  40. data/lib/vedeu/events/all.rb +1 -1
  41. data/lib/vedeu/events/event.rb +26 -10
  42. data/lib/vedeu/events/trigger.rb +11 -3
  43. data/lib/vedeu/geometry/all.rb +2 -0
  44. data/lib/vedeu/geometry/bounding_area.rb +7 -2
  45. data/lib/vedeu/geometry/content_geometry.rb +2 -0
  46. data/lib/vedeu/geometry/coordinate.rb +15 -6
  47. data/lib/vedeu/geometry/grid.rb +3 -1
  48. data/lib/vedeu/geometry/index_position.rb +77 -0
  49. data/lib/vedeu/geometry/limit.rb +15 -1
  50. data/lib/vedeu/geometry/position.rb +7 -2
  51. data/lib/vedeu/{output → geometry}/position_index.rb +12 -2
  52. data/lib/vedeu/geometry/position_validator.rb +9 -1
  53. data/lib/vedeu/input/all.rb +0 -1
  54. data/lib/vedeu/input/input.rb +2 -0
  55. data/lib/vedeu/input/keymap.rb +5 -3
  56. data/lib/vedeu/input/mapper.rb +7 -1
  57. data/lib/vedeu/launcher.rb +1 -1
  58. data/lib/vedeu/models/all.rb +6 -3
  59. data/lib/vedeu/models/char.rb +157 -0
  60. data/lib/vedeu/models/{view/composition.rb → composition.rb} +1 -4
  61. data/lib/vedeu/models/geometry.rb +36 -12
  62. data/lib/vedeu/models/group.rb +7 -3
  63. data/lib/vedeu/models/{view/interface.rb → interface.rb} +26 -10
  64. data/lib/vedeu/models/{view/line.rb → line.rb} +8 -4
  65. data/lib/vedeu/models/menu.rb +11 -3
  66. data/lib/vedeu/models/{view/stream.rb → stream.rb} +9 -4
  67. data/lib/vedeu/output/all.rb +3 -2
  68. data/lib/vedeu/output/background.rb +2 -2
  69. data/lib/vedeu/output/border.rb +65 -22
  70. data/lib/vedeu/output/char_builder.rb +36 -0
  71. data/lib/vedeu/output/clear.rb +62 -0
  72. data/lib/vedeu/output/colour.rb +15 -7
  73. data/lib/vedeu/output/compositor.rb +3 -1
  74. data/lib/vedeu/output/esc.rb +2 -2
  75. data/lib/vedeu/output/foreground.rb +2 -2
  76. data/lib/vedeu/output/html_char.rb +2 -0
  77. data/lib/vedeu/output/html_renderer.rb +6 -3
  78. data/lib/vedeu/output/output.rb +20 -92
  79. data/lib/vedeu/output/presentation.rb +21 -21
  80. data/lib/vedeu/output/renderer.rb +2 -0
  81. data/lib/vedeu/output/style.rb +4 -2
  82. data/lib/vedeu/output/text.rb +7 -1
  83. data/lib/vedeu/output/translator.rb +4 -2
  84. data/lib/vedeu/output/viewport.rb +4 -2
  85. data/lib/vedeu/output/virtual_buffer.rb +11 -1
  86. data/lib/vedeu/output/virtual_terminal.rb +34 -11
  87. data/lib/vedeu/output/wordwrap.rb +31 -20
  88. data/lib/vedeu/repositories/all.rb +3 -0
  89. data/lib/vedeu/repositories/collection.rb +83 -0
  90. data/lib/vedeu/repositories/collections.rb +35 -0
  91. data/lib/vedeu/{models → repositories}/model.rb +2 -0
  92. data/lib/vedeu/repositories/repository.rb +7 -1
  93. data/lib/vedeu/support/log.rb +1 -1
  94. data/lib/vedeu/support/sentence.rb +7 -1
  95. data/lib/vedeu/support/template.rb +14 -2
  96. data/lib/vedeu/support/terminal.rb +6 -6
  97. data/lib/vedeu/support/trace.rb +4 -4
  98. data/lib/vedeu/support/visible.rb +4 -4
  99. data/test/lib/vedeu/dsl/composition_test.rb +23 -0
  100. data/test/lib/vedeu/geometry/index_position_test.rb +121 -0
  101. data/test/lib/vedeu/{output → geometry}/position_index_test.rb +6 -0
  102. data/test/lib/vedeu/input/keymap_test.rb +2 -2
  103. data/test/lib/vedeu/models/{view/char_test.rb → char_test.rb} +31 -15
  104. data/test/lib/vedeu/models/{view/composition_test.rb → composition_test.rb} +0 -0
  105. data/test/lib/vedeu/models/{view/interface_test.rb → interface_test.rb} +0 -0
  106. data/test/lib/vedeu/models/line_test.rb +156 -0
  107. data/test/lib/vedeu/models/{view/stream_test.rb → stream_test.rb} +1 -16
  108. data/test/lib/vedeu/output/char_builder_test.rb +50 -0
  109. data/test/lib/vedeu/output/clear_test.rb +26 -0
  110. data/test/lib/vedeu/output/compositor_test.rb +0 -10
  111. data/test/lib/vedeu/output/html_renderer_test.rb +8 -3
  112. data/test/lib/vedeu/output/output_test.rb +0 -39
  113. data/test/lib/vedeu/output/viewport_test.rb +10 -66
  114. data/test/lib/vedeu/output/virtual_buffer_test.rb +18 -2
  115. data/test/lib/vedeu/output/virtual_terminal_test.rb +3 -14
  116. data/test/lib/vedeu/output/wordwrap_test.rb +8 -15
  117. data/test/lib/vedeu/repositories/collection_test.rb +108 -0
  118. data/test/lib/vedeu/repositories/collections_test.rb +71 -0
  119. data/test/lib/vedeu/{models → repositories}/model_test.rb +0 -0
  120. data/test/lib/vedeu/support/template_test.rb +21 -1
  121. data/test/support/helpers/model_test_class.rb +1 -1
  122. data/test/test_helper.rb +0 -1
  123. data/vedeu.gemspec +1 -1
  124. metadata +40 -44
  125. data/lib/vedeu/events/events.rb +0 -10
  126. data/lib/vedeu/input/keys.rb +0 -10
  127. data/lib/vedeu/models/collection.rb +0 -81
  128. data/lib/vedeu/models/view/all.rb +0 -12
  129. data/lib/vedeu/models/view/char.rb +0 -99
  130. data/lib/vedeu/models/view/chars.rb +0 -10
  131. data/lib/vedeu/models/view/interfaces.rb +0 -10
  132. data/lib/vedeu/models/view/lines.rb +0 -10
  133. data/lib/vedeu/models/view/streams.rb +0 -10
  134. data/lib/vedeu/output/index_position.rb +0 -35
  135. data/test/lib/vedeu/models/collection_test.rb +0 -112
  136. data/test/lib/vedeu/models/view/chars_test.rb +0 -16
  137. data/test/lib/vedeu/models/view/interfaces_test.rb +0 -16
  138. data/test/lib/vedeu/models/view/line_test.rb +0 -214
  139. data/test/lib/vedeu/models/view/lines_test.rb +0 -16
  140. data/test/lib/vedeu/models/view/streams_test.rb +0 -16
  141. data/test/lib/vedeu/output/index_position_test.rb +0 -64
@@ -4,16 +4,32 @@ module Vedeu
4
4
  #
5
5
  class Wordwrap
6
6
 
7
+ # @see {Vedeu::Wordwrap#initialize}
8
+ def self.for(text, options = {})
9
+ new(text, options).content
10
+ end
11
+
7
12
  # @param text [String]
8
13
  # @param options [Hash]
9
- # @option options ellipsis [String]
10
- # @option options width [Fixnum]
14
+ # @option options ellipsis [String] For when using mode `:prune`.
15
+ # @option options mode [Symbol] One of :default, :prune, :wrap
16
+ # @option options width [Fixnum] The width in characters to prune or wrap to.
11
17
  # @return [Vedeu::Wordwrap]
12
18
  def initialize(text, options = {})
13
19
  @text = text
14
20
  @options = defaults.merge!(options)
15
21
  end
16
22
 
23
+ # @return [Vedeu::Lines]
24
+ def content
25
+ case(mode)
26
+ when :prune then to_line_objects(prune)
27
+ when :wrap then to_line_objects(wrap)
28
+ else
29
+ to_line_objects(split_lines)
30
+ end
31
+ end
32
+
17
33
  # @return [Array<String>|String]
18
34
  def prune
19
35
  return text if text.size <= pruned_width
@@ -60,26 +76,15 @@ module Vedeu
60
76
  end
61
77
  end
62
78
 
63
- # @return [Vedeu::Lines]
64
- def as_lines
65
- if __callee__ == :prune_as_lines
66
- to_line_objects(prune)
67
-
68
- elsif __callee__ == :wrap_as_lines
69
- to_line_objects(wrap)
70
-
71
- else
72
- to_line_objects(split_lines)
73
-
74
- end
75
- end
76
- alias_method :prune_as_lines, :as_lines
77
- alias_method :wrap_as_lines, :as_lines
78
-
79
79
  private
80
80
 
81
- attr_reader :text,
82
- :options
81
+ # @!attribute [r] text
82
+ # @return [String]
83
+ attr_reader :text
84
+
85
+ # @!attribute [r] options
86
+ # @return [Hash]
87
+ attr_reader :options
83
88
 
84
89
  # @param text_as_lines [Array<String>]
85
90
  # @return [Vedeu::Lines]
@@ -137,6 +142,11 @@ module Vedeu
137
142
  options.fetch(:ellipsis)
138
143
  end
139
144
 
145
+ # @return [Symbol]
146
+ def mode
147
+ options.fetch(:mode)
148
+ end
149
+
140
150
  # @return [Fixnum]
141
151
  def width
142
152
  options.fetch(:width)
@@ -146,6 +156,7 @@ module Vedeu
146
156
  def defaults
147
157
  {
148
158
  ellipsis: '...',
159
+ mode: :default,
149
160
  width: 70,
150
161
  }
151
162
  end
@@ -1,3 +1,6 @@
1
+ require 'vedeu/repositories/collection'
2
+ require 'vedeu/repositories/collections'
3
+ require 'vedeu/repositories/model'
1
4
  require 'vedeu/repositories/repository'
2
5
 
3
6
  module Vedeu
@@ -0,0 +1,83 @@
1
+ module Vedeu
2
+
3
+ # Convert an Array into an object which has some meaning in the context it
4
+ # is being used.
5
+ #
6
+ class Collection
7
+
8
+ include Enumerable
9
+
10
+ # @!attribute [rw] parent
11
+ # @return [Fixnum]
12
+ attr_accessor :parent
13
+
14
+ # @!attribute [rw] name
15
+ # @return [String]
16
+ attr_accessor :name
17
+
18
+ # @param collection [Array|Vedeu::Collection]
19
+ # @param parent [void]
20
+ # @param name [String|NilClass]
21
+ # @return [Vedeu::Collection]
22
+ def self.coerce(collection = [], parent = nil, name = nil)
23
+ if collection.kind_of?(Vedeu::Collection)
24
+ collection
25
+
26
+ else
27
+ new(Array(collection), parent, name)
28
+
29
+ end
30
+ end
31
+
32
+ # @param collection []
33
+ # @param parent [void]
34
+ # @param name [String|NilClass]
35
+ # @return [Vedeu::Collection]
36
+ def initialize(collection = [], parent = nil, name = nil)
37
+ @collection = collection
38
+ @parent = parent
39
+ @name = name
40
+ end
41
+
42
+ # @param value [Fixnum]
43
+ # @return [void]
44
+ def [](value)
45
+ @collection[value]
46
+ end
47
+
48
+ # @param other [Vedeu::Collection]
49
+ # @return [Vedeu::Collection]
50
+ def add(*other)
51
+ self.class.new(@collection += other, parent, name)
52
+ end
53
+ alias_method :<<, :add
54
+
55
+ # @return [Array]
56
+ def all
57
+ @collection
58
+ end
59
+
60
+ # @param block [Proc]
61
+ # @return [Enumerator]
62
+ def each(&block)
63
+ @collection.each(&block)
64
+ end
65
+
66
+ # @return [Boolean]
67
+ def empty?
68
+ @collection.empty?
69
+ end
70
+
71
+ # @return [Fixnum]
72
+ def size
73
+ @collection.size
74
+ end
75
+
76
+ # @return [String]
77
+ def to_s
78
+ @collection.map(&:to_s).join
79
+ end
80
+
81
+ end # Collection
82
+
83
+ end # Vedeu
@@ -0,0 +1,35 @@
1
+ require 'vedeu/repositories/collection'
2
+
3
+ module Vedeu
4
+
5
+ # A collection of {Vedeu::Char} instances.
6
+ #
7
+ class Chars < Vedeu::Collection
8
+ end # Chars
9
+
10
+ # A collection of {Vedeu::Event} instances.
11
+ #
12
+ class Events < Vedeu::Collection
13
+ end # Events
14
+
15
+ # A collection of {Vedeu::Interface} instances.
16
+ #
17
+ class Interfaces < Vedeu::Collection
18
+ end # Interfaces
19
+
20
+ # A collection of {Vedeu::Key} instances.
21
+ #
22
+ class Keys < Vedeu::Collection
23
+ end # Keys
24
+
25
+ # A collection of {Vedeu::Line} instances.
26
+ #
27
+ class Lines < Vedeu::Collection
28
+ end # Lines
29
+
30
+ # A collection of {Vedeu::Stream} instances.
31
+ #
32
+ class Streams < Vedeu::Collection
33
+ end # Streams
34
+
35
+ end # Vedeu
@@ -5,6 +5,8 @@ module Vedeu
5
5
  #
6
6
  module Model
7
7
 
8
+ # @!attribute [r] repository
9
+ # @return [Vedeu::Repository]
8
10
  attr_reader :repository
9
11
 
10
12
  # When {Vedeu::Model} is included in a class, the methods within this module
@@ -16,7 +16,13 @@ module Vedeu
16
16
  include Vedeu::Common
17
17
  include Enumerable
18
18
 
19
- attr_reader :model, :storage
19
+ # @!attribute [r] model
20
+ # @return [void]
21
+ attr_reader :model
22
+
23
+ # @!attribute [r] storage
24
+ # @return [void]
25
+ attr_reader :storage
20
26
 
21
27
  # @param model [Class]
22
28
  # @param storage [Class|Hash]
@@ -138,7 +138,7 @@ module Vedeu
138
138
 
139
139
  # @return [String]
140
140
  def message_type(type)
141
- Esc.send(message_types.fetch(type, :default)) { "[#{type}]".ljust(9) }
141
+ Vedeu::Esc.send(message_types.fetch(type, :default)) { "[#{type}]".ljust(9) }
142
142
  end
143
143
 
144
144
  # @return [Hash]
@@ -41,7 +41,13 @@ module Vedeu
41
41
 
42
42
  private
43
43
 
44
- attr_reader :elements, :label
44
+ # @!attribute [r] elements
45
+ # @return [Array]
46
+ attr_reader :elements
47
+
48
+ # @!attribute [r] label
49
+ # @return [String]
50
+ attr_reader :label
45
51
 
46
52
  # @return [Boolean]
47
53
  def one?
@@ -17,7 +17,7 @@ module Vedeu
17
17
  # @param path [String]
18
18
  # @return [Template]
19
19
  def initialize(object, path)
20
- @object, @path = object, path
20
+ @object, @path = object, path.to_s
21
21
  end
22
22
 
23
23
  # @return [void]
@@ -27,13 +27,25 @@ module Vedeu
27
27
 
28
28
  private
29
29
 
30
- attr_reader :object, :path
30
+ # @!attribute [r] object
31
+ # @return [Class]
32
+ attr_reader :object
31
33
 
32
34
  # @return [String]
33
35
  def load
34
36
  File.read(path)
35
37
  end
36
38
 
39
+ # @raise [MissingRequired] when the path is empty.
40
+ # @raise [MissingRequired] when the path does not exist.
41
+ # @return [String]
42
+ def path
43
+ fail MissingRequired, 'No path to template specified.' if @path.empty?
44
+ fail MissingRequired, 'Template file cannot be found.' unless File.exist?(@path)
45
+
46
+ @path
47
+ end
48
+
37
49
  end # Template
38
50
 
39
51
  end # Vedeu
@@ -167,7 +167,7 @@ module Vedeu
167
167
  #
168
168
  # @return [Symbol]
169
169
  def mode
170
- @mode ||= Configuration.terminal_mode
170
+ @mode ||= Vedeu::Configuration.terminal_mode
171
171
  end
172
172
 
173
173
  # Returns a coordinate tuple of the format [y, x], where `y` is the row/line
@@ -214,8 +214,8 @@ module Vedeu
214
214
  #
215
215
  # @return [Fixnum]
216
216
  def width
217
- if Configuration.drb?
218
- Configuration.drb_width
217
+ if Vedeu::Configuration.drb?
218
+ Vedeu::Configuration.drb_width
219
219
 
220
220
  else
221
221
  size.last
@@ -232,8 +232,8 @@ module Vedeu
232
232
  #
233
233
  # @return [Fixnum]
234
234
  def height
235
- if Configuration.drb?
236
- Configuration.drb_height
235
+ if Vedeu::Configuration.drb?
236
+ Vedeu::Configuration.drb_height
237
237
 
238
238
  else
239
239
  size.first
@@ -259,7 +259,7 @@ module Vedeu
259
259
 
260
260
  # @return [VirtualTerminal]
261
261
  def virtual
262
- @virtual ||= VirtualTerminal.new(height, width)
262
+ @virtual ||= Vedeu::VirtualTerminal.new(height, width)
263
263
  end
264
264
 
265
265
  end # Terminal
@@ -90,11 +90,11 @@ module Vedeu
90
90
  valclass = value.class.to_s
91
91
  output = (value.is_a?(Proc)) ? '#<Proc:...' : value.inspect
92
92
 
93
- content = Esc.send(class_colour.fetch(valclass, :white)) { output }
93
+ content = Vedeu::Esc.send(class_colour.fetch(valclass, :white)) { output }
94
94
 
95
95
  entries << sprintf("%33s %-10s = %s %s", " ",
96
- Esc.green { variable },
97
- Esc.magenta { valclass },
96
+ Vedeu::Esc.green { variable },
97
+ Vedeu::Esc.magenta { valclass },
98
98
  content)
99
99
  end
100
100
  entries.join("\n")
@@ -232,7 +232,7 @@ module Vedeu
232
232
  # 'Vedeu::Menu',
233
233
  # 'Vedeu::Menus',
234
234
  # 'Vedeu::Model',
235
- # 'Vedeu::Model::Collection',
235
+ # 'Vedeu::Collection',
236
236
  # 'Vedeu::MoveCursor',
237
237
  # 'Vedeu::Node',
238
238
  # 'Vedeu::Output',
@@ -36,10 +36,10 @@ module Vedeu
36
36
  # @return [String]
37
37
  def cursor
38
38
  if visible?
39
- Esc.string('show_cursor')
39
+ Vedeu::Esc.string('show_cursor')
40
40
 
41
41
  else
42
- Esc.string('hide_cursor')
42
+ Vedeu::Esc.string('hide_cursor')
43
43
 
44
44
  end
45
45
  end
@@ -56,12 +56,12 @@ module Vedeu
56
56
 
57
57
  # @return [Visible]
58
58
  def hide
59
- Visible.new(false)
59
+ Vedeu::Visible.new(false)
60
60
  end
61
61
 
62
62
  # @return [Visible]
63
63
  def show
64
- Visible.new(true)
64
+ Vedeu::Visible.new(true)
65
65
  end
66
66
 
67
67
  # @return [Visible]
@@ -32,6 +32,29 @@ module Vedeu
32
32
  end
33
33
  end
34
34
 
35
+ describe '#template_for' do
36
+ let(:_name) {}
37
+ let(:filename) {}
38
+ let(:object) {}
39
+ let(:content) { "Hydrogen\nCarbon\nOxygen\nNitrogen" }
40
+ let(:as_lines) {
41
+ [
42
+ Vedeu::Line.new({ streams: [Vedeu::Stream.new({ value: 'Hydrogen' })] }),
43
+ Vedeu::Line.new({ streams: [Vedeu::Stream.new({ value: 'Carbon' })] }),
44
+ Vedeu::Line.new({ streams: [Vedeu::Stream.new({ value: 'Oxygen' })] }),
45
+ Vedeu::Line.new({ streams: [Vedeu::Stream.new({ value: 'Nitrogen' })] })
46
+ ]
47
+ }
48
+
49
+ before do
50
+ Vedeu::Template.expects(:parse).with(object, filename).returns(content)
51
+ end
52
+
53
+ subject { instance.template_for(_name, filename, object) }
54
+
55
+ it { subject.must_be_instance_of(Vedeu::Interfaces) }
56
+ end
57
+
35
58
  end # Composition
36
59
 
37
60
  end # DSL
@@ -0,0 +1,121 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ describe IndexPosition do
6
+
7
+ let(:described) { Vedeu::IndexPosition }
8
+ let(:instance) { described.new(iy, ix, oy, ox) }
9
+ let(:iy) { 6 }
10
+ let(:ix) { 17 }
11
+ let(:oy) { 3 }
12
+ let(:ox) { 5 }
13
+
14
+ describe 'alias methods' do
15
+ it { instance.must_respond_to(:first) }
16
+ it { instance.must_respond_to(:last) }
17
+ end
18
+
19
+ describe '#initialize' do
20
+ it { instance.must_be_instance_of(described) }
21
+ it { instance.instance_variable_get('@oy').must_equal(3) }
22
+ it { instance.instance_variable_get('@ox').must_equal(5) }
23
+ it { instance.instance_variable_get('@iy').must_equal(6) }
24
+ it { instance.instance_variable_get('@ix').must_equal(17) }
25
+ end
26
+
27
+ describe '.[]' do
28
+ subject { described[iy, ix] }
29
+
30
+ it { subject.must_be_instance_of(Array) }
31
+ it { subject.must_equal([7, 18]) }
32
+ end
33
+
34
+ describe '#[]' do
35
+ subject { instance.[] }
36
+
37
+ it { subject.must_be_instance_of(Array) }
38
+ it { subject.must_equal([9, 22]) }
39
+ end
40
+
41
+ describe '#to_position' do
42
+ subject { instance.to_position }
43
+
44
+ it { subject.must_be_instance_of(Vedeu::Position) }
45
+ end
46
+
47
+ describe '#y' do
48
+ subject { instance.y }
49
+
50
+ context 'when iy is <= 0' do
51
+ let(:iy) { -2 }
52
+
53
+ context 'and oy is <= 1' do
54
+ let(:oy) { -6 }
55
+
56
+ it { subject.must_equal(1) }
57
+ end
58
+
59
+ context 'and oy is > 1' do
60
+ let(:oy) { 4 }
61
+
62
+ it { subject.must_equal(4) }
63
+ end
64
+ end
65
+
66
+ context 'when iy is > 0' do
67
+ let(:iy) { 3 }
68
+
69
+ context 'and oy is <= 1' do
70
+ let(:oy) { -7 }
71
+
72
+ it { subject.must_equal(4) }
73
+ end
74
+
75
+ context 'and oy is > 1' do
76
+ let(:oy) { 5 }
77
+
78
+ it { subject.must_equal(8) }
79
+ end
80
+ end
81
+ end
82
+
83
+ describe '#x' do
84
+ subject { instance.x }
85
+
86
+ context 'when ix is <= 0' do
87
+ let(:ix) { -2 }
88
+
89
+ context 'and ox is <= 1' do
90
+ let(:ox) { -6 }
91
+
92
+ it { subject.must_equal(1) }
93
+ end
94
+
95
+ context 'and ox is > 1' do
96
+ let(:ox) { 4 }
97
+
98
+ it { subject.must_equal(4) }
99
+ end
100
+ end
101
+
102
+ context 'when ix is > 0' do
103
+ let(:ix) { 3 }
104
+
105
+ context 'and ox is <= 1' do
106
+ let(:ox) { -7 }
107
+
108
+ it { subject.must_equal(4) }
109
+ end
110
+
111
+ context 'and ox is > 1' do
112
+ let(:ox) { 5 }
113
+
114
+ it { subject.must_equal(8) }
115
+ end
116
+ end
117
+ end
118
+
119
+ end # IndexPosition
120
+
121
+ end # Vedeu
@@ -41,6 +41,12 @@ module Vedeu
41
41
  it { subject.must_equal([5, 16]) }
42
42
  end
43
43
 
44
+ describe '#to_position' do
45
+ subject { instance.to_position }
46
+
47
+ it { subject.must_be_instance_of(Vedeu::Position) }
48
+ end
49
+
44
50
  describe 'attr_reader' do
45
51
  context '#y' do
46
52
  subject { instance.y }
@@ -46,7 +46,7 @@ module Vedeu
46
46
  subject { instance.key_defined?(input) }
47
47
 
48
48
  context 'when the input is defined' do
49
- let(:keys) { Vedeu::Model::Collection.new([key]) }
49
+ let(:keys) { Vedeu::Keys.new([key]) }
50
50
 
51
51
  it { subject.must_be_instance_of(TrueClass) }
52
52
  end
@@ -65,7 +65,7 @@ module Vedeu
65
65
  let(:key_a) { Vedeu::Key.new('a') { :key_a } }
66
66
  let(:key_b) { Vedeu::Key.new('b') { :key_b } }
67
67
  let(:key_c) { Vedeu::Key.new('c') { :key_c } }
68
- let(:keys) { Vedeu::Model::Collection.new([key_a, key_b, key_c]) }
68
+ let(:keys) { Vedeu::Keys.new([key_a, key_b, key_c]) }
69
69
 
70
70
  it { subject.must_be_instance_of(Array) }
71
71
  it { subject.must_equal([:key_b]) }
@@ -8,15 +8,15 @@ module Vedeu
8
8
  let(:instance) { described.new(attributes) }
9
9
  let(:attributes) {
10
10
  {
11
- colour: colour,
12
- parent: parent,
11
+ colour: colour,
12
+ parent: parent,
13
13
  position: position,
14
- style: style,
15
- value: value,
14
+ style: style,
15
+ value: value,
16
16
  }
17
17
  }
18
18
  let(:value) { 'a' }
19
- let(:parent) { Line.new(parent_attributes) }
19
+ let(:parent) { Vedeu::Line.new(parent_attributes) }
20
20
  let(:parent_attributes) {
21
21
  {
22
22
  streams: [],
@@ -25,6 +25,7 @@ module Vedeu
25
25
  style: parent_style,
26
26
  }
27
27
  }
28
+ let(:border) { nil }
28
29
  let(:colour) { nil }
29
30
  let(:style) { nil }
30
31
  let(:position) { nil }
@@ -32,7 +33,8 @@ module Vedeu
32
33
  let(:parent_style) { nil }
33
34
 
34
35
  describe '#initialize' do
35
- it { instance.must_be_instance_of(Char) }
36
+ it { instance.must_be_instance_of(described) }
37
+ it { instance.instance_variable_get('@border').must_equal(border) }
36
38
  it { instance.instance_variable_get('@colour').must_equal(colour) }
37
39
  it { instance.instance_variable_get('@parent').must_equal(parent) }
38
40
  it { instance.instance_variable_get('@style').must_equal(style) }
@@ -41,6 +43,20 @@ module Vedeu
41
43
  it { instance.must_respond_to(:value) }
42
44
  end
43
45
 
46
+ describe '#inspect' do
47
+ let(:colour) { Vedeu::Colour.new({ foreground: '#00ff00',
48
+ background: '#005500' }) }
49
+ let(:position) { Vedeu::Position.new(17, 2) }
50
+ let(:style) { Vedeu::Style.new('underline') }
51
+
52
+
53
+ subject { instance.inspect }
54
+
55
+ it { subject.must_equal(
56
+ "<Vedeu::Char '\\e[17;2H\\e[38;2;0;255;0m\\e[48;2;0;85;0m\\e[4ma\\e[17;2H'>"
57
+ ) }
58
+ end
59
+
44
60
  describe '#to_html' do
45
61
  subject { instance.to_html }
46
62
 
@@ -53,7 +69,7 @@ module Vedeu
53
69
  it { subject.must_be_instance_of(String) }
54
70
 
55
71
  context 'when a position is specified' do
56
- let(:position) { Position.new(17, 2) }
72
+ let(:position) { Vedeu::Position.new(17, 2) }
57
73
 
58
74
  it { subject.must_equal("\e[17;2Ha\e[17;2H") }
59
75
  end
@@ -65,12 +81,12 @@ module Vedeu
65
81
  end
66
82
 
67
83
  context 'when a colour is specified' do
68
- let(:colour) { Colour.new({ foreground: '#00ff00',
69
- background: '#005500' }) }
84
+ let(:colour) { Vedeu::Colour.new({ foreground: '#00ff00',
85
+ background: '#005500' }) }
70
86
 
71
87
  context 'when a parent colour is specified' do
72
- let(:parent_colour) { Colour.new({ foreground: '#ff0000',
73
- background: '#550000' }) }
88
+ let(:parent_colour) { Vedeu::Colour.new({ foreground: '#ff0000',
89
+ background: '#550000' }) }
74
90
 
75
91
  it { subject.must_equal("\e[38;2;0;255;0m\e[48;2;0;85;0ma\e[38;2;255;0;0m\e[48;2;85;0;0m") }
76
92
  end
@@ -89,10 +105,10 @@ module Vedeu
89
105
  end
90
106
 
91
107
  context 'when a style is specified' do
92
- let(:style) { Style.new('underline') }
108
+ let(:style) { Vedeu::Style.new('underline') }
93
109
 
94
110
  context 'when a parent style is specified' do
95
- let(:parent_style) { Style.new('bold') }
111
+ let(:parent_style) { Vedeu::Style.new('bold') }
96
112
 
97
113
  it { subject.must_equal("\e[4ma\e[1m") }
98
114
  end
@@ -118,7 +134,7 @@ module Vedeu
118
134
  end
119
135
 
120
136
  describe '#x' do
121
- let(:position) { Position.new(17, 2) }
137
+ let(:position) { Vedeu::Position.new(17, 2) }
122
138
 
123
139
  subject { instance.x }
124
140
 
@@ -134,7 +150,7 @@ module Vedeu
134
150
  end
135
151
 
136
152
  describe '#y' do
137
- let(:position) { Position.new(17, 2) }
153
+ let(:position) { Vedeu::Position.new(17, 2) }
138
154
 
139
155
  subject { instance.y }
140
156