sculd 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/test/test_manager.rb CHANGED
@@ -6,109 +6,119 @@ require "helper"
6
6
  #require "pkg/klass.rb"
7
7
 
8
8
  class Sculd::Manager
9
- public :load_file, :show_events, :days_events, :show_tasks
10
- attr_accessor :plans
9
+ public :load_file, :show_events, :days_events, :show_tasks
10
+ attr_accessor :plans
11
11
  end
12
12
 
13
13
  class TC_Manager < Test::Unit::TestCase
14
- def setup
15
- @s00 = Sculd::Manager.new("test/schedule/empty")
16
- # @s01 = Sculd::Manager.new("test/schedule/normal")
17
- end
14
+ def setup
15
+ @s00 = Sculd::Manager.new("test/schedule/empty")
16
+ @s01 = Sculd::Manager.new("test/schedule/normal")
17
+ end
18
18
 
19
- # def test_load_file
20
- # #context "correct data" do #it "should overwrite data" do
21
- # @s00.load_file("test/schedule/normal/a.dat")
22
- # assert_equal(8, @s00.plans.size)
23
- # plans = @s00.plans
24
- # assert(plans.shift.is_a? Sculd::Plan)
25
- # assert(plans.shift.is_a? Sculd::Plan)
26
- # assert(plans.shift.is_a? Sculd::Plan)
27
- # assert(plans.shift.is_a? Sculd::Plan)
28
- # assert(plans.shift.is_a? Sculd::Plan)
29
- # assert(plans.shift.is_a? Sculd::Plan)
30
- # assert(plans.shift.is_a? Sculd::Plan)
31
- # assert(plans.shift.is_a? Sculd::Plan)
32
- # end
19
+ def test_load_file
20
+ #context "correct data" do #it "should overwrite data" do
21
+ @s00.load_file("test/schedule/normal/a.dat")
22
+ assert_equal(8, @s00.plans.size)
23
+ plans = @s00.plans
24
+ assert(plans.shift.is_a? Sculd::Plan)
25
+ assert(plans.shift.is_a? Sculd::Plan)
26
+ assert(plans.shift.is_a? Sculd::Plan)
27
+ assert(plans.shift.is_a? Sculd::Plan)
28
+ assert(plans.shift.is_a? Sculd::Plan)
29
+ assert(plans.shift.is_a? Sculd::Plan)
30
+ assert(plans.shift.is_a? Sculd::Plan)
31
+ assert(plans.shift.is_a? Sculd::Plan)
32
+ end
33
33
 
34
- def test_load_file_empty
35
- @s00.load_file("test/schedule/empty/empty.dat")
36
- assert_equal(0, @s00.plans.size)
34
+ def test_set_weekdays
35
+ assert_raise(Sculd::Manager::ArgumentError){ @s00.set_weekdays(["Sun", "Mon", "Tue", "Wed", "Thu", "Fri"]) }
36
+ end
37
37
 
38
- #context "data containing error" do it "should interrupt with error line." do
39
- io = StringIO.new
40
- assert_raise(Sculd::Manager::LoadError){ @s00.load_file("test/schedule/error/error.dat", io)}
41
- end
38
+ def test_load_file_empty
39
+ @s00.load_file("test/schedule/empty/empty.dat")
40
+ assert_equal(0, @s00.plans.size)
42
41
 
