[前][次][番号順一覧][スレッド一覧]

ruby-changes:47982

From: nobu <ko1@a...>
Date: Mon, 2 Oct 2017 15:46:47 +0900 (JST)
Subject: [ruby-changes:47982] nobu:r60096 (trunk): test_argf.rb: indent here docs

nobu	2017-10-02 15:46:41 +0900 (Mon, 02 Oct 2017)

  New Revision: 60096

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60096

  Log:
    test_argf.rb: indent here docs
    
    * test/ruby/test_argf.rb (assert_src_expected): default line
      number to caller's location.
    
    * test/ruby/test_argf.rb (test_lineno, test_lineno2): get rid of a
      bug of wrong indentation after $. in Emacs 25.3 ruby-mode.el

  Modified files:
    trunk/test/ruby/test_argf.rb
Index: test/ruby/test_argf.rb
===================================================================
--- test/ruby/test_argf.rb	(revision 60095)
+++ test/ruby/test_argf.rb	(revision 60096)
@@ -57,7 +57,7 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L57
     /cygwin|mswin|mingw|bccwin/ =~ RUBY_PLATFORM
   end
 
-  def assert_src_expected(line, src, args = nil)
+  def assert_src_expected(src, args = nil, line: caller_locations(1, 1)[0].lineno+1)
     args ||= [@t1.path, @t2.path, @t3.path]
     expected = src.split(/^/)
     ruby('-e', src, *args) do |f|
@@ -71,7 +71,8 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L71
   end
 
   def test_argf
