diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-05 02:54:48 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2003-12-05 02:54:48 +0000 |
commit | bf625b1809e01a8fe505f5a344149e8df8e3795e (patch) | |
tree | 75d78dfa2134f18d318611d3ca7e3f74e417e5d9 | |
parent | 513dbc6e6858cddf28418396fa7f1a7c652c1cb7 (diff) | |
download | ruby-bf625b1809e01a8fe505f5a344149e8df8e3795e.tar.gz ruby-bf625b1809e01a8fe505f5a344149e8df8e3795e.tar.xz ruby-bf625b1809e01a8fe505f5a344149e8df8e3795e.zip |
* ext/stringio/stringio.c (strio_read): follow IO#read.
* test/ruby/ut_eof.rb, test/ruby/test_file.rb, test/ruby/test_pipe.rb,
test/stringio/test_stringio.rb: add EOF test.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@5115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | ext/stringio/stringio.c | 6 | ||||
-rw-r--r-- | test/ruby/test_beginendblock.rb | 2 | ||||
-rw-r--r-- | test/ruby/test_file.rb | 11 | ||||
-rw-r--r-- | test/ruby/test_pipe.rb | 14 | ||||
-rw-r--r-- | test/ruby/test_system.rb | 2 | ||||
-rw-r--r-- | test/ruby/ut_eof.rb | 46 | ||||
-rw-r--r-- | test/stringio/test_stringio.rb | 17 |
8 files changed, 93 insertions, 14 deletions
@@ -1,3 +1,10 @@ +Fri Dec 5 11:54:45 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * ext/stringio/stringio.c (strio_read): follow IO#read. + + * test/ruby/ut_eof.rb, test/ruby/test_file.rb, test/ruby/test_pipe.rb, + test/stringio/test_stringio.rb: add EOF test. + Fri Dec 5 02:49:35 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises): @@ -15,7 +22,7 @@ Thu Dec 4 23:32:26 2003 Yukihiro Matsumoto <matz@ruby-lang.org> * io.c (read_all): do not depend on lseek position. [ruby-dev:22026] - + Thu Dec 4 22:37:26 2003 Nobuyoshi Nakada <nobu@ruby-lang.org> * eval.c (rb_eval): preserve $! value when retry happens in the diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 0fb60069d..725b5be19 100644 --- a/ext/stringio/stringio.c +++ b/ext/stringio/stringio.c @@ -866,10 +866,12 @@ strio_read(argc, argv, self) rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc); } str = rb_str_substr(ptr->string, ptr->pos, len); - if (len > 0 && - (NIL_P(str) || (ptr->pos += RSTRING(str)->len) >= RSTRING(ptr->string)->len)) { + if (NIL_P(str)) { ptr->flags |= STRIO_EOF; } + else { + ptr->pos += RSTRING(str)->len; + } return str; } diff --git a/test/ruby/test_beginendblock.rb b/test/ruby/test_beginendblock.rb index e8d25a102..b56b596a6 100644 --- a/test/ruby/test_beginendblock.rb +++ b/test/ruby/test_beginendblock.rb @@ -1,6 +1,6 @@ require 'test/unit' require 'tempfile' -$:.unshift(File.dirname(File.expand_path(__FILE__))) +$:.replace([File.dirname(File.expand_path(__FILE__))] | $:) require 'envutil' class TestBeginEndBlock < Test::Unit::TestCase diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index 0d0ea389a..f51e55f0c 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -1,4 +1,7 @@ require 'test/unit' +require 'tempfile' +$:.replace([File.dirname(File.expand_path(__FILE__))] | $:) +require 'ut_eof' $KCODE = 'none' @@ -29,4 +32,12 @@ class TestFile < Test::Unit::TestCase File.unlink(filename) if File.exist?(filename) end end + + include TestEOF + def open_file(content) + f = Tempfile.new("test-eof") + f << content + f.rewind + yield f + end end diff --git a/test/ruby/test_pipe.rb b/test/ruby/test_pipe.rb new file mode 100644 index 000000000..a6363ef78 --- /dev/null +++ b/test/ruby/test_pipe.rb @@ -0,0 +1,14 @@ +require 'test/unit' +$:.replace([File.dirname(File.expand_path(__FILE__))] | $:) +require 'ut_eof' +require 'envutil' + +$KCODE = 'none' + +class TestPipe < Test::Unit::TestCase + include TestEOF + def open_file(content) + f = IO.popen("echo -n #{content}") + yield f + end +end diff --git a/test/ruby/test_system.rb b/test/ruby/test_system.rb index ed7f8b8fd..d756e4a2d 100644 --- a/test/ruby/test_system.rb +++ b/test/ruby/test_system.rb @@ -1,5 +1,5 @@ require 'test/unit' -$:.unshift(File.dirname(File.expand_path(__FILE__))) +$:.replace([File.dirname(File.expand_path(__FILE__))] | $:) require 'envutil' $KCODE = 'none' diff --git a/test/ruby/ut_eof.rb b/test/ruby/ut_eof.rb new file mode 100644 index 000000000..d1ad9a5fe --- /dev/null +++ b/test/ruby/ut_eof.rb @@ -0,0 +1,46 @@ +require 'test/unit' + +module TestEOF + def test_eof_0 + open_file("") {|f| + assert_equal("", f.read(0)) + assert_equal("", f.read(0)) + assert_equal("", f.read) + assert_equal(nil, f.read(0)) + assert_equal(nil, f.read(0)) + } + open_file("") {|f| + assert_equal(nil, f.read(1)) + assert_equal(nil, f.read) + assert_equal(nil, f.read(1)) + } + end + + def test_eof_1 + open_file("a") {|f| + assert_equal("", f.read(0)) + assert_equal("a", f.read(1)) + assert_equal("" , f.read(0)) + assert_equal("" , f.read(0)) + assert_equal("", f.read) + assert_equal(nil, f.read(0)) + assert_equal(nil, f.read(0)) + } + open_file("a") {|f| + assert_equal("a", f.read(1)) + assert_equal(nil, f.read(1)) + } + open_file("a") {|f| + assert_equal("a", f.read(2)) + assert_equal(nil, f.read(1)) + assert_equal(nil, f.read) + assert_equal(nil, f.read(1)) + } + open_file("a") {|f| + assert_equal("a", f.read) + assert_equal(nil, f.read(1)) + assert_equal(nil, f.read) + assert_equal(nil, f.read(1)) + } + end +end diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb index 10390fc6d..3449e33e6 100644 --- a/test/stringio/test_stringio.rb +++ b/test/stringio/test_stringio.rb @@ -1,15 +1,14 @@ require 'test/unit' require 'stringio' +dir = File.expand_path(__FILE__) +2.times {dir = File.dirname(dir)} +$:.replace([File.join(dir, "ruby")] | $:) +require 'ut_eof' 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)) + include TestEOF + def open_file(content) + f = StringIO.new(content) + yield f end end |