summaryrefslogtreecommitdiff
path: root/test/csv/write
diff options
context:
space:
mode:
authorkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-14 21:01:51 +0000
committerkou <kou@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-04-14 21:01:51 +0000
commite3b6c7c7ebca1b051dbaa6f33494e92f5638fcc9 (patch)
treef98e60ecbeb320a9e9d8bdacfa3f9231cd55ddda /test/csv/write
parentfb96811d15f83c6b692e8e00d458eef32032af6a (diff)
Import CSV 3.0.8
This includes performance improvements and backward incompatibility fixes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67560 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/csv/write')
-rw-r--r--test/csv/write/test_converters.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/csv/write/test_converters.rb b/test/csv/write/test_converters.rb
new file mode 100644
index 00000000000..a93b1040ac6
--- /dev/null
+++ b/test/csv/write/test_converters.rb
@@ -0,0 +1,53 @@
+# -*- coding: utf-8 -*-
+# frozen_string_literal: false
+
+require_relative "../helper"
+
+module TestCSVWriteConverters
+ def test_one
+ assert_equal(%Q[=a,=b,=c\n],
+ generate_line(["a", "b", "c"],
+ write_converters: ->(value) {"=" + value}))
+ end
+
+ def test_multiple
+ assert_equal(%Q[=a_,=b_,=c_\n],
+ generate_line(["a", "b", "c"],
+ write_converters: [
+ ->(value) {"=" + value},
+ ->(value) {value + "_"},
+ ]))
+ end
+
+ def test_nil_value
+ assert_equal(%Q[a,NaN,c\n],
+ generate_line(["a", nil, "c"],
+ write_nil_value: "NaN"))
+ end
+
+ def test_empty_value
+ assert_equal(%Q[a,,c\n],
+ generate_line(["a", "", "c"],
+ write_empty_value: nil))
+ end
+end
+
+class TestCSVWriteConvertersGenerateLine < Test::Unit::TestCase
+ include TestCSVWriteConverters
+ extend DifferentOFS
+
+ def generate_line(row, **kwargs)
+ CSV.generate_line(row, **kwargs)
+ end
+end
+
+class TestCSVWriteConvertersGenerate < Test::Unit::TestCase
+ include TestCSVWriteConverters
+ extend DifferentOFS
+
+ def generate_line(row, **kwargs)
+ CSV.generate(**kwargs) do |csv|
+ csv << row
+ end
+ end
+end