-    assert_src_expected(__LINE__+1, <<-'SRC')
+    assert_src_expected("#{<<~"{#"}\n#{<<~'};'}")
+    {#
       a = ARGF
       b = a.dup
       p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["1", 1, "1", 1]
@@ -87,54 +88,59 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L88
       b.rewind
       p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["5", 5, "5", 5]
       p [a.gets.chomp, a.lineno, b.gets.chomp, b.lineno] #=> ["6", 6, "6", 6]
-    SRC
+    };
   end
 
   def test_lineno
-    assert_src_expected(__LINE__+1, <<-'SRC')
+    assert_src_expected("#{<<~"{#"}\n#{<<~'};'}")
+    {#
       a = ARGF
-      a.gets; p $.  #=> 1
-      a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 3
-      a.rewind; p $.  #=> 3
-      a.gets; p $.  #=> 3
-      a.gets; p $.  #=> 4
-      a.rewind; p $.  #=> 4
-      a.gets; p $.  #=> 3
-      a.lineno = 1000; p $.  #=> 1000
-      a.gets; p $.  #=> 1001
-      a.gets; p $.  #=> 1002
+      a.gets; p($.) #=> 1
+      a.gets; p($.) #=> 2
+      a.gets; p($.) #=> 3
+      a.rewind; p($.) #=> 3
+      a.gets; p($.) #=> 3
+      a.gets; p($.) #=> 4
+      a.rewind; p($.) #=> 4
+      a.gets; p($.) #=> 3
+      a.lineno = 1000; p($.) #=> 1000
+      a.gets; p($.) #=> 1001
+      a.gets; p($.) #=> 1002
       $. = 2000
-      a.gets; p $.  #=> 2001
-      a.gets; p $.  #=> 2001
-    SRC
+      a.gets; p($.) #=> 2001
+      a.gets; p($.) #=> 2001
+    };
   end
 
   def test_lineno2
-    assert_src_expected(__LINE__+1, <<-'SRC')
+    assert_src_expected("#{<<~"{#"}\n#{<<~'};'}")
+    {#
       a = ARGF.dup
-      a.gets; p $.  #=> 1
-      a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 1
-      a.rewind; p $.  #=> 1
-      a.gets; p $.  #=> 1
-      a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 1
-      a.lineno = 1000; p $.  #=> 1
-      a.gets; p $.  #=> 2
-      a.gets; p $.  #=> 2
+      a.gets; p($.) #=> 1
+      a.gets; p($.) #=> 2
+      a.gets; p($.) #=> 1
+      a.rewind; p($.) #=> 1
+      a.gets; p($.) #=> 1
+      a.gets; p($.) #=> 2
+      a.gets; p($.) #=> 1
+      a.lineno = 1000; p($.) #=> 1
+      a.gets; p($.) #=> 2
+      a.gets; p($.) #=> 2
       $. = 2000
-      a.gets; p $.  #=> 2000
-      a.gets; p $.  #=> 2000
-    SRC
+      a.gets; p($.) #=> 2000
+      a.gets; p($.) #=> 2000
+    };
   end
 
   def test_lineno3
-    assert_in_out_err(["-", @t1.path, @t2.path], <<-INPUT, %w"1 1 1 2 2 2 3 3 1 4 4 2", [], "[ruby-core:25205]")
+    expected = %w"1 1 1 2 2 2 3 3 1 4 4 2"
+    assert_in_out_err(["-", @t1.path, @t2.path],
+                      "#{<<~"{#"}\n#{<<~'};'}", expected, [], "[ruby-core:25205]")
+    {#
       ARGF.each do |line|
         puts [$., ARGF.lineno, ARGF.file.lineno]
       end
-    INPUT
+    };
   end
 
   def test_new_lineno_each
@@ -159,12 +165,14 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L165
   end
 
   def test_inplace
-    assert_in_out_err(["-", @t1.path, @t2.path, @t3.path], <<-INPUT, [], [])
+    assert_in_out_err(["-", @t1.path, @t2.path, @t3.path],
+                      "#{<<~"{#"}\n#{<<~'};'}")
+    {#
       ARGF.inplace_mode = '.bak'
       while line = ARGF.gets
         puts line.chomp + '.new'
       end
-    INPUT
+    };
     assert_equal("1.new\n2.new\n", File.read(@t1.path))
     assert_equal("3.new\n4.new\n", File.read(@t2.path))
     assert_equal("5.new\n6.new\n", File.read(@t3.path))
@@ -174,7 +182,9 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L182
   end
 
   def test_inplace2
-    assert_in_out_err(["-", @t1.path, @t2.path, @t3.path], <<-INPUT, [], [])
+    assert_in_out_err(["-", @t1.path, @t2.path, @t3.path],
+                      "#{<<~"{#"}\n#{<<~'};'}")
+    {#
       ARGF.inplace_mode = '.bak'
       puts ARGF.gets.chomp + '.new'
       puts ARGF.gets.chomp + '.new'
@@ -188,7 +198,7 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L198
       p ARGF.inplace_mode
       ARGF.inplace_mode = nil
       puts ARGF.gets.chomp + '.new'
-    INPUT
+    };
     assert_equal("1.new\n2.new\n\".bak\"\n3.new\n4.new\nnil\n", File.read(@t1.path))
     assert_equal("3\n4\n", File.read(@t2.path))
     assert_equal("5.new\n\".bak\"\n6.new\n", File.read(@t3.path))
@@ -198,7 +208,9 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L208
   end
 
   def test_inplace3
-    assert_in_out_err(["-i.bak", "-", @t1.path, @t2.path, @t3.path], <<-INPUT, [], [])
+    assert_in_out_err(["-i.bak", "-", @t1.path, @t2.path, @t3.path],
+                      "#{<<~"{#"}\n#{<<~'};'}")
+    {#
       puts ARGF.gets.chomp + '.new'
       puts ARGF.gets.chomp + '.new'
       p $-i
@@ -211,7 +223,7 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L223
       p $-i
       $-i = nil
       puts ARGF.gets.chomp + '.new'
-    INPUT
+    };
     assert_equal("1.new\n2.new\n\".bak\"\n3.new\n4.new\nnil\n", File.read(@t1.path))
     assert_equal("3\n4\n", File.read(@t2.path))
     assert_equal("5.new\n\".bak\"\n6.new\n", File.read(@t3.path))
@@ -223,12 +235,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L235
   def test_inplace_rename_impossible
     t = make_tempfile
 
-    assert_in_out_err(["-", t.path], <<-INPUT) do |r, e|
-      ARGF.inplace_mode = '/\\\\:'
-      while line = ARGF.gets
-        puts line.chomp + '.new'
-      end
-    INPUT
+    assert_in_out_err(["-", t.path], "#{<<~"{#"}\n#{<<~'};'}") do |r, e|
+      {#
+        ARGF.inplace_mode = '/\\\\:'
+        while line = ARGF.gets
+          puts line.chomp + '.new'
+        end
+      };
       assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
       assert_equal([], r)
       assert_equal("foo\nbar\nbaz\n", File.read(t.path))
@@ -245,12 +258,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L258
   def test_inplace_no_backup
     t = make_tempfile
 
-    assert_in_out_err(["-", t.path], <<-INPUT) do |r, e|
-      ARGF.inplace_mode = ''
-      while line = ARGF.gets
-        puts line.chomp + '.new'
-      end
-    INPUT
+    assert_in_out_err(["-", t.path], "#{<<~"{#"}\n#{<<~'};'}") do |r, e|
+      {#
+        ARGF.inplace_mode = ''
+        while line = ARGF.gets
+          puts line.chomp + '.new'
+        end
+      };
       if no_safe_rename
         assert_match(/Can't do inplace edit without backup/, e.join) #'
       else
@@ -264,63 +278,68 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L278
   def test_inplace_dup
     t = make_tempfile
 
-    assert_in_out_err(["-", t.path], <<-INPUT, [], [])
+    assert_in_out_err(["-", t.path], "#{<<~"{#"}\n#{<<~'};'}", [], [])
+    {#
       ARGF.inplace_mode = '.bak'
       f = ARGF.dup
       while line = f.gets
         puts line.chomp + '.new'
       end
-    INPUT
+    };
     assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
   end
 
   def test_inplace_stdin
-    assert_in_out_err(["-", "-"], <<-INPUT, [], /Can't do inplace edit for stdio; skipping/)
+    assert_in_out_err(["-", "-"], "#{<<~"{#"}\n#{<<~'};'}", [], /Can't do inplace edit for stdio; skipping/)
+    {#
       ARGF.inplace_mode = '.bak'
       f = ARGF.dup
       while line = f.gets
         puts line.chomp + '.new'
       end
-    INPUT
+    };
   end
 
   def test_inplace_stdin2
-    assert_in_out_err(["-"], <<-INPUT, [], /Can't do inplace edit for stdio/)
+    assert_in_out_err(["-"], "#{<<~"{#"}\n#{<<~'};'}", [], /Can't do inplace edit for stdio/)
+    {#
       ARGF.inplace_mode = '.bak'
       while line = ARGF.gets
         puts line.chomp + '.new'
       end
-    INPUT
+    };
   end
 
   def test_encoding
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      p ARGF.external_encoding.is_a?(Encoding)
-      p ARGF.internal_encoding.is_a?(Encoding)
-      ARGF.gets
-      p ARGF.external_encoding.is_a?(Encoding)
-      p ARGF.internal_encoding
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        p ARGF.external_encoding.is_a?(Encoding)
+        p ARGF.internal_encoding.is_a?(Encoding)
+        ARGF.gets
+        p ARGF.external_encoding.is_a?(Encoding)
+        p ARGF.internal_encoding
+      };
       assert_equal("true\ntrue\ntrue\nnil\n", f.read)
     end
   end
 
   def test_tell
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      begin
-        ARGF.binmode
-        loop do
-          p ARGF.tell
-          p ARGF.gets
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        begin
+          ARGF.binmode
+          loop do
+            p ARGF.tell
+            p ARGF.gets
+          end
+        rescue ArgumentError
+          puts "end"
         end
-      rescue ArgumentError
-        puts "end"
-      end
-    SRC
+      };
       a = f.read.split("\n")
       [0, 2, 4, 2, 4, 2, 4].map {|i| i.to_s }.
-      zip((1..6).map {|i| '"' + i.to_s + '\n"' } + ["nil"]).flatten.
-      each do |x|
+        zip((1..6).map {|i| '"' + i.to_s + '\n"' } + ["nil"]).flatten.
+        each do |x|
         assert_equal(x, a.shift)
       end
       assert_equal('end', a.shift)
@@ -328,7 +347,8 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L347
   end
 
   def test_seek
-    assert_src_expected(__LINE__+1, <<-'SRC')
+    assert_src_expected("#{<<~"{#"}\n#{<<~'};'}")
+    {#
       ARGF.seek(4)
       p ARGF.gets #=> "3\n"
       ARGF.seek(0, IO::SEEK_END)
@@ -340,11 +360,12 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L360
       rescue
         puts "end" #=> end
       end
-    SRC
+    };
   end
 
   def test_set_pos
-    assert_src_expected(__LINE__+1, <<-'SRC')
+    assert_src_expected("#{<<~"{#"}\n#{<<~'};'}")
+    {#
       ARGF.pos = 4
       p ARGF.gets #=> "3\n"
       ARGF.pos = 4
@@ -356,11 +377,12 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L377
       rescue
         puts "end" #=> end
       end
-    SRC
+    };
   end
 
   def test_rewind
-    assert_src_expected(__LINE__+1, <<-'SRC')
+    assert_src_expected("#{<<~"{#"}\n#{<<~'};'}")
+    {#
       ARGF.pos = 4
       ARGF.rewind
       p ARGF.gets #=> "1\n"
@@ -375,28 +397,29 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L397
       rescue
         puts "end" #=> end
       end
-    SRC
+    };
   end
 
   def test_fileno
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      p ARGF.fileno
-      ARGF.gets
-      ARGF.gets
-      p ARGF.fileno
-      ARGF.gets
-      ARGF.gets
-      p ARGF.fileno
-      ARGF.gets
-      ARGF.gets
-      p ARGF.fileno
-      ARGF.gets
-      begin
-        ARGF.fileno
-      rescue
-        puts "end"
-      end
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        p ARGF.fileno
+        ARGF.gets
+        ARGF.gets
+        p ARGF.fileno
+        ARGF.gets
+        ARGF.gets
+        p ARGF.fileno
+        ARGF.gets
+        ARGF.gets
+        p ARGF.fileno
+        ARGF.gets
+        begin
+          ARGF.fileno
+        rescue
+          puts "end"
+        end
+      };
       a = f.read.split("\n")
       fd1, fd2, fd3, fd4, tag = a
       assert_match(/^\d+$/, fd1)
@@ -408,12 +431,13 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L431
   end
 
   def test_to_io
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      8.times do
-        p ARGF.to_io
-        ARGF.gets
-      end
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        8.times do
+          p ARGF.to_io
+          ARGF.gets
+        end
+      };
       a = f.read.split("\n")
       f11, f12, f13, f21, f22, f31, f32, f4 = a
       assert_equal(f11, f12)
@@ -427,16 +451,17 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L451
   end
 
   def test_eof
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      begin
-        8.times do
-          p ARGF.eof?
-          ARGF.gets
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        begin
+          8.times do
+            p ARGF.eof?
+            ARGF.gets
+          end
+        rescue IOError
+          puts "end"
         end
-      rescue IOError
-        puts "end"
-      end
-    SRC
+      };
       a = f.read.split("\n")
       (%w(false) + (%w(false true) * 3) + %w(end)).each do |x|
         assert_equal(x, a.shift)
@@ -463,66 +488,71 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L488
   end
 
   def test_read2
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = ""
-      ARGF.read(8, s)
-      p s
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = ""
+        ARGF.read(8, s)
+        p s
+      };
       assert_equal("\"1\\n2\\n3\\n4\\n\"\n", f.read)
     end
   end
 
   def test_read2_with_not_empty_buffer
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = "0123456789"
-      ARGF.read(8, s)
-      p s
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = "0123456789"
+        ARGF.read(8, s)
+        p s
+      };
       assert_equal("\"1\\n2\\n3\\n4\\n\"\n", f.read)
     end
   end
 
   def test_read3
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      nil while ARGF.gets
-      p ARGF.read
-      p ARGF.read(0, "")
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        nil while ARGF.gets
+        p ARGF.read
+        p ARGF.read(0, "")
+      };
       assert_equal("nil\n\"\"\n", f.read)
     end
   end
 
   def test_readpartial
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = ""
-      begin
-        loop do
-          s << ARGF.readpartial(1)
-          t = ""; ARGF.readpartial(1, t); s << t
-          # not empty buffer
-          u = "abcdef"; ARGF.readpartial(1, u); s << u
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = ""
+        begin
+          loop do
+            s << ARGF.readpartial(1)
+            t = ""; ARGF.readpartial(1, t); s << t
+            # not empty buffer
+            u = "abcdef"; ARGF.readpartial(1, u); s << u
+          end
+        rescue EOFError
+          puts s
         end
-      rescue EOFError
-        puts s
-      end
-    SRC
+      };
       assert_equal("1\n2\n3\n4\n5\n6\n", f.read)
     end
   end
 
   def test_readpartial2
-    ruby('-e', <<-SRC) do |f|
-      s = ""
-      begin
-        loop do
-          s << ARGF.readpartial(1)
-          t = ""; ARGF.readpartial(1, t); s << t
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}") do |f|
+      {#
+        s = ""
+        begin
+          loop do
+            s << ARGF.readpartial(1)
+            t = ""; ARGF.readpartial(1, t); s << t
+          end
+        rescue EOFError
+          $stdout.binmode
+          puts s
         end
-      rescue EOFError
-        $stdout.binmode
-        puts s
-      end
-    SRC
+      };
       f.binmode
       f.puts("foo")
       f.puts("bar")
@@ -533,76 +563,82 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L563
   end
 
   def test_readpartial_eof_twice
-    ruby('-W1', '-e', <<-SRC, @t1.path) do |f|
-      $stderr = $stdout
-      print ARGF.readpartial(256)
-      ARGF.readpartial(256) rescue p($!.class)
-      ARGF.readpartial(256) rescue p($!.class)
-    SRC
+    ruby('-W1', '-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path) do |f|
+      {#
+        $stderr = $stdout
+        print ARGF.readpartial(256)
+        ARGF.readpartial(256) rescue p($!.class)
+        ARGF.readpartial(256) rescue p($!.class)
+      };
       assert_equal("1\n2\nEOFError\nEOFError\n", f.read)
     end
   end
 
   def test_getc
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = ""
-      while c = ARGF.getc
-        s << c
-      end
-      puts s
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = ""
+        while c = ARGF.getc
+          s << c
+        end
+        puts s
+      };
       assert_equal("1\n2\n3\n4\n5\n6\n", f.read)
     end
   end
 
   def test_getbyte
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = []
-      while c = ARGF.getbyte
-        s << c
-      end
-      p s
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = []
+        while c = ARGF.getbyte
+          s << c
+        end
+        p s
+      };
       assert_equal("[49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10]\n", f.read)
     end
   end
 
   def test_readchar
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = ""
-      begin
-        while c = ARGF.readchar
-          s << c
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = ""
+        begin
+          while c = ARGF.readchar
+            s << c
+          end
+        rescue EOFError
+          puts s
         end
-      rescue EOFError
-        puts s
-      end
-    SRC
+      };
       assert_equal("1\n2\n3\n4\n5\n6\n", f.read)
     end
   end
 
   def test_readbyte
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      begin
-        s = []
-        while c = ARGF.readbyte
-          s << c
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        begin
+          s = []
+          while c = ARGF.readbyte
+            s << c
+          end
+        rescue EOFError
+          p s
         end
-      rescue EOFError
-        p s
-      end
-    SRC
+      };
       assert_equal("[49, 10, 50, 10, 51, 10, 52, 10, 53, 10, 54, 10]\n", f.read)
     end
   end
 
   def test_each_line
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = []
-      ARGF.each_line {|l| s << l }
-      p s
-    SRC
+    ruby('-e', "#{<<~"{#"}\n#{<<~'};'}", @t1.path, @t2.path, @t3.path) do |f|
+      {#
+        s = []
+        ARGF.each_line {|l| s << l }
+        p s
+      };
       assert_equal("[\"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\"]\n", f.read)
     end
   end
@@ -613,32 +649,35 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L649
   end
 
   def test_each_byte
-    ruby('-e', <<-SRC, @t1.path, @t2.path, @t3.path) do |f|
-      s = []
-      ARGF.each_byte {|c| s << c }
-      p s
-    SRC
+    ruby('-e', " (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]