[ruby/stringio] Fix the result of `StringIO#truncate` so compatible with `File`

https://github.com/ruby/stringio/commit/16847fea32
This commit is contained in:
Nobuyoshi Nakada 2022-07-01 00:49:36 +09:00 коммит произвёл git
Родитель b6f6fc6e87
Коммит 302f353fd9
2 изменённых файлов: 3 добавлений и 3 удалений

Просмотреть файл

@ -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