summaryrefslogtreecommitdiff
path: root/test/csv/test_encodings.rb
diff options
context:
space:
mode:
authorSutou Kouhei <kou@clear-code.com>2020-07-19 06:25:05 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-20 02:32:55 +0900
commit4fcfa85cb6a44b4e8c7a47578b50064711dff404 (patch)
treebcbabfa80db2a3cebca9551157b784306d57387c /test/csv/test_encodings.rb
parent178649e6dcb679f4b42cbf723d4f34f81a591304 (diff)
[ruby/csv] CSV.generate_line: use the encoding of the first non ASCII field as the expected encoding
See also: https://github.com/ruby/stringio/issues/13#issuecomment-660543554 https://github.com/ruby/csv/commit/004cf49d18
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3332
Diffstat (limited to 'test/csv/test_encodings.rb')
-rw-r--r--test/csv/test_encodings.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/csv/test_encodings.rb b/test/csv/test_encodings.rb
index cd63af6a83..8d228c05f3 100644
--- a/test/csv/test_encodings.rb
+++ b/test/csv/test_encodings.rb
@@ -242,6 +242,18 @@ class TestCSVEncodings < Test::Unit::TestCase
assert_equal("UTF-8", data.to_csv.encoding.name)
end
+ def test_encoding_is_not_upgraded_for_non_ascii_content_during_writing_as_needed
+ data = ["\u00c0".encode("ISO-8859-1"), "\u3042"]
+ assert_equal([
+ "ISO-8859-1",
+ "UTF-8",
+ ],
+ data.collect {|field| field.encoding.name})
+ assert_raise(Encoding::CompatibilityError) do
+ data.to_csv
+ end
+ end
+
def test_explicit_encoding
bug9766 = '[ruby-core:62113] [Bug #9766]'
s = CSV.generate(encoding: "Windows-31J") do |csv|