43
- # def test_days_events
44
- # #it 'should return hash dates as keys and events as values.' do
45
- # #pp @s01
46
- # results = @s01.days_events
47
- # keys = results.keys
48
- # #pp results
49
- #
50
- # ## normal/a.dat
51
- # assert_equal(Date.new(2012, 9, 15), keys.shift)
52
- # assert_equal(Date.new(2012, 9, 9), keys.shift)
53
- # assert_equal(Date.new(2012, 9, 16), keys.shift)
54
- # assert_equal(Date.new(2012, 9, 17), keys.shift)
55
- # assert_equal(Date.new(2012, 9, 18), keys.shift)
56
- # assert_equal(Date.new(2012, 9, 25), keys.shift)
57
- # assert_equal(Date.new(2012, 8, 17), keys.shift)
58
- # assert_equal(Date.new(2012, 9, 28), keys.shift)
59
- # ## normal/b.dat
60
- # assert_equal(Date.new(2012,10, 15), keys.shift)
61
- # assert_equal(Date.new(2012,10, 9), keys.shift)
62
- # assert_equal(Date.new(2012,10, 16), keys.shift)
63
- # assert_equal(Date.new(2012,10, 17), keys.shift)
64
- # assert_equal(Date.new(2012,10, 18), keys.shift)
65
- # assert_equal(Date.new(2012,10, 25), keys.shift)
66
- # assert_equal(nil , keys.shift)
67
- #
68
- # assert(results[Date.new(2012, 9, 15)].is_a? Array)
69
- # assert(results[Date.new(2012, 9, 15)][0].is_a? Sculd::Plan)
70
- # end
71
- #
72
- # def test_show_events
73
- # #it 'should return itemized days and events' do
74
- # #pp @s01
75
- # io = StringIO.new
76
- # today = Date.new(2012, 9, 15)
77
- # @s01.show_events(2, today, io)
78
- # io.rewind
79
- # results = io.readlines
80
- # #pp results
81
- # #assert_equal(9, results.size)
82
- # assert_equal("Events:\n" , results.shift)
83
- # assert_equal("  2012-09-15 Sat \n",
84
- # results.shift)
85
- # assert_equal(" @ schedule a\n" , results.shift)
86
- # assert_equal(" [23:45]@ schedule a'\n" , results.shift)
87
- # assert_equal("\n" , results.shift)
88
- # assert_equal("  2012-09-16 Sun \n",
89
- # results.shift)
90
- # assert_equal(" ! deadline b\n" , results.shift)
91
- # assert_equal(" [23:45]!30 deadline b'\n" , results.shift)
92
- # assert_equal("\n" , results.shift)
93
- # assert_equal(nil , results.shift)
94
- # end
95
- #
96
- # def test_show_tasks
97
- # #it 'should return sorted tasks' do
98
- # io = StringIO.new
99
- # today = Date.new(2012, 9,20)
100
- # @s01.show_tasks(6, today, io)
101
- # io.rewind
102
- # results = io.readlines
103
- # #pp results
104
- # #assert_equal(7, results.size)
105
- # assert_equal("Tasks:\n" , results.shift)
106
- # assert_equal(" [2012-09-16]!30 deadline b'\n", results.shift)
107
- # assert_equal(" [2012-09-16]! deadline b\n" , results.shift)
108
- # assert_equal(" [2012-09-18]+ todo d\n" , results.shift)
109
- # assert_equal(" [2012-09-18]+10 todo d'\n", results.shift)
110
- # assert_equal(" [2012-09-17]- reminder c'\n", results.shift)
111
- # assert_equal(" [2012-09-17]- reminder c\n" , results.shift)
112
- # assert_equal(nil , results.shift)
113
- # end
42
+ #context "data containing error" do it "should interrupt with error line." do
43
+ io = StringIO.new
44
+ assert_raise(Sculd::Manager::LoadError){ @s00.load_file("test/schedule/error/error.dat", io)}
45
+ end
46
+
47
+ def test_days_events
48
+ #it 'should return hash dates as keys and events as values.' do
49
+ #pp @s01
50
+ results = @s01.days_events
51
+ keys = results.keys
52
+ #pp results
53
+
54
+ ## normal/a.dat
55
+ assert_equal(Date.new(2012, 9, 15), keys.shift)
56
+ assert_equal(Date.new(2012, 9, 9), keys.shift)
57
+ assert_equal(Date.new(2012, 9, 16), keys.shift)
58
+ assert_equal(Date.new(2012, 9, 17), keys.shift)
59
+ assert_equal(Date.new(2012, 9, 18), keys.shift)
60
+ assert_equal(Date.new(2012, 9, 25), keys.shift)
61
+ assert_equal(Date.new(2012, 8, 17), keys.shift)
62
+ assert_equal(Date.new(2012, 9, 28), keys.shift)
63
+ ## normal/b.dat
64
+ assert_equal(Date.new(2012,10, 15), keys.shift)
65
+ assert_equal(Date.new(2012,10, 9), keys.shift)
66
+ assert_equal(Date.new(2012,10, 16), keys.shift)
67
+ assert_equal(Date.new(2012,10, 17), keys.shift)
68
+ assert_equal(Date.new(2012,10, 18), keys.shift)
69
+ assert_equal(Date.new(2012,10, 25), keys.shift)
70
+ assert_equal(nil , keys.shift)
71
+
72
+ assert(results[Date.new(2012, 9, 15)].is_a? Array)
73
+ assert(results[Date.new(2012, 9, 15)][0].is_a? Sculd::Plan)
74
+ end
75
+
76
+ def test_show_events
77
+ io = StringIO.new
78
+ today = Date.new(2012, 9, 15)
79
+ @s01.show_events([today], io)
80
+ io.rewind
81
+ results = io.readlines
82
+ assert_equal("Events:\n" , results.shift)
83
+ assert_equal("  2012-09-15 Sat \n", results.shift)
84
+ assert_equal(" @ schedule a\n" , results.shift)
85
+ assert_equal(" [23:45]@ schedule a'\n" , results.shift)
86
+ assert_equal("\n" , results.shift)
87
+ assert_equal(nil , results.shift)
88
+
89
+ io = StringIO.new
90
+ today = Date.new(2012, 9, 15)
91
+ @s01.show_events([today, today+1], io)
92
+ io.rewind
93
+ results = io.readlines
94
+ assert_equal("Events:\n" , results.shift)
95
+ assert_equal("  2012-09-15 Sat \n", results.shift)
96
+ assert_equal(" @ schedule a\n" , results.shift)
97
+ assert_equal(" [23:45]@ schedule a'\n" , results.shift)
98
+ assert_equal("\n" , results.shift)
99
+ assert_equal("  2012-09-16 Sun \n", results.shift)
100
+ assert_equal(" ! deadline b\n" , results.shift)
101
+ assert_equal(" [23:45]!30 deadline b'\n" , results.shift)
102
+ assert_equal("\n" , results.shift)
103
+ assert_equal(nil , results.shift)
104
+ end
105
+
106
+ def test_show_tasks
107
+ #it 'should return sorted tasks' do
108
+ io = StringIO.new
109
+ today = Date.new(2012, 9,20)
110
+ @s01.show_tasks(6, today, io)
111
+ io.rewind
112
+ results = io.readlines
113
+ #pp results
114
+ #assert_equal(7, results.size)
115
+ assert_equal("Tasks:\n" , results.shift)
116
+ assert_equal(" [2012-09-16]!30 deadline b'\n", results.shift)
117
+ assert_equal(" [2012-09-16]! deadline b\n" , results.shift)
118
+ assert_equal(" [2012-09-18]+ todo d\n" , results.shift)
119
+ assert_equal(" [2012-09-18]+10 todo d'\n", results.shift)
120
+ assert_equal(" [2012-09-17]- reminder c'\n", results.shift)
121
+ assert_equal(" [2012-09-17]- reminder c\n" , results.shift)
122
+ assert_equal(nil , results.shift)
123
+ end
114
124
  end
