aboutsummaryrefslogtreecommitdiffstats
path: root/test/csv/test_interface.rb
diff options
context:
space:
mode:
authorhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-09 04:39:16 +0000
committerhsbt <hsbt@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-05-09 04:39:16 +0000
commit5c1941a9be56a979c27d740370b781882d344f79 (patch)
tree7478e42cde5b470b4df2eb40f89ee25f2621f5aa /test/csv/test_interface.rb
parentdfc56b8c432d6a374c18cba7048d05175bcfba05 (diff)
downloadruby-5c1941a9be56a979c27d740370b781882d344f79.tar.gz
Merge csv-1.0.2 from upstream.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63364 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/test_interface.rb')
-rwxr-xr-xtest/csv/test_interface.rb56
1 files changed, 53 insertions, 3 deletions
diff --git a/test/csv/test_interface.rb b/test/csv/test_interface.rb
index be27fcd616..912e2ec7f5 100755
--- a/test/csv/test_interface.rb
+++ b/test/csv/test_interface.rb
@@ -4,9 +4,7 @@
# tc_interface.rb
#
-# Created by James Edward Gray II on 2005-10-31.
-# Copyright 2005 James Edward Gray II. You can redistribute or modify this code
-# under the terms of Ruby's license.
+# Created by James Edward Gray II on 2005-10-31.
require_relative "base"
require "tempfile"
@@ -64,6 +62,55 @@ class TestCSV::Interface < TestCSV
assert_equal("Return value.", ret)
end
+ def test_open_encoding_valid
+ # U+1F600 GRINNING FACE
+ # U+1F601 GRINNING FACE WITH SMILING EYES
+ File.open(@path, "w") do |file|
+ file << "\u{1F600},\u{1F601}"
+ end
+ CSV.open(@path, encoding: "utf-8") do |csv|
+ assert_equal([["\u{1F600}", "\u{1F601}"]],
+ csv.to_a)
+ end
+ end
+
+ def test_open_encoding_invalid
+ # U+1F600 GRINNING FACE
+ # U+1F601 GRINNING FACE WITH SMILING EYES
+ File.open(@path, "w") do |file|
+ file << "\u{1F600},\u{1F601}"
+ end
+ CSV.open(@path, encoding: "EUC-JP") do |csv|
+ error = assert_raise(CSV::MalformedCSVError) do
+ csv.shift
+ end
+ assert_equal("Invalid byte sequence in EUC-JP in line 1.",
+ error.message)
+ end
+ end
+
+ def test_open_encoding_nonexistent
+ _output, error = capture_io do
+ CSV.open(@path, encoding: "nonexistent") do
+ end
+ end
+ assert_equal("path:0: warning: Unsupported encoding nonexistent ignored\n",
+ error.gsub(/\A.+:\d+: /, "path:0: "))
+ end
+
+ def test_open_encoding_utf_8_with_bom
+ # U+FEFF ZERO WIDTH NO-BREAK SPACE, BOM
+ # U+1F600 GRINNING FACE
+ # U+1F601 GRINNING FACE WITH SMILING EYES
+ File.open(@path, "w") do |file|
+ file << "\u{FEFF}\u{1F600},\u{1F601}"
+ end
+ CSV.open(@path, encoding: "bom|utf-8") do |csv|
+ assert_equal([["\u{1F600}", "\u{1F601}"]],
+ csv.to_a)
+ end
+ end
+
def test_parse
data = File.binread(@path)
assert_equal( @expected,
@@ -161,6 +208,9 @@ class TestCSV::Interface < TestCSV
assert_equal(csv, csv << ["last", %Q{"row"}])
end
assert_equal(%Q{1,2,3\n4,,5\nlast,"""row"""\n}, str)
+
+ out = CSV.generate("test") { |csv| csv << ["row"] }
+ assert_equal("testrow\n", out)
end
def test_generate_line