2019-04-14 17:01:51 -04:00
|
|
|
# -*- 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
|
2020-05-16 22:51:06 -04:00
|
|
|
assert_equal(%Q[a,NaN,29\n],
|
|
|
|
generate_line(["a", nil, 29],
|
2019-04-14 17:01:51 -04:00
|
|
|
write_nil_value: "NaN"))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_empty_value
|
2020-05-16 22:51:06 -04:00
|
|
|
assert_equal(%Q[a,,29\n],
|
|
|
|
generate_line(["a", "", 29],
|
2019-04-14 17:01:51 -04:00
|
|
|
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
|