Commit 9007aafe authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #1630 from carsonmcdonald/morekerneltests

More kernel testing
parents ca642dd3 60cd1c34
...@@ -325,6 +325,57 @@ assert('Kernel#loop', '15.3.1.3.29') do ...@@ -325,6 +325,57 @@ assert('Kernel#loop', '15.3.1.3.29') do
assert_equal i, 100 assert_equal i, 100
end end
assert('Kernel#method_missing', '15.3.1.3.30') do
class MMTestClass
def method_missing(sym)
"A call to #{sym}"
end
end
mm_test = MMTestClass.new
assert_equal 'A call to no_method_named_this', mm_test.no_method_named_this
a = String.new
begin
a.no_method_named_this
rescue NoMethodError => e
assert_equal "undefined method 'no_method_named_this' for \"\"", e.message
end
class ShortInspectClass
def inspect
'An inspect string'
end
end
b = ShortInspectClass.new
begin
b.no_method_named_this
rescue NoMethodError => e
assert_equal "undefined method 'no_method_named_this' for An inspect string", e.message
end
class LongInspectClass
def inspect
"A" * 70
end
end
c = LongInspectClass.new
begin
c.no_method_named_this
rescue NoMethodError => e
assert_equal "undefined method 'no_method_named_this' for #{c.to_s}", e.message
end
class NoInspectClass
undef inspect
end
d = NoInspectClass.new
begin
d.no_method_named_this
rescue NoMethodError => e
assert_equal "undefined method 'no_method_named_this' for #{d.to_s}", e.message
end
end
assert('Kernel#methods', '15.3.1.3.31') do assert('Kernel#methods', '15.3.1.3.31') do
assert_equal Array, methods.class assert_equal Array, methods.class
end end
...@@ -334,7 +385,18 @@ assert('Kernel#nil?', '15.3.1.3.32') do ...@@ -334,7 +385,18 @@ assert('Kernel#nil?', '15.3.1.3.32') do
end end
assert('Kernel#object_id', '15.3.1.3.33') do assert('Kernel#object_id', '15.3.1.3.33') do
assert_equal Fixnum, object_id.class a = ""
b = ""
assert_not_equal a.object_id, b.object_id
assert_kind_of Fixnum, object_id
assert_kind_of Fixnum, "".object_id
assert_kind_of Fixnum, true.object_id
assert_kind_of Fixnum, false.object_id
assert_kind_of Fixnum, nil.object_id
assert_kind_of Fixnum, :no.object_id
assert_kind_of Fixnum, 1.object_id
assert_kind_of Fixnum, 1.0.object_id
end end
# Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34' # Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34'
...@@ -427,3 +489,15 @@ assert('Kernel#respond_to_missing?') do ...@@ -427,3 +489,15 @@ assert('Kernel#respond_to_missing?') do
assert_true Test4RespondToMissing.new.respond_to?(:a_method) assert_true Test4RespondToMissing.new.respond_to?(:a_method)
assert_false Test4RespondToMissing.new.respond_to?(:no_method) assert_false Test4RespondToMissing.new.respond_to?(:no_method)
end end
assert('stack extend') do
def recurse(count, stop)
return count if count > stop
recurse(count+1, stop)
end
assert_equal 61, recurse(0, 60)
assert_raise RuntimeError do
recurse(0, 100000)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment