timr 0.1.0.pre.dev.5 → 0.1.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/lib/timr/window.rb CHANGED
@@ -10,10 +10,10 @@ module TheFox
10
10
  @cursor = 1
11
11
  @has_cursor = false
12
12
  @content_changed = true
13
- @content_refreshes = 1
13
+ @content_refreshes = 0
14
14
  @page = []
15
15
  @page_changed = true
16
- @page_refreshes = 1
16
+ @page_refreshes = 0
17
17
 
18
18
  setup
19
19
  content_refresh
@@ -24,6 +24,9 @@ module TheFox
24
24
  end
25
25
 
26
26
  def content_length=(content_length)
27
+ if @content_length != content_length
28
+ @content_changed = true
29
+ end
27
30
  @content_length = content_length
28
31
  end
29
32
 
@@ -44,13 +47,11 @@ module TheFox
44
47
  @content = content
45
48
  @content_refreshes += 1
46
49
  @content_changed = false
50
+
51
+ @page_changed = true
47
52
  end
48
53
  end
49
54
 
50
- def page_changed
51
- @page_changed = true
52
- end
53
-
54
55
  def page_refreshes
55
56
  @page_refreshes
56
57
  end
@@ -96,7 +97,7 @@ module TheFox
96
97
  add_lines = @content_length
97
98
  end
98
99
 
99
- page_changed
100
+ @page_changed = true
100
101
  @current_line += add_lines if next_page?
101
102
  cursor_set_to_last_if_out_of_range
102
103
  end
@@ -107,7 +108,7 @@ module TheFox
107
108
 
108
109
  def previous_page(length = @content_length)
109
110
  if previous_page?
110
- page_changed
111
+ @page_changed = true
111
112
  @current_line -= length
112
113
  if @current_line < 0
113
114
  @current_line = 0
@@ -116,7 +117,7 @@ module TheFox
116
117
  end
117
118
 
118
119
  def first_page
119
- page_changed
120
+ @page_changed = true
120
121
  @current_line = 0
121
122
  cursor_first_line
122
123
  end
@@ -127,7 +128,7 @@ module TheFox
127
128
 
128
129
  def last_page
129
130
  if !last_page?
130
- page_changed
131
+ @page_changed = true
131
132
 
132
133
  new_current_line = @content.length - @content_length
133
134
  if new_current_line >= 0
@@ -138,12 +139,12 @@ module TheFox
138
139
  end
139
140
 
140
141
  def next_line
141
- page_changed
142
+ @page_changed = true
142
143
  next_page(1)
143
144
  end
144
145
 
145
146
  def previous_line
146
- page_changed
147
+ @page_changed = true
147
148
  previous_page(1)
148
149
  end
149
150
 
@@ -189,7 +190,7 @@ module TheFox
189
190
  else
190
191
 
191
192
  end
192
- elsif @cursor <= border
193
+ elsif @cursor < border
193
194
  if previous_page?
194
195
  @cursor = border
195
196
  previous_line
@@ -29,7 +29,6 @@ module TheFox
29
29
  " #{TASK_NO_TASK_LOADED_C} .. No task loaded.",
30
30
  ' | .. Task stopped.',
31
31
  ' > .. Task is running.',
32
- #'',
33
32
  ]
34
33
  end
35
34
 
@@ -4,16 +4,28 @@ module TheFox
4
4
 
5
5
  class TestWindow < Window
6
6
 
7
+ @lines = nil
8
+
7
9
  def setup
8
10
  @has_cursor = true
11
+ @lines = nil
12
+ end
13
+
14
+ def content=(lines)
15
+ content_changed
16
+ @lines = lines
9
17
  end
10
18
 
11
19
  def content
12
- c = []
13
- (1..30).each do |n|
14
- c << 'LINE %03d 123456789_123456789_123456789_123456789_123456789_123456789' % [n]
20
+ if @lines.nil?
21
+ c = []
22
+ (1..30).each do |n|
23
+ c << 'LINE %03d 123456789_123456789_123456789_123456789_123456789_123456789' % [n]
24
+ end
25
+ c
26
+ else
27
+ @lines
15
28
  end
16
- c
17
29
  end
18
30
 
19
31
  end
