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

ruby-changes:18330

From: nobu <ko1@a...>
Date: Sat, 25 Dec 2010 15:59:07 +0900 (JST)
Subject: [ruby-changes:18330] Ruby:r30353 (trunk): * lib/csv.rb, test/csv: should not assume $, invariant.

nobu	2010-12-25 15:58:58 +0900 (Sat, 25 Dec 2010)

  New Revision: 30353

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30353

  Log:
    * lib/csv.rb, test/csv: should not assume $, invariant.

  Added files:
    trunk/test/csv/base.rb
  Modified files:
    trunk/ChangeLog
    trunk/lib/csv.rb
    trunk/test/csv/test_csv_parsing.rb
    trunk/test/csv/test_csv_writing.rb
    trunk/test/csv/test_data_converters.rb
    trunk/test/csv/test_encodings.rb
    trunk/test/csv/test_features.rb
    trunk/test/csv/test_headers.rb
    trunk/test/csv/test_interface.rb
    trunk/test/csv/test_row.rb
    trunk/test/csv/test_serialization.rb
    trunk/test/csv/test_table.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30352)
+++ ChangeLog	(revision 30353)
@@ -1,3 +1,7 @@
+Sat Dec 25 15:58:55 2010  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/csv.rb, test/csv: should not assume $, invariant.
+
 Sat Dec 25 16:08:06 2010  KOSAKI Motohiro  <kosaki.motohiro@g...>
 
 	* signal.c: change rb_atomic_t definition from uchar to uint.
Index: lib/csv.rb
===================================================================
--- lib/csv.rb	(revision 30352)
+++ lib/csv.rb	(revision 30353)
@@ -505,12 +505,12 @@
       end
       str << ">"
       begin
-        str.join
+        str.join('')
       rescue  # any encoding error
         str.map do |s|
           e = Encoding::Converter.asciicompat_encoding(s.encoding)
           e ? s.encode(e) : s.force_encoding("ASCII-8BIT")
-        end.join
+        end.join('')
       end
     end
   end
@@ -845,7 +845,7 @@
         else
           rows + [row.fields.to_csv(options)]
         end
-      end.join
+      end.join('')
     end
     alias_method :to_s, :to_csv
 
@@ -1973,12 +1973,12 @@
     end
     str << ">"
     begin
-      str.join
+      str.join('')
     rescue  # any encoding error
       str.map do |s|
         e = Encoding::Converter.asciicompat_encoding(s.encoding)
         e ? s.encode(e) : s.force_encoding("ASCII-8BIT")
-      end.join
+      end.join('')
     end
   end
 
@@ -2262,7 +2262,7 @@
   # a backslash cannot be transcoded.
   #
   def escape_re(str)
-    str.chars.map { |c| @re_chars.include?(c) ? @re_esc + c : c }.join
+    str.chars.map { |c| @re_chars.include?(c) ? @re_esc + c : c }.join('')
   end
 
   #
@@ -2278,7 +2278,7 @@
   # that encoding.
   #
   def encode_str(*chunks)
-    chunks.map { |chunk| chunk.encode(@encoding.name) }.join
+    chunks.map { |chunk| chunk.encode(@encoding.name) }.join('')
   end
 
   #
Index: test/csv/test_csv_parsing.rb
===================================================================
--- test/csv/test_csv_parsing.rb	(revision 30352)
+++ test/csv/test_csv_parsing.rb	(revision 30353)
@@ -7,10 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
 require "timeout"
 
-require "csv"
+require_relative "base"
 
 #
 # Following tests are my interpretation of the
@@ -18,7 +17,7 @@
 # document in one place (intentionally) and that is to make the default row
 # separator <tt>$/</tt>.
 #
-class TestCSVParsing < Test::Unit::TestCase
+class TestCSV::Parsing < TestCSV
   BIG_DATA = "123456789\n" * 1024
 
   def test_mastering_regex_example
@@ -217,4 +216,6 @@
       end
     end
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_csv_parsing.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_csv_writing.rb
===================================================================
--- test/csv/test_csv_writing.rb	(revision 30352)
+++ test/csv/test_csv_writing.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestCSVWriting < Test::Unit::TestCase
+class TestCSV::Writing < TestCSV
   def test_writing
     [ ["\t",                      ["\t"]],
       ["foo,\"\"\"\"\"\",baz",    ["foo", "\"\"", "baz"]],
@@ -94,4 +92,6 @@
                   CSV.generate_line( [1, "b", nil, %Q{already "quoted"}],
                                      force_quotes: true ) )
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_csv_writing.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_features.rb
===================================================================
--- test/csv/test_features.rb	(revision 30352)
+++ test/csv/test_features.rb	(revision 30353)
@@ -7,12 +7,11 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
 require "zlib"
 
