-
Notifications
You must be signed in to change notification settings - Fork 12
/
task_test.go
736 lines (637 loc) · 22 KB
/
task_test.go
1
2
3
4
5
6
7
8
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package todotxt
import (
"testing"
"time"
)
var (
testInputTask = "testdata/task_todo.txt"
)
func TestNewTask(t *testing.T) {
task := NewTask()
testExpected = 0
testGot = task.Id
if testGot != testExpected {
t.Errorf("Expected new Task to have default Id [%d], but got [%d]", testExpected, testGot)
}
testExpected = ""
testGot = task.Original
if testGot != testExpected {
t.Errorf("Expected new Task to be empty, but got [%s]", testGot)
}
testExpected = ""
testGot = task.Todo
if testGot != testExpected {
t.Errorf("Expected new Task to be empty, but got [%s]", testGot)
}
testExpected = false
testGot = task.HasPriority()
if testGot != testExpected {
t.Errorf("Expected new Task to have no priority, but got [%v]", testGot)
}
testExpected = 0
testGot = len(task.Projects)
if testGot != testExpected {
t.Errorf("Expected new Task to have %d projects, but got [%d]", testExpected, testGot)
}
testExpected = 0
testGot = len(task.Contexts)
if testGot != testExpected {
t.Errorf("Expected new Task to have %d contexts, but got [%d]", testExpected, testGot)
}
testExpected = 0
testGot = len(task.AdditionalTags)
if testGot != testExpected {
t.Errorf("Expected new Task to have %d additional tags, but got [%d]", testExpected, testGot)
}
testExpected = true
testGot = task.HasCreatedDate()
if testGot != testExpected {
t.Errorf("Expected new Task to have a created date, but got [%v]", testGot)
}
testExpected = false
testGot = task.HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected new Task to not have a completed date, but got [%v]", testGot)
}
testExpected = false
testGot = task.HasDueDate()
if testGot != testExpected {
t.Errorf("Expected new Task to not have a due date, but got [%v]", testGot)
}
testExpected = false
testGot = task.Completed
if testGot != testExpected {
t.Errorf("Expected new Task to not be completed, but got [%v]", testGot)
}
}
func TestParseTask(t *testing.T) {
task, err := ParseTask("x (C) 2014-01-01 @Go due:2014-01-12 Create golang library documentation +go-todotxt ")
if err != nil {
t.Error(err)
}
testExpected = "x (C) 2014-01-01 Create golang library documentation @Go +go-todotxt due:2014-01-12"
testGot = task.Task()
if testGot != testExpected {
t.Errorf("Expected Task to be [%s], but got [%s]", testExpected, testGot)
}
testExpected = 0
testGot = task.Id
if testGot != testExpected {
t.Errorf("Expected Task to have default Id [%d], but got [%d]", testExpected, testGot)
}
testExpected = "x (C) 2014-01-01 @Go due:2014-01-12 Create golang library documentation +go-todotxt"
testGot = task.Original
if testGot != testExpected {
t.Errorf("Expected Task to be [%s], but got [%s]", testExpected, testGot)
}
testExpected = "Create golang library documentation"
testGot = task.Todo
if testGot != testExpected {
t.Errorf("Expected Task to be [%s], but got [%s]", testExpected, testGot)
}
testExpected = true
testGot = task.HasPriority()
if testGot != testExpected {
t.Errorf("Expected Task to have no priority, but got [%v]", testGot)
}
testExpected = "C"
testGot = task.Priority
if testGot != testExpected {
t.Errorf("Expected Task to have priority [%v], but got [%v]", testExpected, testGot)
}
testExpected = 1
testGot = len(task.Projects)
if testGot != testExpected {
t.Errorf("Expected Task to have %d projects, but got [%d]", testExpected, testGot)
}
testExpected = 1
testGot = len(task.Contexts)
if testGot != testExpected {
t.Errorf("Expected Task to have %d contexts, but got [%d]", testExpected, testGot)
}
testExpected = 0
testGot = len(task.AdditionalTags)
if testGot != testExpected {
t.Errorf("Expected Task to have %d additional tags, but got [%d]", testExpected, testGot)
}
testExpected = true
testGot = task.HasCreatedDate()
if testGot != testExpected {
t.Errorf("Expected Task to have a created date, but got [%v]", testGot)
}
testExpected = false
testGot = task.HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task to not have a completed date, but got [%v]", testGot)
}
testExpected = true
testGot = task.HasDueDate()
if testGot != testExpected {
t.Errorf("Expected Task to have a due date, but got [%v]", testGot)
}
testExpected = true
testGot = task.Completed
if testGot != testExpected {
t.Errorf("Expected Task to be completed, but got [%v]", testGot)
}
}
func TestTaskId(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 1
testGot = testTasklist[taskId-1].Id
if testGot != taskId {
t.Errorf("Expected Task[%d] to have Id [%d], but got [%d]", taskId, taskId, testGot)
}
taskId = 5
testGot = testTasklist[taskId-1].Id
if testGot != taskId {
t.Errorf("Expected Task[%d] to have Id [%d], but got [%d]", taskId, taskId, testGot)
}
taskId = 27
testGot = testTasklist[taskId-1].Id
if testGot != taskId {
t.Errorf("Expected Task[%d] to have Id [%d], but got [%d]", taskId, taskId, testGot)
}
taskId++
}
func TestTaskString(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 1
testExpected = "2013-02-22 Pick up milk @GroceryStore"
testGot = testTasklist[taskId-1].String()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be [%s], but got [%s]", taskId, testExpected, testGot)
}
taskId++
testExpected = "x Download Todo.txt mobile app @Phone"
testGot = testTasklist[taskId-1].String()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be [%s], but got [%s]", taskId, testExpected, testGot)
}
taskId++
testExpected = "(B) 2013-12-01 Outline chapter 5 @Computer +Novel Level:5 private:false due:2014-02-17"
testGot = testTasklist[taskId-1].Task()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be [%s], but got [%s]", taskId, testExpected, testGot)
}
taskId++
testExpected = "x 2014-01-02 (B) 2013-12-30 Create golang library test cases @Go +go-todotxt"
testGot = testTasklist[taskId-1].Task()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be [%s], but got [%s]", taskId, testExpected, testGot)
}
taskId++
testExpected = "x 2014-01-03 2014-01-01 Create some more golang library test cases @Go +go-todotxt"
testGot = testTasklist[taskId-1].Task()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be [%s], but got [%s]", taskId, testExpected, testGot)
}
taskId++
}
func TestTaskPriority(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 6
testExpected = "B"
testGot = testTasklist[taskId-1].Priority
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have priority '%s', but got '%s'", taskId, testExpected, testGot)
}
taskId++
testExpected = "C"
testGot = testTasklist[taskId-1].Priority
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have priority '%s', but got '%s'", taskId, testExpected, testGot)
}
taskId++
testExpected = "B"
testGot = testTasklist[taskId-1].Priority
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have priority '%s', but got '%s'", taskId, testExpected, testGot)
}
taskId++
if testTasklist[taskId-1].HasPriority() {
t.Errorf("Expected Task[%d] to have no priority, but got '%s'", taskId, testTasklist[4].Priority)
}
taskId++
}
func TestTaskCreatedDate(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 10
testExpected, err := time.Parse(DateLayout, "2012-01-30")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CreatedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have created date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected, err = time.Parse(DateLayout, "2013-02-22")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CreatedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have created date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected, err = time.Parse(DateLayout, "2014-01-01")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CreatedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have created date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected, err = time.Parse(DateLayout, "2013-12-30")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CreatedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have created date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected, err = time.Parse(DateLayout, "2014-01-01")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CreatedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have created date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
if testTasklist[taskId-1].HasCreatedDate() {
t.Errorf("Expected Task[%d] to have no created date, but got '%v'", taskId, testTasklist[4].CreatedDate)
}
taskId++
}
func TestTaskContexts(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 16
testExpected = []string{"Call", "Phone"}
testGot = testTasklist[taskId-1].Contexts
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have contexts '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = []string{"Office"}
testGot = testTasklist[taskId-1].Contexts
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have contexts '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = []string{"Electricity", "Home", "Of_Super-Importance", "Television"}
testGot = testTasklist[taskId-1].Contexts
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have contexts '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = []string{}
testGot = testTasklist[taskId-1].Contexts
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have no contexts, but got '%v'", taskId, testGot)
}
taskId++
}
func TestTasksProjects(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 20
testExpected = []string{"Gardening", "Improving", "Planning", "Relaxing-Work"}
testGot = testTasklist[taskId-1].Projects
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have projects '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = []string{"Novel"}
testGot = testTasklist[taskId-1].Projects
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have projects '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = []string{}
testGot = testTasklist[taskId-1].Projects
if !compareSlices(testGot.([]string), testExpected.([]string)) {
t.Errorf("Expected Task[%d] to have no projects, but got '%v'", taskId, testGot)
}
taskId++
}
func TestTaskDueDate(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 23
testExpected, err := time.Parse(DateLayout, "2014-02-17")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].DueDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have due date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
if testTasklist[taskId-1].HasDueDate() {
t.Errorf("Expected Task[%d] to have no due date, but got '%v'", taskId, testTasklist[taskId-1].DueDate)
}
taskId++
}
func TestTaskAddonTags(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 25
testExpected = map[string]string{"Level": "5", "private": "false"}
testGot = testTasklist[taskId-1].AdditionalTags
if len(testGot.(map[string]string)) != 2 ||
!compareMaps(testGot.(map[string]string), testExpected.(map[string]string)) {
t.Errorf("Expected Task[%d] to have addon tags '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = map[string]string{"Importance": "Very!"}
testGot = testTasklist[taskId-1].AdditionalTags
if len(testGot.(map[string]string)) != 1 ||
!compareMaps(testGot.(map[string]string), testExpected.(map[string]string)) {
t.Errorf("Expected Task[%d] to have projects '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected = map[string]string{}
testGot = testTasklist[taskId-1].AdditionalTags
if len(testGot.(map[string]string)) != 0 ||
!compareMaps(testGot.(map[string]string), testExpected.(map[string]string)) {
t.Errorf("Expected Task[%d] to have no additional tags, but got '%v'", taskId, testGot)
}
taskId++
testExpected = map[string]string{}
testGot = testTasklist[taskId-1].AdditionalTags
if len(testGot.(map[string]string)) != 0 ||
!compareMaps(testGot.(map[string]string), testExpected.(map[string]string)) {
t.Errorf("Expected Task[%d] to have no additional tags, but got '%v'", taskId, testGot)
}
taskId++
}
func TestTaskCompleted(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 29
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
taskId++
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
taskId++
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
taskId++
testExpected = false
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] not to be completed, but got '%v'", taskId, testGot)
}
taskId++
testExpected = false
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] not to be completed, but got '%v'", taskId, testGot)
}
taskId++
}
func TestTaskCompletedDate(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 34
if testTasklist[taskId-1].HasCompletedDate() {
t.Errorf("Expected Task[%d] to not have a completed date, but got '%v'", taskId, testTasklist[taskId-1].CompletedDate)
}
taskId++
testExpected, err := time.Parse(DateLayout, "2014-01-03")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CompletedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have completed date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
if testTasklist[taskId-1].HasCompletedDate() {
t.Errorf("Expected Task[%d] to not have a completed date, but got '%v'", taskId, testTasklist[taskId-1].CompletedDate)
}
taskId++
testExpected, err = time.Parse(DateLayout, "2014-01-02")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CompletedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have completed date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
testExpected, err = time.Parse(DateLayout, "2014-01-03")
if err != nil {
t.Fatal(err)
}
testGot = testTasklist[taskId-1].CompletedDate
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have completed date '%s', but got '%v'", taskId, testExpected, testGot)
}
taskId++
if testTasklist[taskId-1].HasCompletedDate() {
t.Errorf("Expected Task[%d] to not have a completed date, but got '%v'", taskId, testTasklist[taskId-1].CompletedDate)
}
taskId++
}
func TestTaskIsOverdue(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 40
testGot = testTasklist[taskId-1].IsOverdue()
if !testGot.(bool) {
t.Errorf("Expected Task[%d] to be overdue, but got '%v'", taskId, testGot)
}
taskId++
testGot = testTasklist[taskId-1].IsOverdue()
if testGot.(bool) {
t.Errorf("Expected Task[%d] not to be overdue, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].DueDate = time.Now().AddDate(0, 0, 1)
testGot = testTasklist[taskId-1].Due()
if testGot.(time.Duration).Hours() < 23 ||
testGot.(time.Duration).Hours() > 25 {
t.Errorf("Expected Task[%d] to be due in 24 hours, but got '%v'", taskId, testGot)
}
taskId++
testGot = testTasklist[taskId-1].IsOverdue()
if !testGot.(bool) {
t.Errorf("Expected Task[%d] to be overdue, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].DueDate = time.Now().AddDate(0, 0, -3)
testGot = testTasklist[taskId-1].Due()
if testGot.(time.Duration).Hours() < 71 ||
testGot.(time.Duration).Hours() > 73 {
t.Errorf("Expected Task[%d] to be due since 72 hours, but got '%v'", taskId, testGot)
}
taskId++
testGot = testTasklist[taskId-1].IsOverdue()
if testGot.(bool) {
t.Errorf("Expected Task[%d] not to be overdue, but got '%v'", taskId, testGot)
}
taskId++
}
func TestTaskComplete(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 44
// first 4 tasks should all match the same tests
for i := 0; i < 4; i++ {
testExpected = false
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] not to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] not to have a completed date, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].Complete()
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
testExpected = time.Now().Format(DateLayout)
testGot = testTasklist[taskId-1].CompletedDate.Format(DateLayout)
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date of '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
}
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].Complete()
testGot = testTasklist[taskId-1].Completed // should be unchanged
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate() // should be unchanged
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
testExpected = "2012-01-01" // should be unchanged
testGot = testTasklist[taskId-1].CompletedDate.Format(DateLayout)
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date of '%v', but got '%v'", taskId, testExpected, testGot)
}
taskId++
}
func TestTaskReopen(t *testing.T) {
testTasklist.LoadFromFilename(testInputTask)
taskId := 49
// the first 2 tasks should match the same tests
for i := 0; i < 2; i++ {
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testExpected = false
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].Reopen()
testExpected = false
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to not be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to not have a completed date, but got '%v'", taskId, testGot)
}
taskId++
}
// the next 3 tasks should all match the same tests
for i := 0; i < 3; i++ {
testExpected = true
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].Reopen()
testExpected = false
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to not be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to not have a completed date, but got '%v'", taskId, testGot)
}
taskId++
}
testExpected = false
testGot = testTasklist[taskId-1].Completed
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate()
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
testTasklist[taskId-1].Reopen()
testGot = testTasklist[taskId-1].Completed // should be unchanged
if testGot != testExpected {
t.Errorf("Expected Task[%d] to be completed, but got '%v'", taskId, testGot)
}
testGot = testTasklist[taskId-1].HasCompletedDate() // should be unchanged
if testGot != testExpected {
t.Errorf("Expected Task[%d] to have a completed date, but got '%v'", taskId, testGot)
}
taskId++
}
func compareSlices(list1 []string, list2 []string) bool {
if len(list1) != len(list2) {
return false
}
for i := range list1 {
if list1[i] != list2[i] {
return false
}
}
return true
}
func compareMaps(map1 map[string]string, map2 map[string]string) bool {
if len(map1) != len(map2) {
return false
}
compare := func(map1 map[string]string, map2 map[string]string) bool {
for key, value := range map1 {
if value2, found := map2[key]; !found {
return false
} else if value != value2 {
return false
}
}
return true
}
return compare(map1, map2) && compare(map2, map1)
}