test/test_plan.rb in sculd-0.1.3 vs test/test_plan.rb in sculd-0.2.0

- old
+ new

@@ -4,94 +4,102 @@ require "helper" #require "test/unit" #require "pkg/klass.rb" class TC_Plan < Test::Unit::TestCase - def test_parse - ## correct string - result = Sculd::Plan.parse('[2012-10-23]! deadlineA') - date = DateTime.new(2012, 10, 23, 0, 0, 0) - assert_equal(date , result[:datetime]) - assert_equal("!" , result[:type]) - assert_equal(nil , result[:option]) - assert_equal("deadlineA", result[:description]) - assert_equal(false , result[:flag_time]) + def test_parse + ## correct string + result = Sculd::Plan.parse('[2012-10-23]! deadlineA') + date = DateTime.new(2012, 10, 23, 0, 0, 0) + assert_equal(date , result[:datetime]) + assert_equal("!" , result[:type]) + assert_equal(nil , result[:option]) + assert_equal("deadlineA", result[:description]) + assert_equal(false , result[:flag_time]) - result = Sculd::Plan.parse('[2012-10-23]!30 deadlineA') - date = DateTime.new(2012, 10, 23, 0, 0, 0) - assert_equal(date , result[:datetime]) - assert_equal("!" , result[:type]) - assert_equal(30 , result[:option]) - assert_equal("deadlineA", result[:description]) - assert_equal(false , result[:flag_time]) + result = Sculd::Plan.parse('[2012-10-23]!30 deadlineA') + date = DateTime.new(2012, 10, 23, 0, 0, 0) + assert_equal(date , result[:datetime]) + assert_equal("!" , result[:type]) + assert_equal(30 , result[:option]) + assert_equal("deadlineA", result[:description]) + assert_equal(false , result[:flag_time]) - result = Sculd::Plan.parse('[2012-10-23 01:02:03]@ scheduleA') - date = DateTime.new(2012, 10, 23, 1, 2, 3) - assert_equal(date , result[:datetime]) - assert_equal("@" , result[:type]) - assert_equal(nil , result[:option]) - assert_equal("scheduleA", result[:description]) - assert_equal(true , result[:flag_time]) + result = Sculd::Plan.parse('[2012-10-23 01:02:03]@ scheduleA') + date = DateTime.new(2012, 10, 23, 1, 2, 3) + assert_equal(date , result[:datetime]) + assert_equal("@" , result[:type]) + assert_equal(nil , result[:option]) + assert_equal("scheduleA", result[:description]) + assert_equal(true , result[:flag_time]) - result = Sculd::Plan.parse('[2012-11-01 01:02:03(Thu)]@ scheduleA') - date = DateTime.new(2012, 11, 1, 1, 2, 3) - assert_equal(date , result[:datetime]) - assert_equal("@" , result[:type]) - assert_equal(nil , result[:option]) - assert_equal("scheduleA", result[:description]) - assert_equal(true , result[:flag_time]) + result = Sculd::Plan.parse('[2012-11-01 01:02:03(Thu)]@ scheduleA') + date = DateTime.new(2012, 11, 1, 1, 2, 3) + assert_equal(date , result[:datetime]) + assert_equal("@" , result[:type]) + assert_equal(nil , result[:option]) + assert_equal("scheduleA", result[:description]) + assert_equal(true , result[:flag_time]) - result = Sculd::Plan.parse('[2012-11-01 01:02:03(th)]@ scheduleA') - date = DateTime.new(2012, 11, 01, 1, 2, 3) - assert_equal(date , result[:datetime]) - assert_equal("@" , result[:type]) - assert_equal(nil , result[:option]) - assert_equal("scheduleA", result[:description]) - assert_equal(true , result[:flag_time]) + result = Sculd::Plan.parse('[2012-11-01 01:02:03(th)]@ scheduleA') + date = DateTime.new(2012, 11, 01, 1, 2, 3) + assert_equal(date , result[:datetime]) + assert_equal("@" , result[:type]) + assert_equal(nil , result[:option]) + assert_equal("scheduleA", result[:description]) + assert_equal(true , result[:flag_time]) - #context 'schedule with wrong weekday' do - io = StringIO.new - assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(Sun)]@ scheduleA', io)} + result = Sculd::Plan.parse('[2012-11-01 01:02:03(木)]@ scheduleA') + date = DateTime.new(2012, 11, 01, 1, 2, 3) + assert_equal(date , result[:datetime]) + assert_equal("@" , result[:type]) + assert_equal(nil , result[:option]) + assert_equal("scheduleA", result[:description]) + assert_equal(true , result[:flag_time]) - assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse( "[2012-11-01(Fri)]@ mismach weekday\n", io)} + #context 'schedule with wrong weekday' do + io = StringIO.new + assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(Sun)]@ scheduleA', io)} - assert_raise(Sculd::Plan::NotWeekdayError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(abc)]@ scheduleA', io)} + assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse( "[2012-11-01(Fri)]@ mismach weekday\n", io)} - #Unable to interpret as date in []. - #assert_raise(Sculd::Plan::NotDateError ){ Sculd::Plan.parse('[abc]! deadlineA')} - assert_raise(ArgumentError){ Sculd::Plan.parse('[abc]! deadlineA')} + assert_raise(Sculd::Plan::NotWeekdayError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(abc)]@ scheduleA', io)} - ##Illegal syntax - # '[abc]]! deadlineA' do - assert_raise(Sculd::Plan::NotNumberError){ - Sculd::Plan.parse('[2012-01-01]]! deadlineA') - } - #date = DateTime.new(2012, 01, 01) - #assert_equal(date , result[:datetime]) - #assert_equal("]" , result[:type]) - #assert_equal("!" , result[:option]) - #assert_equal("deadlineA", result[:description]) + #Unable to interpret as date in []. + #assert_raise(Sculd::Plan::NotDateError ){ Sculd::Plan.parse('[abc]! deadlineA')} + assert_raise(ArgumentError){ Sculd::Plan.parse('[abc]! deadlineA')} - #context ' [2012-10-23]! deadlineA with space at head' do - #it 'should return Date, !, deadlineA' do - result = Sculd::Plan.parse(' [2012-10-23]! deadlineA with space at head') - date = DateTime.new(2012, 10, 23) - assert_equal(date , result[:datetime]) - assert_equal("!" , result[:type]) - assert_equal(nil , result[:option]) - assert_equal("deadlineA with space at head", result[:description]) - assert_equal(false , result[:flag_time]) + ##Illegal syntax + # '[abc]]! deadlineA' do + assert_raise(Sculd::Plan::NotNumberError){ + Sculd::Plan.parse('[2012-01-01]]! deadlineA') + } + #date = DateTime.new(2012, 01, 01) + #assert_equal(date , result[:datetime]) + #assert_equal("]" , result[:type]) + #assert_equal("!" , result[:option]) + #assert_equal("deadlineA", result[:description]) - #context '[2012-10-23]!10 deadline with option value' do - #it 'should return Date, !, deadlineA' do - result = Sculd::Plan.parse( '[2012-10-23]!10 deadline with option value') - date = DateTime.new(2012, 10, 23) - assert_equal(date , result[:datetime]) - assert_equal("!" , result[:type]) - assert_equal(10 , result[:option]) - assert_equal("deadline with option value", result[:description]) - assert_equal(false , result[:flag_time]) + #context ' [2012-10-23]! deadlineA with space at head' do + #it 'should return Date, !, deadlineA' do + result = Sculd::Plan.parse(' [2012-10-23]! deadlineA with space at head') + date = DateTime.new(2012, 10, 23) + assert_equal(date , result[:datetime]) + assert_equal("!" , result[:type]) + assert_equal(nil , result[:option]) + assert_equal("deadlineA with space at head", result[:description]) + assert_equal(false , result[:flag_time]) + #context '[2012-10-23]!10 deadline with option value' do + #it 'should return Date, !, deadlineA' do + result = Sculd::Plan.parse( '[2012-10-23]!10 deadline with option value') + date = DateTime.new(2012, 10, 23) + assert_equal(date , result[:datetime]) + assert_equal("!" , result[:type]) + assert_equal(10 , result[:option]) + assert_equal("deadline with option value", result[:description]) + assert_equal(false , result[:flag_time]) + end - - end + #def test_wday + #end end