vedeu 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,28 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
  describe API do
5
+ describe '.event' do
6
+ it 'registers and returns the event' do
7
+ Vedeu.event(:some_event).must_equal(
8
+ {
9
+ delay: 0,
10
+ events: [nil],
11
+ last_exec: 0
12
+ }
13
+ )
14
+ end
15
+ end
16
+
17
+ describe '.events' do
18
+ it 'should not be visible to the client' do
19
+ skip
20
+ end
21
+
22
+ it 'returns the Events singleton' do
23
+ Vedeu.events.must_be_instance_of(API::Events)
24
+ end
25
+ end
26
+
5
27
  describe '.height' do
6
28
  it 'returns the terminal height' do
7
29
  IO.console.stub(:winsize, [24, 40]) do
@@ -10,6 +32,78 @@ module Vedeu
10
32
  end
11
33
  end
12
34
 
35
+ describe '.interface' do
36
+ it 'returns the all of the defined interfaces attributes after defining' \
37
+ ' the interface' do
38
+ Vedeu::Store.reset
39
+
40
+ Vedeu.interface('Vedeu.interface').must_equal(
41
+ {
42
+ "Vedeu.interface" => {
43
+ name: "Vedeu.interface",
44
+ group: "",
45
+ lines: [],
46
+ colour: {},
47
+ style: "",
48
+ geometry: {},
49
+ cursor: true,
50
+ delay: 0.0
51
+ }
52
+ }
53
+ )
54
+ end
55
+ end
56
+
57
+ describe '.keypress' do
58
+ it 'returns' do
59
+ Vedeu.keypress('k').must_equal()
60
+ end
61
+ end
62
+
63
+ describe '.log' do
64
+ it 'returns true after writing the message to the log' do
65
+ Vedeu.log('some message').must_equal(true)
66
+ end
67
+ end
68
+
69
+ describe '.trigger' do
70
+ it 'triggers the specifed event and returns the collection of events' \
71
+ ' which this trigger triggers' do
72
+ Vedeu.trigger(:vedeu_trigger_event, :event_arguments).must_equal([])
73
+ end
74
+ end
75
+
76
+ describe '.use' do
77
+ it 'raises an exception if the interface has not been defined' do
78
+ Vedeu::Store.reset
79
+
80
+ proc { Vedeu.use('some_interface') }.must_raise(Vedeu::EntityNotFound)
81
+ end
82
+
83
+ it 'returns' do
84
+ Vedeu.interface('some_interface')
85
+
86
+ Vedeu.use('some_interface').must_be_instance_of(Vedeu::Interface)
87
+ end
88
+ end
89
+
90
+ describe '.view' do
91
+ it 'returns the view attributes for an interface (see View)' do
92
+ Vedeu.view('some_interface').must_equal(
93
+ { interfaces: [{
94
+ name: "some_interface",
95
+ group: "",
96
+ lines: [],
97
+ colour: {},
98
+ style: "",
99
+ geometry: {},
100
+ cursor: true,
101
+ delay: 0.0
102
+ }] }
103
+ )
104
+ end
105
+ end
106
+
13
107
  describe '.width' do
14
108
  it 'returns the terminal width' do
15
109
  IO.console.stub(:winsize, [24, 40]) do
