ruby-changes:54710
From: naruse <ko1@a...>
Date: Sat, 26 Jan 2019 17:02:53 +0900 (JST)
Subject: [ruby-changes:54710] naruse:r66926 (ruby_2_6): merge revision(s) 66922: [Backport #15521]
naruse 2019-01-26 17:02:47 +0900 (Sat, 26 Jan 2019) New Revision: 66926 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66926 Log: merge revision(s) 66922: [Backport #15521] Upgrade CSV to 3.0.4 Added directories: branches/ruby_2_6/test/csv/parse/ branches/ruby_2_6/test/csv/write/ Added files: branches/ruby_2_6/test/csv/helper.rb Removed files: branches/ruby_2_6/test/csv/base.rb branches/ruby_2_6/test/csv/test_csv_parsing.rb branches/ruby_2_6/test/csv/test_csv_writing.rb branches/ruby_2_6/test/csv/test_headers.rb branches/ruby_2_6/test/csv/ts_all.rb Modified directories: branches/ruby_2_6/ Modified files: branches/ruby_2_6/NEWS branches/ruby_2_6/lib/csv/csv.gemspec branches/ruby_2_6/lib/csv/parser.rb branches/ruby_2_6/lib/csv/row.rb branches/ruby_2_6/lib/csv/table.rb branches/ruby_2_6/lib/csv/version.rb branches/ruby_2_6/lib/csv/writer.rb branches/ruby_2_6/lib/csv.rb branches/ruby_2_6/test/csv/test_data_converters.rb branches/ruby_2_6/test/csv/test_encodings.rb branches/ruby_2_6/test/csv/test_features.rb branches/ruby_2_6/test/csv/test_interface.rb branches/ruby_2_6/test/csv/test_row.rb branches/ruby_2_6/test/csv/test_table.rb branches/ruby_2_6/version.h Index: ruby_2_6/test/csv/base.rb =================================================================== --- ruby_2_6/test/csv/base.rb (revision 66925) +++ ruby_2_6/test/csv/base.rb (nonexistent) @@ -1,9 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/csv/base.rb#L0 -# frozen_string_literal: false -require "test/unit" - -require "csv" - -require_relative "../lib/with_different_ofs.rb" - -class TestCSV < Test::Unit::TestCase -end Property changes on: ruby_2_6/test/csv/base.rb ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Index: ruby_2_6/test/csv/test_headers.rb =================================================================== --- ruby_2_6/test/csv/test_headers.rb (revision 66925) +++ ruby_2_6/test/csv/test_headers.rb (nonexistent) @@ -1,318 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/csv/test_headers.rb#L0 -#!/usr/bin/env ruby -w -# encoding: UTF-8 -# frozen_string_literal: false - -# tc_headers.rb -# -# Created by James Edward Gray II on 2005-10-31. - -require_relative "base" - -class TestCSV::Headers < TestCSV - extend DifferentOFS - - def setup - super - @data = <<-CSV -first,second,third -A,B,C -1,2,3 - CSV - end - - def test_first_row - [:first_row, true].each do |setting| # two names for the same setting - # activate headers - csv = nil - assert_nothing_raised(Exception) do - csv = CSV.parse(@data, headers: setting) - end - - # first data row - skipping headers - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{first A}, %w{second B}, %w{third C}], row.to_a) - - # second data row - row = csv[1] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{first 1}, %w{second 2}, %w{third 3}], row.to_a) - - # empty - assert_nil(csv[2]) - end - end - - def test_array_of_headers - # activate headers - csv = nil - assert_nothing_raised(Exception) do - csv = CSV.parse(@data, headers: [:my, :new, :headers]) - end - - # first data row - skipping headers - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal( [[:my, "first"], [:new, "second"], [:headers, "third"]], - row.to_a ) - - # second data row - row = csv[1] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([[:my, "A"], [:new, "B"], [:headers, "C"]], row.to_a) - - # third data row - row = csv[2] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([[:my, "1"], [:new, "2"], [:headers, "3"]], row.to_a) - - # empty - assert_nil(csv[3]) - - # with return and convert - assert_nothing_raised(Exception) do - csv = CSV.parse( @data, headers: [:my, :new, :headers], - return_headers: true, - header_converters: lambda { |h| h.to_s } ) - end - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([["my", :my], ["new", :new], ["headers", :headers]], row.to_a) - assert_predicate(row, :header_row?) - assert_not_predicate(row, :field_row?) - end - - def test_csv_header_string - # activate headers - csv = nil - assert_nothing_raised(Exception) do - csv = CSV.parse(@data, headers: "my,new,headers") - end - - # first data row - skipping headers - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{my first}, %w{new second}, %w{headers third}], row.to_a) - - # second data row - row = csv[1] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{my A}, %w{new B}, %w{headers C}], row.to_a) - - # third data row - row = csv[2] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{my 1}, %w{new 2}, %w{headers 3}], row.to_a) - - # empty - assert_nil(csv[3]) - - # with return and convert - assert_nothing_raised(Exception) do - csv = CSV.parse( @data, headers: "my,new,headers", - return_headers: true, - header_converters: :symbol ) - end - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([[:my, "my"], [:new, "new"], [:headers, "headers"]], row.to_a) - assert_predicate(row, :header_row?) - assert_not_predicate(row, :field_row?) - end - - def test_csv_header_string_inherits_separators - # parse with custom col_sep - csv = nil - assert_nothing_raised(Exception) do - csv = CSV.parse( @data.tr(",", "|"), col_sep: "|", - headers: "my|new|headers" ) - end - - # verify headers were recognized - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{my first}, %w{new second}, %w{headers third}], row.to_a) - end - - def test_return_headers - # activate headers and request they are returned - csv = nil - assert_nothing_raised(Exception) do - csv = CSV.parse(@data, headers: true, return_headers: true) - end - - # header row - row = csv[0] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal( [%w{first first}, %w{second second}, %w{third third}], - row.to_a ) - assert_predicate(row, :header_row?) - assert_not_predicate(row, :field_row?) - - # first data row - skipping headers - row = csv[1] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{first A}, %w{second B}, %w{third C}], row.to_a) - assert_not_predicate(row, :header_row?) - assert_predicate(row, :field_row?) - - # second data row - row = csv[2] - assert_not_nil(row) - assert_instance_of(CSV::Row, row) - assert_equal([%w{first 1}, %w{second 2}, %w{third 3}], row.to_a) - assert_not_predicate(row, :header_row?) - assert_predicate(row, :field_row?) - - # empty - assert_nil(csv[3]) - end - - def test_converters - # create test data where headers and fields look alike - data = <<-CSV -1,2,3 -1,2,3 - CSV - - # normal converters do not affect headers - csv = CSV.parse( data, headers: true, - return_headers: true, - converters: :numeric ) - assert_equal([%w{1 1}, %w{2 2}, %w{3 3}], csv[0].to_a) - assert_equal([["1", 1], ["2", 2], ["3", 3]], csv[1].to_a) - assert_nil(csv[2]) - - # header converters do affect headers (only) - assert_nothing_raised(Exception) do - csv = CSV.parse( data, headers: true, - return_headers: true, - converters: :numeric, - header_converters: :symbol ) - end - assert_equal([[:"1", "1"], [:"2", "2"], [:"3", "3"]], csv[0].to_a) - assert_equal([[:"1", 1], [:"2", 2], [:"3", 3]], csv[1].to_a) - assert_nil(csv[2]) - end - - def test_builtin_downcase_converter - csv = CSV.parse( "One,TWO Three", headers: true, - return_headers: true, - header_converters: :downcase ) - assert_equal(%w{one two\ three}, csv.headers) - end - - def test_builtin_symbol_converter - # Note that the trailing space is intentional - csv = CSV.parse( "One,TWO Three ", headers: true, - return_headers: true, - header_converters: :symbol ) - assert_equal([:one, :two_three], csv.headers) - end - - def test_builtin_symbol_converter_with_punctuation - csv = CSV.parse( "One, Two & Three ($)", headers: true, - return_headers: true, - header_converters: :symbol ) - assert_equal([:one, :two_three], csv.headers) - end - - def test_builtin_converters_with_blank_header - csv = CSV.parse( "one,,three", headers: true, - return_headers: true, - header_converters: [:downcase, :symbol] ) - assert_equal([:one, nil, :three], csv.headers) - end - - def test_custom_converter - converter = lambda { |header| header.tr(" ", "_") } - csv = CSV.parse( "One,TWO Three", - headers: true, - return_headers: true, - header_converters: converter ) - assert_equal(%w{One TWO_Three}, csv.headers) - end - - def test_table_support - csv = nil - assert_nothing_raised(Exception) do - csv = CSV.parse(@data, headers: true) - end - - assert_instance_of(CSV::Table, csv) - end - - def test_skip_blanks - @data = <<-CSV - - -A,B,C - -1,2,3 - - - - CSV - - expected = [%w[1 2 3]] - CSV.parse(@data, headers: true, skip_blanks: true) do |row| - assert_equal(expected.shift, row.fields) - end - - expected = [%w[A B C], %w[1 2 3]] - CSV.parse( @data, - headers: true, - return_headers: true, - skip_blanks: true ) do |row| - assert_equal(expected.shift, row.fields) - end - end - - def test_headers_reader - # no headers - assert_nil(CSV.new(@data).headers) - - # headers - csv = CSV.new(@data, headers: true) - assert_equal(true, csv.headers) # before headers are read - csv.shift # set headers - assert_equal(%w[first second third], csv.headers) # after headers are read - end - - def test_blank_row - @data += "\n#{@data}" # add a blank row - - # ensure that everything returned is a Row object - CSV.parse(@data, headers: true) do |row| - assert_instance_of(CSV::Row, row) - end - end - - def test_nil_row_header - @data = <<-CSV -A - -1 - CSV - - csv = CSV.parse(@data, headers: true) - - # ensure nil row creates Row object with headers - row = csv[0] - assert_equal([["A"], [nil]], - [row.headers, row.fields]) - end -end Property changes on: ruby_2_6/test/csv/test_headers.rb ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Deleted: svn:executable ## -1 +0,0 ## -* \ No newline at end of property Index: ruby_2_6/test/csv/test_csv_parsing.rb =================================================================== --- ruby_2_6/test/csv/test_csv_parsing.rb (revision 66925) +++ ruby_2_6/test/csv/test_csv_parsing.rb (nonexistent) @@ -1,267 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_6/test/csv/test_csv_parsing.rb#L0 -#!/usr/bin/env ruby -w -# encoding: UTF-8 -# frozen_string_literal: false - -# tc_csv_parsing.rb -# -# Created by James Edward Gray II on 2005-10-31. - -require "timeout" - -require_relative "base" - -# -# Following tests are my interpretation of the -# {CSV RCF}[http://www.ietf.org/rfc/rfc4180.txt]. I only deviate from that -# document in one place (intentionally) and that is to make the default row -# separator <tt>$/</tt>. -# -class TestCSV::Parsing < TestCSV - extend DifferentOFS - - BIG_DATA = "123456789\n" * 1024 - - def test_mastering_regex_example - ex = %Q{Ten Thousand,10000, 2710 ,,"10,000","It's ""10 Grand"", baby",10K} - assert_equal( [ "Ten Thousand", "10000", " 2710 ", nil, "10,000", - "It's \"10 Grand\", baby", "10K" ], - CSV.parse_line(ex) ) - end - - # Old Ruby 1.8 CSV library tests. - def test_std_lib_csv - [ ["\t", ["\t"]], - ["foo,\"\"\"\"\"\",baz", ["foo", "\"\"", "baz"]], - ["foo,\"\"\"bar\"\"\",baz", ["foo", "\"bar\"", "baz"]], - ["\"\"\"\n\",\"\"\"\n\"", ["\"\n", "\"\n"]], - ["foo,\"\r\n\",baz", ["foo", "\r\n", "baz"]], - ["\"\"", [""]], - ["foo,\"\"\"\",baz", ["foo", "\"", "baz"]], - ["foo,\"\r.\n\",baz", ["foo", "\r.\n", "baz"]], - ["foo,\"\r\",baz", ["foo", "\r", "baz"]], - ["foo,\"\",baz", ["foo", "", "baz"]], - ["\",\"", [","]], - ["foo", ["foo"]], - [",,", [nil, nil, nil]], - [",", [nil, nil]], - ["foo,\"\n\",baz", ["foo", "\n", "baz"]], - ["foo,,baz", ["foo", nil, "baz"]], - ["\"\"\"\r\",\"\"\"\r\"", ["\"\r", "\"\r"]], - ["\",\",\",\"", [",", ","]], - ["foo,bar,", ["foo", "bar", nil]], - [",foo,bar", [nil, "foo", "bar"]], - ["foo,bar", ["foo", "bar"]], - [";", [";"]], - ["\t,\t", ["\t", "\t"]], - ["foo,\"\r\n\r\",baz", ["foo", "\r\n\r", "baz"]], - ["foo,\"\r\n\n\",baz", ["foo", "\r\n\n", "baz"]], - ["foo,\"foo,bar\",baz", ["foo", "foo,bar", "baz"]], - [";,;", [";", ";"]] ].each do |csv_test| - assert_equal(csv_test.last, CSV.parse_line(csv_test.first)) - end - - [ ["foo,\"\"\"\"\"\",baz", ["foo", "\"\"", "baz"]], - ["foo,\"\"\"bar\"\"\",baz", ["foo", "\"bar\"", "baz"]], - ["foo,\"\r\n\",baz", ["foo", "\r\n", "baz"]], - ["\"\"", [""]], - ["foo,\"\"\"\",baz", ["foo", "\"", "baz"]], - ["foo,\"\r.\n\",baz", ["foo", "\r.\n", "baz"]], - ["foo,\"\r\",baz", ["foo", "\r", "baz"]], - ["foo,\"\",baz", ["foo", "", "baz"]], - ["foo", ["foo"]], - [",,", [nil, nil, nil]], - [",", [nil, nil]], - ["foo,\"\n\",baz", ["foo", "\n", "baz"]], - ["foo,,baz", ["foo", nil, "baz"]], - ["foo,bar", ["foo", "bar"]], - ["foo,\"\r\n\n\",baz", ["foo", "\r\n\n", "baz"]], - ["foo,\"foo,bar\",baz", ["foo", "foo,bar", "baz"]] ].each do |csv_test| - assert_equal(csv_test.last, CSV.parse_line(csv_test.first)) - end - end - - # From: http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-core/6496 - def test_aras_edge_cases - [ [%Q{a,b}, ["a", "b"]], - [%Q{a,"""b"""}, ["a", "\"b\""]], - [%Q{a,"""b"}, ["a", "\"b"]], - [%Q{a,"b"""}, ["a", "b\""]], - [%Q{a,"\nb"""}, ["a", "\nb\""]], - [%Q{a,"""\nb"}, ["a", "\"\nb"]], - [%Q{a,"""\nb\n"""}, ["a", "\"\nb\n\""]], - [%Q{a,"""\nb\n""",\nc}, ["a", "\"\nb\n\"", nil]], - [%Q{a,,,}, ["a", nil, nil, nil]], - [%Q{,}, [nil, nil]], - [%Q{"",""}, ["", ""]], - [%Q{""""}, ["\""]], - [%Q{"""",""}, ["\"",""]], - [%Q{,""}, [nil,""]], - [%Q{,"\r"}, [nil,"\r"]], - [%Q{"\r\n,"}, ["\r\n,"]], - [%Q{"\r\n,",}, ["\r\n,", nil]] ].each do |edge_case| - assert_equal(edge_case.last, CSV.parse_line(edge_case.first)) - end - end - - def test_james_edge_cases - # A read at eof? should return nil. - assert_equal(nil, CSV.parse_line("")) - # - # With Ruby 1.8 CSV it's impossible to tell an empty line from a line - # containing a single +nil+ field. The old CSV library returns - # <tt>[nil]</tt> in these cases, but <tt>Array.new</tt> makes more sense to - # me. - # - assert_equal(Array.new, CSV.parse_line("\n1,2,3\n")) - end - - def test_rob_edge_cases - [ [%Q{"a\nb"}, ["a\nb"]], - [%Q{"\n\n\n"}, ["\n\n\n"]], - [%Q{a,"b\n\nc"}, ['a', "b\n\nc"]], - [%Q{,"\r\n"}, [nil,"\r\n"]], - [%Q{,"\r\n."}, [nil,"\r\n."]], - [%Q{"a\na","one newline"}, ["a\na", 'one newline']], - [%Q{"a\n\na","two newlines"}, ["a\n\na", 'two newlines']], - [%Q{"a\r\na","one CRLF"}, ["a\r\na", 'one CRLF']], - [%Q{"a\r\n\r\na","two CRLFs"}, ["a\r\n\r\na", 'two CRLFs']], - [%Q{with blank,"start\n\nfinish"\n}, ['with blank', "start\n\nfinish"]], - ].each do |edge_case| - assert_equal(edge_case.last, CSV.parse_line(edge_case.first)) - end - end - - def test_non_regex_edge_cases - # An early version of the non-regex parser fails this test - [ [ "foo,\"foo,bar,baz,foo\",\"foo\"", - ["foo", "foo,bar,baz,foo", "foo"] ] ].each do |edge_case| - assert_equal(edge_case.last, CSV.parse_line(edge_case.first)) - end - - assert_raise(CSV::MalformedCSVError) do - CSV.parse_line("1,\"23\"4\"5\", 6") - end - end - - def test_malformed_csv_cr_first_line - error = assert_raise(CSV::MalformedCSVError) do - CSV.parse_line("1,2\r,3", row_sep: "\n") - end - assert_equal("Unquoted fields do not allow \\r or \\n in line 1.", - error.message) - end - - def test_malformed_csv_cr_middle_line - csv = <<-CSV -line,1,abc -line,2,"def\nghi" - -line,4,some\rjunk -line,5,jkl - CSV - - error = assert_raise(CSV::MalformedCSVError) do - CSV.parse(csv) - end - assert_equal("Unquoted fields do not allow \\r or \\n in line 4.", - error.message) - end - - def test_malformed_csv_unclosed_quote - error = assert_raise(CSV::MalformedCSVError) do - CSV.parse_line('1,2,"3...') - end - assert_equal("Unclosed quoted field in line 1.", - error.message) - end - - def test_malformed_csv_illegal_quote_middle_line - csv = <<-CSV -line,1,abc -line,2,"def\nghi" - -line,4,8'10" -line,5,jkl - CSV - - error = assert_raise(CSV::MalformedCSVError) do - CSV.parse(csv) - end - assert_equal("Illegal quoting in line 4.", - error.message) - end - - def test_the_parse_fails_fast_when_it_can_for_unquoted_fields - assert_parse_errors_out('valid,fields,bad start"' + BIG_DATA) - end - - def test_the_parse_fails_fast_when_it_can_for_unescaped_quotes - assert_parse_errors_out('valid,fields,"bad start"unescaped' + BIG_DATA) - end - - def test_field_size_limit_controls_lookahead - assert_parse_errors_out( 'valid,fields,"' + BIG_DATA + '"', - field_size_limit: 2048 ) - end - - def test_field_size_limit_in_extended_column_not_exceeding - data = <<~DATA - "a","b" - " - 2 - ","" - DATA - assert_nothing_raised(CSV::MalformedCSVError) do - CSV.parse(data, field_size_limit: 4) - end - end - - def test_field_size_limit_in_extended_column_exceeding - data = <<~DATA - "a","b" - " - 2345 - ","" - DATA - assert_parse_errors_out(data, field_size_limit: 5) - end - - def test_col_sep_comma - assert_equal([["a", "b", nil, "d"]], - CSV.parse("a,b,,d", col_sep: ",")) - end - - def test_col_sep_space - assert_equal([["a", "b", nil, "d"]], - CSV.parse("a b d", col_sep: " ")) - end - - def test_row_sep_auto_cr - assert_equal([["a"]], CSV.parse("a\r")) - end - - def test_row_sep_auto_lf - assert_equal([["a"]], CSV.parse("a\n")) - end - - def test_row_sep_auto_cr_lf - assert_equal([["a"]], CSV.parse("a\r\n")) - end - - def test_headers_empty_line - assert_equal(CSV::Table.new([CSV::Row.new(["header1"], [])], - headers: ["header1"]), - CSV.parse("\n", headers: "header1")) - end - - private - - def assert_parse_errors_out(*args) - assert_raise(CSV::MalformedCSVError) do - Timeout.timeout(0.2) do - CSV.parse(*args) - fail("Parse didn't error out") - end - end - end -end Property changes on: ruby_2_6/test/csv/test_csv_parsing.rb ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -LF \ No newline at end of property Deleted: svn:executable ## -1 +0,0 ## -* \ No newline at end of property Index: ruby_2_6/test/csv/test_csv_writing.rb =================================================================== --- ruby_2_6/test/csv/test_csv_writing.rb (revision 66925) + (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/