summaryrefslogtreecommitdiff
path: root/test/ruby/test_argf.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-27 07:30:56 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-10-27 07:30:56 +0000
commit85101b76259d62e03a746524bf75c77f1fb302b7 (patch)
treefcdf8c3e68ffb1ab444ce2e13849856dbc3e91a7 /test/ruby/test_argf.rb
parent0a20a506e1ee9e47ea89bb263c31adca013bcb95 (diff)
* test/ruby/test_argf.rb (test_{argf,lineno,lineno2}): don't repeat
comments and expected results. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19966 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_argf.rb')
-rw-r--r--test/ruby/test_argf.rb33
1 files changed, 17 insertions, 16 deletions
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index eb5556b98ae..2cfcd032879 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -55,7 +55,7 @@ class TestArgf < Test::Unit::TestCase
end
def test_argf
- ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ src = <<-SRC
a = ARGF
b = a.dup
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 1]
@@ -72,23 +72,20 @@ class TestArgf < Test::Unit::TestCase
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 8]
p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 9]
SRC
- a = f.read.split("\n")
- assert_equal('["1", 1, "1", 1]', a.shift)
- assert_equal('["2", 2, "2", 2]', a.shift)
- assert_equal('["1", 1, "1", 3]', a.shift)
- assert_equal('["2", 2, "2", 4]', a.shift)
- assert_equal('["3", 3, "3", 5]', a.shift)
- assert_equal('["4", 4, "4", 6]', a.shift)
- assert_equal('["5", 5, "5", 7]', a.shift)
- assert_equal('["5", 5, "5", 8]', a.shift)
- assert_equal('["6", 6, "6", 9]', a.shift)
+ expected = src.scan(/\#=> *(.*+)/).flatten
+ ruby('-e', src, @t1.path, @t2.path, @t3.path) do |f|
+ f.each_with_index do |a, i|
+ assert_equal(expected.shift, a.chomp, "[ruby-dev:34445]: line #{i}")
+ end
+
+ assert_empty(expected, "[ruby-dev:34445]: remained")
# is this test OK? [ruby-dev:34445]
end
end
def test_lineno
- ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ src = <<-SRC
a = ARGF
a.gets; p $. #=> 1
a.gets; p $. #=> 2
@@ -105,12 +102,14 @@ class TestArgf < Test::Unit::TestCase
a.gets; p $. #=> 2001
a.gets; p $. #=> 2001
SRC
- assert_equal("1,2,3,3,3,4,4,3,1000,1001,1002,2001,2001", f.read.chomp.gsub("\n", ","))
+ expected = src.scan(/\#=> *(.*+)/).join(",")
+ ruby('-e', src, @t1.path, @t2.path, @t3.path) do |f|
+ assert_equal(expected, f.read.chomp.gsub("\n", ","))
end
end
def test_lineno2
- ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
+ src = <<-SRC
a = ARGF.dup
a.gets; p $. #=> 1
a.gets; p $. #=> 2
@@ -123,10 +122,12 @@ class TestArgf < Test::Unit::TestCase
a.gets; p $. #=> 2
a.gets; p $. #=> 2
$. = 2000
- a.gets; p $. #=> 2001
+ a.gets; p $. #=> 2000
a.gets; p $. #=> 2000
SRC
- assert_equal("1,2,1,1,1,2,1,1,2,2,2000,2000", f.read.chomp.gsub("\n", ","))
+ expected = src.scan(/\#=> *(.*+)/).join(",")
+ ruby('-e', src, @t1.path, @t2.path, @t3.path) do |f|
+ assert_equal(expected, f.read.chomp.gsub("\n", ","))
end
end