data/test/test_plan.rb CHANGED
@@ -6,92 +6,100 @@ require "helper"
6
6
  #require "pkg/klass.rb"
7
7
 
8
8
  class TC_Plan < Test::Unit::TestCase
9
- def test_parse
10
- ## correct string
11
- result = Sculd::Plan.parse('[2012-10-23]! deadlineA')
12
- date = DateTime.new(2012, 10, 23, 0, 0, 0)
13
- assert_equal(date , result[:datetime])
14
- assert_equal("!" , result[:type])
15
- assert_equal(nil , result[:option])
16
- assert_equal("deadlineA", result[:description])
17
- assert_equal(false , result[:flag_time])
18
-
19
- result = Sculd::Plan.parse('[2012-10-23]!30 deadlineA')
20
- date = DateTime.new(2012, 10, 23, 0, 0, 0)
21
- assert_equal(date , result[:datetime])
22
- assert_equal("!" , result[:type])
23
- assert_equal(30 , result[:option])
24
- assert_equal("deadlineA", result[:description])
25
- assert_equal(false , result[:flag_time])
26
-
27
- result = Sculd::Plan.parse('[2012-10-23 01:02:03]@ scheduleA')
28
- date = DateTime.new(2012, 10, 23, 1, 2, 3)
29
- assert_equal(date , result[:datetime])
30
- assert_equal("@" , result[:type])
31
- assert_equal(nil , result[:option])
32
- assert_equal("scheduleA", result[:description])
33
- assert_equal(true , result[:flag_time])
34
-
35
- result = Sculd::Plan.parse('[2012-11-01 01:02:03(Thu)]@ scheduleA')
36
- date = DateTime.new(2012, 11, 1, 1, 2, 3)
37
- assert_equal(date , result[:datetime])
38
- assert_equal("@" , result[:type])
39
- assert_equal(nil , result[:option])
40
- assert_equal("scheduleA", result[:description])
41
- assert_equal(true , result[:flag_time])
42
-
43
- result = Sculd::Plan.parse('[2012-11-01 01:02:03(th)]@ scheduleA')
44
- date = DateTime.new(2012, 11, 01, 1, 2, 3)
45
- assert_equal(date , result[:datetime])
46
- assert_equal("@" , result[:type])
47
- assert_equal(nil , result[:option])
48
- assert_equal("scheduleA", result[:description])
49
- assert_equal(true , result[:flag_time])
50
-
51
- #context 'schedule with wrong weekday' do
52
- io = StringIO.new
53
- assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(Sun)]@ scheduleA', io)}
54
-
55
- assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse( "[2012-11-01(Fri)]@ mismach weekday\n", io)}
56
-
57
- assert_raise(Sculd::Plan::NotWeekdayError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(abc)]@ scheduleA', io)}
58
-
59
- #Unable to interpret as date in [].
60
- #assert_raise(Sculd::Plan::NotDateError ){ Sculd::Plan.parse('[abc]! deadlineA')}
61
- assert_raise(ArgumentError){ Sculd::Plan.parse('[abc]! deadlineA')}
62
-
63
- ##Illegal syntax
64
- # '[abc]]! deadlineA' do
65
- assert_raise(Sculd::Plan::NotNumberError){
66
- Sculd::Plan.parse('[2012-01-01]]! deadlineA')
67
- }
68
- #date = DateTime.new(2012, 01, 01)
69
- #assert_equal(date , result[:datetime])
70
- #assert_equal("]" , result[:type])
71
- #assert_equal("!" , result[:option])
72
- #assert_equal("deadlineA", result[:description])
73
-
74
- #context ' [2012-10-23]! deadlineA with space at head' do
75
- #it 'should return Date, !, deadlineA' do
76
- result = Sculd::Plan.parse(' [2012-10-23]! deadlineA with space at head')
77
- date = DateTime.new(2012, 10, 23)
78
- assert_equal(date , result[:datetime])
79
- assert_equal("!" , result[:type])
80
- assert_equal(nil , result[:option])
81
- assert_equal("deadlineA with space at head", result[:description])
82
- assert_equal(false , result[:flag_time])
83
-
84
- #context '[2012-10-23]!10 deadline with option value' do
85
- #it 'should return Date, !, deadlineA' do
86
- result = Sculd::Plan.parse( '[2012-10-23]!10 deadline with option value')
87
- date = DateTime.new(2012, 10, 23)
88
- assert_equal(date , result[:datetime])
89
- assert_equal("!" , result[:type])
90
- assert_equal(10 , result[:option])
91
- assert_equal("deadline with option value", result[:description])
92
- assert_equal(false , result[:flag_time])
93
-
94
-
95
-
96
- end
9
+ def test_parse
10
+ ## correct string
11
+ result = Sculd::Plan.parse('[2012-10-23]! deadlineA')
12
+ date = DateTime.new(2012, 10, 23, 0, 0, 0)
13
+ assert_equal(date , result[:datetime])
14
+ assert_equal("!" , result[:type])
15
+ assert_equal(nil , result[:option])
16
+ assert_equal("deadlineA", result[:description])
17
+ assert_equal(false , result[:flag_time])
18
+
19
+ result = Sculd::Plan.parse('[2012-10-23]!30 deadlineA')
20
+ date = DateTime.new(2012, 10, 23, 0, 0, 0)
21
+ assert_equal(date , result[:datetime])
22
+ assert_equal("!" , result[:type])
23
+ assert_equal(30 , result[:option])
24
+ assert_equal("deadlineA", result[:description])
25
+ assert_equal(false , result[:flag_time])
26
+
27
+ result = Sculd::Plan.parse('[2012-10-23 01:02:03]@ scheduleA')
28
+ date = DateTime.new(2012, 10, 23, 1, 2, 3)
29
+ assert_equal(date , result[:datetime])
30
+ assert_equal("@" , result[:type])
31
+ assert_equal(nil , result[:option])
32
+ assert_equal("scheduleA", result[:description])
33
+ assert_equal(true , result[:flag_time])
34
+
35
+ result = Sculd::Plan.parse('[2012-11-01 01:02:03(Thu)]@ scheduleA')
36
+ date = DateTime.new(2012, 11, 1, 1, 2, 3)
37
+ assert_equal(date , result[:datetime])
38
+ assert_equal("@" , result[:type])
39
+ assert_equal(nil , result[:option])
40
+ assert_equal("scheduleA", result[:description])
41
+ assert_equal(true , result[:flag_time])
42
+
43
+ result = Sculd::Plan.parse('[2012-11-01 01:02:03(th)]@ scheduleA')
44
+ date = DateTime.new(2012, 11, 01, 1, 2, 3)
45
+ assert_equal(date , result[:datetime])
46
+ assert_equal("@" , result[:type])
47
+ assert_equal(nil , result[:option])
48
+ assert_equal("scheduleA", result[:description])
49
+ assert_equal(true , result[:flag_time])
50
+
51
+ result = Sculd::Plan.parse('[2012-11-01 01:02:03(木)]@ scheduleA')
52
+ date = DateTime.new(2012, 11, 01, 1, 2, 3)
53
+ assert_equal(date , result[:datetime])
54
+ assert_equal("@" , result[:type])
55
+ assert_equal(nil , result[:option])
56
+ assert_equal("scheduleA", result[:description])
57
+ assert_equal(true , result[:flag_time])
58
+
59
+ #context 'schedule with wrong weekday' do
60
+ io = StringIO.new
61
+ assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(Sun)]@ scheduleA', io)}
62
+
63
+ assert_raise(Sculd::Plan::WeekdayMismatchError ){ Sculd::Plan.parse( "[2012-11-01(Fri)]@ mismach weekday\n", io)}
64
+
65
+ assert_raise(Sculd::Plan::NotWeekdayError ){ Sculd::Plan.parse('[2012-11-01 01:02:03(abc)]@ scheduleA', io)}
66
+
67
+ #Unable to interpret as date in [].
68
+ #assert_raise(Sculd::Plan::NotDateError ){ Sculd::Plan.parse('[abc]! deadlineA')}
69
+ assert_raise(ArgumentError){ Sculd::Plan.parse('[abc]! deadlineA')}
70
+
71
+ ##Illegal syntax
72
+ # '[abc]]! deadlineA' do
73
+ assert_raise(Sculd::Plan::NotNumberError){
74
+ Sculd::Plan.parse('[2012-01-01]]! deadlineA')
75
+ }
76
+ #date = DateTime.new(2012, 01, 01)
77
+ #assert_equal(date , result[:datetime])
78
+ #assert_equal("]" , result[:type])
79
+ #assert_equal("!" , result[:option])
80
+ #assert_equal("deadlineA", result[:description])
81
+
82
+ #context ' [2012-10-23]! deadlineA with space at head' do
83
+ #it 'should return Date, !, deadlineA' do
84
+ result = Sculd::Plan.parse(' [2012-10-23]! deadlineA with space at head')
85
+ date = DateTime.new(2012, 10, 23)
86
+ assert_equal(date , result[:datetime])
87
+ assert_equal("!" , result[:type])
88
+ assert_equal(nil , result[:option])
89
+ assert_equal("deadlineA with space at head", result[:description])
90
+ assert_equal(false , result[:flag_time])
91
+
92
+ #context '[2012-10-23]!10 deadline with option value' do
93
+ #it 'should return Date, !, deadlineA' do
94
+ result = Sculd::Plan.parse( '[2012-10-23]!10 deadline with option value')
95
+ date = DateTime.new(2012, 10, 23)
96
+ assert_equal(date , result[:datetime])
97
+ assert_equal("!" , result[:type])
98
+ assert_equal(10 , result[:option])
99
+ assert_equal("deadline with option value", result[:description])
100
+ assert_equal(false , result[:flag_time])
101
+ end
102
+
103
+ #def test_wday
104
+ #end
97
105
  end
