mug 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/lib/mug/and-or.rb +26 -26
  3. data/lib/mug/any-and-all.rb +16 -16
  4. data/lib/mug/apply.rb +37 -37
  5. data/lib/mug/array/extend.rb +43 -43
  6. data/lib/mug/array/minus.rb +32 -32
  7. data/lib/mug/bool.rb +71 -71
  8. data/lib/mug/clamp.rb +35 -35
  9. data/lib/mug/counts.rb +27 -27
  10. data/lib/mug/fragile-method-chain.rb +42 -42
  11. data/lib/mug/hash/map.rb +75 -75
  12. data/lib/mug/hash/operations.rb +47 -47
  13. data/lib/mug/iterator/for.rb +7 -7
  14. data/lib/mug/iterator/method.rb +7 -7
  15. data/lib/mug/iterator_c.rb +14 -14
  16. data/lib/mug/loop-with.rb +30 -29
  17. data/lib/mug/matchdata/each.rb +40 -40
  18. data/lib/mug/matchdata/hash.rb +29 -29
  19. data/lib/mug/maybe.rb +33 -33
  20. data/lib/mug/negativity.rb +20 -20
  21. data/lib/mug/not.rb +6 -6
  22. data/lib/mug/rexproc.rb +6 -6
  23. data/lib/mug/self.rb +31 -31
  24. data/lib/mug/to_h.rb +2 -2
  25. data/lib/mug/top.rb +100 -100
  26. data/test/test-and-or.rb +32 -32
  27. data/test/test-any-and-all.rb +19 -19
  28. data/test/test-apply.rb +47 -47
  29. data/test/test-array-extend.rb +54 -54
  30. data/test/test-array-minus.rb +11 -11
  31. data/test/test-bool.rb +48 -48
  32. data/test/test-clamp.rb +42 -42
  33. data/test/test-counts.rb +21 -21
  34. data/test/test-fragile-method-chain.rb +56 -56
  35. data/test/test-hashmap.rb +14 -14
  36. data/test/test-hashop.rb +47 -47
  37. data/test/test-iterator-for.rb +12 -12
  38. data/test/test-loop-with.rb +117 -66
  39. data/test/test-matchdata_each.rb +50 -50
  40. data/test/test-matchdata_hash.rb +40 -40
  41. data/test/test-maybe.rb +76 -76
  42. data/test/test-negativity.rb +40 -40
  43. data/test/test-not.rb +53 -53
  44. data/test/test-rexproc.rb +6 -6
  45. data/test/test-self.rb +21 -21
  46. data/test/test-tau.rb +12 -12
  47. data/test/test-top.rb +100 -100
  48. metadata +4 -4
@@ -2,66 +2,66 @@ require 'test/unit'
2
2
  $VERBOSE = true
3
3
 
4
4
  if RUBY_VERSION.to_f < 1.9
5
- class Symbol
6
- def next
7
- to_s.next.to_sym
8
- end
9
- end
5
+ class Symbol
6
+ def next
7
+ to_s.next.to_sym
8
+ end
9
+ end
10
10
  end
11
11
 
12
12
  require_relative '../lib/mug/array/extend'
13
13
  class Test_array_extend < Test::Unit::TestCase
14
14
 
