ruby-changes:7218
From: akr <ko1@a...>
Date: Thu, 21 Aug 2008 02:01:00 +0900 (JST)
Subject: [ruby-changes:7218] Ruby:r18737 (trunk): * io.c (open_key_args): IO.foreach(path, rs, limit) didn't work.
akr 2008-08-21 01:57:46 +0900 (Thu, 21 Aug 2008) New Revision: 18737 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18737 Log: * io.c (open_key_args): IO.foreach(path, rs, limit) didn't work. Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 18736) +++ ChangeLog (revision 18737) @@ -1,3 +1,7 @@ +Thu Aug 21 01:57:03 2008 Tanaka Akira <akr@f...> + + * io.c (open_key_args): IO.foreach(path, rs, limit) didn't work. + Thu Aug 21 01:31:34 2008 Tanaka Akira <akr@f...> * io.c (rb_file_sysopen_internal): unused function removed. Index: io.c =================================================================== --- io.c (revision 18736) +++ io.c (revision 18737) @@ -6666,7 +6666,7 @@ 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 @@ } 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)) { Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 18736) +++ test/ruby/test_io.rb (revision 18737) @@ -1084,6 +1084,10 @@ 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,8 +1098,30 @@ 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 pipe(proc do |w| printf(w, "foo %s baz\n", "bar") @@ -1219,6 +1245,8 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/