-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog_type_test.go
140 lines (137 loc) Β· 3.33 KB
/
log_type_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
package piyolog
import (
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
)
func Test_Log(t *testing.T) {
date := time.Date(2023, time.December, 31, 0, 0, 0, 0, piyoLoc)
var createdAt = func(h, m int) time.Time {
return date.Add(time.Duration(h)*time.Hour + time.Duration(m)*time.Minute)
}
tests := []struct {
in string
out Log
str string
}{
{
in: `23:00 ζ―δΉ³ ε·¦ 7ε / ε³ 5ε (50ml) γγγγι£²γγ `,
out: NursingLog{
LogItem: LogItem{
typ: "ζ―δΉ³",
content: "ε·¦ 7ε / ε³ 5ε (50ml)",
notes: "γγγγι£²γγ ",
createdAt: createdAt(23, 00),
},
Amount: 50,
Unit: "ml",
},
str: `23:00 ζ―δΉ³ ε·¦ 7ε / ε³ 5ε (50ml) γγγγι£²γγ `,
}, {
in: `08:45 AM γγ«γ― 140ml γγγγ ι£²γγ `,
out: FormulaLog{
LogItem: LogItem{
typ: "γγ«γ―",
content: "140ml",
notes: "γγγγ ι£²γγ ",
createdAt: createdAt(8, 45),
},
Amount: 140,
Unit: "ml",
},
str: `08:45 γγ«γ― 140ml γγγγ ι£²γγ `,
}, {
in: `23:10 ι’δΉ³ι£ γγγγι£γΉγ`,
out: SolidLog{
LogItem: LogItem{
typ: "ι’δΉ³ι£",
content: "",
notes: "γγγγι£γΉγ",
createdAt: createdAt(23, 10),
},
},
str: `23:10 ι’δΉ³ι£ γγγγι£γΉγ`,
}, {
in: `02:55 θ΅·γγ (3ζι35ε) `,
out: WakeUpLog{
LogItem: LogItem{
typ: "θ΅·γγ",
content: "(3ζι35ε)",
notes: "",
createdAt: createdAt(2, 55),
},
Duration: time.Duration(3)*time.Hour + time.Duration(35)*time.Minute,
},
str: `02:55 θ΅·γγ (3ζι35ε)`,
}, {
in: `08:00 PM ε―γ `,
out: SleepLog{
LogItem: LogItem{
typ: "ε―γ",
content: "",
notes: "",
createdAt: createdAt(20, 0),
},
},
str: `20:00 ε―γ`,
}, {
in: `06:40 γγγ£γ `,
out: PeeLog{
LogItem{
typ: "γγγ£γ",
content: "",
notes: "",
createdAt: createdAt(6, 40),
},
},
str: `06:40 γγγ£γ`,
}, {
in: `23:15 γγγ‘ (ε°γͺγ/γ΅γ€γ/η·) γγγγεΊγ`,
out: PoopLog{
LogItem{
typ: "γγγ‘",
content: "(ε°γͺγ/γ΅γ€γ/η·)",
notes: "γγγγεΊγ",
createdAt: createdAt(23, 15),
},
},
str: `23:15 γγγ‘ (ε°γͺγ/γ΅γ€γ/η·) γγγγεΊγ`,
}, {
in: `19:10 γι’¨ε `,
out: BathsLog{
LogItem{
typ: "γι’¨ε",
content: "",
notes: "",
createdAt: createdAt(19, 10),
},
},
str: `19:10 γι’¨ε`,
}, {
in: `14:30 δ½ζΈ© 36.5Β°C `,
out: BodyTemperatureLog{
LogItem: LogItem{
typ: "δ½ζΈ©",
content: "36.5Β°C",
notes: "",
createdAt: createdAt(14, 30),
},
Temperature: 36.5,
Unit: "Β°C",
},
str: `14:30 δ½ζΈ© 36.5Β°C`,
},
}
for _, tt := range tests {
t.Run(tt.in, func(t *testing.T) {
lg := NewLog(tt.in, date)
if diff := cmp.Diff(tt.out, lg, cmpopts.EquateComparable(LogItem{})); diff != "" {
t.Errorf("log parse failure: %s", diff)
}
if diff := cmp.Diff(tt.str, lg.String()); diff != "" {
t.Errorf("log parse failure: %s", diff)
}
})
}
}