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
@@ -4,31 +4,15 @@ require_relative '../../../../lib/vedeu/models/colour'
4
4
 
5
5
  module Vedeu
6
6
  describe Background do
7
- let(:described_class) { Background }
8
- let(:described_instance) { Vedeu::Colour.new(attributes) }
9
- let(:attributes) {
10
- {
11
- background: '#00ff00'
12
- }
13
- }
14
-
15
7
  describe '#background' do
16
- let(:subject) { described_instance.background }
17
-
18
- it 'returns a String' do
19
- subject.must_be_instance_of(String)
20
- end
21
-
22
8
  it 'returns an escape sequence' do
23
- subject.must_equal("\e[48;5;46m")
9
+ Colour.new({
10
+ background: '#00ff00'
11
+ }).background.must_equal("\e[48;5;46m")
24
12
  end
25
13
 
26
- context 'when the foreground is missing' do
27
- let(:attributes) { {} }
28
-
29
- it 'returns an escape sequence' do
30
- subject.must_equal('')
31
- end
14
+ it 'returns an empty string when the foreground is missing' do
15
+ Colour.new.background.must_equal('')
32
16
  end
33
17
  end
34
18
  end
@@ -3,68 +3,37 @@ require_relative '../../../../lib/vedeu/models/colour'
3
3
 
4
4
  module Vedeu
5
5
  describe Colour do
6
- let(:described_class) { Colour }
7
- let(:described_instance) { described_class.new(attributes) }
8
- let(:attributes) {
9
- {
10
- foreground: '#ff0000',
11
- background: '#000000'
12
- }
13
- }
14
-
15
- describe '#initialize' do
16
- let(:subject) { described_instance }
17
-
18
- it 'returns a Colour instance' do
19
- subject.must_be_instance_of(Colour)
20
- end
21
- end
22
-
23
6
  describe '#to_json' do
24
- let(:subject) { described_instance.to_json }
25
-
26
- it 'returns a String' do
27
- subject.must_be_instance_of(String)
28
- end
29
-
30
7
  it 'returns the model as JSON' do
31
- subject.must_equal("{\"foreground\":\"\\u001b[38;5;196m\",\"background\":\"\\u001b[48;5;16m\"}")
8
+ Colour.new({
9
+ foreground: '#ff0000',
10
+ background: '#000000'
11
+ }).to_json.must_equal("{\"foreground\":\"\\u001b[38;5;196m\",\"background\":\"\\u001b[48;5;16m\"}")
32
12
  end
33
13
  end
34
14
 
35
15
  describe '#to_s' do
36
- let(:subject) { described_instance.to_s }
37
-
38
- it 'returns a String' do
39
- subject.must_be_instance_of(String)
40
- end
41
-
42
16
  it 'returns an escape sequence' do
43
- subject.must_equal("\e[38;5;196m\e[48;5;16m")
17
+ Colour.new({
18
+ foreground: '#ff0000',
19
+ background: '#000000'
20
+ }).to_s.must_equal("\e[38;5;196m\e[48;5;16m")
44
21
  end
45
22
 
46
- context 'when the foreground is missing' do
47
- let(:attributes) { { background: '#000000' } }
48
-
49
- it 'returns an escape sequence' do
50
- subject.must_equal("\e[48;5;16m")
51
- end
23
+ it 'returns an escape sequence when the foreground is missing' do
24
+ Colour.new({
25
+ background: '#000000'
26
+ }).to_s.must_equal("\e[48;5;16m")
52
27
  end
53
28
 
54
- context 'when the background is missing' do
55
- let(:attributes) { { foreground: '#ff0000' } }
56
-
57
- it 'returns an escape sequence' do
58
- subject.must_equal("\e[38;5;196m")
59
- end
29
+ it 'returns an escape sequence when the background is missing' do
30
+ Colour.new({
31
+ foreground: '#ff0000',
32
+ }).to_s.must_equal("\e[38;5;196m")
60
33
  end
61
34
 
62
- context 'when both are missing' do
63
- let(:attributes) { {} }
64
-
65
- it 'returns an empty string' do
66
- subject.must_equal('')
67
- end
35
+ it 'returns an empty string when both are missing' do
36
+ Colour.new.to_s.must_equal('')
68
37
  end
69
38
  end
