Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tests for CSV.build with custom separator/quote_char #6008

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/std/csv/csv_build_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ describe CSV do
string.should eq(%("hello,world"\n))
end

it "builds with custom separator" do
string = CSV.build(separator: ';') do |csv|
csv.row do |row|
row << "one"
row << "two"
row << "thr;ee"
end
end
string.should eq(%(one;two;"thr;ee"\n))
end

it "builds with quotes" do
string = CSV.build do |csv|
csv.row do |row|
Expand All @@ -49,6 +60,15 @@ describe CSV do
string.should eq(%("he said ""no"""\n))
end

it "builds with custom quote character" do
string = CSV.build(quote_char: '\'') do |csv|
csv.row do |row|
row << %(he said 'no')
end
end
string.should eq(%('he said ''no'''\n))
end

it "builds row from enumerable" do
string = CSV.build do |csv|
csv.row [1, 2, 3]
Expand Down