@@ -6,33 +6,33 @@ require "helper"
6
6
  #require "pkg/klass.rb"
7
7
 
8
8
  class TC_Klass < Test::Unit::TestCase
9
- def setup
10
- date = Date.new(2012, 10, 23)
11
- @r00 = Sculd::Plan::Reminder.new(date, false, 10, 'reminderA')
12
-
13
- date = DateTime.new(2012, 10, 23, 23, 45, 00)
14
- @r01 = Sculd::Plan::Reminder.new(date, false, 10, 'reminderA')
15
- end
16
-
17
- def test_priority
18
- #it 'return REMINDER_PRIORITY when the day is today .' do
19
- date = Date.new(2012, 10, 23)
20
- assert_equal(10000, @r00.priority(date))
21
-
22
- #it 'return REMINDER_PRIORITY -1 when the day is yesterday .' do
23
- date = Date.new(2012, 10, 24)
24
- assert_equal(9999, @r00.priority(date))
25
- end
26
-
27
- def test_event_dates
28
- #it 'return a Sculd::Event instance.' do
29
- results = @r00.event_dates
30
- assert_equal([Date.new(2012, 10, 23)], results)
31
-
32
- results = @r01.event_dates
33
- assert_equal(1 , results.size)
34
- assert_equal(Date.new(2012, 10, 23), results[0] )
35
- assert_equal(Date , results[0].class )
36
- end
9
+ def setup
10
+ date = Date.new(2012, 10, 23)
11
+ @r00 = Sculd::Plan::Reminder.new(date, false, 10, 'reminderA')
12
+
13
+ date = DateTime.new(2012, 10, 23, 23, 45, 00)
14
+ @r01 = Sculd::Plan::Reminder.new(date, false, 10, 'reminderA')
15
+ end
16
+
17
+ def test_priority
18
+ #it 'return REMINDER_PRIORITY when the day is today .' do
19
+ date = Date.new(2012, 10, 23)
20
+ assert_equal(10000, @r00.priority(date))
21
+
22
+ #it 'return REMINDER_PRIORITY -1 when the day is yesterday .' do
23
+ date = Date.new(2012, 10, 24)
24
+ assert_equal(9999, @r00.priority(date))
25
+ end
26
+
27
+ def test_event_dates
28
+ #it 'return a Sculd::Event instance.' do
29
+ results = @r00.event_dates
30
+ assert_equal([Date.new(2012, 10, 23)], results)
31
+
32
+ results = @r01.event_dates
33
+ assert_equal(1 , results.size)
34
+ assert_equal(Date.new(2012, 10, 23), results[0] )
35
+ assert_equal(Date , results[0].class )
36
+ end
37
37
  end
38
38