ruby-changes:72378
From: Nobuyoshi <ko1@a...>
Date: Fri, 1 Jul 2022 00:52:46 +0900 (JST)
Subject: [ruby-changes:72378] 302f353fd9 (master): [ruby/stringio] Fix the result of `StringIO#truncate` so compatible with `File`
https://git.ruby-lang.org/ruby.git/commit/?id=302f353fd9 From 302f353fd9223d020e48495eaa7a03ce5d539409 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Fri, 1 Jul 2022 00:49:36 +0900 Subject: [ruby/stringio] Fix the result of `StringIO#truncate` so compatible with `File` https://github.com/ruby/stringio/commit/16847fea32 --- ext/stringio/stringio.c | 2 +- test/stringio/test_stringio.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 1b21c2e60f..9ba2cd92a1 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -1668,7 +1668,7 @@ strio_truncate(VALUE self, VALUE len) https://github.com/ruby/ruby/blob/trunk/ext/stringio/stringio.c#L1668 if (plen < l) { MEMZERO(RSTRING_PTR(string) + plen, char, l - plen); } - return len; + return INT2FIX(0); } /* diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 3fcb20e1fa..34c4748185 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -39,11 +39,11 @@ class TestStringIO < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/stringio/test_stringio.rb#L39 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/