File: test_tsv.rb

package info (click to toggle)
ruby-csv 3.3.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 800 kB
  • sloc: ruby: 6,862; makefile: 4; sh: 4
file content (32 lines) | stat: -rw-r--r-- 746 bytes parent folder | download
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
require_relative "helper"

class TestTSV < Test::Unit::TestCase
  def test_default_separator
    tsv = CSV::TSV.new(String.new)
    assert_equal("\t", tsv.col_sep)
  end

  def test_override_separator
    tsv = CSV::TSV.new(String.new, col_sep: ",")
    assert_equal(",", tsv.col_sep)
  end

  def test_read_tsv_data
    data = "a\tb\tc\n1\t2\t3"
    result = CSV::TSV.parse(data)
    assert_equal([["a", "b", "c"], ["1", "2", "3"]], result.to_a)
  end

  def test_write_tsv_data
    output = String.new
    CSV::TSV.generate(output) do |tsv|
      tsv << ["a", "b", "c"]
      tsv << ["1", "2", "3"]
    end
    assert_equal("a\tb\tc\n1\t2\t3\n", output)
  end

  def test_inheritance
    assert_kind_of(CSV, CSV::TSV.new(String.new))
  end
end