Add rb_str_resize coderange test
This commit is contained in:
parent
9c7374b0e6
commit
04467218ce
@ -16,9 +16,17 @@ bug_str_append(VALUE str, VALUE addendum)
|
|||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
bug_str_resize(VALUE str, VALUE len)
|
||||||
|
{
|
||||||
|
rb_str_resize(str, NUM2LONG(len));
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
Init_string_set_len(VALUE klass)
|
Init_string_set_len(VALUE klass)
|
||||||
{
|
{
|
||||||
rb_define_method(klass, "set_len", bug_str_set_len, 1);
|
rb_define_method(klass, "set_len", bug_str_set_len, 1);
|
||||||
rb_define_method(klass, "append", bug_str_append, 1);
|
rb_define_method(klass, "append", bug_str_append, 1);
|
||||||
|
rb_define_method(klass, "resize", bug_str_resize, 1);
|
||||||
}
|
}
|
||||||
|
@ -63,4 +63,22 @@ class Test_StrSetLen < Test::Unit::TestCase
|
|||||||
assert_not_predicate str, :ascii_only?
|
assert_not_predicate str, :ascii_only?
|
||||||
assert_equal u, str
|
assert_equal u, str
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_valid_encoding_after_resized
|
||||||
|
s = "\0\0".force_encoding(Encoding::UTF_16BE)
|
||||||
|
str = Bug::String.new(s)
|
||||||
|
assert_predicate str, :valid_encoding?
|
||||||
|
str.resize(1)
|
||||||
|
assert_not_predicate str, :valid_encoding?
|
||||||
|
str.resize(2)
|
||||||
|
assert_predicate str, :valid_encoding?
|
||||||
|
str.resize(3)
|
||||||
|
assert_not_predicate str, :valid_encoding?
|
||||||
|
|
||||||
|
s = "\xDB\x00\xDC\x00".force_encoding(Encoding::UTF_16BE)
|
||||||
|
str = Bug::String.new(s)
|
||||||
|
assert_predicate str, :valid_encoding?
|
||||||
|
str.resize(2)
|
||||||
|
assert_not_predicate str, :valid_encoding?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user