Skip to content

Commit

Permalink
Adding specific test for empty_value_replace_char set to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
silasb committed Jun 15, 2020
1 parent 53e9d8f commit 448cdd4
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions spec/csv-to-json_spec.cr
Expand Up @@ -35,18 +35,36 @@ describe Csv::To::Json do

context "with options" do
context "with empty_value_replace_char option" do
it "will replace each empty value with the empty_value_replace_char char" do
in_io = IO::Memory.new("field 1,field 2\nvalue 1,\n")
out_io = IO::Memory.new()
context "with it set to blah" do
it "will replace each empty value with the empty_value_replace_char char" do
in_io = IO::Memory.new("field 1,field 2\nvalue 1,\n")
out_io = IO::Memory.new()

options = {
:empty_value_replace_char => "blah"
}
options = {
:empty_value_replace_char => "blah"
}

Csv::To::Json.run(in_io, out_io, options)
Csv::To::Json.run(in_io, out_io, options)

out_io.seek(0)
out_io.to_s.should contain("blah")
out_io.seek(0)
out_io.to_s.should contain("blah")
end
end

context "with it set to nil" do
it "will replace each empty value with the empty_value_replace_char char" do
in_io = IO::Memory.new("field 1,field 2\nvalue 1,\n")
out_io = IO::Memory.new()

options = {
:empty_value_replace_char => nil
}

Csv::To::Json.run(in_io, out_io, options)

out_io.seek(0)
out_io.to_s.should contain("[\n{\"field 1\":\"value 1\",\"field 2\":null}\n]\n")
end
end
end

Expand Down

0 comments on commit 448cdd4

Please sign in to comment.