ruby-changes:53970
From: nobu <ko1@a...>
Date: Tue, 4 Dec 2018 18:16:53 +0900 (JST)
Subject: [ruby-changes:53970] nobu:r66190 (trunk): Fix error message
nobu 2018-12-04 18:16:49 +0900 (Tue, 04 Dec 2018) New Revision: 66190 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66190 Log: Fix error message * array.c (ary_take_first_or_last): expected optional argument. Modified files: trunk/array.c trunk/test/ruby/test_array.rb Index: array.c =================================================================== --- array.c (revision 66189) +++ array.c (revision 66190) @@ -1108,13 +1108,17 @@ enum ary_take_pos_flags https://github.com/ruby/ruby/blob/trunk/array.c#L1108 static VALUE ary_take_first_or_last(int argc, const VALUE *argv, VALUE ary, enum ary_take_pos_flags last) { - VALUE nv; long n; long len; long offset = 0; - rb_scan_args(argc, argv, "1", &nv); - n = NUM2LONG(nv); + argc = rb_check_arity(argc, 0, 1); + /* the case optional argument is ommited should be handled in + * callers of this function. if another arity case is added, + * this arity check needs to rewrite. */ + RUBY_ASSERT_WHEN(TRUE, argc == 1); + + n = NUM2LONG(argv[0]); len = RARRAY_LEN(ary); if (n > len) { n = len; Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 66189) +++ test/ruby/test_array.rb (revision 66190) @@ -146,14 +146,17 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L146 assert_equal(1, x.first) assert_equal([1], x.first(1)) assert_equal([1, 2, 3], x.first(3)) + assert_raise_with_message(ArgumentError, /0\.\.1/) {x.first(1, 2)} assert_equal(5, x.last) assert_equal([5], x.last(1)) assert_equal([3, 4, 5], x.last(3)) + assert_raise_with_message(ArgumentError, /0\.\.1/) {x.last(1, 2)} assert_equal(1, x.shift) assert_equal([2, 3, 4], x.shift(3)) assert_equal([5], x) + assert_raise_with_message(ArgumentError, /0\.\.1/) {x.first(1, 2)} assert_equal([2, 3, 4, 5], x.unshift(2, 3, 4)) assert_equal([1, 2, 3, 4, 5], x.unshift(1)) @@ -162,6 +165,7 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L165 assert_equal(5, x.pop) assert_equal([3, 4], x.pop(2)) assert_equal([1, 2], x) + assert_raise_with_message(ArgumentError, /0\.\.1/) {x.pop(1, 2)} assert_equal([1, 2, 3, 4], x.push(3, 4)) assert_equal([1, 2, 3, 4, 5], x.push(5)) @@ -1585,7 +1589,7 @@ class TestArray < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_array.rb#L1589 def o.to_ary foo_bar() end - assert_match(/foo_bar/, assert_raise(NoMethodError) {a.concat(o)}.message) + assert_raise_with_message(NoMethodError, /foo_bar/) {a.concat(o)} end def test_to_s -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/