summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-21 16:08:40 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-01-21 16:08:40 +0000
commit45c2671e370a67686e0a64a7364baa00b628cceb (patch)
tree3b9d1091d12319feee6f67639786b5186d6b0bd2 /test/ruby
parentc758a9069377ed672d5e82a29e5c0555818d9928 (diff)
* test/ruby/test_bignum.rb, test/ruby/test_class.rb,
test/ruby/test_defined.rb, test/ruby/test_hash.rb, test/ruby/test_primitive.rb, test/ruby/test_variable.rb: add some tests (for coverage). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26370 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_bignum.rb1
-rw-r--r--test/ruby/test_class.rb9
-rw-r--r--test/ruby/test_defined.rb7
-rw-r--r--test/ruby/test_hash.rb4
-rw-r--r--test/ruby/test_primitive.rb6
-rw-r--r--test/ruby/test_variable.rb4
6 files changed, 31 insertions, 0 deletions
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index cba935f121..40c4f21c3f 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -420,6 +420,7 @@ class TestBignum < Test::Unit::TestCase
b = 1E+300.to_i
assert_equal(b, (b ** 2).fdiv(b))
assert(@big.fdiv(0.0 / 0.0).nan?)
+ assert_in_delta(1E+300, (10**500).fdiv(1E+200), 1E+285)
end
def test_obj_fdiv
diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb
index a1f087ad63..b444d4e8ab 100644
--- a/test/ruby/test_class.rb
+++ b/test/ruby/test_class.rb
@@ -209,4 +209,13 @@ class TestClass < Test::Unit::TestCase
c = eval("class C\u{df}; self; end")
assert_equal("TestClass::C\u{df}", c.name, '[ruby-core:24600]')
end
+
+ def test_invalid_jump_from_class_definition
+ assert_raise(SyntaxError) { eval("class C; next; end") }
+ assert_raise(SyntaxError) { eval("class C; break; end") }
+ assert_raise(SyntaxError) { eval("class C; redo; end") }
+ assert_raise(SyntaxError) { eval("class C; retry; end") }
+ assert_raise(SyntaxError) { eval("class C; return; end") }
+ assert_raise(SyntaxError) { eval("class C; yield; end") }
+ end
end
diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb
index bfcd7fb667..07485bd2cc 100644
--- a/test/ruby/test_defined.rb
+++ b/test/ruby/test_defined.rb
@@ -12,6 +12,10 @@ class TestDefined < Test::Unit::TestCase
end
def baz(f)
end
+ attr_accessor :attr
+ def attrasgn_test
+ yield(defined?(self.attr = 1))
+ end
end
def defined_test
@@ -32,6 +36,7 @@ class TestDefined < Test::Unit::TestCase
assert(defined?(::Array)) # toplevel constant
assert(defined?(File::Constants)) # nested constant
assert(defined?(Object.new)) # method
+ assert(defined?(Object::new)) # method
assert(!defined?(Object.print)) # private method
assert(defined?(1 == 2)) # operator expression
@@ -45,6 +50,8 @@ class TestDefined < Test::Unit::TestCase
assert_nil(defined?(f.quux(x)))
assert(defined?(print(x)))
assert_nil(defined?(quux(x)))
+ assert(defined?(f.attr = 1))
+ f.attrasgn_test { |v| assert(v) }
assert(defined_test) # not iterator
assert(!defined_test{}) # called as iterator
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index c860b25239..acff4821f5 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -871,4 +871,8 @@ class TestHash < Test::Unit::TestCase
def o.hash; 2<<100; end
assert_equal({x=>1}.hash, {x=>1}.hash)
end
+
+ def test_hash_poped
+ assert_nothing_raised { eval("a = 1; {a => a}; a") }
+ end
end
diff --git a/test/ruby/test_primitive.rb b/test/ruby/test_primitive.rb
index 46133eff8c..d701348f26 100644
--- a/test/ruby/test_primitive.rb
+++ b/test/ruby/test_primitive.rb
@@ -228,6 +228,12 @@ class TestRubyPrimitive < Test::Unit::TestCase
assert_equal 7, a[0]
a[0] ||= 3
assert_equal 7, a[0]
+
+ a = [0, 1, nil, 3, 4]
+ a[*[2]] ||= :foo
+ assert_equal [0, 1, :foo, 3, 4], a
+ a[*[1,3]] &&= [:bar]
+ assert_equal [0, :bar, 4], a
end
def test_opassign_and_or
diff --git a/test/ruby/test_variable.rb b/test/ruby/test_variable.rb
index a842c31c3f..990658cb5a 100644
--- a/test/ruby/test_variable.rb
+++ b/test/ruby/test_variable.rb
@@ -81,4 +81,8 @@ class TestVariable < Test::Unit::TestCase
def test_global_variable_0
assert_in_out_err(["-e", "$0='t'*1000;print $0"], "", /\At+\z/, [])
end
+
+ def test_global_variable_poped
+ assert_nothing_raised { eval("$foo; 1") }
+ end
end