From 0c15b3a2221ff156452a9979b70b3e36d7bad6c0 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 18 Nov 2003 09:23:07 +0000 Subject: [PATCH] * test/stringio/test_stringio.rb: imported from [ruby-dev:21941]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++-- ext/stringio/stringio.c | 4 ++++ test/stringio/test_stringio.rb | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 test/stringio/test_stringio.rb diff --git a/ChangeLog b/ChangeLog index e88e3d5420..20c978dd42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,15 @@ -Tue Nov 18 18:09:37 2003 Nobuyoshi Nakada +Tue Nov 18 18:23:05 2003 Nobuyoshi Nakada * ext/stringio/stringio.c (strio_read): behave as IO at empty string. - [ruby-dev:21939] + [ruby-dev:21939], [ruby-dev:21941] * ext/stringio/stringio.c (strio_getc, strio_getline): set EOF flag. * ext/stringio/stringio.c (strio_rewind, strio_seek, strio_ungetc): clear EOF flag. + * test/stringio/test_stringio.rb: imported from [ruby-dev:21941]. + Tue Nov 18 14:06:35 2003 Minero Aoki * lib/fileutils.rb (fu_each_src_dest): raise if src==dest. diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index d6d5b7694a..0fb60069de 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -849,6 +849,9 @@ strio_read(argc, argv, self) ptr->flags |= STRIO_EOF; return Qnil; } + else if (ptr->flags & STRIO_EOF) { + return Qnil; + } break; } /* fall through */ @@ -856,6 +859,7 @@ strio_read(argc, argv, self) len = RSTRING(ptr->string)->len - ptr->pos; if (len == 0 && ptr->pos == RSTRING(ptr->string)->len) { if (ptr->flags & STRIO_EOF) return Qnil; + ptr->flags |= STRIO_EOF; } break; default: diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb new file mode 100644 index 0000000000..10390fc6da --- /dev/null +++ b/test/stringio/test_stringio.rb @@ -0,0 +1,15 @@ +require 'test/unit' +require 'stringio' + +class TestStringIO < Test::Unit::TestCase + def test_empty_file + f = StringIO.new("") + assert_equal("", f.read(0)) + assert_equal("", f.read) + assert_equal(nil, f.read(0)) + f = StringIO.new("") + assert_equal(nil, f.read(1)) + assert_equal(nil, f.read) + assert_equal(nil, f.read(1)) + end +end