test/raw_prog_test.rb in openwferu-0.9.16 vs test/raw_prog_test.rb in openwferu-0.9.17

- old
+ new

@@ -6,32 +6,30 @@ # # Mon Oct 9 22:19:44 JST 2006 # require 'test/unit' -require 'openwfe/expressions/raw_prog' +require 'openwfe/def' +require 'openwfe/expool/parser' class RawProgTest < Test::Unit::TestCase - DEBUG = false - #def setup #end #def teardown #end - XML_DEF = """ -<process-definition name='test0' revision='0'> - <sequence> - <participant ref='a'/> - <participant ref='b'/> - </sequence> -</process-definition>""".strip + XML_DEF = + "<process-definition name='test0' revision='0'>"+ + "<sequence>"+ + "<participant ref='a'/>"+ + "<participant ref='b'/>"+ + "</sequence>"+ + "</process-definition>" - # # TEST 0 # class TestDefinition < OpenWFE::ProcessDefinition @@ -45,38 +43,31 @@ end end def test_prog_0 - s = TestDefinition.new().make.to_s + s = OpenWFE::ExpressionTree.to_s(TestDefinition.new.make) - puts s if DEBUG - - assert \ - s == XML_DEF, - "parsing failed (0)" + assert_equal XML_DEF, s end def test_prog_0b - s = TestDefinition.do_make.to_s + #s = TestDefinition.do_make.to_s + s = OpenWFE::ExpressionTree.to_s(TestDefinition.do_make) - puts s if DEBUG - - assert \ - s == XML_DEF, - "parsing failed (0b)" + assert_equal XML_DEF, s end # # TEST 1 # def test_prog_1 - pg = OpenWFE::ProcessDefinition.new() + pg = OpenWFE::ProcessDefinition.new class << pg def my_proc process_definition :name => "test0", :revision => "0" do sequence do @@ -87,15 +78,11 @@ end end pdef = pg.my_proc s = pdef.to_s - puts s if DEBUG - - assert \ - s == XML_DEF, - "parsing failed (1)" + assert XML_DEF, s end # # TEST 2 @@ -112,28 +99,26 @@ end end end end - XML_DEF2 = """ -<process-definition name='test2' revision='0'> - <sequence> - <set field='toto'>nada</set> - <participant ref='b'/> - </sequence> -</process-definition>""".strip + XML_DEF2 = + "<process-definition name='test2' revision='0'>"+ + "<sequence>"+ + "<set field='toto'>"+ + "nada"+ + "</set>"+ + "<participant ref='b'/>"+ + "</sequence>"+ + "</process-definition>" def test_prog_2 - s = TestDefinition2.do_make.to_s + s = OpenWFE::ExpressionTree.to_s(TestDefinition2.do_make) - puts s if DEBUG + assert_equal XML_DEF2, s - assert \ - s == XML_DEF2, - "parsing failed (2)" - #puts #puts TestDefinition2.do_make.to_code_s end @@ -150,17 +135,17 @@ end end end end - XML_DEF3 = """ -<process-definition name='test3' revision='0'> - <if> - <equals field-value='nada' other-value='surf'/> - <participant ref='b'/> - </if> -</process-definition>""".strip + XML_DEF3 = + "<process-definition name='test3' revision='0'>"+ + "<if>"+ + "<equals field-value='nada' other-value='surf'/>"+ + "<participant ref='b'/>"+ + "</if>"+ + "</process-definition>" CODE_DEF3 = """ process_definition :name => 'test3', :revision => '0' do _if do equals :field_value => 'nada', :other_value => 'surf' @@ -168,30 +153,22 @@ end end""".strip def test_prog_3 - s = TestDefinition3.do_make.to_s + s = OpenWFE::ExpressionTree.to_s(TestDefinition3.do_make) - puts s if DEBUG + assert_equal XML_DEF3, s - assert \ - s == XML_DEF3, - "parsing failed (3)" + assert_equal( + CODE_DEF3, + OpenWFE::ExpressionTree.to_code_s(TestDefinition3.do_make)) - #puts - #puts TestDefinition3.do_make.to_code_s + #r = OpenWFE::SimpleExpRepresentation.from_xml(s) + r = OpenWFE::DefParser.parse_xml s - assert \ - TestDefinition3.do_make.to_code_s == CODE_DEF3, - "to_code_s() not working properly (3)" - - r = OpenWFE::SimpleExpRepresentation.from_xml(s) - #puts r.class.name - #puts r.to_code_s - - assert_equal r.to_code_s, CODE_DEF3 + assert_equal CODE_DEF3, OpenWFE::ExpressionTree.to_code_s(r) end # # TEST 4 @@ -221,13 +198,13 @@ #puts #puts TestDefinition4.do_make.to_s #puts #puts TestDefinition4.do_make.to_code_s - assert \ - TestDefinition4.do_make.to_code_s == CODE_DEF4, - "to_code_s() not working properly (4)" + assert_equal( + CODE_DEF4, + OpenWFE::ExpressionTree.to_code_s(TestDefinition4.do_make)) end # # TEST 4b @@ -242,11 +219,11 @@ end end end CODE_DEF4b = """ -process_definition :name => 'TestDefinition4b', :revision => '0' do +process_definition :name => 'Test', :revision => '4b' do sequence do participant do 'b' end participant do @@ -258,18 +235,13 @@ end end""".strip def test_prog_4b - #puts - #puts TestDefinition4.do_make.to_s - #puts - #puts TestDefinition4b.do_make.to_code_s - - assert \ - TestDefinition4b.do_make.to_code_s == CODE_DEF4b, - "to_code_s() not working properly (4b)" + assert_equal( + CODE_DEF4b, + OpenWFE::ExpressionTree.to_code_s(TestDefinition4b.do_make)) end # # TEST 5 @@ -298,18 +270,13 @@ end end""".strip def test_prog_5 - #puts - #puts TestDefinition5.do_make.to_s - #puts - #puts TestDefinition5.do_make.to_code_s - - assert \ - TestDefinition5.do_make.to_code_s == CODE_DEF5, - "to_code_s() not working properly (5)" + assert_equal( + CODE_DEF5, + OpenWFE::ExpressionTree.to_code_s(TestDefinition5.do_make)) end # # TEST 6 @@ -332,18 +299,13 @@ end end""".strip def test_prog_6 - #puts - #puts TestDefinition60.do_make.to_s - #puts - #puts TestDefinition60.do_make.to_code_s - - assert \ - TestDefinition60.do_make.to_code_s == CODE_DEF6, - "to_code_s() not working properly (6)" + assert_equal( + CODE_DEF6, + OpenWFE::ExpressionTree.to_code_s(TestDefinition60.do_make)) end # # TEST 7 @@ -360,53 +322,67 @@ participant :ref => 'toto' end""".strip A_DEF7 = [ "process-definition", - {"name"=>"TestDefinitionSeven", "revision"=>"0"}, - [ - ["participant", {"ref"=>:toto}, []] - ] + { "name"=>"TestDefinitionSeven", "revision"=>"0" }, + [ [ "participant", { "ref" => :toto }, [] ] ] ] def test_prog_7 - #puts - #puts TestDefinition7.do_make.to_s - #puts - #puts TestDefinition7.do_make.to_code_s + assert_equal( + CODE_DEF7, + OpenWFE::ExpressionTree.to_code_s(TestDefinitionSeven.do_make)) - assert_equal TestDefinitionSeven.do_make.to_code_s, CODE_DEF7 - - assert_equal TestDefinitionSeven.do_make.to_a, A_DEF7 + assert_equal( + A_DEF7, + TestDefinitionSeven.do_make) end # # TEST 8 # - def do_test(class_name, pdef) + def do_test (class_name, pdef) + # + # losing my time with an eval + # result = eval """ class #{class_name} < OpenWFE::ProcessDefinition def make participant 'nada' end end #{class_name}.do_make """ - assert_equal result.attributes['name'], pdef[0] - assert_equal result.attributes['revision'], pdef[1] + assert_equal result[1]['name'], pdef[0] + assert_equal result[1]['revision'], pdef[1] end def test_process_names - do_test("MyProcessDefinition_10", ["MyProcess", "10"]) - do_test("MyProcessDefinition10", ["MyProcess", "10"]) - do_test("MyProcessDefinition1_0", ["MyProcess", "1.0"]) - do_test("MyProcessThing_1_0", ["MyProcessThing", "1.0"]) + + do_test "MyProcessDefinition_10", ["MyProcess", "10"] + do_test "MyProcessDefinition10", ["MyProcess", "10"] + do_test "MyProcessDefinition1_0", ["MyProcess", "1.0"] + do_test "MyProcessThing_1_0", ["MyProcessThing", "1.0"] end + def do_test_2 (raw_name, expected) + assert_equal( + expected, + OpenWFE::ProcessDefinition.extract_name_and_revision(raw_name)) + end + + def test_process_names_2 + + do_test_2 "MyProcessDefinition_10", ["MyProcess", "10"] + do_test_2 "MyProcessDefinition5b", ["MyProcess", "5b"] + end + + # # TEST 9 # class TestDefinition9 < OpenWFE::ProcessDefinition @@ -425,20 +401,12 @@ participant :ref => 'toto' nada end end""".strip - def xxxx_prog_9 - #def test_prog_9 + def _test_prog_9 - #puts - #puts TestDefinition60.do_make.to_s - puts - puts TestDefinition9.do_make.to_code_s - - assert \ - TestDefinition9.do_make.to_code_s == CODE_DEF9, - "to_code_s() not working properly (9)" + assert CODE_DEF9, TestDefinition9.do_make.to_code_s end end