Sha256: 4c6ec1d6d3e278c4a8e43dd3207d3981b8334a1b9e1742a02e5109a94c6d694d

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

require File.join(File.expand_path(File.dirname(__FILE__)), '../..', 'test_helper.rb')
require 'rbbt/tsv'
require 'rbbt/tsv/change_id'

class TestTSVChangeID < Test::Unit::TestCase

  FILE1=<<-EOF
#: :sep=' '
#A B C
a b c
aa bb cc
  EOF

  FILE2=<<-EOF
#: :sep=' '
#X Y Z
x y z
xx yy zz
  EOF

  IDENTIFIERS=<<-EOF
#: :sep=' '
#A X
a x
aa xx
  EOF

  def tsv(text, options = {})
    options = Misc.add_defaults options, :type => :list
    TSV.open StringIO.new(text), options
  end

  def setup
    @f1 = tsv(FILE1)
    @f2 = tsv(FILE2)
    @f3 = tsv(FILE2, :key_field => "Y")
    @id = tsv(IDENTIFIERS)
  end

  def test_swap_id
    @f3.identifiers = @id
    assert_equal "a", @f3.swap_id("X","A")["y"]["A"]
  end


  def test_change_key
    @f1.identifiers = @id
    assert @f1.change_key("X").include? "x"
  end

  def test_translate_key
    @f1.identifiers = @id
    assert TSV.translate(@f1, @f1.key_field, "X", :persist => false).include? "x"
  end

  def test_translate_key_persist
    @f1.identifiers = @id
    assert TSV.translate(@f1, @f1.key_field, "X", :persist => true).include? "x"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rbbt-util-5.14.34 test/rbbt/tsv/test_change_id.rb