@@ -28,7 +28,7 @@ module TheFox
28
28
  }
29
29
  .flatten
30
30
  .sort{ |task_a, task_b|
31
- task_a.begin <=> task_b.begin || task_a.end <=> task_b.end
31
+ task_a.begin_time <=> task_b.begin_time || task_a.end_time <=> task_b.end_time
32
32
  }
33
33
  end
34
34
  end
data/tests/tc_stack.rb ADDED
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'minitest/autorun'
4
+ require 'timr'
5
+
6
+
7
+ class TestStack < MiniTest::Test
8
+ def test_class_name
9
+ stack = TheFox::Timr::Stack.new
10
+
11
+ assert_equal('TheFox::Timr::Stack', stack.class.to_s)
12
+ end
13
+
14
+ def test_has_task
15
+ stack = TheFox::Timr::Stack.new
16
+ assert_equal(false, stack.has_task?)
17
+ end
18
+
19
+ def test_push_pop
20
+ task1 = TheFox::Timr::Task.new
21
+ task1.name = 'task1'
22
+ task2 = TheFox::Timr::Task.new
23
+ task2.name = 'task2'
24
+
25
+ stack = TheFox::Timr::Stack.new
26
+ assert_equal([], stack.tasks_texts)
27
+ assert_equal(nil, stack.task)
28
+ assert_equal(0, stack.length)
29
+
30
+ push_res = stack.push(task1)
31
+ assert_equal(true, push_res)
32
+ assert_equal(task1, stack.task)
33
+ assert_equal(1, stack.length)
34
+ assert_equal(true, task1.running?)
35
+ assert_equal(['* task1'], stack.tasks_texts)
36
+
37
+ push_res = stack.push(task2)
38
+ assert_equal(true, push_res)
39
+ assert_equal(task2, stack.task)
40
+ assert_equal(2, stack.length)
41
+ assert_equal(true, task2.running?)
42
+ assert_equal(false, task1.running?)
43
+ assert_equal(['| task1', '* task2'], stack.tasks_texts)
44
+
45
+ # if !@tasks.include?(task)
46
+ push_res = stack.push(task2)
47
+ assert_equal(false, push_res)
48
+ assert_equal(2, stack.length)
49
+
50
+ pop_res = stack.pop
51
+ assert_equal(true, pop_res)
52
+ assert_equal(task1, stack.task)
53
+ assert_equal(1, stack.length)
54
+ assert_equal(true, task1.running?)
55
+ assert_equal(false, task2.running?)
56
+ assert_equal(['* task1'], stack.tasks_texts)
57
+
58
+ pop_res = stack.pop
59
+ assert_equal(true, pop_res)
60
+ assert_equal([], stack.tasks_texts)
61
+ assert_equal(nil, stack.task)
62
+ assert_equal(0, stack.length)
63
+
64
+ # if !old.nil?
65
+ pop_res = stack.pop
66
+ assert_equal(false, pop_res)
67
+
68
+
69
+ # Pop All
70
+ task3 = TheFox::Timr::Task.new
71
+ task3.name = 'task3'
72
+ task4 = TheFox::Timr::Task.new
73
+ task4.name = 'task4'
74
+ task5 = TheFox::Timr::Task.new
75
+ task5.name = 'task5'
76
+
77
+ stack.push(task3)
78
+ stack.push(task4)
79
+ assert_equal(2, stack.length)
80
+ pop_all_res = stack.pop_all(task5)
81
+ assert_equal(true, pop_all_res)
82
+ assert_equal(1, stack.length)
83
+
84
+ pop_all_res = stack.pop_all(task5)
85
+ assert_equal(false, pop_all_res)
86
+ assert_equal(1, stack.length)
87
+
88
+ assert_equal(false, task3.running?)
89
+ assert_equal(false, task4.running?)
90
+ assert_equal(true, task5.running?)
91
+
92
+ pop_all_res = stack.pop_all
93
+ assert_equal(true, pop_all_res)
94
+ assert_equal(0, stack.length)
95
+ end
96
+ end
data/tests/tc_task.rb ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'minitest/autorun'
4
+ require 'time'
5
+ require 'fileutils'
6
+ require 'timr'
7
+
8
+
9
+ class TestTask < MiniTest::Test
10
+ def test_class_name
11
+ task = TheFox::Timr::Task.new
12
+
13
+ assert_equal('TheFox::Timr::Task', task.class.to_s)
14
+ end
15
+
16
+ def test_save_load
17
+ task1 = TheFox::Timr::Task.new
18
+
19
+ file_path = task1.save_to_file('tmp')
20
+ assert_equal(false, File.exist?(file_path))
21
+
22
+ task1.name = 'task1'
23
+ task1.description = 'description2'
24
+ file_path = task1.save_to_file('tmp')
25
+ assert_equal(true, File.exist?(file_path))
26
+
27
+ task2 = TheFox::Timr::Task.new
28
+ task2.load_from_file(file_path)
29
+
30
+ assert_equal(task1.id, task2.id)
31
+ assert_equal('task1', task2.name)
32
+ assert_equal('description2', task2.description)
33
+
34
+ FileUtils.rm_r(file_path)
35
+ end
36
+
37
+ def test_running
38
+ task1 = TheFox::Timr::Task.new
39
+ assert_equal(false, task1.running?)
40
+ assert_equal(?|, task1.status)
41
+
42
+ task1.start
43
+ assert_equal(true, task1.running?)
44
+ assert_equal(?>, task1.status)
45
+
46
+ task1.stop
47
+ assert_equal(false, task1.running?)
48
+ assert_equal(?|, task1.status)
49
+ end
50
+
51
+ def test_track
52
+ task1 = TheFox::Timr::Task.new
53
+ assert_equal(false, task1.has_track?)
54
+ assert_equal(0, task1.timeline.length)
55
+
56
+ task1.start
57
+ assert_equal(true, task1.has_track?)
58
+ assert_equal(1, task1.timeline.length)
59
+
60
+ task1.stop
61
+ assert_equal(false, task1.has_track?)
62
+ assert_equal(1, task1.timeline.length)
63
+
64
+ task1.start
65
+ assert_equal(true, task1.has_track?)
66
+ assert_equal(2, task1.timeline.length)
67
+
68
+ task1.stop
69
+ assert_equal(false, task1.has_track?)
70
+ assert_equal(2, task1.timeline.length)
71
+
72
+ task1.toggle
73
+ assert_equal(true, task1.has_track?)
74
+ assert_equal(3, task1.timeline.length)
75
+
76
+ task1.toggle
77
+ assert_equal(false, task1.has_track?)
78
+ assert_equal(3, task1.timeline.length)
79
+ end
80
+
81
+ def test_to_s
82
+ task1 = TheFox::Timr::Task.new
83
+ assert_equal(nil, task1.to_s)
84
+
85
+ task1.name = 'task1'
86
+ assert_equal('task1', task1.to_s)
87
+ end
88
+
89
+ def test_run_time_track
90
+ task1 = TheFox::Timr::Task.new
91
+
92
+ task1.start
93
+ task1.track.begin_time = Time.parse('1987-02-21 09:58:59')
94
+ assert_equal([24, 3, 2], task1.run_time_track(Time.parse('1987-02-22 10:02:01')))
95
+ end
96
+
97
+ def test_run_time_total
98
+ task1 = TheFox::Timr::Task.new
99
+ task1.toggle
100
+ task1.toggle
101
+ task1.toggle
102
+ task1.toggle
103
+ task1.toggle
104
+ task1.toggle
105
+
106
+ timeline = task1.timeline
107
+ timeline[0].begin_time = Time.parse('1986-11-20 01:01:01')
108
+ timeline[0].end_time = Time.parse('1986-11-20 02:02:02')
109
+ timeline[1].begin_time = Time.parse('1991-07-19 03:03:03')
110
+ timeline[1].end_time = Time.parse('1991-07-19 04:04:04')
111
+ timeline[2].begin_time = Time.parse('1991-08-24 05:05:05')
112
+ timeline[2].end_time = Time.parse('1991-08-24 06:06:06')
113
+ assert_equal([3, 3, 3], task1.run_time_total)
114
+
115
+ task1.toggle
116
+ timeline[3].begin_time = Time.parse('2001-01-01 07:07:07')
117
+ assert_equal([4, 4, 5], task1.run_time_total(Time.parse('2001-01-01 08:08:09')))
118
+ end
119
+ end
data/tests/tc_track.rb ADDED
@@ -0,0 +1,86 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'minitest/autorun'
4
+ require 'time'
5
+ require 'fileutils'
6
+ require 'timr'
7
+
8
+
9
+ class TestTrack < MiniTest::Test
10
+ def test_class_name
11
+ track = TheFox::Timr::Track.new
12
+
13
+ assert_equal('TheFox::Timr::Track', track.class.to_s)
14
+ end
15
+
16
+ def test_basic
17
+ track = TheFox::Timr::Track.new
18
+ assert_equal(Time.now.to_date, track.begin_time.to_date)
19
+ end
20
+
21
+ def test_diff
22
+ track = TheFox::Timr::Track.new
23
+ assert_equal(0, track.diff)
24
+
25
+ track.begin_time = Time.parse('1986-04-08 13:37:02')
26
+ track.end_time = Time.parse('1986-04-08 13:38:01')
27
+ assert_equal(59, track.diff)
28
+ assert_equal(Fixnum, track.diff.class)
29
+
30
+ track.begin_time = Time.parse('2015-01-16 23:00:00')
31
+ track.end_time = Time.parse('2015-06-04 15:30:01')
32
+ assert_equal(11979001, track.diff)
33
+ assert_equal(Fixnum, track.diff.class)
34
+ end
35
+
36
+ def test_to_h
37
+ track = TheFox::Timr::Track.new(nil, nil, nil)
38
+ h = track.to_h
39
+ assert_equal(nil, h['b'])
40
+ assert_equal(nil, h['e'])
41
+
42
+ track.begin_time = Time.parse('1990-02-21 09:45')
43
+ h = track.to_h
44
+ assert_equal('1990-02-21T08:45:00+0000', h['b'])
45
+ assert_equal(nil, h['e'])
46
+
47
+ track.begin_time = Time.parse('1989-10-19 12:59')
48
+ track.end_time = Time.parse('2012-12-14 20:45')
49
+ h = track.to_h
50
+ assert_equal('1989-10-19T11:59:00+0000', h['b'])
51
+ assert_equal('2012-12-14T19:45:00+0000', h['e'])
52
+
53
+ track.begin_time = Time.parse('2013-11-23 23:00')
54
+ track.end_time = Time.parse('2013-11-24 09:00')
55
+ h = track.to_h
56
+ assert_equal('2013-11-23T22:00:00+0000', h['b'])
57
+ assert_equal('2013-11-24T08:00:00+0000', h['e'])
58
+ end
59
+
60
+ def test_to_list_s
61
+ track = TheFox::Timr::Track.new(nil, Time.parse('1990-08-29 12:34:56'))
62
+ assert_equal('1990-08-29 12:34 - xx:xx ', track.to_list_s)
63
+
64
+ task = TheFox::Timr::Task.new
65
+ task.name = 'task1'
66
+ track = TheFox::Timr::Track.new(task, Time.parse('1990-08-29 12:34:56'))
67
+ assert_equal('1990-08-29 12:34 - xx:xx task1', track.to_list_s)
68
+
69
+ track.begin_time = Time.parse('1987-06-11 12:00:00')
70
+ track.end_time = Time.parse('1987-06-12 23:00:00')
71
+ assert_equal('1987-06-11 12:00 - 23:00 1987-06-12 task1', track.to_list_s)
72
+ end
73
+
74
+ def test_from_h
75
+ track = TheFox::Timr::Track.from_h({})
76
+ assert_equal(nil, track.begin_time)
77
+ assert_equal(nil, track.end_time)
78
+
79
+ track = TheFox::Timr::Track.from_h({
80
+ 'b' => '1986-06-18 12:34:56+0000',
81
+ 'e' => '2014-11-11 19:05:12+0000',
82
+ })
83
+ assert_equal('1986-06-18 14:34:56', track.begin_time.strftime('%Y-%m-%d %H:%M:%S'))
84
+ assert_equal('2014-11-11 20:05:12', track.end_time.strftime('%Y-%m-%d %H:%M:%S'))
85
+ end
86
+ end