From 6395c3b38de70621232102597ee24c1fd136ca1b Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 10 Dec 2003 08:16:14 +0000 Subject: * ext/stringio/stringio.c (strio_read): adjust behavior at reading beyond EOF to IO. [ruby-dev:22205] * test/ruby/ut_eof.rb (TestEOF::Seek): test behaviors at reading beyond EOF. * test/ruby/test_file.rb, * test/stringio/test_stringio.rb: include TestEOF::Seek test case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5158 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 23 +++++++++++++++++------ ext/stringio/stringio.c | 1 + test/ruby/test_file.rb | 2 ++ test/ruby/ut_eof.rb | 27 +++++++++++++++++++++++++++ test/stringio/test_stringio.rb | 2 ++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 61d5aaeaa5..febdaf2997 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,18 @@ +Wed Dec 10 17:16:06 2003 Nobuyoshi Nakada + + * ext/stringio/stringio.c (strio_read): adjust behavior at reading + beyond EOF to IO. [ruby-dev:22205] + + * test/ruby/ut_eof.rb (TestEOF::Seek): test behaviors at reading + beyond EOF. + + * test/ruby/test_file.rb, * test/stringio/test_stringio.rb: + include TestEOF::Seek test case. + Wed Dec 10 15:01:19 2003 Shugo Maeda * test/monitor/test_monitor.rb (test_cond): use Queue#deq - insteadof sleep. + instead of sleep. Wed Dec 10 14:45:39 2003 WATANABE Hirofumi @@ -20,12 +31,12 @@ Wed Dec 10 12:53:05 2003 WATANABE Hirofumi Tue Dec 9 23:32:23 2003 Hidetoshi NAGAI - * ext/tk/lib/tk.rb, ext/tk/lib/tkcanvas.rb, ext/tk/lib/tkdialog.rb, - ext/tk/lib/tkentry.rb, ext/tk/lib/tkscrollbox.rb, ext/tk/lib/tktext.rb, - ext/tk/sample/tkalignbox.rb, ext/tk/sample/tkcombobox.rb, + * ext/tk/lib/tk.rb, ext/tk/lib/tkcanvas.rb, ext/tk/lib/tkdialog.rb, + ext/tk/lib/tkentry.rb, ext/tk/lib/tkscrollbox.rb, ext/tk/lib/tktext.rb, + ext/tk/sample/tkalignbox.rb, ext/tk/sample/tkcombobox.rb, ext/tk/sample/tkmultilistbox.rb, ext/tk/sample/tkoptdb.rb, ext/tk/sample/tktextframe.rb, - ext/tk/sample/demos-en/dialog1.rb, ext/tk/sample/demos-en/dialog2.rb, - ext/tk/sample/demos-jp/dialog1.rb, ext/tk/sample/demos-jp/dialog2.rb: + ext/tk/sample/demos-en/dialog1.rb, ext/tk/sample/demos-en/dialog2.rb, + ext/tk/sample/demos-jp/dialog1.rb, ext/tk/sample/demos-jp/dialog2.rb: overrided instance methods, which are private methods on the super class, are changed to 'private' diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 725b5be192..f94c860728 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -867,6 +867,7 @@ strio_read(argc, argv, self) } str = rb_str_substr(ptr->string, ptr->pos, len); if (NIL_P(str)) { + if (!(ptr->flags & STRIO_EOF)) str = rb_str_new(0, 0); ptr->flags |= STRIO_EOF; } else { diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 3cf90f7101..b35a2661c9 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -41,4 +41,6 @@ class TestFile < Test::Unit::TestCase yield f end alias open_file_rw open_file + + include TestEOF::Seek end diff --git a/test/ruby/ut_eof.rb b/test/ruby/ut_eof.rb index f1ce4f7198..ffd9ba65ab 100644 --- a/test/ruby/ut_eof.rb +++ b/test/ruby/ut_eof.rb @@ -53,4 +53,31 @@ module TestEOF assert_equal(nil, f.read(1)) } end + + module Seek + def open_file_seek(content, pos) + open_file(content) do |f| + f.seek(pos) + yield f + end + end + + def test_eof_0_seek + open_file_seek("", 10) {|f| + assert_equal("", f.read) + assert_equal(nil, f.read) + } + end + + def test_eof_1_seek + open_file_seek("a", 10) {|f| + assert_equal("", f.read) + assert_equal(nil, f.read) + } + open_file_seek("a", 1) {|f| + assert_equal("", f.read) + assert_equal(nil, f.read) + } + end + end end diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index e16bd0e37b..a62fa491b8 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -12,4 +12,6 @@ class TestStringIO < Test::Unit::TestCase yield f end alias open_file_rw open_file + + include TestEOF::Seek end -- cgit v1.2.3