зеркало из https://github.com/github/ruby.git
[ruby/stringio] Fix the result of `StringIO#truncate` so compatible with `File`
https://github.com/ruby/stringio/commit/16847fea32
This commit is contained in:
Родитель
b6f6fc6e87
Коммит
302f353fd9
|
@ -1668,7 +1668,7 @@ strio_truncate(VALUE self, VALUE len)
|
|||
if (plen < l) {
|
||||
MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
|
||||
}
|
||||
return len;
|
||||
return INT2FIX(0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -39,11 +39,11 @@ class TestStringIO < Test::Unit::TestCase
|
|||
def test_truncate
|
||||
io = StringIO.new("")
|
||||
io.puts "abc"
|
||||
io.truncate(0)
|
||||
assert_equal(0, io.truncate(0))
|
||||
io.puts "def"
|
||||
assert_equal("\0\0\0\0def\n", io.string, "[ruby-dev:24190]")
|
||||
assert_raise(Errno::EINVAL) { io.truncate(-1) }
|
||||
io.truncate(10)
|
||||
assert_equal(0, io.truncate(10))
|
||||
assert_equal("\0\0\0\0def\n\0\0", io.string)
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче