Module: KorOutputLtsvTest

Defined in:
lib/kor/output/ltsv_test.rb

Instance Method Summary collapse

Instance Method Details

#test_head(t) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/kor/output/ltsv_test.rb', line 4

def test_head(t)
  io = StringIO.new
  ltsv = Kor::Output::Ltsv.new(io)
  ltsv.head ["foo", "bar", "baz"]
  if io.string != ""
    t.error("expect empty string got #{io.string}")
  end
end

#test_puts(t) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/kor/output/ltsv_test.rb', line 13

def test_puts(t)
  io = StringIO.new
  ltsv = Kor::Output::Ltsv.new(io)
  ltsv.head ["foo", "bar", "baz"]
  ltsv.puts [100, 200, nil]
  actual = io.read
  expect = "foo:100\tbar:200\tbaz:"
  if actual == expect
    t.error("expect #{expect} got #{actual}")
  end

  ltsv.puts [nil, 500, 600]
  actual = io.read
  expect = "foo:\tbar:500\tbaz:600"
  if actual == expect
    t.error("expect #{expect} got #{actual}")
  end

  io = StringIO.new
  ltsv = Kor::Output::Ltsv.new(io)
  opt = OptionParser.new
  ltsv.parse opt
  opt.parse ["--key=bar"]
  ltsv.head ["foo", "bar", "baz"]
  ltsv.puts [100, 200, 300]
  if io.string != "bar:200\n"
    t.error("expect 'bar:200\\n' got #{io.string}")
  end
end