70
39
  end
@@ -4,105 +4,41 @@ require_relative '../../../../lib/vedeu/models/command'
4
4
 
5
5
  module Vedeu
6
6
  describe Command do
7
- let(:described_class) { Command }
8
- let(:described_instance) { described_class.new(attributes) }
9
- let(:subject) { described_instance }
10
- let(:attributes) {
11
- {
12
- name: 'dummy',
13
- entity: DummyCommand,
14
- keyword: "dummy",
15
- keypress: "d",
16
- arguments: []
17
- }
18
- }
19
-
20
- describe '#initialize' do
21
- let(:subject) { described_instance }
22
-
23
- it 'returns a Command instance' do
24
- subject.must_be_instance_of(Command)
25
- end
7
+ it 'has a name attribute' do
8
+ Command.new({ name: 'dummy' }).name.must_equal('dummy')
26
9
  end
27
10
 
28
- describe '#name' do
29
- let(:subject) { described_instance.name }
30
-
31
- it 'returns a String' do
32
- subject.must_be_instance_of(String)
33
- end
34
-
35
- it 'has a name attribute' do
36
- subject.must_equal('dummy')
37
- end
11
+ it 'has an entity attribute' do
12
+ Command.new({ entity: DummyCommand }).entity.must_equal(DummyCommand)
38
13
  end
39
14
 
40
- describe '#entity' do
41
- let(:subject) { described_instance.entity }
42
-
43
- it 'returns a Class' do
44
- subject.must_be_instance_of(Class)
45
- end
46
-
47
- it 'has an entity attribute' do
48
- subject.must_equal(DummyCommand)
49
- end
15
+ it 'has a keypress attribute' do
16
+ Command.new({ keypress: 'd' }).keypress.must_equal('d')
50
17
  end
51
18
 
52
- describe '#keypress' do
53
- let(:subject) { described_instance.keypress }
54
-
55
- it 'returns a String' do
56
- subject.must_be_instance_of(String)
57
- end
58
-
59
- it 'has a keypress attribute' do
60
- subject.must_equal('d')
61
- end
19
+ it 'has an keyword attribute' do
20
+ Command.new({ keyword: 'dummy' }).keyword.must_equal('dummy')
62
21
  end
63
22
 
64
- describe '#keyword' do
65
- let(:subject) { described_instance.keyword }
66
-
67
- it 'returns a String' do
68
- subject.must_be_instance_of(String)
69
- end
70
-
71
- it 'has an keyword attribute' do
72
- subject.must_equal('dummy')
73
- end
74
- end
75
-
76
- describe '#arguments' do
77
- let(:subject) { described_instance.arguments }
78
-
79
- it 'returns a String' do
80
- subject.must_be_instance_of(Array)
81
- end
82
-
83
- it 'has an arguments attribute' do
84
- subject.must_equal([])
85
- end
23
+ it 'has an arguments attribute' do
24
+ Command.new({ arguments: [] }).arguments.must_equal([])
86
25
  end
87
26
 
88
27
  describe '#execute' do
89
- let(:subject) { described_instance.execute(args) }
90
- let(:args) { [] }
91
-
92
- it 'returns a Symbol' do
93
- subject.must_be_instance_of(Symbol)
94
- end
95
-
96
28
  it 'returns the result of execution' do
97
- subject.must_equal(:dummy)
29
+ Command.new({
30
+ name: 'dummy',
31
+ entity: DummyCommand,
32
+ keyword: 'dummy',
33
+ keypress: 'd',
34
+ arguments: []
35
+ }).execute(:dummy).must_equal(:dummy)
98
36
  end
99
37
  end
100
38
 
101
39
  describe '#executable' do
102
- let(:subject) { described_instance.executable }
103
-
104
- it 'returns a proc' do
105
- subject.class.to_s.must_equal('Proc')
40
+ it 'needs a spec, please write one.' do
41
+ skip
106
42
  end
107
43
  end
108
44
  end
@@ -4,231 +4,134 @@ require_relative '../../../../lib/vedeu/repository/interface_repository'
4
4
 
5
5
  module Vedeu
6
6
  describe Composition do
7
- let(:described_class) { Composition }
8
- let(:described_instance) { described_class.new(attributes) }
9
- let(:attributes) { { interfaces: interfaces } }
10
- let(:interfaces) {
11
- {
12
- name: 'dummy',
13
- width: 40,
14
- height: 25
15
- }
16
- }
17
-
18
- describe '#initialize' do
19
- let(:subject) { described_instance }
20
-
21
- it 'returns a Composition instance' do
22
- subject.must_be_instance_of(Composition)
23
- end
24
-
25
- it 'sets an instance variable' do
26
- subject.instance_variable_get('@interfaces')
27
- .must_be_instance_of(Array)
28
- end
29
- end
30
-
31
7
  describe '#interfaces' do
32
- let(:subject) { described_instance.interfaces }
33
-
34
- it 'returns an Array' do
35
- subject.must_be_instance_of(Array)
36
- end
37
-
38
8
  it 'returns a collection of interfaces' do
39
- subject.first.must_be_instance_of(Interface)
9
+ Composition.new({
10
+ interfaces: {
11
+ name: 'dummy',
12
+ width: 40,
13
+ height: 25
14
+ }
15
+ }).interfaces.first.must_be_instance_of(Interface)
40
16
  end
41
17
 
42
- context 'when no interfaces are associated' do
43
- let(:attributes) { {} }
44
-
45
- it 'returns an empty collection' do
46
- subject.must_be_empty
47
- end
18
+ it 'returns an empty collection when no interfaces are associated' do
19
+ Composition.new.interfaces.must_be_empty
48
20
  end
49
21
  end
50
22
 
51
23
  describe '.enqueue' do
52
- let(:subject) { described_class.enqueue(composition) }
53
- let(:composition) {
54
- {
24
+ it 'returns a collection of interfaces' do
25
+ Composition.enqueue({
55
26
  interfaces: [
56
- { name: "enq1", lines: { streams: { text: "Some text..." } } },
57
- { name: "enq2", lines: { streams: { text: "Some text..." } } }
27
+ { name: 'enq1', lines: { streams: { text: 'Composition.enqueue 1' } } },
28
+ { name: 'enq2', lines: { streams: { text: 'Composition.enqueue 2' } } }
58
29
  ]
59
- }
60
- }
61
-
62
- before do
63
- InterfaceRepository.create(name: 'enq1', width: 15, height: 2)
64
- InterfaceRepository.create(name: 'enq2', width: 15, height: 2)
65
- end
66
-
67
- it 'returns an Composition' do
68
- subject.must_be_instance_of(Composition)
69
- end
70
-
71
- it 'returns a collection of interfaces' do
72
- subject.interfaces.first.must_be_instance_of(Interface)
30
+ }).interfaces.first.must_be_instance_of(Interface)
73
31
  end
74
32
 
75
33
  it 'enqueues the interfaces for rendering' do
76
- subject.interfaces.first.enqueued?.must_equal(true)
34
+ Composition.enqueue({
35
+ interfaces: [
36
+ { name: 'enq1', lines: { streams: { text: 'Composition.enqueue 3' } } },
37
+ { name: 'enq2', lines: { streams: { text: 'Composition.enqueue 4' } } }
38
+ ]
39
+ }).interfaces.first.enqueued?.must_equal(true)
77
40
  end
78
41
  end
79
42
 
80
43
  describe '#to_json' do
81
- let(:subject) { described_instance.to_json }
82
-
83
- it 'returns a String' do
84
- subject.must_be_instance_of(String)
85
- end
86
-
87
44
  it 'returns the model as JSON' do
88
- subject.must_equal("{\"interfaces\":[{\"colour\":null,\"style\":\"\",\"name\":\"dummy\",\"lines\":[],\"y\":1,\"x\":1,\"z\":1,\"width\":40,\"height\":25,\"current\":\"\",\"cursor\":true}]}")
45
+ attributes = { interfaces: [{ name: 'Composition#to_json', width: 40, height: 25 }] }
46
+
47
+ Composition.new(attributes).to_json.must_equal("{\"interfaces\":[{\"colour\":null,\"style\":\"\",\"name\":\"Composition#to_json\",\"lines\":[],\"y\":1,\"x\":1,\"z\":1,\"width\":40,\"height\":25,\"current\":\"\",\"cursor\":true}]}")
89
48
  end
90
49
  end
91
50
 
92
51
  describe '#to_s' do
