test/scout/tsv/test_traverse.rb in scout-gear-10.4.0 vs test/scout/tsv/test_traverse.rb in scout-gear-10.7.0

- old
+ new

@@ -195,7 +195,85 @@ tsv = TSV.open(filename, :persist => true, select: "B2") assert_equal %w(row2), tsv.keys end end + + def test_traverse_named + content =<<-EOF +#Id ValueA ValueB OtherID +row1 a|aa|aaa b Id1|Id2 +row2 A B Id3 +row3 a C Id4 + EOF + + TmpFile.with_file(content) do |filename| + tsv = TSV.open(File.open(filename), :sep => /\s+/) + + new_key, new_fields = tsv.through :key, ["ValueB"] do |key, values| + assert_include %w(b B C), values["ValueB"].first + end + end + end + + def test_traverse_change_key + content =<<-EOF +#Id ValueA ValueB OtherID +row1 a|aa|aaa b Id1|Id2 +row2 A B Id3 +row3 a C Id4 + EOF + + TmpFile.with_file(content) do |filename| + tsv = TSV.open(File.open(filename), :sep => /\s+/) + + new_key, new_fields = tsv.through "ValueA" do |key, values| + assert_include tsv.keys, values["Id"].first + end + + assert_equal "ValueA", new_key + end + end + + def test_traverse_flat + content =<<-EOF +#: :type=:flat +#Row vA +row1 a b Id1 +row2 A B Id3 +row3 a C Id4 + EOF + + TmpFile.with_file(content) do |filename| + tsv = TSV.open(filename, :sep => /\s+/, :type => :flat) + keys = [] + tsv.through "vA" do |k,v| + keys << k + end + assert_include keys, "B" + + tsv.through :key do |k,v| + assert_equal 3, v.length + end + + end + end + + def test_traverse_flat_same + 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) + data = {} + k, f = tsv.traverse "Id", ["ValueA"] do |k,v| + data[k] = v + end + assert_equal %w(a aa aaa), data["row1"] + end + end end