@@ -0,0 +1,72 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+ module API
5
+ describe '#views' do
6
+ it 'allows multiple views to be defined at once' do
7
+ Vedeu.views do
8
+ view 'view_1' do
9
+ line do
10
+ text '1. A line of text in view 1.'
11
+ text '2. Another line of text in view 1.'
12
+ end
13
+ end
14
+ view 'view_2' do
15
+ line do
16
+ text '1. A line of text in view 2.'
17
+ text '2. Another line of text in view 2.'
18
+ end
19
+ end
20
+ end.must_equal(
21
+ {
22
+ interfaces: [
23
+ {
24
+ name: "view_1",
25
+ group: "",
26
+ lines: [
27
+ {
28
+ colour: {},
29
+ streams: [
30
+ {
31
+ text: "1. A line of text in view 1."
32
+ }, {
33
+ text: "2. Another line of text in view 1."
34
+ }
35
+ ],
36
+ style: []
37
+ }
38
+ ],
39
+ colour: {},
40
+ style: "",
41
+ geometry: {},
42
+ cursor: true,
43
+ delay: 0.0
44
+ }, {
45
+ name: "view_2",
46
+ group: "",
47
+ lines: [
48
+ {
49
+ colour: {},
50
+ streams: [
51
+ {
52
+ text: "1. A line of text in view 2."
53
+ }, {
54
+ text: "2. Another line of text in view 2."
55
+ }
56
+ ],
57
+ style: []
58
+ }
59
+ ],
60
+ colour: {},
61
+ style: "",
62
+ geometry: {},
63
+ cursor: true,
64
+ delay: 0.0
65
+ }
66
+ ]
67
+ }
68
+ )
69
+ end
70
+ end
71
+ end
72
+ end
@@ -9,37 +9,20 @@ module Vedeu
9
9
  interface = Interface.new({ name: 'widget' })
10
10
 
11
11
  it 'creates and stores a new interface' do
12
- interface.define.must_be_instance_of(Vedeu::Interface)
13
- end
14
-
15
- it 'allows interfaces to share behaviour' do
16
- IO.console.stub :winsize, [10, 40] do
17
- main = Vedeu.interface('main') do
18
- colour foreground: '#ff0000', background: '#000000'
19
- cursor false
20
- centred true
21
- width 10
22
- height 2
23
- group 'example_group'
24
- delay 0.25
25
- end
26
- status = Vedeu.interface('status') do
27
- colour foreground: 'aadd00', background: '#4040cc'
28
- cursor true
29
- centred true
30
- width 10
31
- height 1
32
- y use('main').bottom
33
- x use('main').left
34
- group 'example_group'
35
- delay 0.25
36
- end
37
-
38
- main.left.must_equal(15)
39
- main.top.must_equal(4)
40
- status.left.must_equal(15)
41
- status.top.must_equal(5)
42
- end
12
+ interface.define.must_equal(
13
+ {
14
+ 'widget' => {
15
+ name: 'widget',
16
+ group: '',
17
+ lines: [],
18
+ colour: {},
19
+ style: '',
20
+ geometry: {},
21
+ cursor: true,
22
+ delay: 0.0
23
+ }
24
+ }
25
+ )
43
26
  end
44
27
 
45
28
  it 'raises an exception when the value is out of bounds' do
@@ -93,7 +76,7 @@ module Vedeu
93
76
  text '2. Another line of text.'
94
77
  end
95
78
  end.must_equal(
96
- {
79
+ { interfaces: [{
97
80
  name: 'testing_view',
98
81
  group: '',
99
82
  colour: {},
@@ -114,7 +97,7 @@ module Vedeu
114
97
  ]
115
98
  }
116
99
  ]
117
- }
100
+ }] }
118
101
  )
119
102
  end
120
103
 
@@ -124,7 +107,7 @@ module Vedeu
124
107
  text '1. Line without colours.'
125
108
  end
126
109
  end.must_equal(
127
- {
110
+ { interfaces: [{
128
111
  name: 'testing_view',
129
112
  group: '',
130
113
  colour: {},
@@ -139,7 +122,7 @@ module Vedeu
139
122
  streams: [{ text: '1. Line without colours.' }]
140
123
  }
141
124
  ]
142
- }
125
+ }] }
143
126
  )
144
127
  end
145
128
 
@@ -150,7 +133,7 @@ module Vedeu
150
133
  text '2. Line with colours.'
151
134
  end
152
135
  end.must_equal(
153
- {
136
+ { interfaces: [{
154
137
  name: 'testing_view',
155
138
  group: '',
156
139
  colour: {},
@@ -165,7 +148,7 @@ module Vedeu
165
148
  streams: [{ text: '2. Line with colours.' }]
166
149
  }
167
150
  ]
168
- }
151
+ }] }
169
152
  )
