Skip to content

Commit 29723a0

Browse files
BurdetteLamarkou
andauthored
csv-filter: add --input-quote-char (#333)
Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
1 parent 559fbf7 commit 29723a0

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

bin/csv-filter

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ parser.on('--input-col-sep=SEPARATOR',
2222
options[:input_col_sep] = value
2323
end
2424

25+
parser.on('--input-quote-char=SEPARATOR',
26+
'Input quote character.') do |value|
27+
options[:input_quote_char] = value
28+
end
29+
2530
parser.on('--input-row-sep=SEPARATOR',
2631
'Input row separator string.') do |value|
2732
options[:input_row_sep] = value

test/csv/test_csv_filter.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@ def test_option_input_col_sep
7878
run_csv_filter(csv, "--input-col-sep=:"))
7979
end
8080

81+
def test_option_input_quote_char
82+
input_quote_char = "'"
83+
csv_text = CSV.generate(quote_char: input_quote_char) do |csv|
84+
csv << ['foo', 0]
85+
csv << ["'bar'", 1]
86+
csv << ['"baz"', 2]
87+
end
88+
expected = <<-EXPECTED
89+
foo,0
90+
'bar',1
91+
"""baz""",2
92+
EXPECTED
93+
assert_equal([expected, ""], run_csv_filter(csv_text, "--input-quote-char=#{input_quote_char}"))
94+
end
95+
8196
def test_option_input_row_sep
8297
csv = "aaa,bbb,ccc:ddd,eee,fff:"
8398
assert_equal(["aaa,bbb,ccc\nddd,eee,fff\n", ""],

0 commit comments

Comments
 (0)