1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[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 committed by git
parent b6f6fc6e87
commit 302f353fd9
2 changed files with 3 additions and 3 deletions

View file

@ -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);
}
/*

View file

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