mug 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/mug/and-or.rb +26 -26
- data/lib/mug/any-and-all.rb +16 -16
- data/lib/mug/apply.rb +37 -37
- data/lib/mug/array/extend.rb +43 -43
- data/lib/mug/array/minus.rb +32 -32
- data/lib/mug/bool.rb +71 -71
- data/lib/mug/clamp.rb +35 -35
- data/lib/mug/counts.rb +27 -27
- data/lib/mug/fragile-method-chain.rb +42 -42
- data/lib/mug/hash/map.rb +75 -75
- data/lib/mug/hash/operations.rb +47 -47
- data/lib/mug/iterator/for.rb +7 -7
- data/lib/mug/iterator/method.rb +7 -7
- data/lib/mug/iterator_c.rb +14 -14
- data/lib/mug/loop-with.rb +30 -29
- data/lib/mug/matchdata/each.rb +40 -40
- data/lib/mug/matchdata/hash.rb +29 -29
- data/lib/mug/maybe.rb +33 -33
- data/lib/mug/negativity.rb +20 -20
- data/lib/mug/not.rb +6 -6
- data/lib/mug/rexproc.rb +6 -6
- data/lib/mug/self.rb +31 -31
- data/lib/mug/to_h.rb +2 -2
- data/lib/mug/top.rb +100 -100
- data/test/test-and-or.rb +32 -32
- data/test/test-any-and-all.rb +19 -19
- data/test/test-apply.rb +47 -47
- data/test/test-array-extend.rb +54 -54
- data/test/test-array-minus.rb +11 -11
- data/test/test-bool.rb +48 -48
- data/test/test-clamp.rb +42 -42
- data/test/test-counts.rb +21 -21
- data/test/test-fragile-method-chain.rb +56 -56
- data/test/test-hashmap.rb +14 -14
- data/test/test-hashop.rb +47 -47
- data/test/test-iterator-for.rb +12 -12
- data/test/test-loop-with.rb +117 -66
- data/test/test-matchdata_each.rb +50 -50
- data/test/test-matchdata_hash.rb +40 -40
- data/test/test-maybe.rb +76 -76
- data/test/test-negativity.rb +40 -40
- data/test/test-not.rb +53 -53
- data/test/test-rexproc.rb +6 -6
- data/test/test-self.rb +21 -21
- data/test/test-tau.rb +12 -12
- data/test/test-top.rb +100 -100
- metadata +4 -4
data/test/test-matchdata_hash.rb
CHANGED
@@ -3,45 +3,45 @@ $VERBOSE = true
|
|
3
3
|
|
4
4
|
require_relative '../lib/mug/matchdata/hash'
|
5
5
|
class Test_matchdata_hash < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
6
|
+
def test__matchdata__to_h
|
7
|
+
str = 'a12b'
|
8
|
+
[
|
9
|
+
[/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
|
10
|
+
[/(?<x>\d)(?<y>\d)/x.match(str), {'x'=>'1', 'y'=>'2'}],
|
11
|
+
[/( \d)(?<y>\d)/x.match(str), { 'y'=>'2'}], # ):
|
12
|
+
].each do |m, x|
|
13
|
+
assert_equal( x, m.to_h )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def test__matchdata__named_captures
|
17
|
+
str = 'a12b'
|
18
|
+
[
|
19
|
+
[/( \d)( \d)/x.match(str), { }],
|
20
|
+
[/(?<x>\d)(?<y>\d)/x.match(str), {'x'=>'1', 'y'=>'2'}],
|
21
|
+
[/( \d)(?<y>\d)/x.match(str), { 'y'=>'2'}],
|
22
|
+
].each do |m, x|
|
23
|
+
assert_equal( x, m.named_captures )
|
24
|
+
end
|
25
|
+
end
|
26
|
+
def test__matchdata__positional_captures
|
27
|
+
str = 'a12b'
|
28
|
+
[
|
29
|
+
[/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
|
30
|
+
[/(?<x>\d)(?<y>\d)/x.match(str), { }],
|
31
|
+
[/( \d)(?<y>\d)/x.match(str), { }], # D:
|
32
|
+
].each do |m, x|
|
33
|
+
assert_equal( x, m.positional_captures )
|
34
|
+
end
|
35
|
+
end
|
36
|
+
def test__matchdata__positional_captures2
|
37
|
+
str = 'a12b'
|
38
|
+
[
|
39
|
+
[/( \d)( \d)/x.match(str), { 1 =>'1', 2 =>'2'}],
|
40
|
+
[/(?<x>\d)(?<y>\d)/x.match(str), { 1 =>'1', 2 =>'2'}],
|
41
|
+
[/( \d)(?<y>\d)/x.match(str), { 1 =>'2'}], # ):
|
42
|
+
].each do |m, x|
|
43
|
+
assert_equal( x, m.positional_captures(include_names: true) )
|
44
|
+
end
|
45
|
+
end
|
46
46
|
end
|
47
47
|
|
data/test/test-maybe.rb
CHANGED
@@ -2,89 +2,89 @@ require 'test/unit'
|
|
2
2
|
$VERBOSE = true
|
3
3
|
|
4
4
|
module MaybeTest
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
class A
|
6
|
+
def initialize; @b = B.new; end
|
7
|
+
attr_accessor :b
|
8
|
+
end
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
class B
|
11
|
+
def initialize; @c = C.new; end
|
12
|
+
attr_accessor :c
|
13
|
+
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
15
|
+
class C
|
16
|
+
def to_i; 1; end
|
17
|
+
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def false.c
|
21
|
-
|
21
|
+
2
|
22
22
|
end
|
23
23
|
|
24
24
|
require_relative '../lib/mug/maybe'
|
25
25
|
class Test_maybe < Test::Unit::TestCase
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
26
|
+
def test_maybe_block_nil
|
27
|
+
a = MaybeTest::A.new
|
28
|
+
assert_equal( 1, a.maybe{ b.maybe{ c } }.to_i )
|
29
|
+
assert_equal( 1, a.maybe{ b.c.to_i } )
|
30
|
+
assert_equal( 1, a.maybe{ b }.c.to_i )
|
31
|
+
a.b.c = nil
|
32
|
+
assert_equal( 0, a.maybe{ b.maybe{ c } }.to_i )
|
33
|
+
assert_equal( 0, a.maybe{ b.c.to_i } )
|
34
|
+
assert_equal( 0, a.maybe{ b }.c.to_i )
|
35
|
+
a.b = nil
|
36
|
+
assert_nil( a.maybe{ b.maybe{ c } } )
|
37
|
+
assert_raise(NoMethodError) { a.maybe{ b.c } }
|
38
|
+
assert_raise(NoMethodError) { a.maybe{ b }.c }
|
39
|
+
a = nil
|
40
|
+
assert_nil( a.maybe{ b.maybe{ c } } )
|
41
|
+
assert_nil( a.maybe{ b.c } )
|
42
|
+
assert_raise(NoMethodError) { a.maybe{ b }.c }
|
43
|
+
end
|
44
|
+
def test_maybe_block_false
|
45
|
+
a = MaybeTest::A.new
|
46
|
+
assert_equal( 1, a.maybe{ b.maybe{ c } }.to_i )
|
47
|
+
assert_equal( 1, a.maybe{ b.c.to_i } )
|
48
|
+
assert_equal( 1, a.maybe{ b }.c.to_i )
|
49
|
+
a.b.c = false
|
50
|
+
assert_raise(NoMethodError) { a.maybe{ b.maybe{ c } }.to_i }
|
51
|
+
assert_raise(NoMethodError) { a.maybe{ b.c.to_i } }
|
52
|
+
assert_raise(NoMethodError) { a.maybe{ b }.c.to_i }
|
53
|
+
a.b = false
|
54
|
+
assert_equal( false, a.maybe{ b.maybe{ c } } )
|
55
|
+
assert_equal( 2, a.maybe{ b.c } )
|
56
|
+
assert_equal( 2, a.maybe{ b }.c )
|
57
|
+
a = false
|
58
|
+
assert_equal( false, a.maybe{ b.maybe{ c } } )
|
59
|
+
assert_equal( false, a.maybe{ b.c } )
|
60
|
+
assert_equal( 2, a.maybe{ b }.c )
|
61
|
+
end
|
62
|
+
def test_maybe_delegator_nil
|
63
|
+
a = MaybeTest::A.new
|
64
|
+
assert_equal( 1, a.maybe.b.maybe.c.to_i )
|
65
|
+
assert_equal( 1, a.maybe.b.c.to_i )
|
66
|
+
a.b.c = nil
|
67
|
+
assert_nil( a.maybe.b.maybe.c )
|
68
|
+
assert_nil( a.maybe.b.c )
|
69
|
+
a.b = nil
|
70
|
+
assert_nil( a.maybe.b.maybe.c )
|
71
|
+
assert_raise(NoMethodError) { a.maybe.b.c }
|
72
|
+
a = nil
|
73
|
+
assert_nil( a.maybe.b.maybe.c )
|
74
|
+
assert_raise(NoMethodError) { a.maybe.b.c }
|
75
|
+
end
|
76
|
+
def test_maybe_delegator_false
|
77
|
+
a = MaybeTest::A.new
|
78
|
+
assert_equal( 1, a.maybe.b.maybe.c.to_i )
|
79
|
+
assert_equal( 1, a.maybe.b.c.to_i )
|
80
|
+
a.b.c = false
|
81
|
+
assert_equal( false, a.maybe.b.maybe.c )
|
82
|
+
assert_equal( false, a.maybe.b.c )
|
83
|
+
a.b = false
|
84
|
+
assert_equal( false, a.maybe.b.maybe.c )
|
85
|
+
assert_equal( 2, a.maybe.b.c )
|
86
|
+
a = false
|
87
|
+
assert_equal( false, a.maybe.b.maybe.c )
|
88
|
+
assert_equal( 2, a.maybe.b.c )
|
89
|
+
end
|
90
90
|
end
|
data/test/test-negativity.rb
CHANGED
@@ -11,46 +11,46 @@ $err = [ Complex(1,1) ]
|
|
11
11
|
require_relative '../lib/mug/negativity'
|
12
12
|
class Test_negativity < Test::Unit::TestCase
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
14
|
+
alias :assert_true :assert
|
15
|
+
def assert_false val, msg=UNASSIGNED
|
16
|
+
assert !val, msg
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_negative
|
20
|
+
$neg.each {|n| assert_true n.negative?, "#{n} should be negative" }
|
21
|
+
$pos.each {|n| assert_false n.negative?, "#{n} should not be negative" }
|
22
|
+
$zer.each {|n| assert_false n.negative?, "#{n} should not be negative" }
|
23
|
+
$err.each do |n|
|
24
|
+
assert_raise(NoMethodError) { n.negative? }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_positive
|
29
|
+
$neg.each {|n| assert_false n.positive?, "#{n} should not be positive" }
|
30
|
+
$pos.each {|n| assert_true n.positive?, "#{n} should be positive" }
|
31
|
+
$zer.each {|n| assert_false n.positive?, "#{n} should not be positive" }
|
32
|
+
$err.each do |n|
|
33
|
+
assert_raise(NoMethodError) { n.positive? }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_nonnegative
|
38
|
+
$neg.each {|n| assert_false n.nonnegative?, "#{n} should not be nonnegative" }
|
39
|
+
$pos.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
|
40
|
+
$zer.each {|n| assert_true n.nonnegative?, "#{n} should be nonnegative" }
|
41
|
+
$err.each do |n|
|
42
|
+
assert_raise(NoMethodError) { n.nonnegative? }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_nonpositive
|
47
|
+
$neg.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
|
48
|
+
$pos.each {|n| assert_false n.nonpositive?, "#{n} should not be nonpositive" }
|
49
|
+
$zer.each {|n| assert_true n.nonpositive?, "#{n} should be nonpositive" }
|
50
|
+
$err.each do |n|
|
51
|
+
assert_raise(NoMethodError) { n.nonpositive? }
|
52
|
+
end
|
53
|
+
end
|
54
54
|
|
55
55
|
end
|
56
56
|
|
data/test/test-not.rb
CHANGED
@@ -3,58 +3,58 @@ $VERBOSE = true
|
|
3
3
|
|
4
4
|
require_relative '../lib/mug/not'
|
5
5
|
class Test_not < Test::Unit::TestCase
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
6
|
+
def test_not__noargs
|
7
|
+
[
|
8
|
+
[true, false],
|
9
|
+
[99, false],
|
10
|
+
[false, true],
|
11
|
+
[nil, true],
|
12
|
+
].each do |o, x|
|
13
|
+
assert_equal( x, o.not, "#{o.inspect}.not should be #{x}" )
|
14
|
+
end
|
15
|
+
end
|
16
|
+
def test_not__method
|
17
|
+
[
|
18
|
+
[[], false],
|
19
|
+
[[99], true],
|
20
|
+
].each do |o, x|
|
21
|
+
assert_equal( x, o.not(:empty?), "#{o.inspect}.not(:empty?) should be #{x}" )
|
22
|
+
end
|
23
|
+
end
|
24
|
+
def test_not__method2
|
25
|
+
[
|
26
|
+
[[], false],
|
27
|
+
[[99], true],
|
28
|
+
].each do |o, x|
|
29
|
+
assert_equal( x, o.not(&:empty?), "#{o.inspect}.not(&:empty?) should be #{x}" )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def test_not__args
|
33
|
+
[
|
34
|
+
[1, true],
|
35
|
+
[0, true],
|
36
|
+
[-1, false],
|
37
|
+
].each do |o, x|
|
38
|
+
assert_equal( x, o.not(:<, 0), "#{o.inspect}.not(:<, 0) should be #{x}" )
|
39
|
+
end
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
42
|
+
def test_not__block
|
43
|
+
[
|
44
|
+
[1, true],
|
45
|
+
[0, true],
|
46
|
+
[-1, false],
|
47
|
+
].each do |o, x|
|
48
|
+
assert_equal( x, o.not {|obj| obj < 0 }, "#{o.inspect}.not{|obj|obj<0} should be #{x}" )
|
49
|
+
end
|
50
|
+
end
|
51
|
+
def test_not__method_block
|
52
|
+
[
|
53
|
+
[[], true],
|
54
|
+
[[0,-1], true],
|
55
|
+
[[0,99], false],
|
56
|
+
].each do |o, x|
|
57
|
+
assert_equal( x, o.not(:any?) {|item| item > 0 }, "#{o.inspect}.not(:any?){|item|item>0} should be #{x}" )
|
58
|
+
end
|
59
|
+
end
|
60
60
|
end
|