15
- def test_array_extend_err
16
- a = []
17
- assert_raise(ArgumentError) { a.extend }
18
- assert_raise(ArgumentError) { a.extend(1,2,3) }
19
- assert_raise(ArgumentError) { a.extend(-1) }
20
- end
21
- def test_array_extend_1
22
- a = [1,2]
23
- assert_equal( [1,2,nil], a.extend(1) )
24
- assert_equal( [1,2,nil,nil], a.extend(2) )
25
- assert_equal( [1,2,3], a.extend(1,3) )
26
- assert_equal( [1,2,3,3], a.extend(2,3) )
27
- end
28
- def test_array_extend_2
29
- a = [1,2]
30
- b = [9,8]
31
- assert_equal( [1,2,1,2], a.extend(a) )
32
- assert_equal( [1,2,9,8], a.extend(b) )
33
- end
34
- def test_array_extend_3
35
- a = ['a','b']
36
- assert_equal( ['a','b',2,3,4], a.extend(3){|i| i } )
37
- assert_equal( ['a','b'], a )
38
- end
15
+ def test_array_extend_err
16
+ a = []
17
+ assert_raise(ArgumentError) { a.extend }
18
+ assert_raise(ArgumentError) { a.extend(1,2,3) }
19
+ assert_raise(ArgumentError) { a.extend(-1) }
20
+ end
21
+ def test_array_extend_1
22
+ a = [1,2]
23
+ assert_equal( [1,2,nil], a.extend(1) )
24
+ assert_equal( [1,2,nil,nil], a.extend(2) )
25
+ assert_equal( [1,2,3], a.extend(1,3) )
26
+ assert_equal( [1,2,3,3], a.extend(2,3) )
27
+ end
28
+ def test_array_extend_2
29
+ a = [1,2]
30
+ b = [9,8]
31
+ assert_equal( [1,2,1,2], a.extend(a) )
32
+ assert_equal( [1,2,9,8], a.extend(b) )
33
+ end
34
+ def test_array_extend_3
35
+ a = ['a','b']
36
+ assert_equal( ['a','b',2,3,4], a.extend(3){|i| i } )
37
+ assert_equal( ['a','b'], a )
38
+ end
39
39
 
40
- def test_array_extendbang_err
41
- a = []
42
- assert_raise(ArgumentError) { a.extend! }
43
- assert_raise(ArgumentError) { a.extend!(1,2,3) }
44
- assert_raise(ArgumentError) { a.extend!(-1) }
45
- end
46
- def test_array_extendbang_1
47
- a = [1,2]
48
- assert_equal( [1,2,nil], a.extend!(1) )
49
- assert_equal( [1,2,nil,nil,nil], a.extend!(2) )
50
- a = [1,2]
51
- assert_equal( [1,2,3], a.extend!(1,3) )
52
- assert_equal( [1,2,3,3,3], a.extend!(2,3) )
53
- end
54
- def test_array_extendbang_2
55
- a = [1,2]
56
- b = [9,8]
57
- assert_equal( [1,2,1,2], a.extend!(a) )
58
- assert_equal( [1,2,1,2,9,8], a.extend!(b) )
59
- end
60
- def test_array_extendbang_3
61
- a = ['a','b']
62
- assert_equal( ['a','b',2,3,4], a.extend!(3){|i| i } )
63
- assert_equal( ['a','b',2,3,4], a )
64
- end
40
+ def test_array_extendbang_err
41
+ a = []
42
+ assert_raise(ArgumentError) { a.extend! }
43
+ assert_raise(ArgumentError) { a.extend!(1,2,3) }
44
+ assert_raise(ArgumentError) { a.extend!(-1) }
45
+ end
46
+ def test_array_extendbang_1
47
+ a = [1,2]
48
+ assert_equal( [1,2,nil], a.extend!(1) )
49
+ assert_equal( [1,2,nil,nil,nil], a.extend!(2) )
50
+ a = [1,2]
51
+ assert_equal( [1,2,3], a.extend!(1,3) )
52
+ assert_equal( [1,2,3,3,3], a.extend!(2,3) )
53
+ end
54
+ def test_array_extendbang_2
55
+ a = [1,2]
56
+ b = [9,8]
57
+ assert_equal( [1,2,1,2], a.extend!(a) )
58
+ assert_equal( [1,2,1,2,9,8], a.extend!(b) )
59
+ end
60
+ def test_array_extendbang_3
61
+ a = ['a','b']
62
+ assert_equal( ['a','b',2,3,4], a.extend!(3){|i| i } )
63
+ assert_equal( ['a','b',2,3,4], a )
64
+ end
65
65
  end
66
66
 
67
67
 
@@ -4,16 +4,16 @@ $VERBOSE = true
4
4
  require_relative '../lib/mug/array/minus'
5
5
  class Test_array_minus < Test::Unit::TestCase
6
6
 
7
- def test_array_minus
8
- a = %w[q q w e r e e ]
9
- b = %w[q w e e t]
10
- c = %w[ q r e ]
11
- d = %w[ t]
12
- assert_equal( c, a.minus(b) )
13
- assert_equal( d, b.minus(a) )
14
- assert_equal( c, a.minus(b, remainder: false) )
15
- assert_equal( [c,d], a.minus(b, remainder: true ) )
16
- assert_equal( [d,c], b.minus(a, remainder: true ) )
17
- end
7
+ def test_array_minus
8
+ a = %w[q q w e r e e ]
9
+ b = %w[q w e e t]
10
+ c = %w[ q r e ]
11
+ d = %w[ t]
12
+ assert_equal( c, a.minus(b) )
13
+ assert_equal( d, b.minus(a) )
14
+ assert_equal( c, a.minus(b, remainder: false) )
15
+ assert_equal( [c,d], a.minus(b, remainder: true ) )
16
+ assert_equal( [d,c], b.minus(a, remainder: true ) )
17
+ end
18
18
  end
19
19
 
@@ -2,9 +2,9 @@ require 'test/unit'
2
2
  $VERBOSE = true
3
3
 
4
4
  class MyEnum
5
- include Enumerable
6
- def initialize(*a) @a=a; end
7
- def each(&b) @a.each(&b); end
5
+ include Enumerable
6
+ def initialize(*a) @a=a; end
7
+ def each(&b) @a.each(&b); end
8
8
  end
9
9
 
10
10
  if RUBY_VERSION.to_i >= 2
@@ -18,53 +18,53 @@ end
18
18
  require_relative '../lib/mug/bool'
19
19
  class Test_bool < Test::Unit::TestCase
20
20
 
21
- alias :assert_true :assert
22
- def assert_false val, msg=UNASSIGNED
23
- assert !val, msg
24
- end
25
- def true_msg o, m=nil
26
- m &&= ".#{m}"
27
- "#{o.inspect}#{m} should be true"
28
- end
29
- def false_msg o, m=nil
30
- m &&= ".#{m}"
31
- "#{o.inspect}#{m} should be false"
32
- end
21
+ alias :assert_true :assert
22
+ def assert_false val, msg=UNASSIGNED
23
+ assert !val, msg
24
+ end
25
+ def true_msg o, m=nil
26
+ m &&= ".#{m}"
27
+ "#{o.inspect}#{m} should be true"
28
+ end
29
+ def false_msg o, m=nil
30
+ m &&= ".#{m}"
31
+ "#{o.inspect}#{m} should be false"
32
+ end
33
33
 
34
- def test_Bool
35
- assert_true( Bool(true), true_msg(true) )
36
- assert_false( Bool(false), false_msg(false) )
37
- assert_false( Bool(nil), false_msg(false) )
38
- $truthy.each do |o|
39
- assert_true( Bool(o), true_msg(o) )
40
- end
41
- $falsy.each do |o|
42
- assert_true( Bool(o), true_msg(o) )
43
- end
44
- end
34
+ def test_Bool
35
+ assert_true( Bool(true), true_msg(true) )
36
+ assert_false( Bool(false), false_msg(false) )
37
+ assert_false( Bool(nil), false_msg(false) )
38
+ $truthy.each do |o|
39
+ assert_true( Bool(o), true_msg(o) )
40
+ end
41
+ $falsy.each do |o|
42
+ assert_true( Bool(o), true_msg(o) )
43
+ end
44
+ end
45
45
 
46
- def test_to_bool
47
- assert_true( true.to_bool, true_msg(true,'to_bool') )
48
- assert_false( false.to_bool, false_msg(false,'to_bool') )
49
- assert_false( nil.to_bool, false_msg(nil,'to_bool') )
50
- $truthy.each do |o|
51
- assert_true( o.to_bool, true_msg(o,'to_bool') )
52
- end
53
- $falsy.each do |o|
54
- assert_true( o.to_bool, true_msg(o,'to_bool') )
55
- end
56
- end
46
+ def test_to_bool
47
+ assert_true( true.to_bool, true_msg(true,'to_bool') )
48
+ assert_false( false.to_bool, false_msg(false,'to_bool') )
49
+ assert_false( nil.to_bool, false_msg(nil,'to_bool') )
50
+ $truthy.each do |o|
51
+ assert_true( o.to_bool, true_msg(o,'to_bool') )
52
+ end
53
+ $falsy.each do |o|
54
+ assert_true( o.to_bool, true_msg(o,'to_bool') )
55
+ end
56
+ end
57
57
 
