Skip to content

Commit 16847fe

Browse files
committed
Fix the result of StringIO#truncate so compatible with File
1 parent 0fe2e0c commit 16847fe

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

ext/stringio/stringio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1668,7 +1668,7 @@ strio_truncate(VALUE self, VALUE len)
16681668
if (plen < l) {
16691669
MEMZERO(RSTRING_PTR(string) + plen, char, l - plen);
16701670
}
1671-
return len;
1671+
return INT2FIX(0);
16721672
}
16731673

16741674
/*

test/stringio/test_stringio.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ def o.to_str
3939
def test_truncate
4040
io = StringIO.new("")
4141
io.puts "abc"
42-
io.truncate(0)
42+
assert_equal(0, io.truncate(0))
4343
io.puts "def"
4444
assert_equal("\0\0\0\0def\n", io.string, "[ruby-dev:24190]")
4545
assert_raise(Errno::EINVAL) { io.truncate(-1) }
46-
io.truncate(10)
46+
assert_equal(0, io.truncate(10))
4747
assert_equal("\0\0\0\0def\n\0\0", io.string)
4848
end
4949

0 commit comments

Comments
 (0)