# # Testing OpenWFEru # # John Mettraux at openwfe.org # # Sun Oct 29 15:41:44 JST 2006 # require 'test/unit' #require 'pp' require 'openwfe/workitem' require 'openwfe/participants/csvparticipants' #require 'rutest_utils' include OpenWFE class CsvTest < Test::Unit::TestCase #def setup #end #def teardown #end CSV0 = \ """ ,, in:fx,in:fy,out:fz ,, a,b,0 c,d,1 e,f,2 """ def test_csv_0 wi = InFlowWorkItem.new() wi.fx = "c" wi.fy = "d" do_test(CSV0, wi, { "fz" => "1" }, false) wi.attributes.clear() wi.fx = "a" wi.fy = "d" do_test(CSV0, wi, { "fz" => nil }, false) end CSV1 = \ """ ,, in:fx,in:fy,out:fz ,, a,${f:fx},0 c,d,${f:fx} e,f,${r:3+4} """ def test_csv_1 wi = InFlowWorkItem.new() wi.fx = "c" wi.fy = "d" do_test(CSV1, wi, { "fz" => "c" }, false) wi.attributes.clear() wi.fx = "e" wi.fy = "f" do_test(CSV1, wi, { "fz" => "7" }, false) wi.attributes.clear() wi.fx = "a" wi.fy = "a" do_test(CSV1, wi, { "fz" => "0" }, false) end CSV2 = \ """ in:fx, in:fy, out:fz ,, a, b, 0 c, d, 1 e, f, 2 """ def test_csv_2 wi = InFlowWorkItem.new() wi.fx = "c" wi.fy = "d" do_test(CSV2, wi, { "fz" => "1" }, false) wi.attributes.clear() wi.fx = "a" wi.fy = "d" do_test(CSV2, wi, { "fz" => nil }, false) end CSV3 = \ """ in:weather, in:month, out:take_umbrella? ,, raining, , yes sunny, , no cloudy, june, yes cloudy, may, yes cloudy, , no """ def test_csv_3 wi = InFlowWorkItem.new() wi.weather = "raining" wi.month = "december" do_test(CSV3, wi, { "take_umbrella?" => "yes" }, false) wi.attributes.clear() wi.weather = "cloudy" wi.month = "june" do_test(CSV3, wi, { "take_umbrella?" => "yes" }, false) wi.attributes.clear() wi.weather = "cloudy" wi.month = "march" do_test(CSV3, wi, { "take_umbrella?" => "no" }, false) end def test_csv_3b h = {} h["weather"] = "raining" h["month"] = "december" do_test(CSV3, h, { "take_umbrella?" => "yes" }, false) h = {} h["weather"] = "cloudy" h["month"] = "june" do_test(CSV3, h, { "take_umbrella?" => "yes" }, false) h = {} h["weather"] = "cloudy" h["month"] = "march" do_test(CSV3, h, { "take_umbrella?" => "no" }, false) end def test_csv_3c table = CsvTable.new(""" in:topic,in:region,out:team_member sports,europe,Alice sports,,Bob finance,america,Charly finance,europe,Donald finance,,Ernest politics,asia,Fujio politics,america,Gilbert politics,,Henry ,,Zach """) h = {} h["topic"] = "politics" table.transform(h) assert h["team_member"] == "Henry" end # CSV4 = \ #''' #"in:weather", "in:month", "out:take_umbrella?" #"","","" #"raining","","yes" #"sunny","","no" #"cloudy","june","yes" #"cloudy","may","yes" #"cloudy","","no" #''' #def test_csv_4 # h = {} # h["weather"] = "raining" # h["month"] = "december" # do_test(CSV4, h, { "take_umbrella?" => "yes" }, false) # h = {} # h["weather"] = "cloudy" # h["month"] = "june" # do_test(CSV4, h, { "take_umbrella?" => "yes" }, false) # h = {} # h["weather"] = "cloudy" # h["month"] = "march" # do_test(CSV4, h, { "take_umbrella?" => "no" }, false) #end CSV5 = \ """ through,ignorecase,, ,,, in:fx, in:fy, out:fX, out:fY ,,, a, , true, , a, , true b, , false, , b, , false """ def test_csv_5 wi = InFlowWorkItem.new() wi.fx = "a" wi.fy = "a" do_test(CSV5, wi, { "fX" => "true", "fY" => "true" }, false) wi.attributes.clear wi.fx = "a" wi.fy = "b" do_test(CSV5, wi, { "fX" => "true", "fY" => "false" }, false) wi.attributes.clear wi.fx = "A" wi.fy = "b" do_test(CSV5, wi, { "fX" => "true", "fY" => "false" }, false) end protected def do_test (table_data, wi, expected_result, verbose=false) table = CsvTable.new(table_data) if verbose puts puts "before :" puts wi end wi = if wi.kind_of? Hash table.transform(wi) else table.transform_wi(nil, wi) end if verbose puts puts "after :" puts wi end expected_result.each do |k, v| #if wi.attributes[k] != v #end value = if wi.kind_of? Hash wi[k] else wi.attributes[k] end assert \ value == v, "attribute '#{k}' should be set to '#{v}' "+ "but is set to '#{value}'" end end end