aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-22 05:51:43 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-22 05:51:43 +0000
commitc71cc2db7f4b179e1a204a0045cea2d80c041874 (patch)
tree24d0f0bd6510791a7655ce251165e5682a1a025b /test
parent3b7b70650c744f8d045328f782fcad360bdd9f46 (diff)
downloadruby-c71cc2db7f4b179e1a204a0045cea2d80c041874.tar.gz
Proc#<< and Proc#>>
[Feature #6284] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65914 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_method.rb19
-rw-r--r--test/ruby/test_proc.rb31
2 files changed, 28 insertions, 22 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 5193ac6889..65d9e3d2e1 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -1048,9 +1048,9 @@ class TestMethod < Test::Unit::TestCase
}
f = c.new.method(:f)
g = c.new.method(:g)
- h = f * g
- assert_equal(6, h.call(2))
+ assert_equal(6, (f << g).call(2))
+ assert_equal(6, (g >> f).call(2))
end
def test_compose_with_proc
@@ -1059,9 +1059,9 @@ class TestMethod < Test::Unit::TestCase
}
f = c.new.method(:f)
g = proc {|x| x + 1}
- h = f * g
- assert_equal(6, h.call(2))
+ assert_equal(6, (f << g).call(2))
+ assert_equal(6, (g >> f).call(2))
end
def test_compose_with_callable
@@ -1072,9 +1072,10 @@ class TestMethod < Test::Unit::TestCase
def call(x) x + 1 end
}
f = c.new.method(:f)
- g = f * c2.new
+ g = c2.new
- assert_equal(6, g.call(2))
+ assert_equal(6, (f << g).call(2))
+ assert_equal(5, (f >> g).call(2))
end
def test_compose_with_noncallable
@@ -1082,10 +1083,12 @@ class TestMethod < Test::Unit::TestCase
def f(x) x * 2 end
}
f = c.new.method(:f)
- g = f * 5
assert_raise(NoMethodError) {
- g.call(2)
+ (f << 5).call(2)
+ }
+ assert_raise(NoMethodError) {
+ (f >> 5).call(2)
}
end
end
diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb
index f70345ed74..8e8f719892 100644
--- a/test/ruby/test_proc.rb
+++ b/test/ruby/test_proc.rb
@@ -1420,33 +1420,33 @@ class TestProc < Test::Unit::TestCase
def test_compose
f = proc {|x| x * 2}
g = proc {|x| x + 1}
- h = f * g
- assert_equal(6, h.call(2))
+ assert_equal(6, (f << g).call(2))
+ assert_equal(6, (g >> f).call(2))
end
def test_compose_with_multiple_args
f = proc {|x| x * 2}
g = proc {|x, y| x + y}
- h = f * g
- assert_equal(6, h.call(1, 2))
+ assert_equal(6, (f << g).call(1, 2))
+ assert_equal(6, (g >> f).call(1, 2))
end
def test_compose_with_block
f = proc {|x| x * 2}
g = proc {|&blk| blk.call(1) }
- h = f * g
- assert_equal(8, h.call { |x| x + 3 })
+ assert_equal(8, (f << g).call { |x| x + 3 })
+ assert_equal(8, (g >> f).call { |x| x + 3 })
end
def test_compose_with_lambda
f = lambda {|x| x * 2}
g = lambda {|x| x}
- h = f * g
- assert_predicate(h, :lambda?)
+ assert_predicate((f << g), :lambda?)
+ assert_predicate((g >> f), :lambda?)
end
def test_compose_with_method
@@ -1455,9 +1455,9 @@ class TestProc < Test::Unit::TestCase
def g(x) x + 1 end
}
g = c.new.method(:g)
- h = f * g
- assert_equal(6, h.call(2))
+ assert_equal(6, (f << g).call(2))
+ assert_equal(5, (f >> g).call(2))
end
def test_compose_with_callable
@@ -1465,17 +1465,20 @@ class TestProc < Test::Unit::TestCase
c = Class.new {
def call(x) x + 1 end
}
- g = f * c.new
+ g = c.new
- assert_equal(6, g.call(2))
+ assert_equal(6, (f << g).call(2))
+ assert_equal(5, (f >> g).call(2))
end
def test_compose_with_noncallable
f = proc {|x| x * 2}
- g = f * 5
assert_raise(NoMethodError) {
- g.call(2)
+ (f << 5).call(2)
+ }
+ assert_raise(NoMethodError) {
+ (f >> 5).call(2)
}
end
end