summaryrefslogtreecommitdiff
path: root/test/csv/interface
diff options
context:
space:
mode:
authorKoichi ITO <koic.ito@gmail.com>2020-06-02 08:30:25 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-07-20 02:32:51 +0900
commit4e33a878793a5ced47a4f14b8a73cbc2795d97b7 (patch)
treecd3173a3b2dbbe97d84e800598a874c8620d00bf /test/csv/interface
parentcf8157e0016dd0eb60fe6f03bef168261f729b83 (diff)
[ruby/csv] Add `undef: :replace` for `CSV.open` (#129)
This PR adds `undef: :replace` option for `CSV.open`. `File.open` has `undef: :replace` option, but `CSV.open` does not. It would be convenient if `CSV.open` could have a shortcut by having `undef: :replace` option. https://github.com/ruby/csv/commit/cff8b18480
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3332
Diffstat (limited to 'test/csv/interface')
-rw-r--r--test/csv/interface/test_read.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/csv/interface/test_read.rb b/test/csv/interface/test_read.rb
index 58ec188f94..4b0f5e7e96 100644
--- a/test/csv/interface/test_read.rb
+++ b/test/csv/interface/test_read.rb
@@ -125,6 +125,28 @@ class TestCSVInterfaceRead < Test::Unit::TestCase
end
end
+ def test_open_with_undef_replace
+ # U+00B7 Middle Dot
+ CSV.open(@input.path, "w", encoding: Encoding::CP932, undef: :replace) do |rows|
+ rows << ["\u00B7"]
+ end
+ CSV.open(@input.path, encoding: Encoding::CP932) do |csv|
+ assert_equal([["?"]],
+ csv.to_a)
+ end
+ end
+
+ def test_open_with_undef_replace_and_replace_string
+ # U+00B7 Middle Dot
+ CSV.open(@input.path, "w", encoding: Encoding::CP932, undef: :replace, replace: "X") do |rows|
+ rows << ["\u00B7"]
+ end
+ CSV.open(@input.path, encoding: Encoding::CP932) do |csv|
+ assert_equal([["X"]],
+ csv.to_a)
+ end
+ end
+
def test_parse
assert_equal(@rows,
CSV.parse(@data, col_sep: "\t", row_sep: "\r\n"))