58
- def test_to_b
59
- assert_true( true.to_b, true_msg(true,'to_b') )
60
- assert_false( false.to_b, false_msg(false,'to_b') )
61
- assert_false( nil.to_b, false_msg(nil,'to_b') )
62
- $truthy.each do |o|
63
- assert_true( o.to_b, true_msg(o,'to_b') )
64
- end
65
- $falsy.each do |o|
66
- assert_false( o.to_b, false_msg(o,'to_b') )
67
- end
68
- end
58
+ def test_to_b
59
+ assert_true( true.to_b, true_msg(true,'to_b') )
60
+ assert_false( false.to_b, false_msg(false,'to_b') )
61
+ assert_false( nil.to_b, false_msg(nil,'to_b') )
62
+ $truthy.each do |o|
63
+ assert_true( o.to_b, true_msg(o,'to_b') )
64
+ end
65
+ $falsy.each do |o|
66
+ assert_false( o.to_b, false_msg(o,'to_b') )
67
+ end
68
+ end
69
69
  end
70
70
 
@@ -4,48 +4,48 @@ $VERBOSE = true
4
4
  require_relative '../lib/mug/clamp'
5
5
  class Test_clamp < Test::Unit::TestCase
6
6
 
7
- def test_clamp
8
- [
9
- [2,3],
10
- [3,3],
11
- [4,4],
12
- [5,5],
13
- [6,5],
14
- ].each do |num, ex|
15
- assert_equal( ex, num.clamp(3,5) )
16
- end
17
- assert_raise(ArgumentError) { 0.clamp(5,3) }
18
- end
19
-
20
- def test_clamp__range
21
- rng = 3..5
22
- assert_equal( 3, 2.clamp(rng) )
23
- assert_equal( 4, 4.clamp(rng) )
24
- assert_equal( 5, 6.clamp(rng) )
25
-
26
- rng = 3...5
27
- assert_equal( 3, 2.clamp(rng) )
28
- assert_equal( 4, 4.clamp(rng) )
29
- assert_raise(ArgumentError) { 6.clamp(rng) }
30
- end
31
-
32
- def test_bound__inclusive
33
- rng = 3..5
34
- assert_equal( 3, rng.bound(2) )
35
- assert_equal( 3, rng.bound(3) )
36
- assert_equal( 4, rng.bound(4) )
37
- assert_equal( 5, rng.bound(5) )
38
- assert_equal( 5, rng.bound(6) )
39
- end
40
-
41
- def test_bound__exclusive
42
- rng = 3...5
43
- assert_equal( 3, rng.bound(2) )
44
- assert_equal( 3, rng.bound(3) )
45
- assert_equal( 4, rng.bound(4) )
46
- assert_raise(ArgumentError) { rng.bound(5) }
47
- assert_raise(ArgumentError) { rng.bound(6) }
48
- end
7
+ def test_clamp
8
+ [
9
+ [2,3],
10
+ [3,3],
11
+ [4,4],
12
+ [5,5],
13
+ [6,5],
14
+ ].each do |num, ex|
15
+ assert_equal( ex, num.clamp(3,5) )
16
+ end
17
+ assert_raise(ArgumentError) { 0.clamp(5,3) }
18
+ end
19
+
20
+ def test_clamp__range
21
+ rng = 3..5
22
+ assert_equal( 3, 2.clamp(rng) )
23
+ assert_equal( 4, 4.clamp(rng) )
24
+ assert_equal( 5, 6.clamp(rng) )
25
+
26
+ rng = 3...5
27
+ assert_equal( 3, 2.clamp(rng) )
28
+ assert_equal( 4, 4.clamp(rng) )
29
+ assert_raise(ArgumentError) { 6.clamp(rng) }
30
+ end
31
+
32
+ def test_bound__inclusive
33
+ rng = 3..5
34
+ assert_equal( 3, rng.bound(2) )
35
+ assert_equal( 3, rng.bound(3) )
36
+ assert_equal( 4, rng.bound(4) )
37
+ assert_equal( 5, rng.bound(5) )
38
+ assert_equal( 5, rng.bound(6) )
39
+ end
40
+
41
+ def test_bound__exclusive
42
+ rng = 3...5
43
+ assert_equal( 3, rng.bound(2) )
44
+ assert_equal( 3, rng.bound(3) )
45
+ assert_equal( 4, rng.bound(4) )
46
+ assert_raise(ArgumentError) { rng.bound(5) }
47
+ assert_raise(ArgumentError) { rng.bound(6) }
48
+ end
49
49
 
