summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-25 06:58:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-12-25 06:58:58 +0000
commitd05217109fb5e909bbd7849bcc799b6404c7c8b0 (patch)
tree59c6e741e5c94660ea5860d745fffec33274121b /test
parent47a1cd1291f1f52cc8d36cb533e0d653d128930a (diff)
* lib/csv.rb, test/csv: should not assume $, invariant.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/csv/base.rb20
-rwxr-xr-x[-rw-r--r--]test/csv/test_csv_parsing.rb7
-rwxr-xr-x[-rw-r--r--]test/csv/test_csv_writing.rb8
-rwxr-xr-x[-rw-r--r--]test/csv/test_data_converters.rb8
-rwxr-xr-x[-rw-r--r--]test/csv/test_encodings.rb16
-rwxr-xr-x[-rw-r--r--]test/csv/test_features.rb7
-rwxr-xr-x[-rw-r--r--]test/csv/test_headers.rb8
-rwxr-xr-x[-rw-r--r--]test/csv/test_interface.rb8
-rwxr-xr-x[-rw-r--r--]test/csv/test_row.rb8
-rwxr-xr-x[-rw-r--r--]test/csv/test_serialization.rb16
-rwxr-xr-x[-rw-r--r--]test/csv/test_table.rb10
11 files changed, 69 insertions, 47 deletions
diff --git a/test/csv/base.rb b/test/csv/base.rb
new file mode 100644
index 0000000000..c0f5bd990b
--- /dev/null
+++ b/test/csv/base.rb
@@ -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
diff --git a/test/csv/test_csv_parsing.rb b/test/csv/test_csv_parsing.rb
index c0b8d83f96..6b50ab382e 100644..100755
--- a/test/csv/test_csv_parsing.rb
+++ b/test/csv/test_csv_parsing.rb
@@ -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 @@ require "csv"
# 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 @@ class TestCSVParsing < Test::Unit::TestCase
end
end
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_csv_writing.rb b/test/csv/test_csv_writing.rb
index eacba49613..73a27d2b96 100644..100755
--- a/test/csv/test_csv_writing.rb
+++ b/test/csv/test_csv_writing.rb
@@ -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 @@ class TestCSVWriting < Test::Unit::TestCase
CSV.generate_line( [1, "b", nil, %Q{already "quoted"}],
force_quotes: true ) )
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_data_converters.rb b/test/csv/test_data_converters.rb
index 1ad5093424..06653f5ec9 100644..100755
--- a/test/csv/test_data_converters.rb
+++ b/test/csv/test_data_converters.rb
@@ -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 @@ class TestDataConverters < Test::Unit::TestCase
assert_respond_to(row, :unconverted_fields)
assert_equal(Array.new, row.unconverted_fields)
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_encodings.rb b/test/csv/test_encodings.rb
index 82dca914fe..6681470097 100644..100755
--- a/test/csv/test_encodings.rb
+++ b/test/csv/test_encodings.rb
@@ -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 @@ class TestEncodings < Test::Unit::TestCase
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 @@ class TestEncodings < Test::Unit::TestCase
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 @@ class TestEncodings < Test::Unit::TestCase
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 @@ class TestEncodings < Test::Unit::TestCase
yield encoding
end
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb
index 58efd1c9b3..4141f39480 100644..100755
--- a/test/csv/test_features.rb
+++ b/test/csv/test_features.rb
@@ -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 @@ class TestCSVFeatures < Test::Unit::TestCase
assert(CSV::VERSION.frozen?)
assert_match(/\A\d\.\d\.\d\Z/, CSV::VERSION)
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_headers.rb b/test/csv/test_headers.rb
index 6e56ffc27c..ef955fb492 100644..100755
--- a/test/csv/test_headers.rb
+++ b/test/csv/test_headers.rb
@@ -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 @@ class TestCSVHeaders < Test::Unit::TestCase
assert_instance_of(CSV::Row, row)
end
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb
index a58e9c6179..8bcd134781 100644..100755
--- a/test/csv/test_interface.rb
+++ b/test/csv/test_interface.rb
@@ -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 @@ class TestCSVInterface < Test::Unit::TestCase
assert_equal(STDOUT, CSV.instance.instance_eval { @io })
assert_equal(STDOUT, CSV { |new_csv| new_csv.instance_eval { @io } })
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_row.rb b/test/csv/test_row.rb
index f9aa959701..b2d94fa4d6 100644..100755
--- a/test/csv/test_row.rb
+++ b/test/csv/test_row.rb
@@ -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 @@ class TestCSVRow < Test::Unit::TestCase
"Header field pair not found." )
end
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_serialization.rb b/test/csv/test_serialization.rb
index 5f0201ed90..989a7e98b5 100644..100755
--- a/test/csv/test_serialization.rb
+++ b/test/csv/test_serialization.rb
@@ -7,9 +7,7 @@
# Copyright 2005 James Edward Gray II. You can redistribute or modify this code
# under the terms of Ruby's license.
-require "test/unit"
-
-require "csv"
+require_relative "base"
# An example of how to provide custom CSV serialization.
class Hash
@@ -26,7 +24,7 @@ class Hash
end
end
-class TestSerialization < Test::Unit::TestCase
+class TestCSV::Serialization < TestCSV
### Classes Used to Test Serialization ###
@@ -71,7 +69,7 @@ class TestSerialization < Test::Unit::TestCase
@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 @@ class TestSerialization < Test::Unit::TestCase
@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 @@ class TestSerialization < Test::Unit::TestCase
@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 @@ class TestSerialization < Test::Unit::TestCase
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 @@ class TestSerialization < Test::Unit::TestCase
obj = {1 => "simple", test: Hash}
assert_equal(obj, CSV.load(CSV.dump([obj])).first)
end
+
+ with_diffrent_ofs
end
diff --git a/test/csv/test_table.rb b/test/csv/test_table.rb
index d0b421750f..67e5b54daf 100644..100755
--- a/test/csv/test_table.rb
+++ b/test/csv/test_table.rb
@@ -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 @@ class TestCSVTable < Test::Unit::TestCase
# 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 @@ class TestCSVTable < Test::Unit::TestCase
@table.inspect.encoding ),
"inspect() was not ASCII compatible." )
end
+
+ with_diffrent_ofs
end