mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (open_key_args): IO.foreach(path, rs, limit) didn't work.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18737 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1bfaed8f8d
commit
4a2cd03fbd
3 changed files with 34 additions and 3 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Aug 21 01:57:03 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (open_key_args): IO.foreach(path, rs, limit) didn't work.
|
||||
|
||||
Thu Aug 21 01:31:34 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (rb_file_sysopen_internal): unused function removed.
|
||||
|
|
5
io.c
5
io.c
|
@ -6666,7 +6666,7 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
|
|||
|
||||
FilePathValue(argv[0]);
|
||||
arg->io = 0;
|
||||
arg->argc = argc > 1 ? 1 : 0;
|
||||
arg->argc = argc - 1;
|
||||
arg->argv = argv + 1;
|
||||
if (argc == 1) {
|
||||
no_key:
|
||||
|
@ -6675,8 +6675,7 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
|
|||
}
|
||||
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
|
||||
if (NIL_P(opt)) goto no_key;
|
||||
if (argc > 2) arg->argc = 1;
|
||||
else arg->argc = 0;
|
||||
arg->argc--;
|
||||
|
||||
v = rb_hash_aref(opt, sym_open_args);
|
||||
if (!NIL_P(v)) {
|
||||
|
|
|
@ -1083,6 +1083,10 @@ class TestIO < Test::Unit::TestCase
|
|||
|
||||
t = make_tempfile
|
||||
|
||||
a = []
|
||||
IO.foreach(t.path) {|x| a << x }
|
||||
assert_equal(["foo\n", "bar\n", "baz\n"], a)
|
||||
|
||||
a = []
|
||||
IO.foreach(t.path, {:mode => "r" }) {|x| a << x }
|
||||
assert_equal(["foo\n", "bar\n", "baz\n"], a)
|
||||
|
@ -1094,6 +1098,28 @@ class TestIO < Test::Unit::TestCase
|
|||
a = []
|
||||
IO.foreach(t.path, {:open_args => ["r"] }) {|x| a << x }
|
||||
assert_equal(["foo\n", "bar\n", "baz\n"], a)
|
||||
|
||||
a = []
|
||||
IO.foreach(t.path, "b") {|x| a << x }
|
||||
assert_equal(["foo\nb", "ar\nb", "az\n"], a)
|
||||
|
||||
a = []
|
||||
IO.foreach(t.path, 3) {|x| a << x }
|
||||
assert_equal(["foo", "\n", "bar", "\n", "baz", "\n"], a)
|
||||
|
||||
a = []
|
||||
IO.foreach(t.path, "b", 3) {|x| a << x }
|
||||
assert_equal(["foo", "\nb", "ar\n", "b", "az\n"], a)
|
||||
|
||||
end
|
||||
|
||||
def test_s_readlines
|
||||
t = make_tempfile
|
||||
|
||||
assert_equal(["foo\n", "bar\n", "baz\n"], IO.readlines(t.path))
|
||||
assert_equal(["foo\nb", "ar\nb", "az\n"], IO.readlines(t.path, "b"))
|
||||
assert_equal(["fo", "o\n", "ba", "r\n", "ba", "z\n"], IO.readlines(t.path, 2))
|
||||
assert_equal(["fo", "o\n", "b", "ar", "\nb", "az", "\n"], IO.readlines(t.path, "b", 2))
|
||||
end
|
||||
|
||||
def test_printf
|
||||
|
@ -1219,6 +1245,8 @@ class TestIO < Test::Unit::TestCase
|
|||
def test_s_read
|
||||
t = make_tempfile
|
||||
|
||||
assert_equal("foo\nbar\nbaz\n", File.read(t.path))
|
||||
assert_equal("foo\nba", File.read(t.path, 6))
|
||||
assert_equal("bar\n", File.read(t.path, 4, 4))
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue