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.
- checksums.yaml +7 -0
- data/CHANGES +15 -2
- data/Gemfile +6 -8
- data/VERSION +1 -1
- data/bin/dates +0 -1
- data/bin/sculd +76 -31
- data/lib/sculd/manager.rb +142 -141
- data/lib/sculd/plan.rb +72 -78
- data/lib/sculd/plan/deadline.rb +27 -27
- data/lib/sculd/plan/reminder.rb +12 -12
- data/lib/sculd/plan/schedule.rb +8 -8
- data/lib/sculd/plan/todo.rb +25 -25
- data/sculd.gemspec +24 -20
- data/test/helper.rb +4 -4
- data/test/test_deadline.rb +47 -47
- data/test/test_manager.rb +108 -98
- data/test/test_plan.rb +96 -88
- data/test/test_reminder.rb +28 -28
- data/test/test_schedule.rb +17 -17
- data/test/test_todo.rb +40 -40
- metadata +44 -45
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
|
-
|
10
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def setup
|
15
|
+
@s00 = Sculd::Manager.new("test/schedule/empty")
|
16
|
+
@s01 = Sculd::Manager.new("test/schedule/normal")
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
#
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
39
|
-
|
40
|
-
|
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
|
-
#
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#
|
50
|
-
#
|
51
|
-
|
52
|
-
|
53
|
-
#
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
#
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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(" [37m[44m 2012-09-15 Sat [0m\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(" [37m[44m 2012-09-15 Sat [0m\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(" [37m[41m 2012-09-16 Sun [0m\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
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
data/test/test_reminder.rb
CHANGED
@@ -6,33 +6,33 @@ require "helper"
|
|
6
6
|
#require "pkg/klass.rb"
|
7
7
|
|
8
8
|
class TC_Klass < Test::Unit::TestCase
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
|