ruby-changes:54511
From: mrkn <ko1@a...>
Date: Sun, 6 Jan 2019 00:09:49 +0900 (JST)
Subject: [ruby-changes:54511] mrkn:r66726 (trunk): test/ruby/test_range.rb: add assertions
mrkn 2019-01-06 00:09:44 +0900 (Sun, 06 Jan 2019) New Revision: 66726 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66726 Log: 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. Modified files: trunk/test/ruby/test_range.rb Index: test/ruby/test_range.rb =================================================================== --- test/ruby/test_range.rb (revision 66725) +++ test/ruby/test_range.rb (revision 66726) @@ -435,6 +435,19 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L435 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/