170
153
  end
171
154
 
@@ -176,7 +159,7 @@ module Vedeu
176
159
  text '3. Line with explicit colour declaration.'
177
160
  end
178
161
  end.must_equal(
179
- {
162
+ { interfaces: [{
180
163
  name: 'testing_view',
181
164
  group: '',
182
165
  colour: {},
@@ -191,7 +174,7 @@ module Vedeu
191
174
  streams: [{ text: '3. Line with explicit colour declaration.' }]
192
175
  }
193
176
  ]
194
- }
177
+ }] }
195
178
  )
196
179
  end
197
180
 
@@ -203,7 +186,7 @@ module Vedeu
203
186
  end
204
187
  end
205
188
  end.must_equal(
206
- {
189
+ { interfaces: [{
207
190
  name: 'testing_view',
208
191
  group: '',
209
192
  colour: {},
@@ -224,7 +207,7 @@ module Vedeu
224
207
  }]
225
208
  }
226
209
  ]
227
- }
210
+ }] }
228
211
  )
229
212
  end
230
213
 
@@ -236,7 +219,7 @@ module Vedeu
236
219
  end
237
220
  end
238
221
  end.must_equal(
239
- {
222
+ { interfaces: [{
240
223
  name: 'testing_view',
241
224
  group: '',
242
225
  colour: {},
@@ -257,7 +240,7 @@ module Vedeu
257
240
  }]
258
241
  }
259
242
  ]
260
- }
243
+ }] }
261
244
  )
262
245
  end
263
246
 
@@ -268,7 +251,7 @@ module Vedeu
268
251
  text '1. Line with a normal style.'
269
252
  end
270
253
  end.must_equal(
271
- {
254
+ { interfaces: [{
272
255
  name: 'testing_view',
273
256
  group: '',
274
257
  colour: {},
@@ -285,7 +268,7 @@ module Vedeu
285
268
  }]
286
269
  }
287
270
  ]
288
- }
271
+ }] }
289
272
  )
290
273
  end
291
274
 
@@ -296,7 +279,7 @@ module Vedeu
296
279
  text '2. Line with an underline style.'
297
280
  end
298
281
  end.must_equal(
299
- {
282
+ { interfaces: [{
300
283
  name: 'testing_view',
301
284
  group: '',
302
285
  colour: {},
@@ -313,7 +296,7 @@ module Vedeu
313
296
  }]
314
297
  }
315
298
  ]
316
- }
299
+ }] }
317
300
  )
318
301
  end
319
302
 
@@ -325,7 +308,7 @@ module Vedeu
325
308
  end
326
309
  end
327
310
  end.must_equal(
328
- {
311
+ { interfaces: [{
329
312
  name: 'testing_view',
330
313
  group: '',
331
314
  colour: {},
@@ -346,7 +329,7 @@ module Vedeu
346
329
  }]
347
330
  }
348
331
  ]
349
- }
332
+ }] }
350
333
  )
351
334
  end
352
335
 
@@ -358,7 +341,7 @@ module Vedeu
358
341
  end
359
342
  end
360
343
  end.must_equal(
361
- {
344
+ { interfaces: [{
362
345
  name: 'testing_view',
363
346
  group: '',
364
347
  colour: {},
@@ -379,7 +362,7 @@ module Vedeu
379
362
  }]
380
363
  }
381
364
  ]
382
- }
365
+ }] }
383
366
  )
384
367
  end
385
368
 
@@ -391,7 +374,7 @@ module Vedeu
391
374
  end
392
375
  end
393
376
  end.must_equal(
394
- {
377
+ { interfaces: [{
395
378
  name: 'testing_view',
396
379
  group: '',
397
380
  colour: {},
@@ -414,7 +397,7 @@ module Vedeu
414
397
  ]
415
398
  }
416
399
  ]
417
- }
400
+ }] }
418
401
  )
