tins 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/tests/tins_test.rb DELETED
@@ -1,651 +0,0 @@
1
- require 'test_helper'
2
- require 'tins'
3
-
4
- module Tins
5
- class MinimizeTest < Test::Unit::TestCase
6
- class ::Array
7
- include Tins::Minimize
8
- end
9
-
10
- def test_minimize
11
- assert_equal [], [].minimize
12
- assert_equal [ 1..1 ], [ 1 ].minimize
13
- assert_equal [ 1..2 ], [ 1, 2 ].minimize
14
- assert_equal [ 1..1, 7..7 ], [ 1, 7 ].minimize
15
- assert_equal [ 1..3, 7..7, 11..14 ],
16
- [ 1, 2, 3, 7, 11, 12, 13, 14 ].minimize
17
- assert_equal [ 'A'..'C', 'G'..'G', 'K'..'M' ],
18
- [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ].minimize
19
- end
20
-
21
- def test_minimize!
22
- assert_equal [], [].minimize!
23
- assert_equal [ 1..1 ], [ 1 ].minimize!
24
- assert_equal [ 1..2 ], [ 1, 2 ].minimize!
25
- assert_equal [ 1..1, 7..7 ], [ 1, 7 ].minimize!
26
- assert_equal [ 1..3, 7..7, 11..14 ],
27
- [ 1, 2, 3, 7, 11, 12, 13, 14 ].minimize!
28
- assert_equal [ 'A'..'C', 'G'..'G', 'K'..'M' ],
29
- [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ].minimize!
30
- end
31
-
32
- def test_unminimize
33
- assert_equal [], [].unminimize
34
- assert_equal [ 1 ], [ 1..1 ].unminimize
35
- assert_equal [ 1, 2 ], [ 1..2 ].unminimize
36
- assert_equal [ 1, 7 ], [ 1..1, 7..7 ].unminimize
37
- assert_equal [ 1, 2, 3, 7, 11, 12, 13, 14 ],
38
- [ 1..3, 7..7, 11..14 ].unminimize
39
- assert_equal [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ],
40
- [ 'A'..'C', 'G'..'G', 'K'..'M' ].unminimize
41
- end
42
-
43
- def test_unminimize!
44
- assert_equal [], [].unminimize!
45
- assert_equal [ 1 ], [ 1..1 ].unminimize!
46
- assert_equal [ 1, 2 ], [ 1..2 ].unminimize!
47
- assert_equal [ 1, 7 ], [ 1..1, 7..7 ].unminimize!
48
- assert_equal [ 1, 2, 3, 7, 11, 12, 13, 14 ],
49
- [ 1..3, 7..7, 11..14 ].unminimize!
50
- assert_equal [ 'A', 'B', 'C', 'G', 'K', 'L', 'M' ],
51
- [ 'A'..'C', 'G'..'G', 'K'..'M' ].unminimize!
52
- end
53
- end
54
-
55
- class PartialApplicationTest < Test::Unit::TestCase
56
- require 'tins/xt/partial_application'
57
-
58
- def mul(x, y) x * y end
59
-
60
- define_method(:dup) { |y| method(:mul).partial(2)[y] }
61
-
62
- define_method(:trip) { |y| method(:mul).partial(3)[y] }
63
-
64
-
65
- def test_proc
66
- mul = lambda { |x, y| x * y }
67
- klon = mul.partial
68
- dup = mul.partial(2)
69
- trip = mul.partial(3)
70
- assert_equal [ 6, 9, 12 ], [ dup[3], trip[3], mul[4, 3] ]
71
- assert_equal [ 6, 9, 12 ], [ dup[3], trip[3], klon[4, 3] ]
72
- assert_raises(ArgumentError) do
73
- mul.partial(1, 2, 3)
74
- end
75
- end
76
-
77
- def test_method
78
- assert_equal [ 6, 9, 12 ], [ dup(3), trip(3), mul(4, 3) ]
79
- end
80
- end
81
-
82
- class GeneratorTest < Test::Unit::TestCase
83
- def setup
84
- @numeric = [ 1, 2, 3 ]
85
- @string = %w[a b c]
86
- @chars = 'abc'
87
- end
88
-
89
- def test_generator
90
- g = Tins::Generator[@numeric, @string]
91
- assert_equal 2, g.size
92
- g.add_dimension(@chars, :each_byte)
93
- assert_equal 3, g.size
94
- assert_equal\
95
- [[1, "a", 97],
96
- [1, "a", 98],
97
- [1, "a", 99],
98
- [1, "b", 97],
99
- [1, "b", 98],
100
- [1, "b", 99],
101
- [1, "c", 97],
102
- [1, "c", 98],
103
- [1, "c", 99],
104
- [2, "a", 97],
105
- [2, "a", 98],
106
- [2, "a", 99],
107
- [2, "b", 97],
108
- [2, "b", 98],
109
- [2, "b", 99],
110
- [2, "c", 97],
111
- [2, "c", 98],
112
- [2, "c", 99],
113
- [3, "a", 97],
114
- [3, "a", 98],
115
- [3, "a", 99],
116
- [3, "b", 97],
117
- [3, "b", 98],
118
- [3, "b", 99],
119
- [3, "c", 97],
120
- [3, "c", 98],
121
- [3, "c", 99]], g.to_a
122
- end
123
- end
124
-
125
- class RoundTest < Test::Unit::TestCase
126
- require 'tins/xt/round'
127
-
128
- def test_standard
129
- assert_equal(1, 1.round)
130
- assert_equal(-1, -1.round)
131
- assert_equal(2, 1.5.round)
132
- assert_kind_of Integer, 1.5.round
133
- assert_equal(-1, -1.4.round)
134
- assert_equal(-2, -1.5.round)
135
- end
136
-
137
- def test_inclusion
138
- assert_equal(10, 12.round(-1))
139
- assert_kind_of Integer, 12.round(-1)
140
- assert_equal(-10, -12.round(-1))
141
- assert_raises(ArgumentError) { 12.round(-2) }
142
- assert_raises(ArgumentError) { -12.round(-2) }
143
- assert_in_delta(1.6, 1.55.round(1), 1E-1)
144
- assert_kind_of Float, 1.55.round(1)
145
- assert_equal(2, 1.55.round(0))
146
- assert_in_delta(-1.5, -1.45.round(1), 1E-1)
147
- assert_equal(-1, -1.45.round(0))
148
- assert_in_delta(-1.6, -1.55.round(1), 1E-1)
149
- assert_equal(-2, -1.55.round(0))
150
- assert_in_delta(-1.55, -1.55.round(999), 1E-2)
151
- end
152
- end
153
-
154
- class ModuleGroupTest < Test::Unit::TestCase
155
- MyClasses = Tins::ModuleGroup[ Array, String, Hash ]
156
-
157
- def test_module_group
158
- assert MyClasses === []
159
- assert MyClasses === ""
160
- assert MyClasses === {}
161
- assert !(MyClasses === :nix)
162
- case []
163
- when MyClasses
164
- assert true
165
- when Array
166
- assert false
167
- end
168
- case :nix
169
- when MyClasses
170
- assert false
171
- when Array
172
- assert false
173
- when Symbol
174
- assert true
175
- end
176
- end
177
- end
178
-
179
- class UniqByTest < Test::Unit::TestCase
180
- require 'tins/xt/uniq_by'
181
-
182
- unless defined?(Point)
183
- class Point < Struct.new :x, :y
184
- end
185
- end
186
-
187
- def test_uniq_by
188
- assert_equal [ 1, 2, 3 ], [ 1, 2, 2, 3 ].uniq_by.sort
189
- a = [ 1, 2, 2, 3 ]; a.uniq_by!
190
- assert_equal [ 1, 2, 3 ], a.sort
191
- p1 = Point.new 1, 2
192
- p2 = Point.new 2, 2
193
- p3 = Point.new 2, 2
194
- p4 = Point.new 3, 3
195
- a = [ p1, p2, p3, p4 ]
196
- a_uniq = a.uniq_by { |p| p.y }
197
- assert_equal 2, a_uniq.size
198
- assert a_uniq.include?(p4)
199
- assert [ p1, p2, p3 ].any? { |p| a_uniq.include? p }
200
- a.uniq_by! { |p| p.y }
201
- assert_equal 2, a.size
202
- assert a.include?(p4)
203
- assert [ p1, p2, p3 ].any? { |p| a.include? p }
204
- end
205
- end
206
-
207
- class CountByTest < Test::Unit::TestCase
208
- require 'tins/xt/count_by'
209
-
210
- def test_count_by
211
- assert_equal 0, [].count_by { |x| x % 2 == 0 }
212
- assert_equal 0, [ 1 ].count_by { |x| x % 2 == 0 }
213
- assert_equal 1, [ 1 ].count_by { |x| x % 2 == 1 }
214
- assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 0 }
215
- assert_equal 1, [ 1, 2 ].count_by { |x| x % 2 == 1 }
216
- assert_equal 2, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 0 }
217
- assert_equal 3, [ 1, 2, 3, 4, 5 ].count_by { |x| x % 2 == 1 }
218
- end
219
- end
220
-
221
- if Tins::Shuffle === Array
222
- class ShuffleTest < Test::Unit::TestCase
223
- require 'tins/xt/shuffle'
224
-
225
- def setup
226
- @a = [ 1, 2, 3 ]
227
- srand 666
228
- end
229
-
230
- def test_shuffle
231
- assert_equal(a = [2, 3, 1], a = @a.shuffle)
232
- assert_not_same @a, a
233
- assert_equal(b = [3, 1, 2], b = @a.shuffle)
234
- assert_not_same a, b
235
- assert_not_same @a, b
236
- end
237
-
238
- def test_shuffle_bang
239
- assert_equal([2, 3, 1], a = @a.shuffle!)
240
- assert_same @a, a
241
- assert_equal([1, 2, 3], b = @a.shuffle!)
242
- assert_same a, b
243
- assert_same @a, b
244
- end
245
- end
246
- end
247
-
248
- class LimitedTest < Test::Unit::TestCase
249
- class ::Array
250
- include Tins::Shuffle
251
- end
252
-
253
- def test_limited
254
- count = {}
255
- limited = Tins::Limited.new(5)
256
- 5.times do
257
- limited.execute do
258
- count[Thread.current] = true
259
- sleep
260
- end
261
- end
262
- until count.size >= 5
263
- sleep 0.1
264
- end
265
- assert_equal 5, count.keys.uniq.size
266
- end
267
- end
268
-
269
- class MemoizeTest < Test::Unit::TestCase
270
- class A
271
- def initialize(var)
272
- @var = var
273
- end
274
-
275
- def foo(n)
276
- r = n * @var
277
- @var += 1
278
- r
279
- end
280
- memoize_method :foo
281
-
282
- def bar(n)
283
- r = n * @var
284
- @var += 1
285
- r
286
- end
287
- memoize_function :bar
288
- end
289
-
290
- def setup
291
- @a23 = A.new(23)
292
- @a42 = A.new(42)
293
- end
294
-
295
- def test_memoize_method
296
- assert Module.__memoize_cache__.empty?
297
- assert_equal 2 * 23, @a23.foo(2)
298
- assert_equal 2 * 23, @a23.foo(2)
299
- assert_equal 3 * 24, @a23.foo(3)
300
- assert_equal 2 * 42, @a42.foo(2)
301
- assert_equal 2 * 42, @a42.foo(2)
302
- assert_equal 3 * 43, @a42.foo(3)
303
- assert !Module.__memoize_cache__.empty?
304
- @a23, @a42 = nil, nil
305
- GC.start
306
- # XXX test fails atm, assert Module.__memoize_cache__.empty?
307
- end
308
-
309
- def test_memoize_function
310
- assert A.__memoize_cache__.empty?
311
- assert_equal 2 * 23, @a23.bar(2)
312
- assert_equal 2 * 23, @a23.bar(2)
313
- assert_equal 3 * 24, @a23.bar(3)
314
- assert_equal 2 * 23, @a42.bar(2)
315
- assert_equal 2 * 23, @a42.bar(2)
316
- assert_equal 3 * 24, @a42.bar(3)
317
- assert !A.__memoize_cache__.empty?
318
- end
319
- end
320
-
321
- class HashUnionTest < Test::Unit::TestCase
322
- require 'tins/xt/hash_union'
323
-
324
- class HashLike1
325
- def to_hash
326
- { 'foo' => true }
327
- end
328
- end
329
-
330
- class HashLike2
331
- def to_h
332
- { 'foo' => true }
333
- end
334
- end
335
-
336
- def test_union
337
- defaults = { 'foo' => true, 'bar' => false, 'quux' => nil }
338
- hash = { 'foo' => false }
339
- assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ],
340
- (hash | defaults).sort
341
- hash |= defaults
342
- assert_equal [ ['bar', false], ['foo', false], ['quux', nil] ],
343
- hash.sort
344
- hash = { 'foo' => false }
345
- hash |= {
346
- 'quux' => true,
347
- 'baz' => 23,
348
- } | defaults
349
- assert_equal [ ['bar', false], [ 'baz', 23 ], ['foo', false],
350
- ['quux', true] ],
351
- hash.sort
352
- end
353
-
354
- def test_hash_conversion
355
- assert_equal({ 'foo' => true }, { } | HashLike1.new)
356
- assert_equal({ 'foo' => true }, { } | HashLike2.new)
357
- end
358
- end
359
-
360
- class HashSymbolizeKeysRecursiveTest < Test::Unit::TestCase
361
- require 'tins/xt/hash_symbolize_keys_recursive'
362
-
363
- def test_symbolize
364
- hash = {
365
- 'key' => [
366
- {
367
- 'key' => {
368
- 'key' => true
369
- }
370
- }
371
- ],
372
- }
373
- hash2 = hash.symbolize_keys_recursive
374
- assert hash2[:key][0][:key][:key]
375
- hash.symbolize_keys_recursive!
376
- assert hash[:key][0][:key][:key]
377
- end
378
- end
379
-
380
- class SubhashTest < Test::Unit::TestCase
381
- require 'tins/xt/subhash'
382
-
383
- def test_subhash
384
- h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 }
385
- assert_equal [ [ 'bar666', 666 ] ], h.subhash(/\Abar/).to_a
386
- assert h.subhash(/\Abaz/).empty?
387
- assert_equal [ [ 'foo1', 1 ], [ 'foo2', 2 ] ], h.subhash(/\Afoo\d/).to_a
388
- assert_equal [ [ 'foo2', 2 ] ], h.subhash('foo2').to_a
389
- end
390
-
391
- def test_subhash_bang
392
- h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 }
393
- h.subhash!('foo2')
394
- assert_equal [ [ 'foo2', 2 ] ], h.to_a
395
- end
396
-
397
- def test_subhash_with_block
398
- h = { 'foo1' => 1, 'foo2' => 2, 'bar666' => 666 }
399
- assert h.subhash(/\Abaz/) { :foo }.empty?
400
- assert_equal [ [ 'foo1', 1 ], [ 'foo2', 2 ] ],
401
- h.subhash(/\Afoo(\d)/) { |_,_,m| Integer(m[1]) }.to_a
402
- end
403
- end
404
-
405
- class NullTest < Test::Unit::TestCase
406
- require 'tins/xt/null'
407
-
408
- def test_null
409
- assert_equal NULL, NULL.foo
410
- assert_equal NULL, NULL.foo.bar
411
- assert_equal 'NULL', NULL.inspect
412
- assert_equal '', NULL.to_s
413
- assert_equal 1, Null(1)
414
- assert_equal NULL, Null(nil)
415
- end
416
- end
417
-
418
- class TimeDummyTest < Test::Unit::TestCase
419
- require 'tins/xt/time_dummy'
420
- require 'time'
421
-
422
- def test_time_dummy
423
- time = Time.parse('2009-09-09 21:09:09')
424
- assert_not_equal time, Time.now
425
- Time.dummy = time
426
- assert_equal time, Time.now
427
- Time.dummy = nil
428
- assert_not_equal time, Time.now
429
- end
430
- end
431
-
432
- class BlankFullTest < Test::Unit::TestCase
433
- require 'tins/xt/full'
434
- require 'tins/xt/symbol_to_proc'
435
- require 'set'
436
-
437
- def test_blank
438
- assert !true.blank?
439
- assert false.blank?
440
- assert nil.blank?
441
- assert [].blank?
442
- assert ![23].blank?
443
- assert Set[].blank?
444
- assert !Set[23].blank?
445
- assert({}.blank?)
446
- assert !{ :foo => 23 }.blank?
447
- assert "".blank?
448
- assert " ".blank?
449
- assert !"foo".blank?
450
- end
451
-
452
- def test_full
453
- assert_equal true, true.full?
454
- assert_nil false.full?
455
- assert_nil nil.full?
456
- assert_nil [].full?
457
- assert_equal [ 23 ], [ 23 ].full?
458
- assert_nil Set[].full?
459
- assert_equal Set[23], Set[23].full?
460
- assert_nil({}.full?)
461
- assert_equal({ :foo => 23 }, { :foo => 23 }.full?)
462
- assert_nil "".full?
463
- assert_nil " ".full?
464
- assert_equal "foo", "foo".full?
465
- assert_nil " ".full?(&:size)
466
- assert_equal 3, "foo".full?(&:size)
467
- assert_nil " ".full?(&:size)
468
- assert_equal 3, "foo".full?(&:size)
469
- assert_nil " ".full?(:size)
470
- assert_equal 3, "foo".full?(:size)
471
- assert_nil " ".full?(:size)
472
- assert_equal 3, "foo".full?(:size)
473
- end
474
- end
475
-
476
- class BlankFullTest < Test::Unit::TestCase
477
- require 'tins/xt/deep_dup'
478
-
479
- def test_deep_dup
480
- a = [1,2,3]
481
- assert_equal a, a.deep_dup
482
- assert_not_same a, a.deep_dup
483
- end
484
-
485
- def test_deep_dup_proc
486
- f = lambda { |x| 2 * x }
487
- g = f.deep_dup
488
- assert_equal f[3], g[3]
489
- assert_equal f, g
490
- assert_same f, g
491
- end
492
- end
493
-
494
- class BijectionTest < Test::Unit::TestCase
495
- def test_bijection
496
- assert_equal [ [ 1, 2 ], [ 3, 4 ] ], Tins::Bijection[ 1, 2, 3, 4 ].to_a.sort
497
- assert_raise(ArgumentError) do
498
- Tins::Bijection[1,2,3]
499
- end
500
- assert_raise(ArgumentError) do
501
- Tins::Bijection[1,2,3,2]
502
- end
503
- assert_raise(ArgumentError) do
504
- Tins::Bijection[1,2,1,3]
505
- end
506
- end
507
- end
508
-
509
- class TryTest < Test::Unit::TestCase
510
- require 'tins/xt/attempt'
511
-
512
- def test_attempt_block_condition
513
- assert attempt(:attempts => 1, :exception_class => nil) { |c| c == 1 }
514
- assert attempt(:attempts => 3, :exception_class => nil) { |c| c == 1 }
515
- assert_equal false, attempt(:attempts => 3, :exception_class => nil) { |c| c == 4 }
516
- assert_nil attempt(:attempts => 0, :exception_class => nil) { |c| c == 4 }
517
- assert_raise(Exception) { attempt(:attempts => 3, :exception_class => nil) { raise Exception } }
518
- end
519
-
520
- class MyError < StandardError; end
521
- class MyException < Exception; end
522
-
523
- def test_attempt_default_exception
524
- assert attempt(1) { |c| c != 1 and raise MyError }
525
- assert attempt(3) { |c| c != 1 and raise MyError }
526
- assert_equal false, attempt(3) { |c| c != 4 and raise MyError }
527
- assert_nil attempt(0) { |c| c != 4 and raise MyError }
528
- assert_raise(Exception) { attempt(3) { raise Exception } }
529
- end
530
-
531
- def test_attempt_exception
532
- assert attempt(:attempts => 1, :exception_class => MyException) { |c| c != 1 and raise MyException }
533
- assert attempt(:attempts => 3, :exception_class => MyException) { |c| c != 1 and raise MyException }
534
- assert_equal false, attempt(:attempts => 3, :exception_class => MyException) { |c| c != 4 and raise MyException }
535
- assert_nil attempt(:attempts => 0, :exception_class => MyException) { |c| c != 4 and raise MyException }
536
- assert_raise(Exception) { attempt(:attempts => 3, :exception_class => MyException) { raise Exception } }
537
- end
538
- end
539
-
540
- class RangePlustTest < Test::Unit::TestCase
541
- require 'tins/xt/range_plus'
542
-
543
- def test_range_plus
544
- assert_equal [], (0...0) + (0...0)
545
- assert_equal [ 0 ], (0..0) + (0...0)
546
- assert_equal [ 0, 0 ], (0..0) + (0..0)
547
- assert_equal((1..5).to_a, (1...3) + (3..5))
548
- end
549
- end
550
-
551
- class NamedTest < Test::Unit::TestCase
552
- require 'tins/xt/named'
553
-
554
- def test_named_simple
555
- a = [ 1, 2, 3 ]
556
- a.named(:plus1, :map) { |x| x + 1 }
557
- assert_equal [ 2, 3, 4 ], a.plus1
558
- Array.named(:odd, :select) { |x| x % 2 == 1 }
559
- assert_equal [ 3 ], a.plus1.odd
560
- end
561
-
562
- if RUBY_VERSION >= '1.9'
563
- def foo(x, y, &block)
564
- block.call x * y
565
- end
566
-
567
- def test_more_complex
568
- Object.named(:foo_with_block, :foo) do |z|
569
- z ** 2
570
- end
571
- assert_equal foo(2, 3) { |z| z ** 2 }, foo_with_block(2, 3)
572
- Object.named(:foo_23, :foo, 2, 3)
573
- assert_equal foo(2, 3) { |z| z ** 2 }, foo_23 { |z| z ** 2 }
574
- Object.named(:foo_2, :foo, 2)
575
- assert_equal foo(2, 3) { |z| z ** 2 }, foo_2(3) { |z| z ** 2 }
576
- end
577
- end
578
- end
579
-
580
- require 'tins/xt/string'
581
- class StringCamelizeTest < Test::Unit::TestCase
582
- def test_camelize
583
- assert_equal 'FooBar', 'foo_bar'.camelize
584
- assert_equal 'FooBar', 'foo_bar'.camelize(:upper)
585
- assert_equal 'FooBar', 'foo_bar'.camelize(true)
586
- assert_equal 'fooBar', 'foo_bar'.camelize(:lower)
587
- assert_equal 'fooBar', 'foo_bar'.camelize(false)
588
- assert_equal 'FooBar', 'foo_bar'.camelcase
589
- assert_equal 'Foo::Bar', 'foo/bar'.camelize
590
- assert_equal 'Foo::Bar', 'foo/bar'.camelize(:upper)
591
- assert_equal 'Foo::Bar', 'foo/bar'.camelize(true)
592
- assert_equal 'foo::Bar', 'foo/bar'.camelize(:lower)
593
- assert_equal 'foo::Bar', 'foo/bar'.camelize(false)
594
- assert_equal 'Foo::Bar', 'foo/bar'.camelcase
595
- end
596
- end
597
-
598
- class StringUnderscoreTest < Test::Unit::TestCase
599
- def test_underscore
600
- assert_equal 'foo_bar', 'FooBar'.underscore
601
- assert_equal 'foo/bar', 'Foo::Bar'.underscore
602
- end
603
- end
604
-
605
- class StringVersionTest < Test::Unit::TestCase
606
- def test_comparison
607
- assert_operator '1.2'.version, :<, '1.3'.version
608
- assert_operator '1.3'.version, :>, '1.2'.version
609
- assert_operator '1.2'.version, :<=, '1.2'.version
610
- assert_operator '1.2'.version, :>=, '1.2'.version
611
- assert_operator '1.2'.version, :==, '1.2'.version
612
- end
613
-
614
- def test_change
615
- s = '1.2'
616
- s.version.revision = 1
617
- assert_equal '1.2.0.1', s
618
- s.version.revision += 1
619
- assert_equal '1.2.0.2', s
620
- s.version.succ!
621
- assert_equal '1.2.0.3', s
622
- s.version.pred!
623
- assert_equal '1.2.0.2', s
624
- assert_raise(ArgumentError) { s.version.build -= 1 }
625
- s.version.major = 2
626
- assert_equal '2.2.0.2', s
627
- s.version.minor = 1
628
- assert_equal '2.1.0.2', s
629
- end
630
- end
631
-
632
- require 'tins/xt/require_maybe'
633
- class RequireMaybeTest < Test::Unit::TestCase
634
- def test_require_maybe_failed
635
- executed = false
636
- require_maybe 'nix' do
637
- executed = true
638
- end
639
- assert executed, 'require did not fail'
640
- end
641
-
642
- def test_require_maybe_succeeded
643
- not_executed = true
644
- result = require_maybe 'tins' do
645
- not_executed = false
646
- end
647
- assert [ false, true ].include?(result)
648
- assert not_executed, 'require failed'
649
- end
650
- end
651
- end