mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
fb96811d15
commit
e3b6c7c7eb
23 changed files with 1534 additions and 650 deletions
51
test/csv/interface/test_read_write.rb
Normal file
51
test/csv/interface/test_read_write.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# frozen_string_literal: false
|
||||
|
||||
require_relative "../helper"
|
||||
|
||||
class TestCSVInterfaceReadWrite < Test::Unit::TestCase
|
||||
extend DifferentOFS
|
||||
|
||||
def test_filter
|
||||
rows = [[1, 2, 3], [4, 5]]
|
||||
input = <<-CSV
|
||||
1;2;3
|
||||
4;5
|
||||
CSV
|
||||
output = ""
|
||||
CSV.filter(input, output,
|
||||
in_col_sep: ";",
|
||||
out_col_sep: ",",
|
||||
converters: :all) do |row|
|
||||
row.map! {|n| n * 2}
|
||||
row << "Added\r"
|
||||
end
|
||||
assert_equal(<<-CSV, output)
|
||||
2,4,6,"Added\r"
|
||||
8,10,"Added\r"
|
||||
CSV
|
||||
end
|
||||
|
||||
def test_instance_same
|
||||
data = ""
|
||||
assert_equal(CSV.instance(data, col_sep: ";").object_id,
|
||||
CSV.instance(data, col_sep: ";").object_id)
|
||||
end
|
||||
|
||||
def test_instance_append
|
||||
output = ""
|
||||
CSV.instance(output, col_sep: ";") << ["a", "b", "c"]
|
||||
assert_equal(<<-CSV, output)
|
||||
a;b;c
|
||||
CSV
|
||||
CSV.instance(output, col_sep: ";") << [1, 2, 3]
|
||||
assert_equal(<<-CSV, output)
|
||||
a;b;c
|
||||
1;2;3
|
||||
CSV
|
||||
end
|
||||
|
||||
def test_instance_shortcut
|
||||
assert_equal(CSV.instance,
|
||||
CSV {|csv| csv})
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue