summaryrefslogtreecommitdiff
path: root/test/csv/write/test_quote_empty.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/csv/write/test_quote_empty.rb')
-rw-r--r--test/csv/write/test_quote_empty.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/csv/write/test_quote_empty.rb b/test/csv/write/test_quote_empty.rb
new file mode 100644
index 0000000000..70f73dad4a
--- /dev/null
+++ b/test/csv/write/test_quote_empty.rb
@@ -0,0 +1,70 @@
+# -*- coding: utf-8 -*-
+# frozen_string_literal: false
+
+require_relative "../helper"
+
+module TestCSVWriteQuoteEmpty
+ def test_quote_empty_default
+ assert_equal(%Q["""",""#{$INPUT_RECORD_SEPARATOR}],
+ generate_line([%Q["], ""]))
+ end
+
+ def test_quote_empty_false
+ assert_equal(%Q["""",#{$INPUT_RECORD_SEPARATOR}],
+ generate_line([%Q["], ""],
+ quote_empty: false))
+ end
+
+ def test_empty_default
+ assert_equal(%Q[foo,"",baz#{$INPUT_RECORD_SEPARATOR}],
+ generate_line(["foo", "", "baz"]))
+ end
+
+ def test_empty_false
+ assert_equal(%Q[foo,,baz#{$INPUT_RECORD_SEPARATOR}],
+ generate_line(["foo", "", "baz"],
+ quote_empty: false))
+ end
+
+ def test_empty_only_default
+ assert_equal(%Q[""#{$INPUT_RECORD_SEPARATOR}],
+ generate_line([""]))
+ end
+
+ def test_empty_only_false
+ assert_equal(%Q[#{$INPUT_RECORD_SEPARATOR}],
+ generate_line([""],
+ quote_empty: false))
+ end
+
+ def test_empty_double_default
+ assert_equal(%Q["",""#{$INPUT_RECORD_SEPARATOR}],
+ generate_line(["", ""]))
+ end
+
+ def test_empty_double_false
+ assert_equal(%Q[,#{$INPUT_RECORD_SEPARATOR}],
+ generate_line(["", ""],
+ quote_empty: false))
+ end
+end
+
+class TestCSVWriteQuoteEmptyGenerateLine < Test::Unit::TestCase
+ include TestCSVWriteQuoteEmpty
+ extend DifferentOFS
+
+ def generate_line(row, **kwargs)
+ CSV.generate_line(row, **kwargs)
+ end
+end
+
+class TestCSVWriteQuoteEmptyGenerate < Test::Unit::TestCase
+ include TestCSVWriteQuoteEmpty
+ extend DifferentOFS
+
+ def generate_line(row, **kwargs)
+ CSV.generate(**kwargs) do |csv|
+ csv << row
+ end
+ end
+end