test/rbbt/tsv/test_manipulate.rb in rbbt-util-4.0.2 vs test/rbbt/tsv/test_manipulate.rb in rbbt-util-4.1.0

- old
+ new

@@ -2,10 +2,24 @@ require 'rbbt/tsv' require 'rbbt/tsv/manipulate' class TestTSVManipulate < Test::Unit::TestCase + def test_zipped + content =<<-EOF +#Id ValueA ValueB ValueC +rowA A|AA B|BB C|CC +rowa a|aa b|BB C|CC + EOF + + TmpFile.with_file(content) do |filename| + tsv = TSV.open(File.open(filename), :sep => /\s+/, :type => :double) + assert_equal ["A", "AA", "a", "aa"].sort, tsv.reorder("ValueA", nil, :zipped => true).keys.sort + end + end + + def test_through content =<<-EOF #Id ValueA ValueB OtherID row1 a|aa|aaa b Id1|Id2 row2 A B Id3 @@ -102,18 +116,21 @@ assert_equal %w(row1 row3).sort, new.keys new = tsv.select "ValueB" => /b|Id4/ assert_equal %w(row1).sort, new.keys - tsv = TSV.open(filename, :sep => /\s+/, :type => :flat) - assert tsv.type != :double new = tsv.select %w(b Id4) assert_equal %w(row1 row3).sort, new.keys.sort - new = tsv.select do |k,v| v["ValueA"].include? "A" end + new = tsv.select do |k,v| + v["ValueA"].include? "A" + end assert_equal %w(row2).sort, new.keys.sort + + tsv = TSV.open(filename, :sep => /\s+/, :type => :flat) + assert tsv.type != :double end end def test_process content =<<-EOF @@ -188,7 +205,24 @@ assert test end end + + def test_reorder_flat + content =<<-EOF +#Id ValueA +row1 a aa aaa +row2 A +row3 a + EOF + + TmpFile.with_file(content) do |filename| + tsv = TSV.open(File.open(filename), :sep => /\s+/, :type => :flat) + + assert_equal ["row1", "row3"].sort, tsv.reorder("ValueA")["a"] + + end + end + end