summaryrefslogtreecommitdiff
path: root/test/ruby/test_io.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-20 16:57:46 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-20 16:57:46 +0000
commit4a2cd03fbd73cefdc87e9602dc3dd1cf86a5a63d (patch)
tree61f7a6904baf2cea189c8dd78d5ba9ba36fe427d /test/ruby/test_io.rb
parent1bfaed8f8d4de9eba8f5b282a18e886aed278a2a (diff)
* 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
Diffstat (limited to 'test/ruby/test_io.rb')
-rw-r--r--test/ruby/test_io.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index a181b41023..e487927ebe 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1084,6 +1084,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