summaryrefslogtreecommitdiff
path: root/spec/ruby/library/csv/generate_line_spec.rb
blob: 0830bbdb63fdd783321da3d2c1b0a7a3fafb8d72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require_relative '../../spec_helper'

ruby_version_is ""..."3.4" do
  require 'csv'

  describe "CSV.generate_line" do

    it "generates an empty string" do
      result = CSV.generate_line([])
      result.should == "\n"
    end

    it "generates the string 'foo,bar'" do
      result = CSV.generate_line(["foo", "bar"])
      result.should == "foo,bar\n"
    end

    it "generates the string 'foo;bar'" do
      result = CSV.generate_line(["foo", "bar"], col_sep: ?;)
      result.should == "foo;bar\n"
    end

    it "generates the string 'foo,,bar'" do
      result = CSV.generate_line(["foo", nil, "bar"])
      result.should == "foo,,bar\n"
    end

    it "generates the string 'foo;;bar'" do
      result = CSV.generate_line(["foo", nil, "bar"], col_sep: ?;)
      result.should == "foo;;bar\n"
    end
  end
end