sugarcube 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,39 @@
1
+ describe "UIColor" do
2
+
3
+ describe "modified == method" do
4
+
5
+ it "should be intuitive" do
6
+ :red.uicolor.should == :red.uicolor
7
+ :blue.uicolor.should == :blue.uicolor
8
+ :black.uicolor.should == :black.uicolor
9
+ :white.uicolor.should == :white.uicolor
10
+ :clear.uicolor.should == :clear.uicolor
11
+ end
12
+
13
+ it "should be pretty smart" do
14
+ :red.uicolor(0.1).should == :red.uicolor(0.1)
15
+ :blue.uicolor(0.2).should == :blue.uicolor(0.2)
16
+ :black.uicolor(0.3).should == :black.uicolor(0.3)
17
+ :white.uicolor(0.4).should == :white.uicolor(0.4)
18
+ :clear.uicolor(0.5).should == :clear.uicolor(0.5)
19
+ end
20
+
21
+ it "should support hex codes" do
22
+ '#59684f'.uicolor.should == '#59684f'.uicolor
23
+ '#b87a3b'.uicolor.should == '#b87a3b'.uicolor
24
+ '#e0214d'.uicolor.should == '#e0214d'.uicolor
25
+ '#51504a'.uicolor.should == '#51504a'.uicolor
26
+ '#4dc223'.uicolor(0.5).should == '#4dc223'.uicolor(0.5)
27
+ end
28
+
29
+ it "should support css names" do
30
+ :blanchedalmond.uicolor.should == :blanchedalmond.uicolor
31
+ :chartreuse.uicolor.should == :chartreuse.uicolor
32
+ :darkgreen.uicolor.should == :darkgreen.uicolor
33
+ :deepskyblue.uicolor.should == :deepskyblue.uicolor
34
+ :floralwhite.uicolor(0.5).should == :floralwhite.uicolor(0.5)
35
+ end
36
+
37
+ end
38
+
39
+ end
@@ -0,0 +1,471 @@
1
+ describe 'UIImage' do
2
+
3
+ describe 'UIImage.canvas' do
4
+
5
+ it 'should create an image' do
6
+ UIImage.canvas(size: [10, 10]).should.is_a UIImage
7
+ end
8
+
9
+ it 'should have the right size' do
10
+ CGSizeEqualToSize(UIImage.canvas(size: [10, 10]).size, [10, 10]).should == true
11
+ end
12
+
13
+ it 'should have the right scale' do
14
+ UIImage.canvas(size: [10, 10], scale: 2).scale.should == 2
15
+ end
16
+
17
+ describe 'should have the right opacity' do
18
+ it "should be opaque" do
19
+ image = UIImage.canvas(size: [10, 10], scale: 2, opaque: true)
20
+ image.color_at([0, 0]).alpha.should == 1
21
+ end
22
+ it "should be clear" do
23
+ image = UIImage.canvas(size: [10, 10], scale: 2, opaque: false)
24
+ image.color_at([0, 0]).alpha.should == 0
25
+ end
26
+ end
27
+
28
+ it 'should draw an image' do
29
+ image = UIImage.canvas(size: [10, 10], scale: 2) do |context|
30
+ :red.uicolor.set
31
+ CGContextAddRect(context, [[0, 0], [10, 10]])
32
+ CGContextFillPath(context)
33
+ end
34
+ image.color_at([0, 0]).should == :red.uicolor
35
+ end
36
+
37
+ end
38
+
39
+ describe '`<<` method should combine two images' do
40
+
41
+ before do
42
+ red = UIImage.canvas(size: [10, 10]) do |context|
43
+ :red.uicolor.set
44
+ CGContextAddRect(context, [[0, 0], [10, 10]])
45
+ CGContextFillPath(context)
46
+ end
47
+ blue = UIImage.canvas(size: [10, 10]) do |context|
48
+ :blue.uicolor.set
49
+ CGContextAddRect(context, [[1, 1], [8, 8]])
50
+ CGContextFillPath(context)
51
+ end
52
+ @img = (red << blue)
53
+ end
54
+
55
+ it 'should be red in the UL corner' do
56
+ @img.color_at([0, 0]).should == :red.uicolor
57
+ end
58
+ it 'should be blue in the UL-inset corner' do
59
+ @img.color_at([1, 1]).should == :blue.uicolor
60
+ end
61
+ it 'should be blue in the BR-inset corner' do
62
+ @img.color_at([8, 8]).should == :blue.uicolor
63
+ end
64
+ it 'should be red in the BR corner' do
65
+ @img.color_at([9, 9]).should == :red.uicolor
66
+ end
67
+
68
+ end
69
+
70
+ describe '`merge` method should combine images' do
71
+
72
+ describe 'should merge at top_left' do
73
+
74
+ before do
75
+ @red = UIImage.canvas(size: [10, 10]) do |context|
76
+ :red.uicolor.set
77
+ CGContextAddRect(context, [[0, 0], [10, 10]])
78
+ CGContextFillPath(context)
79
+ end
80
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
81
+ :blue.uicolor.set
82
+ CGContextAddRect(context, [[0, 0], [8, 8]])
83
+ CGContextFillPath(context)
84
+ end
85
+ @img = @red.merge(@blue, at: :top_left)
86
+ end
87
+
88
+ it 'should work at top left corner' do
89
+ @img.color_at([0, 0]).should == :blue.uicolor
90
+ end
91
+ it 'should work at top center' do
92
+ @img.color_at([4, 0]).should == :blue.uicolor
93
+ end
94
+ it 'should work at top right corner' do
95
+ @img.color_at([9, 0]).should == :red.uicolor
96
+ end
97
+ it 'should work at left side' do
98
+ @img.color_at([0, 4]).should == :blue.uicolor
99
+ end
100
+ it 'should work at center' do
101
+ @img.color_at([4, 4]).should == :blue.uicolor
102
+ end
103
+ it 'should work at right side' do
104
+ @img.color_at([9, 4]).should == :red.uicolor
105
+ end
106
+ it 'should work at bottom left corner' do
107
+ @img.color_at([0, 9]).should == :red.uicolor
108
+ end
109
+ it 'should work at bottom center' do
110
+ @img.color_at([4, 9]).should == :red.uicolor
111
+ end
112
+ it 'should work at bottom right corner' do
113
+ @img.color_at([9, 9]).should == :red.uicolor
114
+ end
115
+ end
116
+
117
+ describe 'should merge at top' do
118
+ before do
119
+ @red = UIImage.canvas(size: [10, 10]) do |context|
120
+ :red.uicolor.set
121
+ CGContextAddRect(context, [[0, 0], [10, 10]])
122
+ CGContextFillPath(context)
123
+ end
124
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
125
+ :blue.uicolor.set
126
+ CGContextAddRect(context, [[0, 0], [8, 8]])
127
+ CGContextFillPath(context)
128
+ end
129
+ @img = @red.merge(@blue, at: :top)
130
+ end
131
+
132
+ it 'should work at top left corner' do
133
+ @img.color_at([0, 0]).should == :red.uicolor
134
+ end
135
+ it 'should work at top center' do
136
+ @img.color_at([4, 0]).should == :blue.uicolor
137
+ end
138
+ it 'should work at top right corner' do
139
+ @img.color_at([9, 0]).should == :red.uicolor
140
+ end
141
+ it 'should work at left side' do
142
+ @img.color_at([0, 4]).should == :red.uicolor
143
+ end
144
+ it 'should work at center' do
145
+ @img.color_at([4, 4]).should == :blue.uicolor
146
+ end
147
+ it 'should work at right side' do
148
+ @img.color_at([9, 4]).should == :red.uicolor
149
+ end
150
+ it 'should work at bottom left corner' do
151
+ @img.color_at([0, 9]).should == :red.uicolor
152
+ end
153
+ it 'should work at bottom center' do
154
+ @img.color_at([4, 9]).should == :red.uicolor
155
+ end
156
+ it 'should work at bottom right corner' do
157
+ @img.color_at([9, 9]).should == :red.uicolor
158
+ end
159
+ end
160
+
161
+ describe 'should merge at top_right' do
162
+ before do
163
+ @red = UIImage.canvas(size: [10, 10]) do |context|
164
+ :red.uicolor.set
165
+ CGContextAddRect(context, [[0, 0], [10, 10]])
166
+ CGContextFillPath(context)
167
+ end
168
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
169
+ :blue.uicolor.set
170
+ CGContextAddRect(context, [[0, 0], [8, 8]])
171
+ CGContextFillPath(context)
172
+ end
173
+ @img = @red.merge(@blue, at: :top_right)
174
+ end
175
+
176
+ it 'should work at top left corner' do
177
+ @img.color_at([0, 0]).should == :red.uicolor
178
+ end
179
+ it 'should work at top center' do
180
+ @img.color_at([4, 0]).should == :blue.uicolor
181
+ end
182
+ it 'should work at top right corner' do
183
+ @img.color_at([9, 0]).should == :blue.uicolor
184
+ end
185
+ it 'should work at left side' do
186
+ @img.color_at([0, 4]).should == :red.uicolor
187
+ end
188
+ it 'should work at center' do
189
+ @img.color_at([4, 4]).should == :blue.uicolor
190
+ end
191
+ it 'should work at right side' do
192
+ @img.color_at([9, 4]).should == :blue.uicolor
193
+ end
194
+ it 'should work at bottom left corner' do
195
+ @img.color_at([0, 9]).should == :red.uicolor
196
+ end
197
+ it 'should work at bottom center' do
198
+ @img.color_at([4, 9]).should == :red.uicolor
199
+ end
200
+ it 'should work at bottom right corner' do
201
+ @img.color_at([9, 9]).should == :red.uicolor
202
+ end
203
+ end
204
+
205
+ describe 'should merge at left' do
206
+ before do
207
+ @red = UIImage.canvas(size: [10, 10]) do |context|
208
+ :red.uicolor.set
209
+ CGContextAddRect(context, [[0, 0], [10, 10]])
210
+ CGContextFillPath(context)
211
+ end
212
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
213
+ :blue.uicolor.set
214
+ CGContextAddRect(context, [[0, 0], [8, 8]])
215
+ CGContextFillPath(context)
216
+ end
217
+ @img = @red.merge(@blue, at: :left)
218
+ end
219
+
220
+ it 'should work at top left corner' do
221
+ @img.color_at([0, 0]).should == :red.uicolor
222
+ end
223
+ it 'should work at top center' do
224
+ @img.color_at([4, 0]).should == :red.uicolor
225
+ end
226
+ it 'should work at top right corner' do
227
+ @img.color_at([9, 0]).should == :red.uicolor
228
+ end
229
+ it 'should work at left side' do
230
+ @img.color_at([0, 4]).should == :blue.uicolor
231
+ end
232
+ it 'should work at center' do
233
+ @img.color_at([4, 4]).should == :blue.uicolor
234
+ end
235
+ it 'should work at right side' do
236
+ @img.color_at([9, 4]).should == :red.uicolor
237
+ end
238
+ it 'should work at bottom left corner' do
239
+ @img.color_at([0, 9]).should == :red.uicolor
240
+ end
241
+ it 'should work at bottom center' do
242
+ @img.color_at([4, 9]).should == :red.uicolor
243
+ end
244
+ it 'should work at bottom right corner' do
245
+ @img.color_at([9, 9]).should == :red.uicolor
246
+ end
247
+ end
248
+
249
+ describe 'should merge at center' do
250
+ before do
251
+ @red = UIImage.canvas(size: [10, 10]) do |context|
252
+ :red.uicolor.set
253
+ CGContextAddRect(context, [[0, 0], [10, 10]])
254
+ CGContextFillPath(context)
255
+ end
256
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
257
+ :blue.uicolor.set
258
+ CGContextAddRect(context, [[0, 0], [8, 8]])
259
+ CGContextFillPath(context)
260
+ end
261
+ @img = @red.merge(@blue, at: :center)
262
+ end
263
+
264
+ it 'should work at top left corner' do
265
+ @img.color_at([0, 0]).should == :red.uicolor
266
+ end
267
+ it 'should work at top center' do
268
+ @img.color_at([4, 0]).should == :red.uicolor
269
+ end
270
+ it 'should work at top right corner' do
271
+ @img.color_at([9, 0]).should == :red.uicolor
272
+ end
273
+ it 'should work at left side' do
274
+ @img.color_at([0, 4]).should == :red.uicolor
275
+ end
276
+ it 'should work at center' do
277
+ @img.color_at([4, 4]).should == :blue.uicolor
278
+ end
279
+ it 'should work at right side' do
280
+ @img.color_at([9, 4]).should == :red.uicolor
281
+ end
282
+ it 'should work at bottom left corner' do
283
+ @img.color_at([0, 9]).should == :red.uicolor
284
+ end
285
+ it 'should work at bottom center' do
286
+ @img.color_at([4, 9]).should == :red.uicolor
287
+ end
288
+ it 'should work at bottom right corner' do
289
+ @img.color_at([9, 9]).should == :red.uicolor
290
+ end
291
+ end
292
+
293
+ describe 'should merge at right' do
294
+ before do
295
+ @red = UIImage.canvas(size: [10, 10]) do |context|
296
+ :red.uicolor.set
297
+ CGContextAddRect(context, [[0, 0], [10, 10]])
298
+ CGContextFillPath(context)
299
+ end
300
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
301
+ :blue.uicolor.set
302
+ CGContextAddRect(context, [[0, 0], [8, 8]])
303
+ CGContextFillPath(context)
304
+ end
305
+ @img = @red.merge(@blue, at: :right)
306
+ end
307
+
308
+ it 'should work at top left corner' do
309
+ @img.color_at([0, 0]).should == :red.uicolor
310
+ end
311
+ it 'should work at top center' do
312
+ @img.color_at([4, 0]).should == :red.uicolor
313
+ end
314
+ it 'should work at top right corner' do
315
+ @img.color_at([9, 0]).should == :red.uicolor
316
+ end
317
+ it 'should work at left side' do
318
+ @img.color_at([0, 4]).should == :red.uicolor
319
+ end
320
+ it 'should work at center' do
321
+ @img.color_at([4, 4]).should == :blue.uicolor
322
+ end
323
+ it 'should work at right side' do
324
+ @img.color_at([9, 4]).should == :blue.uicolor
325
+ end
326
+ it 'should work at bottom left corner' do
327
+ @img.color_at([0, 9]).should == :red.uicolor
328
+ end
329
+ it 'should work at bottom center' do
330
+ @img.color_at([4, 9]).should == :red.uicolor
331
+ end
332
+ it 'should work at bottom right corner' do
333
+ @img.color_at([9, 9]).should == :red.uicolor
334
+ end
335
+ end
336
+
337
+ describe 'should merge at bottom_left' do
338
+ before do
339
+ @red = UIImage.canvas(size: [10, 10]) do |context|
340
+ :red.uicolor.set
341
+ CGContextAddRect(context, [[0, 0], [10, 10]])
342
+ CGContextFillPath(context)
343
+ end
344
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
345
+ :blue.uicolor.set
346
+ CGContextAddRect(context, [[0, 0], [8, 8]])
347
+ CGContextFillPath(context)
348
+ end
349
+ @img = @red.merge(@blue, at: :bottom_left)
350
+ end
351
+
352
+ it 'should work at top left corner' do
353
+ @img.color_at([0, 0]).should == :red.uicolor
354
+ end
355
+ it 'should work at top center' do
356
+ @img.color_at([4, 0]).should == :red.uicolor
357
+ end
358
+ it 'should work at top right corner' do
359
+ @img.color_at([9, 0]).should == :red.uicolor
360
+ end
361
+ it 'should work at left side' do
362
+ @img.color_at([0, 4]).should == :blue.uicolor
363
+ end
364
+ it 'should work at center' do
365
+ @img.color_at([4, 4]).should == :blue.uicolor
366
+ end
367
+ it 'should work at right side' do
368
+ @img.color_at([9, 4]).should == :red.uicolor
369
+ end
370
+ it 'should work at bottom left corner' do
371
+ @img.color_at([0, 9]).should == :blue.uicolor
372
+ end
373
+ it 'should work at bottom center' do
374
+ @img.color_at([4, 9]).should == :blue.uicolor
375
+ end
376
+ it 'should work at bottom right corner' do
377
+ @img.color_at([9, 9]).should == :red.uicolor
378
+ end
379
+ end
380
+
381
+ describe 'should merge at bottom' do
382
+ before do
383
+ @red = UIImage.canvas(size: [10, 10]) do |context|
384
+ :red.uicolor.set
385
+ CGContextAddRect(context, [[0, 0], [10, 10]])
386
+ CGContextFillPath(context)
387
+ end
388
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
389
+ :blue.uicolor.set
390
+ CGContextAddRect(context, [[0, 0], [8, 8]])
391
+ CGContextFillPath(context)
392
+ end
393
+ @img = @red.merge(@blue, at: :bottom)
394
+ end
395
+
396
+ it 'should work at top left corner' do
397
+ @img.color_at([0, 0]).should == :red.uicolor
398
+ end
399
+ it 'should work at top center' do
400
+ @img.color_at([4, 0]).should == :red.uicolor
401
+ end
402
+ it 'should work at top right corner' do
403
+ @img.color_at([9, 0]).should == :red.uicolor
404
+ end
405
+ it 'should work at left side' do
406
+ @img.color_at([0, 4]).should == :red.uicolor
407
+ end
408
+ it 'should work at center' do
409
+ @img.color_at([4, 4]).should == :blue.uicolor
410
+ end
411
+ it 'should work at right side' do
412
+ @img.color_at([9, 4]).should == :red.uicolor
413
+ end
414
+ it 'should work at bottom left corner' do
415
+ @img.color_at([0, 9]).should == :red.uicolor
416
+ end
417
+ it 'should work at bottom center' do
418
+ @img.color_at([4, 9]).should == :blue.uicolor
419
+ end
420
+ it 'should work at bottom right corner' do
421
+ @img.color_at([9, 9]).should == :red.uicolor
422
+ end
423
+ end
424
+
425
+ describe 'should merge at bottom_right' do
426
+ before do
427
+ @red = UIImage.canvas(size: [10, 10]) do |context|
428
+ :red.uicolor.set
429
+ CGContextAddRect(context, [[0, 0], [10, 10]])
430
+ CGContextFillPath(context)
431
+ end
432
+ @blue = UIImage.canvas(size: [8, 8]) do |context|
433
+ :blue.uicolor.set
434
+ CGContextAddRect(context, [[0, 0], [8, 8]])
435
+ CGContextFillPath(context)
436
+ end
437
+ @img = @red.merge(@blue, at: :bottom_right)
438
+ end
439
+
440
+ it 'should work at top left corner' do
441
+ @img.color_at([0, 0]).should == :red.uicolor
442
+ end
443
+ it 'should work at top center' do
444
+ @img.color_at([4, 0]).should == :red.uicolor
445
+ end
446
+ it 'should work at top right corner' do
447
+ @img.color_at([9, 0]).should == :red.uicolor
448
+ end
449
+ it 'should work at left side' do
450
+ @img.color_at([0, 4]).should == :red.uicolor
451
+ end
452
+ it 'should work at center' do
453
+ @img.color_at([4, 4]).should == :blue.uicolor
454
+ end
455
+ it 'should work at right side' do
456
+ @img.color_at([9, 4]).should == :blue.uicolor
457
+ end
458
+ it 'should work at bottom left corner' do
459
+ @img.color_at([0, 9]).should == :red.uicolor
460
+ end
461
+ it 'should work at bottom center' do
462
+ @img.color_at([4, 9]).should == :blue.uicolor
463
+ end
464
+ it 'should work at bottom right corner' do
465
+ @img.color_at([9, 9]).should == :blue.uicolor
466
+ end
467
+ end
468
+
469
+ end
470
+
471
+ end