50
50
  end
51
51
 
@@ -3,26 +3,26 @@ $VERBOSE = true
3
3
 
4
4
  require_relative '../lib/mug/counts'
5
5
  class Test_hashmap < Test::Unit::TestCase
6
- def test_counts
7
- a = %w(a b b c c c)
8
- c = {'a'=>1, 'b'=>2, 'c'=>3}
9
- assert_equal( c, a.counts )
10
- end
11
- def test_counts__block
12
- a = %w(a b b c c c)
13
- c = {'A'=>1, 'B'=>2, 'C'=>3}
14
- assert_equal( c, a.counts{|i|i.upcase} )
15
- end
16
- def test_counts_by
17
- a = %w(a b b c c c)
18
- c = {'A'=>1, 'B'=>2, 'C'=>3}
19
- assert_equal( c, a.counts_by{|i|i.upcase} )
20
- end
21
- def test_counts_by__noblock
22
- a = %w(a b b c c c)
23
- c = {'A'=>1, 'B'=>2, 'C'=>3}
24
- e = a.counts_by
25
- assert_equal( c, e.each{|i|i.upcase} )
26
- end
6
+ def test_counts
7
+ a = %w(a b b c c c)
8
+ c = {'a'=>1, 'b'=>2, 'c'=>3}
9
+ assert_equal( c, a.counts )
10
+ end
11
+ def test_counts__block
12
+ a = %w(a b b c c c)
13
+ c = {'A'=>1, 'B'=>2, 'C'=>3}
14
+ assert_equal( c, a.counts{|i|i.upcase} )
15
+ end
16
+ def test_counts_by
17
+ a = %w(a b b c c c)
18
+ c = {'A'=>1, 'B'=>2, 'C'=>3}
19
+ assert_equal( c, a.counts_by{|i|i.upcase} )
20
+ end
21
+ def test_counts_by__noblock
22
+ a = %w(a b b c c c)
23
+ c = {'A'=>1, 'B'=>2, 'C'=>3}
24
+ e = a.counts_by
25
+ assert_equal( c, e.each{|i|i.upcase} )
26
+ end
27
27
  end
28
28
 
@@ -2,70 +2,70 @@ require 'test/unit'
2
2
  $VERBOSE = true
3
3
 
4
4
  module FMCTest
5
- class A
6
- def initialize; @b = B.new; end
7
- attr_accessor :b
8
- end
5
+ class A
6
+ def initialize; @b = B.new; end
7
+ attr_accessor :b
8
+ end
9
9
 
10
- class B
11
- def initialize; @c = C.new; end
12
- attr_accessor :c
13
- end
10
+ class B
11
+ def initialize; @c = C.new; end
12
+ attr_accessor :c
13
+ end
14
14
 
15
- class C
16
- def to_i; 1; end
17
- end
15
+ class C
16
+ def to_i; 1; end
17
+ end
18
18
  end
19
19
 
20
20
  def false.c
21
- 2
21
+ 2
22
22
  end
23
23
 
24
24
  require_relative '../lib/mug/fragile-method-chain'
25
25
  class Test_fmc < Test::Unit::TestCase
