diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-05 15:09:44 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-01-05 15:09:44 +0000 |
commit | 6ce2ef33b562deaa4b4e3d94269fe64c93d3f985 (patch) | |
tree | 221e26e612e131fdd9d55431a4fae83f02cc77d6 /test/ruby/test_range.rb | |
parent | b6b4c7cbb4581b8ce505e775a46531d33a6b3df6 (diff) |
test/ruby/test_range.rb: add assertions
Add assertions of Range#first and Range#last to examine the type
conversion of the arguments and the negative value check.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66726 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_range.rb')
-rw-r--r-- | test/ruby/test_range.rb | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb index f58d1f817c..8c3eb08aa7 100644 --- a/test/ruby/test_range.rb +++ b/test/ruby/test_range.rb @@ -435,6 +435,19 @@ class TestRange < Test::Unit::TestCase assert_equal("a", ("a"..nil).first) assert_raise(RangeError) { (0..nil).last } assert_raise(RangeError) { (0..nil).last(3) } + + assert_equal([0, 1, 2], (0..10).first(3.0)) + assert_equal([8, 9, 10], (0..10).last(3.0)) + assert_raise(TypeError) { (0..10).first("3") } + assert_raise(TypeError) { (0..10).last("3") } + class << (o = Object.new) + def to_int; 3; end + end + assert_equal([0, 1, 2], (0..10).first(o)) + assert_equal([8, 9, 10], (0..10).last(o)) + + assert_raise(ArgumentError) { (0..10).first(-1) } + assert_raise(ArgumentError) { (0..10).last(-1) } end def test_to_s |