ruby-changes:8435
From: nobu <ko1@a...>
Date: Mon, 27 Oct 2008 16:31:05 +0900 (JST)
Subject: [ruby-changes:8435] Ruby:r19966 (trunk): * test/ruby/test_argf.rb (test_{argf,lineno,lineno2}): don't repeat
nobu 2008-10-27 16:30:56 +0900 (Mon, 27 Oct 2008) New Revision: 19966 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=19966 Log: * test/ruby/test_argf.rb (test_{argf,lineno,lineno2}): don't repeat comments and expected results. Modified files: trunk/test/ruby/test_argf.rb Index: test/ruby/test_argf.rb =================================================================== --- test/ruby/test_argf.rb (revision 19965) +++ test/ruby/test_argf.rb (revision 19966) @@ -55,7 +55,7 @@ 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 @@ 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 @@ 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 @@ 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/