зеркало из https://github.com/github/ruby.git
range.c: check if range modifiable
* range.c (range_modify): frozen object cannot be modified. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
04a4fd8957
Коммит
1a7aba1b47
1
range.c
1
range.c
|
@ -80,6 +80,7 @@ rb_range_new(VALUE beg, VALUE end, int exclude_end)
|
|||
static void
|
||||
range_modify(VALUE range)
|
||||
{
|
||||
rb_check_frozen(range);
|
||||
/* Ranges are immutable, so that they should be initialized only once. */
|
||||
if (RANGE_EXCL(range) != Qnil) {
|
||||
rb_name_err_raise("`initialize' called twice", range, ID2SYM(idInitialize));
|
||||
|
|
|
@ -11,6 +11,12 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_equal((0...2), Range.new(0, 2, true))
|
||||
end
|
||||
|
||||
def test_frozen_initialize
|
||||
r = Range.allocate
|
||||
r.freeze
|
||||
assert_raise(RuntimeError){r.__send__(:initialize, 1, 2)}
|
||||
end
|
||||
|
||||
def test_range_string
|
||||
# XXX: Is this really the test of Range?
|
||||
assert_equal([], ("a" ... "a").to_a)
|
||||
|
|
Загрузка…
Ссылка в новой задаче