419
402
  end
420
403
 
@@ -432,7 +415,7 @@ module Vedeu
432
415
  end
433
416
  end
434
417
  end.must_equal(
435
- {
418
+ { interfaces: [{
436
419
  name: 'testing_view',
437
420
  group: '',
438
421
  colour: {},
@@ -461,7 +444,7 @@ module Vedeu
461
444
  ]
462
445
  }
463
446
  ]
464
- }
447
+ }] }
465
448
  )
466
449
  end
467
450
 
@@ -478,7 +461,7 @@ module Vedeu
478
461
  end
479
462
  end
480
463
  end.must_equal(
481
- {
464
+ { interfaces: [{
482
465
  name: 'testing_view',
483
466
  group: '',
484
467
  colour: {},
@@ -510,7 +493,7 @@ module Vedeu
510
493
  ]
511
494
  }
512
495
  ]
513
- }
496
+ }] }
514
497
  )
515
498
  end
516
499
 
@@ -527,7 +510,7 @@ module Vedeu
527
510
  end
528
511
  end
529
512
  end.must_equal(
530
- {
513
+ { interfaces: [{
531
514
  name: 'testing_view',
532
515
  group: '',
533
516
  colour: {},
@@ -556,7 +539,7 @@ module Vedeu
556
539
  ]
557
540
  }
558
541
  ]
559
- }
542
+ }] }
560
543
  )
561
544
  end
562
545
 
@@ -569,7 +552,7 @@ module Vedeu
569
552
  end
570
553
  end
571
554
  end.must_equal(
572
- {
555
+ { interfaces: [{
573
556
  name: 'testing_view',
574
557
  group: '',
575
558
  colour: {},
@@ -588,7 +571,7 @@ module Vedeu
588
571
  text: 'This is aligned left, and padded with spaces.'
589
572
  }]
590
573
  }]
591
- }
574
+ }] }
592
575
  )
593
576
  end
594
577
 
@@ -602,7 +585,7 @@ module Vedeu
602
585
  end
603
586
  end
604
587
  end.must_equal(
605
- {
588
+ { interfaces: [{
606
589
  name: 'testing_view',
607
590
  group: '',
608
591
  colour: {},
@@ -621,7 +604,7 @@ module Vedeu
621
604
  text: 'This is aligned left, and padded with spaces.'
622
605
  }]
623
606
  }]
624
- }
607
+ }] }
625
608
  )
626
609
  end
627
610
 
@@ -635,7 +618,7 @@ module Vedeu
635
618
  end
636
619
  end
637
620
  end.must_equal(
638
- {
621
+ { interfaces: [{
639
622
  name: 'testing_view',
640
623
  group: '',
641
624
  colour: {},
@@ -654,7 +637,7 @@ module Vedeu
654
637
  text: 'This is aligned centrally, and padded with spaces.'
655
638
  }]
656
639
  }]
657
- }
640
+ }] }
658
641
  )
659
642
  end
660
643
 
@@ -668,7 +651,7 @@ module Vedeu
668
651
  end
669
652
  end
670
653
  end.must_equal(
671
- {
654
+ { interfaces: [{
672
655
  name: 'testing_view',
673
656
  group: '',
674
657
  colour: {},
@@ -687,7 +670,7 @@ module Vedeu
687
670
  text: 'This is aligned right, and padded with spaces.'
688
671
  }]
689
672
  }]
690
- }
673
+ }] }
691
674
  )
692
675
  end
693
676
 
@@ -710,7 +693,7 @@ module Vedeu
710
693
  text " Quit"
711
694
  end
712
695
  end.must_equal(
713
- {
696
+ { interfaces: [{
714
697
  name: 'testing_view',
715
698
  group: '',
716
699
  colour: {},
@@ -777,7 +760,7 @@ module Vedeu
777
760
  ]
778
761
  }
779
762
  ]
780
- }
763
+ }] }
781
764
  )
782
765
  end
783
766