-require "csv"
+require_relative "base"
 
-class TestCSVFeatures < Test::Unit::TestCase
+class TestCSV::Features < TestCSV
   TEST_CASES = [ [%Q{a,b},               ["a", "b"]],
                  [%Q{a,"""b"""},         ["a", "\"b\""]],
                  [%Q{a,"""b"},           ["a", "\"b"]],
@@ -264,4 +263,6 @@
     assert(CSV::VERSION.frozen?)
     assert_match(/\A\d\.\d\.\d\Z/, CSV::VERSION)
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_features.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_interface.rb
===================================================================
--- test/csv/test_interface.rb	(revision 30352)
+++ test/csv/test_interface.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestCSVInterface < Test::Unit::TestCase
+class TestCSV::Interface < TestCSV
   def setup
     @path = File.join(File.dirname(__FILE__), "temp_test_data.csv")
 
@@ -306,4 +304,6 @@
     assert_equal(STDOUT, CSV.instance.instance_eval { @io })
     assert_equal(STDOUT, CSV { |new_csv| new_csv.instance_eval { @io } })
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_interface.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_data_converters.rb
===================================================================
--- test/csv/test_data_converters.rb	(revision 30352)
+++ test/csv/test_data_converters.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestDataConverters < Test::Unit::TestCase
+class TestCSV::DataConverters < TestCSV
   def setup
     @data   = "Numbers,:integer,1,:float,3.015"
     @parser = CSV.new(@data)
@@ -258,4 +256,6 @@
     assert_respond_to(row, :unconverted_fields)
     assert_equal(Array.new, row.unconverted_fields)
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_data_converters.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_row.rb
===================================================================
--- test/csv/test_row.rb	(revision 30352)
+++ test/csv/test_row.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestCSVRow < Test::Unit::TestCase
+class TestCSV::Row < TestCSV
   def setup
     @row = CSV::Row.new(%w{A B C A A}, [1, 2, 3, 4])
   end
@@ -309,4 +307,6 @@
               "Header field pair not found." )
     end
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_row.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_table.rb
===================================================================
--- test/csv/test_table.rb	(revision 30352)
+++ test/csv/test_table.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestCSVTable < Test::Unit::TestCase
+class TestCSV::Table < TestCSV
   def setup
     @rows  = [ CSV::Row.new(%w{A B C}, [1, 2, 3]),
                CSV::Row.new(%w{A B C}, [4, 5, 6]),
@@ -253,7 +251,7 @@
     # with options
     assert_equal( csv.gsub(",", "|").gsub("\n", "\r\n"),
                   @table.to_csv(col_sep: "|", row_sep: "\r\n") )
-    assert_equal( csv.lines.to_a[1..-1].join,
+    assert_equal( csv.lines.to_a[1..-1].join(''),
                   @table.to_csv(:write_headers => false) )
 
     # with headers
@@ -413,4 +411,6 @@
                                   @table.inspect.encoding ),
             "inspect() was not ASCII compatible." )
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_table.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_encodings.rb
===================================================================
--- test/csv/test_encodings.rb	(revision 30352)
+++ test/csv/test_encodings.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2008 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestEncodings < Test::Unit::TestCase
+class TestCSV::Encodings < TestCSV
   def setup
     require 'tempfile'
     @temp_csv_file = Tempfile.new(%w"test_csv. .csv")
@@ -225,7 +223,7 @@
     data = ["foo".force_encoding("US-ASCII"), "\u3042"]
     assert_equal("US-ASCII", data.first.encoding.name)
     assert_equal("UTF-8",    data.last.encoding.name)
-    assert_equal("UTF-8",    data.join.encoding.name)
+    assert_equal("UTF-8",    data.join('').encoding.name)
     assert_equal("UTF-8",    data.to_csv.encoding.name)
   end
   
@@ -233,7 +231,7 @@
     data = ["foo".force_encoding("ISO-8859-1"), "\u3042"]
     assert_equal("ISO-8859-1", data.first.encoding.name)
     assert_equal("UTF-8",      data.last.encoding.name)
-    assert_equal("UTF-8",      data.join.encoding.name)
+    assert_equal("UTF-8",      data.join('').encoding.name)
     assert_equal("UTF-8",      data.to_csv.encoding.name)
   end
 
@@ -260,9 +258,9 @@
     row_sep    = (options[:row_sep]    || "\n").encode(encoding)
     ary.map { |row|
       row.map { |field|
-        [quote_char, field.encode(encoding), quote_char].join
+        [quote_char, field.encode(encoding), quote_char].join('')
       }.join(col_sep) + row_sep
-    }.join.encode(encoding)
+    }.join('').encode(encoding)
   end
   
   def encode_for_tests(data, options = { })
@@ -276,4 +274,6 @@
       yield encoding
     end
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_encodings.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/base.rb
===================================================================
--- test/csv/base.rb	(revision 0)
+++ test/csv/base.rb	(revision 30353)
@@ -0,0 +1,20 @@
+require "test/unit"
+
+require "csv"
+
+class TestCSV < Test::Unit::TestCase
+  module DifferentOFS
+    def setup
+      super
+      @ofs, $, = $,, "-"
+    end
+    def teardown
+      $, = @ofs
+      super
+    end
+  end
+
+  def self.with_diffrent_ofs
+    Class.new(self).class_eval {include DifferentOFS}
+  end
+end

Property changes on: test/csv/base.rb
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: test/csv/test_headers.rb
===================================================================
--- test/csv/test_headers.rb	(revision 30352)
+++ test/csv/test_headers.rb	(revision 30353)
@@ -7,11 +7,9 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
-class TestCSVHeaders < Test::Unit::TestCase
+class TestCSV::Headers < TestCSV
   def setup
     @data = <<-END_CSV.gsub(/^\s+/, "")
     first,second,third
@@ -285,4 +283,6 @@
       assert_instance_of(CSV::Row, row)
     end
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_headers.rb
___________________________________________________________________
Added: svn:executable
   + *

Index: test/csv/test_serialization.rb
===================================================================
--- test/csv/test_serialization.rb	(revision 30352)
+++ test/csv/test_serialization.rb	(revision 30353)
@@ -7,10 +7,8 @@
 #  Copyright 2005 James Edward Gray II. You can redistribute or modify this code
 #  under the terms of Ruby's license.
 
-require "test/unit"
+require_relative "base"
 
-require "csv"
-
 # An example of how to provide custom CSV serialization.
 class Hash
   def self.csv_load( meta, headers, fields )
@@ -26,7 +24,7 @@
   end
 end
 
-class TestSerialization < Test::Unit::TestCase
+class TestCSV::Serialization < TestCSV
 
   ### Classes Used to Test Serialization ###
 
@@ -71,7 +69,7 @@
       @data = CSV.dump(@names)
     end
     assert_equal(<<-END_CLASS_DUMP.gsub(/^\s*/, ""), @data)
-    class,TestSerialization::ReadOnlyName
+    class,TestCSV::Serialization::ReadOnlyName
     @first,@last
     James,Gray
     Dana,Gray
@@ -90,7 +88,7 @@
       @data = CSV.dump(@names)
     end
     assert_equal(<<-END_STRUCT_DUMP.gsub(/^\s*/, ""), @data)
-    class,TestSerialization::Name
+    class,TestCSV::Serialization::Name
     first=,last=
     James,Gray
     Dana,Gray
@@ -109,7 +107,7 @@
       @data = CSV.dump(@names)
     end
     assert_equal(<<-END_STRUCT_DUMP.gsub(/^\s*/, ""), @data)
-    class,TestSerialization::FullName
+    class,TestCSV::Serialization::FullName
     @suffix,first=,last=
     II,James,Gray
     ,Dana,Gray
@@ -137,7 +135,7 @@
 
     assert(File.exist?(data_file))
     assert_equal(<<-END_IO_DUMP.gsub(/^\s*/, ""), File.read(data_file))
-    class,TestSerialization::ReadOnlyName
+    class,TestCSV::Serialization::ReadOnlyName
     @first,@last
     James,Gray
     Dana,Gray
@@ -153,4 +151,6 @@
     obj = {1 => "simple", test: Hash}
     assert_equal(obj, CSV.load(CSV.dump([obj])).first)
   end
+
+  with_diffrent_ofs
 end

Property changes on: test/csv/test_serialization.rb
___________________________________________________________________
Added: svn:executable
   + *


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

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