summaryrefslogtreecommitdiffhomepage
path: root/test/t/kernel.rb
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-12-31 19:19:11 -0800
committerYukihiro "Matz" Matsumoto <[email protected]>2013-12-31 19:19:11 -0800
commit9007aafef4ca4cc213712455607ad762752f1f2e (patch)
treebfef3728fa6ec4d70095566a3387e30acdf644c6 /test/t/kernel.rb
parentca642dd3ef5c654f737ea6553d1ed9476acb172e (diff)
parent60cd1c341b5f26fc03669d2d3978dab21ba9452b (diff)
downloadmruby-9007aafef4ca4cc213712455607ad762752f1f2e.tar.gz
mruby-9007aafef4ca4cc213712455607ad762752f1f2e.zip
Merge pull request #1630 from carsonmcdonald/morekerneltests
More kernel testing
Diffstat (limited to 'test/t/kernel.rb')
-rw-r--r--test/t/kernel.rb76
1 files changed, 75 insertions, 1 deletions
diff --git a/test/t/kernel.rb b/test/t/kernel.rb
index 3e802b219..96783a5d4 100644
--- a/test/t/kernel.rb
+++ b/test/t/kernel.rb
@@ -325,6 +325,57 @@ assert('Kernel#loop', '15.3.1.3.29') do
assert_equal i, 100
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_equal Array, methods.class
end
@@ -334,7 +385,18 @@ assert('Kernel#nil?', '15.3.1.3.32') do
end
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
# Kernel#p is defined in mruby-print mrbgem. '15.3.1.3.34'
@@ -427,3 +489,15 @@ assert('Kernel#respond_to_missing?') do
assert_true Test4RespondToMissing.new.respond_to?(:a_method)
assert_false Test4RespondToMissing.new.respond_to?(:no_method)
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