Sha256: a74723c3fc900c54558f3b6a19d6e011c97ab3ae66bf2b1f318fadd9bc7e6b85

Contents?: true

Size: 1.1 KB

Versions: 9

Compression:

Stored size: 1.1 KB

Contents

require File.expand_path(__FILE__).sub(%r(/test/.*), '/test/test_helper.rb')
require File.expand_path(__FILE__).sub(%r(.*/test/), '').sub(/test_(.*)\.rb/,'\1')

require 'scout/tsv'
class TestTSVProcess < Test::Unit::TestCase
  def test_process
    content =<<-'EOF'
#: :sep=/\s+/#:type=:double
#Id    ValueA    ValueB    OtherID
row1    a|aa|aaa    b    Id1|Id2
row2    A    B    Id3
row2    AA    BB    Id33
    EOF

    tsv = TmpFile.with_file(content) do |filename|
      TSV.open(filename)
    end

    tsv.process "ValueA" do |v|
      v.collect{|e| e.upcase }
    end

    assert_equal %w(A AA AAA), tsv["row1"][0]
  end

  def test_add_field
    content =<<-'EOF'
#: :sep=/\s+/#:type=:double
#Id    ValueA    ValueB    OtherID
row1    a|aa|aaa    b    Id1|Id2
row2    A    B    Id3
row2    AA    BB    Id33
    EOF

    tsv = TmpFile.with_file(content) do |filename|
      TSV.open(filename)
    end

    tsv.add_field "ValueC" do |k,v|
      v[0].collect{|e| e.gsub("a", "c").gsub("A", "C") }
    end

    assert_equal %w(c cc ccc), tsv["row1"]["ValueC"]
    assert_equal %w(C CC), tsv["row2"]["ValueC"]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
scout-gear-10.3.0 test/scout/tsv/util/test_process.rb
scout-gear-10.2.0 test/scout/tsv/util/test_process.rb
scout-gear-10.1.0 test/scout/tsv/util/test_process.rb
scout-gear-10.0.1 test/scout/tsv/util/test_process.rb
scout-gear-9.1.0 test/scout/tsv/util/test_process.rb
scout-gear-9.0.0 test/scout/tsv/util/test_process.rb
scout-gear-8.1.0 test/scout/tsv/util/test_process.rb
scout-gear-8.0.0 test/scout/tsv/util/test_process.rb
scout-gear-7.3.0 test/scout/tsv/util/test_process.rb