* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@5115 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e3ed269193
commit
7fbf13f7f2
@ -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>
|
Fri Dec 5 02:49:35 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/test/unit/assertions.rb (Test::Unit::Assertions::assert_raises):
|
* 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.
|
* io.c (read_all): do not depend on lseek position.
|
||||||
[ruby-dev:22026]
|
[ruby-dev:22026]
|
||||||
|
|
||||||
Thu Dec 4 22:37:26 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Thu Dec 4 22:37:26 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (rb_eval): preserve $! value when retry happens in the
|
* eval.c (rb_eval): preserve $! value when retry happens in the
|
||||||
|
@ -866,10 +866,12 @@ strio_read(argc, argv, self)
|
|||||||
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
|
rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc);
|
||||||
}
|
}
|
||||||
str = rb_str_substr(ptr->string, ptr->pos, len);
|
str = rb_str_substr(ptr->string, ptr->pos, len);
|
||||||
if (len > 0 &&
|
if (NIL_P(str)) {
|
||||||
(NIL_P(str) || (ptr->pos += RSTRING(str)->len) >= RSTRING(ptr->string)->len)) {
|
|
||||||
ptr->flags |= STRIO_EOF;
|
ptr->flags |= STRIO_EOF;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
ptr->pos += RSTRING(str)->len;
|
||||||
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'tempfile'
|
require 'tempfile'
|
||||||
$:.unshift(File.dirname(File.expand_path(__FILE__)))
|
$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
|
||||||
require 'envutil'
|
require 'envutil'
|
||||||
|
|
||||||
class TestBeginEndBlock < Test::Unit::TestCase
|
class TestBeginEndBlock < Test::Unit::TestCase
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
|
require 'tempfile'
|
||||||
|
$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
|
||||||
|
require 'ut_eof'
|
||||||
|
|
||||||
$KCODE = 'none'
|
$KCODE = 'none'
|
||||||
|
|
||||||
@ -29,4 +32,12 @@ class TestFile < Test::Unit::TestCase
|
|||||||
File.unlink(filename) if File.exist?(filename)
|
File.unlink(filename) if File.exist?(filename)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
include TestEOF
|
||||||
|
def open_file(content)
|
||||||
|
f = Tempfile.new("test-eof")
|
||||||
|
f << content
|
||||||
|
f.rewind
|
||||||
|
yield f
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
14
test/ruby/test_pipe.rb
Normal file
14
test/ruby/test_pipe.rb
Normal file
@ -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
|
@ -1,5 +1,5 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
$:.unshift(File.dirname(File.expand_path(__FILE__)))
|
$:.replace([File.dirname(File.expand_path(__FILE__))] | $:)
|
||||||
require 'envutil'
|
require 'envutil'
|
||||||
|
|
||||||
$KCODE = 'none'
|
$KCODE = 'none'
|
||||||
|
46
test/ruby/ut_eof.rb
Normal file
46
test/ruby/ut_eof.rb
Normal file
@ -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
|
@ -1,15 +1,14 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'stringio'
|
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
|
class TestStringIO < Test::Unit::TestCase
|
||||||
def test_empty_file
|
include TestEOF
|
||||||
f = StringIO.new("")
|
def open_file(content)
|
||||||
assert_equal("", f.read(0))
|
f = StringIO.new(content)
|
||||||
assert_equal("", f.read)
|
yield f
|
||||||
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
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user