-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser_test.go
95 lines (88 loc) · 2.45 KB
/
parser_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
package main
import (
_ "embed"
"fmt"
"strings"
"testing"
"time"
)
// TODO
func NoTestParseLine(t *testing.T) {
t.Parallel()
category, parsedDate, err := parseLine(
"## 2021-12-02 Thu 02:46 PM WET (toil, deprovisions)")
if err != nil {
t.Errorf("test got error: %s", err.Error())
}
if category != "toil, deprovisions" {
t.Errorf("got incorrect category: %s", category)
}
testDate, _ := time.Parse(
"2006-01-02 Mon 15:04 PM MST",
"2021-12-02 Thu 02:46 PM WET")
fmt.Printf("\n\n-p---------> %s\n", parsedDate)
fmt.Printf("\n\n-t---------> %s\n", testDate)
if parsedDate != testDate {
t.Errorf("got incorrect date: %+v", parsedDate)
}
category, parsedDate, err = parseLine(
"## 2021-12-02 Thu 04:15 PM WET (break)")
if err != nil {
t.Errorf("test got error: %s", err.Error())
}
if category != "break" {
t.Errorf("got incorrect category: %s", category)
}
testDate, _ = time.Parse(time.RFC3339, "2021-12-02T16:15:00+00:00")
if parsedDate != testDate {
t.Errorf("got incorrect date: %+v", parsedDate)
}
category, parsedDate, err = parseLine(
"## 2021-12-02 Thu 05:00 PM WET (fun, gerber work)")
if err != nil {
t.Errorf("test got error: %s", err.Error())
}
if category != "fun, gerber work" {
t.Errorf("got incorrect category: %s", category)
}
testDate, _ = time.Parse(time.RFC3339, "2021-12-02T17:00:00+00:00")
if parsedDate != testDate {
t.Errorf("got incorrect date: %+v", parsedDate)
}
category, parsedDate, err = parseLine(
"## 2021-12-02 Thu 06:00 PM WET (more fun, gerber work, wow)")
if err != nil {
t.Errorf("test got error: %s", err.Error())
}
if category != "more fun, gerber work, wow" {
t.Errorf("got incorrect category: %s", category)
}
testDate, _ = time.Parse(time.RFC3339, "2021-12-02T18:00:00+00:00")
if parsedDate != testDate {
t.Errorf("got incorrect date: %+v", parsedDate)
}
}
func TestParseLineMalformedLineError(t *testing.T) {
t.Parallel()
_, _, err := parseLine(
"## 2021-12-02 Thu 02:46 PM WET")
if err == nil {
t.Errorf("expected error but got none")
return
}
if !strings.Contains(err.Error(), "found malformed line") {
t.Errorf("did not get malformed line error")
}
}
func TestParseLineDateParseError(t *testing.T) {
t.Parallel()
_, _, err := parseLine(
"## 2021-12-99 BLAH 02:46 PM NOO (fun, gerber work)")
if err == nil {
t.Errorf("expected error but got none")
return
}
if !strings.Contains(err.Error(), "error parsing date") {
t.Errorf("did not get date parse error")
}
}