From 8d653baee9dd3dd965e4b33e5d1e1b365f824115 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Fri, 28 Feb 2025 13:24:26 -0600 Subject: [PATCH 1/6] csv-filter: add --input_quote_char --- bin/csv-filter | 5 +++++ test/csv/test_csv_filter.rb | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/bin/csv-filter b/bin/csv-filter index 8eddc538..da8de1dd 100755 --- a/bin/csv-filter +++ b/bin/csv-filter @@ -22,6 +22,11 @@ parser.on('--input-col-sep=SEPARATOR', options[:input_col_sep] = value end +parser.on('--input-quote_char=SEPARATOR', + 'Input quote character.') do |value| + options[:input_quote_char] = value +end + parser.on('--input-row-sep=SEPARATOR', 'Input row separator string.') do |value| options[:input_row_sep] = value diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index dc9f432a..10aa8460 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -78,6 +78,17 @@ def test_option_input_col_sep run_csv_filter(csv, "--input-col-sep=:")) end + def test_option_input_quote_char + input_quote_char = "'" + str = CSV.generate(quote_char: input_quote_char) do |csv| + csv << ['foo', 0] + csv << ["'bar'", 1] + csv << ['"baz"', 2] + end + assert_equal(["foo,0\n" + "'bar',1\n" + "\"\"\"baz\"\"\",2\n", ""], + run_csv_filter(str, "--input-quote_char=#{input_quote_char}")) + end + def test_option_input_row_sep csv = "aaa,bbb,ccc:ddd,eee,fff:" assert_equal(["aaa,bbb,ccc\nddd,eee,fff\n", ""], From b3eb9c8f746630ad058734474ec4c91ececeed5f Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Fri, 28 Feb 2025 18:18:56 -0600 Subject: [PATCH 2/6] Update bin/csv-filter Co-authored-by: Sutou Kouhei --- bin/csv-filter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/csv-filter b/bin/csv-filter index da8de1dd..8f273984 100755 --- a/bin/csv-filter +++ b/bin/csv-filter @@ -22,7 +22,7 @@ parser.on('--input-col-sep=SEPARATOR', options[:input_col_sep] = value end -parser.on('--input-quote_char=SEPARATOR', +parser.on('--input-quote-char=SEPARATOR', 'Input quote character.') do |value| options[:input_quote_char] = value end From 37306396c27a2ccf1b37198a122fae6e6ba05050 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Fri, 28 Feb 2025 18:19:07 -0600 Subject: [PATCH 3/6] Update test/csv/test_csv_filter.rb Co-authored-by: Sutou Kouhei --- test/csv/test_csv_filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index 10aa8460..37435c75 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -86,7 +86,7 @@ def test_option_input_quote_char csv << ['"baz"', 2] end assert_equal(["foo,0\n" + "'bar',1\n" + "\"\"\"baz\"\"\",2\n", ""], - run_csv_filter(str, "--input-quote_char=#{input_quote_char}")) + run_csv_filter(str, "--input-quote-char=#{input_quote_char}")) end def test_option_input_row_sep From 8ca18f5936639b9c83856debf0818336089383e9 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 1 Mar 2025 10:29:52 -0600 Subject: [PATCH 4/6] Update test/csv/test_csv_filter.rb Co-authored-by: Sutou Kouhei --- test/csv/test_csv_filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index 37435c75..fe4da462 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -80,7 +80,7 @@ def test_option_input_col_sep def test_option_input_quote_char input_quote_char = "'" - str = CSV.generate(quote_char: input_quote_char) do |csv| + csv_text = CSV.generate(quote_char: input_quote_char) do |csv| csv << ['foo', 0] csv << ["'bar'", 1] csv << ['"baz"', 2] From 05a6408de4419b37e88b33ae6a4ed95fddab8003 Mon Sep 17 00:00:00 2001 From: Burdette Lamar Date: Sat, 1 Mar 2025 10:30:23 -0600 Subject: [PATCH 5/6] Update test/csv/test_csv_filter.rb Co-authored-by: Sutou Kouhei --- test/csv/test_csv_filter.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index fe4da462..bbb28a59 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -85,8 +85,11 @@ def test_option_input_quote_char csv << ["'bar'", 1] csv << ['"baz"', 2] end - assert_equal(["foo,0\n" + "'bar',1\n" + "\"\"\"baz\"\"\",2\n", ""], - run_csv_filter(str, "--input-quote-char=#{input_quote_char}")) + assert_equal([<<-OUTPUT, ""], run_csv_filter(str, "--input-quote-char=#{input_quote_char}")) +foo,0 +'bar',1 +"""baz""",2 + OUTPUT end def test_option_input_row_sep From 6989d9c125877c9576644598a06a6e90e8dc981f Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sun, 2 Mar 2025 10:46:57 -0600 Subject: [PATCH 6/6] Update test/csv/test_csv_filter.rb --- test/csv/test_csv_filter.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index bbb28a59..bbe13910 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -85,11 +85,12 @@ def test_option_input_quote_char csv << ["'bar'", 1] csv << ['"baz"', 2] end - assert_equal([<<-OUTPUT, ""], run_csv_filter(str, "--input-quote-char=#{input_quote_char}")) + expected = <<-EXPECTED foo,0 'bar',1 """baz""",2 - OUTPUT + EXPECTED + assert_equal([expected, ""], run_csv_filter(csv_text, "--input-quote-char=#{input_quote_char}")) end def test_option_input_row_sep