summaryrefslogtreecommitdiffhomepage
path: root/mrbgems/mruby-method/test/method.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2019-07-17 10:35:41 +0900
committerGitHub <[email protected]>2019-07-17 10:35:41 +0900
commitd605b72c1d6fa4564a0a5e88535504b6850463b5 (patch)
tree774fc0de56002abb3bb2b1c3387ff08f91876d17 /mrbgems/mruby-method/test/method.rb
parent2af92d0ebcbeca6d3d85a27c8193273080a63090 (diff)
parent9af3b7c6258de327218dd04e69d76ae68caf17b1 (diff)
downloadmruby-d605b72c1d6fa4564a0a5e88535504b6850463b5.tar.gz
mruby-d605b72c1d6fa4564a0a5e88535504b6850463b5.zip
Merge branch 'master' into i110/inspect-recursion
Diffstat (limited to 'mrbgems/mruby-method/test/method.rb')
-rw-r--r--mrbgems/mruby-method/test/method.rb38
1 files changed, 28 insertions, 10 deletions
diff --git a/mrbgems/mruby-method/test/method.rb b/mrbgems/mruby-method/test/method.rb
index b229a4560..0b67d3e61 100644
--- a/mrbgems/mruby-method/test/method.rb
+++ b/mrbgems/mruby-method/test/method.rb
@@ -21,7 +21,7 @@ class Interpreter
}
def interpret(string)
@ret = ""
- string.each_char {|b| Dispatcher[b].bind(self).call }
+ string.split("").each {|b| Dispatcher[b].bind(self).call }
end
end
@@ -102,10 +102,7 @@ end
assert 'Method#call for regression' do
obj = BasicObject.new
- def obj.foo
- :ok
- end
- assert_equal :ok, Kernel.instance_method(:send).bind(obj).call(:foo), "https://github.com/ksss/mruby-method/issues/4"
+ assert_equal String, Kernel.instance_method(:inspect).bind(obj).call().class, "https://github.com/ksss/mruby-method/issues/4"
end
assert 'Method#call with undefined method' do
@@ -149,7 +146,7 @@ assert 'Method#source_location' do
assert_equal [filename, lineno], klass.new.method(:find_me_if_you_can).source_location
lineno = __LINE__ + 1
- klass.define_singleton_method(:s_find_me_if_you_can) {}
+ class <<klass; define_method(:s_find_me_if_you_can) {}; end
assert_equal [filename, lineno], klass.method(:s_find_me_if_you_can).source_location
klass = Class.new { def respond_to_missing?(m, b); m == :nothing; end }
@@ -243,7 +240,7 @@ assert 'owner' do
assert_equal(c, c.new.method(:foo).owner)
assert_equal(c, c2.new.method(:foo).owner)
- assert_equal(c.singleton_class, c2.method(:bar).owner)
+ assert_equal((class <<c; self; end), c2.method(:bar).owner)
end
assert 'owner missing' do
@@ -374,6 +371,25 @@ assert "Method#initialize_copy" do
assert_equal(m1, m2)
end
+assert "Method#<< and Method#>>" do
+ obj = Object.new
+ class << obj
+ def mul2(n); n * 2; end
+ def add3(n); n + 3; end
+ end
+
+ f = obj.method(:mul2)
+ g = obj.method(:add3)
+
+ m1 = f << g
+ assert_kind_of Proc, m1
+ assert_equal 16, m1.call(5)
+
+ m2 = f >> g
+ assert_kind_of Proc, m2
+ assert_equal 13, m2.call(5)
+end
+
assert 'UnboundMethod#arity' do
c = Class.new {
def foo(a, b)
@@ -413,12 +429,14 @@ assert 'UnboundMethod#bind' do
assert_equal(:meth, m.bind(1).call)
assert_equal(:meth, m.bind(:sym).call)
assert_equal(:meth, m.bind(Object.new).call)
- sc = Class.new {
- class << self
+ sc = nil
+ Class.new {
+ sc = class << self
def foo
end
+ self
end
- }.singleton_class
+ }
assert_raise(TypeError) { sc.instance_method(:foo).bind([]) }
assert_raise(TypeError) { Array.instance_method(:each).bind(1) }
assert_kind_of Method, Object.instance_method(:object_id).bind(Object.new)