mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Additional fix and tests for r53851
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53854 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c00d51c739
commit
d092fc5398
2 changed files with 14 additions and 3 deletions
6
string.c
6
string.c
|
@ -1383,6 +1383,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str)
|
||||||
vcapa = kwargs[1];
|
vcapa = kwargs[1];
|
||||||
if (vcapa != Qundef && !NIL_P(vcapa)) {
|
if (vcapa != Qundef && !NIL_P(vcapa)) {
|
||||||
long capa = NUM2LONG(vcapa);
|
long capa = NUM2LONG(vcapa);
|
||||||
|
str_discard(str);
|
||||||
if (capa < STR_BUF_MIN_SIZE) {
|
if (capa < STR_BUF_MIN_SIZE) {
|
||||||
capa = STR_BUF_MIN_SIZE;
|
capa = STR_BUF_MIN_SIZE;
|
||||||
}
|
}
|
||||||
|
@ -1405,6 +1406,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str)
|
||||||
}
|
}
|
||||||
else if (n == 1) {
|
else if (n == 1) {
|
||||||
StringValue(orig);
|
StringValue(orig);
|
||||||
|
str_discard(str);
|
||||||
str_replace(str, orig);
|
str_replace(str, orig);
|
||||||
}
|
}
|
||||||
if (enc != Qundef && !NIL_P(enc)) {
|
if (enc != Qundef && !NIL_P(enc)) {
|
||||||
|
@ -1414,9 +1416,7 @@ rb_str_init(int argc, VALUE *argv, VALUE str)
|
||||||
}
|
}
|
||||||
else if (n == 1) {
|
else if (n == 1) {
|
||||||
StringValue(orig);
|
StringValue(orig);
|
||||||
if (OBJ_FROZEN(str)) {
|
str_discard(str);
|
||||||
rb_error_frozen_object(str);
|
|
||||||
}
|
|
||||||
str_replace(str, orig);
|
str_replace(str, orig);
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
|
|
|
@ -59,6 +59,17 @@ class TestString < Test::Unit::TestCase
|
||||||
assert_equal(Encoding::EUC_JP, S("", capacity: 1000, encoding: "euc-jp").encoding)
|
assert_equal(Encoding::EUC_JP, S("", capacity: 1000, encoding: "euc-jp").encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_initialize
|
||||||
|
str = S("").freeze
|
||||||
|
assert_equal("", str.__send__(:initialize))
|
||||||
|
assert_raise(RuntimeError){ str.__send__(:initialize, 'abc') }
|
||||||
|
assert_raise(RuntimeError){ str.__send__(:initialize, capacity: 1000) }
|
||||||
|
assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000) }
|
||||||
|
assert_raise(RuntimeError){ str.__send__(:initialize, encoding: 'euc-jp') }
|
||||||
|
assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') }
|
||||||
|
assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') }
|
||||||
|
end
|
||||||
|
|
||||||
def test_AREF # '[]'
|
def test_AREF # '[]'
|
||||||
assert_equal("A", S("AooBar")[0])
|
assert_equal("A", S("AooBar")[0])
|
||||||
assert_equal("B", S("FooBaB")[-1])
|
assert_equal("B", S("FooBaB")[-1])
|
||||||
|
|
Loading…
Reference in a new issue