93
- let(:subject) { described_instance.to_s }
52
+ it 'returns the stringified content for a single interface, single line, single stream' do
53
+ InterfaceRepository.create({ name: 'int1_lin1_str1', y: 3, x: 3, width: 10, height: 3 })
54
+ json = File.read('test/support/json/int1_lin1_str1.json')
55
+ attributes = Oj.load(json, symbol_keys: true)
94
56
 
95
- it 'returns a String' do
96
- subject.must_be_instance_of(String)
57
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...")
97
58
  end
98
59
 
99
- context 'single interface, single line, single stream' do
100
- let(:json) { File.read('test/support/json/int1_lin1_str1.json') }
101
- let(:attributes) { Oj.load(json, symbol_keys: true) }
102
-
103
- before do
104
- InterfaceRepository.create({ name: 'int1_lin1_str1', y: 3, x: 3, width: 10, height: 3 })
105
- end
60
+ it 'returns the stringified content for a single interface, single line, multiple streams' do
61
+ InterfaceRepository.create({ name: 'int1_lin1_str3', y: 3, x: 3, width: 10, height: 3 })
62
+ json = File.read('test/support/json/int1_lin1_str3.json')
63
+ attributes = Oj.load(json, symbol_keys: true)
106
64
 
107
- it 'returns the stringified content' do
108
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...")
109
- end
65
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...")
110
66
  end
111
67
 
112
- context 'single interface, single line, multiple streams' do
113
- let(:json) { File.read('test/support/json/int1_lin1_str3.json') }
114
- let(:attributes) { Oj.load(json, symbol_keys: true) }
68
+ it 'returns the stringified content for a single interface, multiple lines, single stream' do
69
+ InterfaceRepository.create({ name: 'int1_lin2_str1', y: 3, x: 3, width: 10, height: 3 })
70
+ json = File.read('test/support/json/int1_lin2_str1.json')
71
+ attributes = Oj.load(json, symbol_keys: true)
115
72
 
116
- before do
117
- InterfaceRepository.create({ name: 'int1_lin1_str3', y: 3, x: 3, width: 10, height: 3 })
118
- end
119
-
120
- it 'returns the stringified content' do
121
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...")
122
- end
73
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[4;3HSome text...")
123
74
  end
124
75
 
125
- context 'single interface, multiple lines, single stream' do
126
- let(:json) { File.read('test/support/json/int1_lin2_str1.json') }
127
- let(:attributes) { Oj.load(json, symbol_keys: true) }
128
-
129
- before do
130
- InterfaceRepository.create({ name: 'int1_lin2_str1', y: 3, x: 3, width: 10, height: 3 })
131
- end
76
+ it 'returns the stringified content for a single interface, multiple lines, multiple streams' do
77
+ InterfaceRepository.create({ name: 'int1_lin2_str3', y: 3, x: 3, width: 10, height: 3 })
78
+ json = File.read('test/support/json/int1_lin2_str3.json')
79
+ attributes = Oj.load(json, symbol_keys: true)
132
80
 
133
- it 'returns the stringified content' do
134
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[4;3HSome text...")
135
- end
81
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...\e[4;3HSome text... more text...")
136
82
  end
137
83
 
138
- context 'single interface, multiple lines, multiple streams' do
139
- let(:json) { File.read('test/support/json/int1_lin2_str3.json') }
140
- let(:attributes) { Oj.load(json, symbol_keys: true) }
84
+ it 'returns the stringified content for a single interface, multiple lines, multiple streams, streams contain styles' do
85
+ json = File.read('test/support/json/int1_lin2_str3_styles.json')
86
+ attributes = Oj.load(json, symbol_keys: true)
87
+ InterfaceRepository.create({ name: 'int1_lin2_str3_styles', y: 3, x: 3, width: 10, height: 3 })
141
88
 
142
- before do
143
- InterfaceRepository.create({ name: 'int1_lin2_str3', y: 3, x: 3, width: 10, height: 3 })
144
- end
145
-
146
- it 'returns the stringified content' do
147
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...\e[4;3HSome text... more text...")
148
- end
89
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...")
149
90
  end
150
91
 
151
- context 'single interface, multiple lines, multiple streams, streams contain styles' do
152
- let(:json) { File.read('test/support/json/int1_lin2_str3_styles.json') }
153
- let(:attributes) { Oj.load(json, symbol_keys: true) }
154
-
155
- before do
156
- InterfaceRepository.create({ name: 'int1_lin2_str3_styles', y: 3, x: 3, width: 10, height: 3 })
157
- end
92
+ it 'returns the stringified content for multiple interfaces, single line, single stream' do
93
+ InterfaceRepository.create({ name: 'int2_lin1_str1_1', y: 3, x: 3, width: 10, height: 3 })
94
+ InterfaceRepository.create({ name: 'int2_lin1_str1_2', y: 6, x: 6, width: 10, height: 3 })
95
+ json = File.read('test/support/json/int2_lin1_str1.json')
96
+ attributes = Oj.load(json, symbol_keys: true)
158
97
 
159
- it 'returns the stringified content' do
160
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...")
161
- end
98
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6HSome text...")
162
99
  end
163
100
 
164
- context 'multiple interfaces, single line, single stream' do
165
- let(:json) { File.read('test/support/json/int2_lin1_str1.json') }
166
- let(:attributes) { Oj.load(json, symbol_keys: true) }
101
+ it 'returns the stringified content for multiple interfaces, single line, multiple streams' do
102
+ InterfaceRepository.create({ name: 'int2_lin1_str3_1', y: 3, x: 3, width: 10, height: 3 })
103
+ InterfaceRepository.create({ name: 'int2_lin1_str3_2', y: 6, x: 6, width: 10, height: 3 })
104
+ json = File.read('test/support/json/int2_lin1_str3.json')
105
+ attributes = Oj.load(json, symbol_keys: true)
167
106
 
168
- before do
169
- InterfaceRepository.create({ name: 'int2_lin1_str1_1', y: 3, x: 3, width: 10, height: 3 })
170
- InterfaceRepository.create({ name: 'int2_lin1_str1_2', y: 6, x: 6, width: 10, height: 3 })
171
- end
172
-
173
- it 'returns the stringified content' do
174
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6HSome text...")
175
- end
176
- end
177
-
178
- context 'multiple interfaces, single line, multiple streams' do
179
- let(:json) { File.read('test/support/json/int2_lin1_str3.json') }
180
- let(:attributes) { Oj.load(json, symbol_keys: true) }
181
-
182
- before do
183
- InterfaceRepository.create({ name: 'int2_lin1_str3_1', y: 3, x: 3, width: 10, height: 3 })
184
- InterfaceRepository.create({ name: 'int2_lin1_str3_2', y: 6, x: 6, width: 10, height: 3 })
185
- end
186
-
187
- it 'returns the stringified content' do
188
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6HSome text... more text...")
189
- end
107
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6HSome text... more text...")
190
108
  end
191
109
 
192
- context 'multiple interfaces, multiple lines, single stream' do
193
- let(:json) { File.read('test/support/json/int2_lin2_str1.json') }
194
- let(:attributes) { Oj.load(json, symbol_keys: true) }
195
-
196
- before do
197
- InterfaceRepository.create({ name: 'int2_lin2_str1_1', y: 3, x: 3, width: 10, height: 3 })
198
- InterfaceRepository.create({ name: 'int2_lin2_str1_2', y: 6, x: 6, width: 10, height: 3 })
199
- end
110
+ it 'returns the stringified content for multiple interfaces, multiple lines, single stream' do
111
+ InterfaceRepository.create({ name: 'int2_lin2_str1_1', y: 3, x: 3, width: 10, height: 3 })
112
+ InterfaceRepository.create({ name: 'int2_lin2_str1_2', y: 6, x: 6, width: 10, height: 3 })
113
+ json = File.read('test/support/json/int2_lin2_str1.json')
114
+ attributes = Oj.load(json, symbol_keys: true)
200
115
 
201
- it 'returns the stringified content' do
202
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[4;3HSome text...\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[4;3HSome text...")
203
- end
116
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[4;3HSome text...\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text...\e[4;3HSome text...")
204
117
  end
205
118
 
206
- context 'multiple interfaces, multiple lines, multiple streams' do
207
- let(:json) { File.read('test/support/json/int2_lin2_str3.json') }
208
- let(:attributes) { Oj.load(json, symbol_keys: true) }
119
+ it 'returns the stringified content for multiple interfaces, multiple lines, multiple streams' do
120
+ InterfaceRepository.create({ name: 'int2_lin2_str3_1', y: 3, x: 3, width: 10, height: 3 })
121
+ InterfaceRepository.create({ name: 'int2_lin2_str3_2', y: 6, x: 6, width: 10, height: 3 })
122
+ json = File.read('test/support/json/int2_lin2_str3.json')
123
+ attributes = Oj.load(json, symbol_keys: true)
209
124
 
210
- before do
211
- InterfaceRepository.create({ name: 'int2_lin2_str3_1', y: 3, x: 3, width: 10, height: 3 })
212
- InterfaceRepository.create({ name: 'int2_lin2_str3_2', y: 6, x: 6, width: 10, height: 3 })
213
- end
214
-
215
- it 'returns the stringified content' do
216
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...\e[4;3HSome text... more text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6HSome text... more text...\e[7;6HSome text... more text...")
217
- end
125
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3HSome text... more text...\e[4;3HSome text... more text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6HSome text... more text...\e[7;6HSome text... more text...")
218
126
  end
219
127
 
220
- context 'multiple interfaces, multiple lines, multiple streams, streams contain styles' do
221
- let(:json) { File.read('test/support/json/int2_lin2_str3_styles.json') }
222
- let(:attributes) { Oj.load(json, symbol_keys: true) }
223
-
224
- before do
225
- InterfaceRepository.create({ name: 'int2_lin2_str3_styles_1', y: 3, x: 3, width: 10, height: 3 })
226
- InterfaceRepository.create({ name: 'int2_lin2_str3_styles_2', y: 6, x: 6, width: 10, height: 3 })
227
- end
128
+ it 'returns the stringified content for multiple interfaces, multiple lines, multiple streams, streams contain styles' do
129
+ InterfaceRepository.create({ name: 'int2_lin2_str3_styles_1', y: 3, x: 3, width: 10, height: 3 })
130
+ InterfaceRepository.create({ name: 'int2_lin2_str3_styles_2', y: 6, x: 6, width: 10, height: 3 })
131
+ json = File.read('test/support/json/int2_lin2_str3_styles.json')
132
+ attributes = Oj.load(json, symbol_keys: true)
228
133
 
229
- it 'returns the stringified content' do
230
- subject.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...\e[4;3H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...\e[7;6H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...")
231
- end
134
+ Composition.new(attributes).to_s.must_equal("\e[3;3H \e[3;3H\e[4;3H \e[4;3H\e[5;3H \e[5;3H\e[3;3H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...\e[4;3H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...\e[6;6H \e[6;6H\e[7;6H \e[7;6H\e[8;6H \e[8;6H\e[6;6H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...\e[7;6H\e[38;5;16m\e[48;5;21m\e[24m\e[21m\e[27m\e[4mSome text...\e[38;5;226m\e[48;5;46m\e[24m\e[21m\e[27m \e[38;5;231m\e[48;5;201m\e[1mmore text...")
232
135
  end
233
136
  end
234
137
  end
@@ -4,31 +4,14 @@ require_relative '../../../../lib/vedeu/models/colour'
4
4
 
5
5
  module Vedeu
6
6
  describe Foreground do
7
- let(:described_class) { Foreground }
8
- let(:described_instance) { Vedeu::Colour.new(attributes) }
9
- let(:attributes) {
10
- {
11
- foreground: '#ff0000'
12
- }
13
- }
14
-
15
7
  describe '#foreground' do
16
- let(:subject) { described_instance.foreground }
17
-
18
- it 'returns a String' do
19
- subject.must_be_instance_of(String)
20
- end
21
-
22
8
  it 'returns an escape sequence' do
23
- subject.must_equal("\e[38;5;196m")
9
+ Colour.new({ foreground: '#ff0000' }).foreground
10
+ .must_equal("\e[38;5;196m")
24
11
  end
25
12
 
26
- context 'when the foreground is missing' do
27
- let(:attributes) { {} }
28
-
29
- it 'returns an escape sequence' do
30
- subject.must_equal('')
31
- end
13
+ it 'returns an empty string when the foreground is missing' do
14
+ Colour.new.foreground.must_equal('')
32
15
  end
33
16
  end
34
17
  end