vedeu 0.5.13 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/bin/vedeu_drb_server +1 -0
  4. data/config/rubocop_enabled.yml +2 -2
  5. data/docs/events.md +2 -0
  6. data/docs/getting_started.md +1 -1
  7. data/examples/drb_app.rb +1 -0
  8. data/examples/editor_app.rb +76 -0
  9. data/lib/vedeu/all.rb +13 -7
  10. data/lib/vedeu/{bindings.rb → bindings/bindings.rb} +2 -0
  11. data/lib/vedeu/bindings/focus.rb +66 -0
  12. data/lib/vedeu/bindings/refresh.rb +77 -0
  13. data/lib/vedeu/bindings/system.rb +19 -88
  14. data/lib/vedeu/buffers/buffer.rb +8 -8
  15. data/lib/vedeu/configuration/api.rb +32 -11
  16. data/lib/vedeu/configuration/cli.rb +8 -0
  17. data/lib/vedeu/cursor/move.rb +1 -0
  18. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -0
  19. data/lib/vedeu/{dsl.rb → dsl/dsl.rb} +0 -0
  20. data/lib/vedeu/exceptions.rb +1 -1
  21. data/lib/vedeu/geometry/position.rb +28 -0
  22. data/lib/vedeu/input/capture.rb +76 -0
  23. data/lib/vedeu/input/editor/all.rb +19 -0
  24. data/lib/vedeu/input/editor/cropper.rb +74 -0
  25. data/lib/vedeu/input/editor/document.rb +254 -0
  26. data/lib/vedeu/input/editor/documents.rb +18 -0
  27. data/lib/vedeu/input/editor/editor.rb +100 -0
  28. data/lib/vedeu/input/editor/line.rb +143 -0
  29. data/lib/vedeu/input/editor/lines.rb +199 -0
  30. data/lib/vedeu/input/editor/virtual_cursor.rb +167 -0
  31. data/lib/vedeu/input/input.rb +9 -93
  32. data/lib/vedeu/input/input_translator.rb +155 -0
  33. data/lib/vedeu/internal_api.rb +9 -0
  34. data/lib/vedeu/log/lockless_log_device.rb +1 -1
  35. data/lib/vedeu/models/escape.rb +7 -8
  36. data/lib/vedeu/output/direct.rb +59 -0
  37. data/lib/vedeu/output/renderers/terminal.rb +8 -0
  38. data/lib/vedeu/output/viewport.rb +2 -3
  39. data/lib/vedeu/{plugins.rb → plugins/plugins.rb} +0 -0
  40. data/lib/vedeu/refresh/refresh_cursor.rb +1 -0
  41. data/lib/vedeu/{repositories.rb → repositories/repositories.rb} +0 -0
  42. data/lib/vedeu/terminal/content.rb +88 -0
  43. data/lib/vedeu/terminal/mode.rb +79 -0
  44. data/lib/vedeu/{terminal.rb → terminal/terminal.rb} +9 -25
  45. data/lib/vedeu/version.rb +1 -1
  46. data/test/lib/vedeu/{bindings_test.rb → bindings/bindings_test.rb} +0 -0
  47. data/test/lib/vedeu/bindings/focus_test.rb +19 -0
  48. data/test/lib/vedeu/bindings/refresh_test.rb +19 -0
  49. data/test/lib/vedeu/bindings/system_test.rb +1 -6
  50. data/test/lib/vedeu/borders/render_border_test.rb +43 -10
  51. data/test/lib/vedeu/buffers/buffer_test.rb +18 -0
  52. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +15 -0
  53. data/test/lib/vedeu/configuration/api_test.rb +18 -2
  54. data/test/lib/vedeu/configuration/cli_test.rb +5 -0
  55. data/test/lib/vedeu/cursor/move_test.rb +1 -1
  56. data/test/lib/vedeu/dsl/dsl_test.rb +8 -0
  57. data/test/lib/vedeu/dsl/shared_test.rb +12 -0
  58. data/test/lib/vedeu/{output → esc}/esc_test.rb +0 -0
  59. data/test/lib/vedeu/geometry/position_test.rb +56 -0
  60. data/test/lib/vedeu/input/capture_test.rb +63 -0
  61. data/test/lib/vedeu/input/editor/cropper_test.rb +82 -0
  62. data/test/lib/vedeu/input/editor/document_test.rb +190 -0
  63. data/test/lib/vedeu/input/editor/documents_test.rb +17 -0
  64. data/test/lib/vedeu/input/editor/editor_test.rb +170 -0
  65. data/test/lib/vedeu/input/editor/line_test.rb +333 -0
  66. data/test/lib/vedeu/input/editor/lines_test.rb +561 -0
  67. data/test/lib/vedeu/input/editor/virtual_cursor_test.rb +184 -0
  68. data/test/lib/vedeu/input/input_test.rb +20 -4
  69. data/test/lib/vedeu/input/input_translator_test.rb +32 -0
  70. data/test/lib/vedeu/internal_api_test.rb +1 -0
  71. data/test/lib/vedeu/models/escape_test.rb +6 -6
  72. data/test/lib/vedeu/models/views/view_test.rb +15 -2
  73. data/test/lib/vedeu/null/null_test.rb +8 -0
  74. data/test/lib/vedeu/output/direct_test.rb +70 -0
  75. data/test/lib/vedeu/{plugins_test.rb → plugins/plugins_test.rb} +0 -0
  76. data/test/lib/vedeu/{repositories_test.rb → repositories/repositories_test.rb} +0 -0
  77. data/test/lib/vedeu/terminal/content_test.rb +100 -0
  78. data/test/lib/vedeu/terminal/mode_test.rb +95 -0
  79. data/test/lib/vedeu/{terminal_test.rb → terminal/terminal_test.rb} +23 -23
  80. data/test/test_helper.rb +1 -0
  81. metadata +67 -20
  82. data/lib/vedeu/terminal_mode.rb +0 -59
  83. data/test/lib/vedeu/terminal_mode_test.rb +0 -72
@@ -0,0 +1,561 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ describe Lines do
8
+
9
+ let(:described) { Vedeu::Editor::Lines }
10
+ let(:instance) { described.new(lines) }
11
+ let(:lines) {
12
+ [
13
+ Vedeu::Editor::Line.new('Some text...'),
14
+ Vedeu::Editor::Line.new('More text...'),
15
+ Vedeu::Editor::Line.new('Other text...')
16
+ ]
17
+ }
18
+
19
+ describe '#initialize' do
20
+ it { instance.must_be_instance_of(described) }
21
+ it { instance.instance_variable_get('@lines').must_equal(lines) }
22
+
23
+ context 'when lines were not given' do
24
+ let(:lines) {}
25
+
26
+ it { instance.instance_variable_get('@lines').must_equal([]) }
27
+ end
28
+ end
29
+
30
+ describe 'accessors' do
31
+ it { instance.must_respond_to(:lines) }
32
+ it { instance.must_respond_to(:lines=) }
33
+ end
34
+
35
+ describe '.coerce' do
36
+ let(:document) {}
37
+
38
+ subject { described.coerce(document) }
39
+
40
+ it { subject.must_be_instance_of(described) }
41
+
42
+ context 'when the document is already a Vedeu::Editor::Lines object' do
43
+ let(:document) { Vedeu::Editor::Lines.new(lines) }
44
+
45
+ it { subject.must_equal(document) }
46
+ it { subject.lines.must_equal(lines) }
47
+ end
48
+
49
+ context 'when the document is an empty Array' do
50
+ let(:document) { [] }
51
+
52
+ it { subject.lines.must_equal([]) }
53
+ end
54
+
55
+ context 'when the document is an Array' do
56
+ let(:document) {
57
+ [
58
+ Vedeu::Editor::Line.new('Some text...'),
59
+ :more_text,
60
+ 'Other text...',
61
+ ]
62
+ }
63
+ let(:expected) {
64
+ [
65
+ Vedeu::Editor::Line.new('Some text...'),
66
+ Vedeu::Editor::Line.new(''),
67
+ Vedeu::Editor::Line.new('Other text...'),
68
+ ]
69
+ }
70
+
71
+ it { subject.lines.must_equal(expected) }
72
+ end
73
+
74
+ context 'when the document is a String' do
75
+ let(:document) { "Some text...\nMore text..." }
76
+
77
+ context 'but it is empty' do
78
+ let(:document) { '' }
79
+
80
+ it { subject.must_equal(Vedeu::Editor::Lines.new) }
81
+ end
82
+
83
+ context 'but it has no line breaks' do
84
+
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#[]' do
90
+ subject { instance.[](index) }
91
+
92
+ context 'when index is a Fixnum' do
93
+ let(:index) { 2 }
94
+ let(:expected) {
95
+ Vedeu::Editor::Line.new('Other text...')
96
+ }
97
+
98
+ it { subject.must_equal(expected) }
99
+ end
100
+
101
+ context 'when index is a Range' do
102
+ let(:index) { (1..2) }
103
+ let(:expected) {
104
+ [
105
+ Vedeu::Editor::Line.new('More text...'),
106
+ Vedeu::Editor::Line.new('Other text...')
107
+ ]
108
+ }
109
+
110
+ it { subject.must_equal(expected) }
111
+ end
112
+ end
113
+
114
+ describe '#delete_character' do
115
+ let(:x) { 0 }
116
+ let(:y) { 0 }
117
+
118
+ subject { instance.delete_character(y, x) }
119
+
120
+ context 'when there are no lines' do
121
+ let(:lines) {
122
+ [
123
+ Vedeu::Editor::Line.new('')
124
+ ]
125
+ }
126
+ let(:expected) {
127
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('')])
128
+ }
129
+
130
+ it { subject.must_equal(expected) }
131
+ end
132
+
133
+ context 'when there is one line' do
134
+ let(:lines) {
135
+ [
136
+ Vedeu::Editor::Line.new('Hydrogen')
137
+ ]
138
+ }
139
+
140
+ context 'and x is the first character of the line' do
141
+ let(:x) { 0 }
142
+ let(:expected) {
143
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('Hydrogen')])
144
+ }
145
+
146
+ it { subject.must_equal(expected) }
147
+ end
148
+
149
+ context 'and x is somewhere on the line' do
150
+ let(:x) { 4 }
151
+ let(:expected) {
152
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('Hydrgen')])
153
+ }
154
+
155
+ it { subject.must_equal(expected) }
156
+ end
157
+
158
+ context 'and x is the last character of the line' do
159
+ let(:x) { 15 }
160
+ let(:expected) {
161
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('Hydroge')])
162
+ }
163
+
164
+ it { subject.must_equal(expected) }
165
+ end
166
+ end
167
+
168
+ context 'when there are multiple lines' do
169
+ let(:y) { 1 }
170
+ let(:lines) {
171
+ [
172
+ Vedeu::Editor::Line.new('Hydrogen'),
173
+ Vedeu::Editor::Line.new('Helium'),
174
+ Vedeu::Editor::Line.new('Lithium'),
175
+ ]
176
+ }
177
+
178
+ context 'and x is the first character of the line' do
179
+ let(:x) { 0 }
180
+ let(:expected) {
181
+ Vedeu::Editor::Lines.new([
182
+ Vedeu::Editor::Line.new('Hydrogen'),
183
+ Vedeu::Editor::Line.new('Helium'),
184
+ Vedeu::Editor::Line.new('Lithium'),
185
+ ])
186
+ }
187
+
188
+ it { subject.must_equal(expected) }
189
+ end
190
+
191
+ context 'and x is somewhere on the line' do
192
+ let(:x) { 4 }
193
+ let(:expected) {
194
+ Vedeu::Editor::Lines.new([
195
+ Vedeu::Editor::Line.new('Hydrogen'),
196
+ Vedeu::Editor::Line.new('Helim'),
197
+ Vedeu::Editor::Line.new('Lithium'),
198
+ ])
199
+ }
200
+
201
+ it { subject.must_equal(expected) }
202
+ end
203
+
204
+ context 'and x is the last character of the line' do
205
+ let(:x) { 15 }
206
+ let(:expected) {
207
+ Vedeu::Editor::Lines.new([
208
+ Vedeu::Editor::Line.new('Hydrogen'),
209
+ Vedeu::Editor::Line.new('Heliu'),
210
+ Vedeu::Editor::Line.new('Lithium'),
211
+ ])
212
+ }
213
+
214
+ it { subject.must_equal(expected) }
215
+ end
216
+ end
217
+ end
218
+
219
+ describe '#delete_line' do
220
+ let(:index) { 1 }
221
+
222
+ subject { instance.delete_line(index) }
223
+
224
+ it { subject.must_be_instance_of(described) }
225
+
226
+ context 'when the lines are empty' do
227
+ let(:lines) { [] }
228
+
229
+ it { subject.must_equal(Vedeu::Editor::Lines.new) }
230
+ end
231
+
232
+ context 'when the lines are not empty' do
233
+ context 'when an index is not given' do
234
+ let(:index) {}
235
+ let(:expected) {
236
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...'])
237
+ }
238
+
239
+ it { subject.must_equal(expected) }
240
+ end
241
+
242
+ context 'when a negative index is given' do
243
+ let(:index) { -4 }
244
+ let(:expected) {
245
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...', 'Other text...'])
246
+ }
247
+
248
+ it { subject.must_equal(expected) }
249
+ end
250
+
251
+ context 'when an index is given' do
252
+ let(:expected) {
253
+ Vedeu::Editor::Lines.coerce(['Some text...', 'Other text...'])
254
+ }
255
+
256
+ it { subject.must_equal(expected) }
257
+ end
258
+
259
+ context 'when an index of the last line is given' do
260
+ let(:index) { 2 }
261
+ let(:expected) {
262
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...'])
263
+ }
264
+
265
+ it { subject.must_equal(expected) }
266
+ end
267
+
268
+ context 'when an index greater than the number of lines is given' do
269
+ let(:index) { 10 }
270
+ let(:expected) {
271
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...'])
272
+ }
273
+
274
+ it { subject.must_equal(expected) }
275
+ end
276
+ end
277
+ end
278
+
279
+ describe '#empty?' do
280
+ subject { instance.empty? }
281
+
282
+ context 'when the line is empty' do
283
+ let(:lines) {}
284
+
285
+ it { subject.must_equal(true) }
286
+ end
287
+
288
+ context 'when the line is not empty' do
289
+ it { subject.must_equal(false) }
290
+ end
291
+ end
292
+
293
+ describe '#eql?' do
294
+ let(:other) { instance }
295
+
296
+ subject { instance.eql?(other) }
297
+
298
+ it { subject.must_equal(true) }
299
+
300
+ context 'when different to other' do
301
+ let(:other) { described.new('Other text...') }
302
+
303
+ it { subject.must_equal(false) }
304
+ end
305
+ end
306
+
307
+ describe '#insert_character' do
308
+ let(:x) { 0 }
309
+ let(:y) { 0 }
310
+ let(:character) { 'a' }
311
+
312
+ subject { instance.insert_character(character, y, x) }
313
+
314
+ context 'when there are no lines' do
315
+ let(:lines) {
316
+ [
317
+ Vedeu::Editor::Line.new('')
318
+ ]
319
+ }
320
+ let(:expected) {
321
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('a')])
322
+ }
323
+
324
+ it { subject.must_equal(expected) }
325
+ end
326
+
327
+ context 'when there is one line' do
328
+ let(:lines) {
329
+ [
330
+ Vedeu::Editor::Line.new('Hydrogen')
331
+ ]
332
+ }
333
+
334
+ context 'and x is the first character of the line' do
335
+ let(:x) { 0 }
336
+ let(:expected) {
337
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('aHydrogen')])
338
+ }
339
+
340
+ it { subject.must_equal(expected) }
341
+ end
342
+
343
+ context 'and x is somewhere on the line' do
344
+ let(:x) { 4 }
345
+ let(:expected) {
346
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('Hydraogen')])
347
+ }
348
+
349
+ it { subject.must_equal(expected) }
350
+ end
351
+
352
+ context 'and x is the last character of the line' do
353
+ let(:x) { 15 }
354
+ let(:expected) {
355
+ Vedeu::Editor::Lines.new([Vedeu::Editor::Line.new('Hydrogena')])
356
+ }
357
+
358
+ it { subject.must_equal(expected) }
359
+ end
360
+ end
361
+
362
+ context 'when there are multiple lines' do
363
+ let(:y) { 1 }
364
+ let(:lines) {
365
+ [
366
+ Vedeu::Editor::Line.new('Hydrogen'),
367
+ Vedeu::Editor::Line.new('Helium'),
368
+ Vedeu::Editor::Line.new('Lithium'),
369
+ ]
370
+ }
371
+
372
+ context 'and x is the first character of the line' do
373
+ let(:x) { 0 }
374
+ let(:expected) {
375
+ Vedeu::Editor::Lines.new([
376
+ Vedeu::Editor::Line.new('Hydrogen'),
377
+ Vedeu::Editor::Line.new('aHelium'),
378
+ Vedeu::Editor::Line.new('Lithium'),
379
+ ])
380
+ }
381
+
382
+ it { subject.must_equal(expected) }
383
+ end
384
+
385
+ context 'and x is somewhere on the line' do
386
+ let(:x) { 4 }
387
+ let(:expected) {
388
+ Vedeu::Editor::Lines.new([
389
+ Vedeu::Editor::Line.new('Hydrogen'),
390
+ Vedeu::Editor::Line.new('Heliaum'),
391
+ Vedeu::Editor::Line.new('Lithium'),
392
+ ])
393
+ }
394
+
395
+ it { subject.must_equal(expected) }
396
+ end
397
+
398
+ context 'and x is the last character of the line' do
399
+ let(:x) { 15 }
400
+ let(:expected) {
401
+ Vedeu::Editor::Lines.new([
402
+ Vedeu::Editor::Line.new('Hydrogen'),
403
+ Vedeu::Editor::Line.new('Heliuma'),
404
+ Vedeu::Editor::Line.new('Lithium'),
405
+ ])
406
+ }
407
+
408
+ it { subject.must_equal(expected) }
409
+ end
410
+ end
411
+ end
412
+
413
+ describe '#insert_line' do
414
+ let(:line) { "Many text..." }
415
+ let(:index) { 1 }
416
+
417
+ subject { instance.insert_line(line, index) }
418
+
419
+ it { subject.must_be_instance_of(described) }
420
+
421
+ context 'when a line is not given' do
422
+ let(:line) {}
423
+ let(:expected) {
424
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...', 'Other text...'])
425
+ }
426
+
427
+ it { subject.must_equal(expected) }
428
+ end
429
+
430
+ context 'when a line is given' do
431
+ context 'and an index is not given' do
432
+ let(:index) {}
433
+ let(:expected) {
434
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...', 'Other text...', 'Many text...'])
435
+ }
436
+
437
+ it { subject.must_equal(expected) }
438
+ end
439
+
440
+ context 'and a negative index is given' do
441
+ let(:index) { -4 }
442
+ let(:expected) {
443
+ Vedeu::Editor::Lines.coerce(['Many text...', 'Some text...', 'More text...', 'Other text...'])
444
+ }
445
+
446
+ it { subject.must_equal(expected) }
447
+ end
448
+
449
+ context 'and an index is given' do
450
+ let(:expected) {
451
+ Vedeu::Editor::Lines.coerce(['Some text...', 'Many text...', 'More text...', 'Other text...'])
452
+ }
453
+
454
+ it { subject.must_equal(expected) }
455
+ end
456
+
457
+ context 'and an index of the last line is given' do
458
+ let(:index) { 5 }
459
+ let(:expected) {
460
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...', 'Other text...', 'Many text...'])
461
+ }
462
+
463
+ it { subject.must_equal(expected) }
464
+ end
465
+
466
+ context 'and an index greater than the number of lines is given' do
467
+ let(:index) { 10 }
468
+ let(:expected) {
469
+ Vedeu::Editor::Lines.coerce(['Some text...', 'More text...', 'Other text...', 'Many text...'])
470
+ }
471
+
472
+ it { subject.must_equal(expected) }
473
+ end
474
+ end
475
+ end
476
+
477
+ describe '#line' do
478
+ let(:index) { 1 }
479
+
480
+ subject { instance.line(index) }
481
+
482
+ it { subject.must_be_instance_of(Vedeu::Editor::Line) }
483
+
484
+ context 'when there are no lines' do
485
+ let(:lines) {}
486
+
487
+ it { subject.must_equal(Vedeu::Editor::Line.new) }
488
+ end
489
+
490
+ context 'when there are lines' do
491
+ context 'and an index is not given' do
492
+ let(:index) {}
493
+
494
+ it 'returns the last line' do
495
+ subject.must_equal(Vedeu::Editor::Line.new('Other text...'))
496
+ end
497
+ end
498
+
499
+ context 'and an index is given' do
500
+ context 'and a negative index is given' do
501
+ let(:index) { -4 }
502
+
503
+ it 'returns the first line' do
504
+ subject.must_equal(Vedeu::Editor::Line.new('Some text...'))
505
+ end
506
+ end
507
+
508
+ context 'and an index is given' do
509
+ it { subject.must_equal(Vedeu::Editor::Line.new('More text...')) }
510
+ end
511
+
512
+ context 'and an index of the last line is given' do
513
+ let(:index) { 5 }
514
+
515
+ it { subject.must_equal(Vedeu::Editor::Line.new('Other text...')) }
516
+ end
517
+
518
+ context 'and an index greater than the number of lines is given' do
519
+ let(:index) { 10 }
520
+
521
+ it { subject.must_equal(Vedeu::Editor::Line.new('Other text...')) }
522
+ end
523
+ end
524
+ end
525
+ end
526
+
527
+ describe '#size' do
528
+ subject { instance.size }
529
+
530
+ context 'when there are no lines' do
531
+ let(:lines) {}
532
+
533
+ it { subject.must_equal(0) }
534
+ end
535
+
536
+ context 'when there are lines' do
537
+ it { subject.must_equal(3) }
538
+ end
539
+ end
540
+
541
+ describe '#to_s' do
542
+ subject { instance.to_s }
543
+
544
+ context 'when there are no lines' do
545
+ let(:lines) {}
546
+
547
+ it { subject.must_equal("") }
548
+ end
549
+
550
+ context 'when there are lines' do
551
+ let(:expected) { "Some text...More text...Other text..." }
552
+
553
+ it { subject.must_equal(expected) }
554
+ end
555
+ end
556
+
557
+ end # Lines
558
+
559
+ end # Editor
560
+
561
+ end # Vedeu