26
- def test_fmc_nil
27
- a = FMCTest::A.new
28
- assert_equal( 1, a._?.b.c.to_i._! )
29
- assert_equal( 1, a._?.b.c._!.to_i )
30
- assert_equal( 1, a._?.b._!.c.to_i )
31
- a.b.c = nil
32
- assert_nil( a._?.b.c.to_i._! )
33
- assert_equal( 0, a._?.b.c._!.to_i )
34
- assert_equal( 0, a._?.b._!.c.to_i )
35
- a.b = nil
36
- assert_nil( a._?.b.c.to_i._! )
37
- assert_equal( 0, a._?.b.c._!.to_i )
38
- assert_raise(NoMethodError) { a._?.b._!.c.to_i }
39
- a = nil
40
- assert_nil( a._?.b.c.to_i._! )
41
- end
42
- def test_fmc_false
43
- a = FMCTest::A.new
44
- assert_equal( 1, a._?.b.c.to_i._! )
45
- assert_equal( 1, a._?.b.c._!.to_i )
46
- assert_equal( 1, a._?.b._!.c.to_i )
47
- a.b.c = false
48
- assert_equal( false, a._?.b.c.to_i._! )
49
- assert_raise(NoMethodError) { a._?.b.c._!.to_i }
50
- assert_raise(NoMethodError) { a._?.b._!.c.to_i }
51
- a.b = false
52
- assert_equal( false, a._?.b.c.to_i._! )
53
- assert_raise(NoMethodError) { a._?.b.c._!.to_i }
54
- assert_equal( 2, a._?.b._!.c.to_i )
55
- a = false
56
- assert_equal( false, a._?.b.c.to_i._! )
57
- assert_raise(NoMethodError) { a._?.b.c._!.to_i }
58
- assert_equal( 2, a._?.b._!.c.to_i )
59
- end
60
- def test_fmc_nested
61
- a = FMCTest::A.new
62
- assert_equal( 1, a._?.b._?.c._!.to_i._! )
63
- a.b.c = false
64
- assert_equal( false, a._?.b._?.c._!.to_i._! )
65
- a.b = false
66
- assert_equal( false, a._?.b._?.c._!.to_i._! )
67
- a = false
68
- assert_equal( false, a._?.b._?.c._!.to_i._! )
69
- end
26
+ def test_fmc_nil
27
+ a = FMCTest::A.new
28
+ assert_equal( 1, a._?.b.c.to_i._! )
29
+ assert_equal( 1, a._?.b.c._!.to_i )
30
+ assert_equal( 1, a._?.b._!.c.to_i )
31
+ a.b.c = nil
32
+ assert_nil( a._?.b.c.to_i._! )
33
+ assert_equal( 0, a._?.b.c._!.to_i )
34
+ assert_equal( 0, a._?.b._!.c.to_i )
35
+ a.b = nil
36
+ assert_nil( a._?.b.c.to_i._! )
37
+ assert_equal( 0, a._?.b.c._!.to_i )
38
+ assert_raise(NoMethodError) { a._?.b._!.c.to_i }
39
+ a = nil
40
+ assert_nil( a._?.b.c.to_i._! )
41
+ end
42
+ def test_fmc_false
43
+ a = FMCTest::A.new
44
+ assert_equal( 1, a._?.b.c.to_i._! )
45
+ assert_equal( 1, a._?.b.c._!.to_i )
46
+ assert_equal( 1, a._?.b._!.c.to_i )
47
+ a.b.c = false
48
+ assert_equal( false, a._?.b.c.to_i._! )
49
+ assert_raise(NoMethodError) { a._?.b.c._!.to_i }
50
+ assert_raise(NoMethodError) { a._?.b._!.c.to_i }
51
+ a.b = false
52
+ assert_equal( false, a._?.b.c.to_i._! )
53
+ assert_raise(NoMethodError) { a._?.b.c._!.to_i }
54
+ assert_equal( 2, a._?.b._!.c.to_i )
55
+ a = false
56
+ assert_equal( false, a._?.b.c.to_i._! )
57
+ assert_raise(NoMethodError) { a._?.b.c._!.to_i }
58
+ assert_equal( 2, a._?.b._!.c.to_i )
59
+ end
60
+ def test_fmc_nested
61
+ a = FMCTest::A.new
62
+ assert_equal( 1, a._?.b._?.c._!.to_i._! )
63
+ a.b.c = false
64
+ assert_equal( false, a._?.b._?.c._!.to_i._! )
65
+ a.b = false
66
+ assert_equal( false, a._?.b._?.c._!.to_i._! )
67
+ a = false
68
+ assert_equal( false, a._?.b._?.c._!.to_i._! )
69
+ end
70
70
  end
71
71