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
53
test/csv/write/test_converters.rb
Normal file
53
test/csv/write/test_converters.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# frozen_string_literal: false
|
||||
|
||||
require_relative "../helper"
|
||||
|
||||
module TestCSVWriteConverters
|
||||
def test_one
|
||||
assert_equal(%Q[=a,=b,=c\n],
|
||||
generate_line(["a", "b", "c"],
|
||||
write_converters: ->(value) {"=" + value}))
|
||||
end
|
||||
|
||||
def test_multiple
|
||||
assert_equal(%Q[=a_,=b_,=c_\n],
|
||||
generate_line(["a", "b", "c"],
|
||||
write_converters: [
|
||||
->(value) {"=" + value},
|
||||
->(value) {value + "_"},
|
||||
]))
|
||||
end
|
||||
|
||||
def test_nil_value
|
||||
assert_equal(%Q[a,NaN,c\n],
|
||||
generate_line(["a", nil, "c"],
|
||||
write_nil_value: "NaN"))
|
||||
end
|
||||
|
||||
def test_empty_value
|
||||
assert_equal(%Q[a,,c\n],
|
||||
generate_line(["a", "", "c"],
|
||||
write_empty_value: nil))
|
||||
end
|
||||
end
|
||||
|
||||
class TestCSVWriteConvertersGenerateLine < Test::Unit::TestCase
|
||||
include TestCSVWriteConverters
|
||||
extend DifferentOFS
|
||||
|
||||
def generate_line(row, **kwargs)
|
||||
CSV.generate_line(row, **kwargs)
|
||||
end
|
||||
end
|
||||
|
||||
class TestCSVWriteConvertersGenerate < Test::Unit::TestCase
|
||||
include TestCSVWriteConverters
|
||||
extend DifferentOFS
|
||||
|
||||
def generate_line(row, **kwargs)
|
||||
CSV.generate(**kwargs) do |csv|
|
||||
csv << row
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue