forked from dromara/carbon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang.kr_test.go
executable file
·260 lines (225 loc) · 7.29 KB
/
lang.kr_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
package carbon
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
)
var korean = "kr"
func TestLang_Korean_Constellation(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
expected string // 期望值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{6, "2020-01-05", "염소자리"},
{7, "2020-02-05", "물병자리"},
{8, "2020-03-05", "물고기자리"},
{9, "2020-04-05", "양자리"},
{10, "2020-05-05", "황소자리"},
{11, "2020-06-05", "쌍둥이자리"},
{12, "2020-07-05", "게자리"},
{13, "2020-08-05", "사자자리"},
{14, "2020-09-05", "처녀자리"},
{15, "2020-10-05", "천칭자리"},
{16, "2020-11-05", "전갈자리"},
{17, "2020-12-05", "사수자리"},
}
for _, test := range tests {
c := SetTimezone(PRC).Parse(test.input).SetLocale(korean)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Constellation(), "Current test id is "+strconv.Itoa(test.id))
}
}
func TestLang_Korean_Season(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
expected string // 期望值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{6, "2020-01-05", "겨울"},
{7, "2020-02-05", "겨울"},
{8, "2020-03-05", "봄"},
{9, "2020-04-05", "봄"},
{10, "2020-05-05", "봄"},
{11, "2020-06-05", "여름"},
{12, "2020-07-05", "여름"},
{13, "2020-08-05", "여름"},
{14, "2020-09-05", "가을"},
{15, "2020-10-05", "가을"},
{16, "2020-11-05", "가을"},
{17, "2020-12-05", "겨울"},
}
for _, test := range tests {
c := SetTimezone(PRC).Parse(test.input).SetLocale(korean)
assert.Nil(c.Error)
assert.Equal(test.expected, c.Season(), "Current test id is "+strconv.Itoa(test.id))
}
}
func TestLang_Korean_ToMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
expected string // 期望值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{6, "2020-01-05", "일월"},
{7, "2020-02-05", "이월"},
{8, "2020-03-05", "삼월"},
{9, "2020-04-05", "사월"},
{10, "2020-05-05", "오월"},
{11, "2020-06-05", "유월"},
{12, "2020-07-05", "칠월"},
{13, "2020-08-05", "팔월"},
{14, "2020-09-05", "구월"},
{15, "2020-10-05", "시월"},
{16, "2020-11-05", "십일월"},
{17, "2020-12-05", "십이월"},
}
for _, test := range tests {
c := SetTimezone(PRC).Parse(test.input).SetLocale(korean)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToMonthString(), "Current test id is "+strconv.Itoa(test.id))
}
}
func TestLang_Korean_ToShortMonthString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
expected string // 期望值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{6, "2020-01-05", "1월"},
{7, "2020-02-05", "2월"},
{8, "2020-03-05", "3월"},
{9, "2020-04-05", "4월"},
{10, "2020-05-05", "5월"},
{11, "2020-06-05", "6월"},
{12, "2020-07-05", "7월"},
{13, "2020-08-05", "8월"},
{14, "2020-09-05", "9월"},
{15, "2020-10-05", "10월"},
{16, "2020-11-05", "11월"},
{17, "2020-12-05", "12월"},
}
for _, test := range tests {
c := SetTimezone(PRC).Parse(test.input).SetLocale(korean)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortMonthString(), "Current test id is "+strconv.Itoa(test.id))
}
}
func TestLang_Korean_ToWeekString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
expected string // 期望值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{6, "2020-08-01", "토요일"},
{7, "2020-08-02", "일요일"},
{8, "2020-08-03", "월요일"},
{9, "2020-08-04", "화요일"},
{10, "2020-08-05", "수요일"},
{11, "2020-08-06", "목요일"},
{12, "2020-08-07", "금요일"},
}
for _, test := range tests {
c := SetTimezone(PRC).Parse(test.input).SetLocale(korean)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToWeekString(), "Current test id is "+strconv.Itoa(test.id))
}
}
func TestLang_Korean_ToShortWeekString(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input string // 输入值
expected string // 期望值
}{
{1, "", ""},
{2, "0", ""},
{3, "0000-00-00", ""},
{4, "00:00:00", ""},
{5, "0000-00-00 00:00:00", ""},
{6, "2020-08-01", "토요일"},
{7, "2020-08-02", "일요일"},
{8, "2020-08-03", "월요일"},
{9, "2020-08-04", "화요일"},
{10, "2020-08-05", "수요일"},
{11, "2020-08-06", "목요일"},
{12, "2020-08-07", "금요일"},
}
for _, test := range tests {
c := SetTimezone(PRC).Parse(test.input).SetLocale(korean)
assert.Nil(c.Error)
assert.Equal(test.expected, c.ToShortWeekString(), "Current test id is "+strconv.Itoa(test.id))
}
}
func TestLang_Korean_DiffForHumans(t *testing.T) {
assert := assert.New(t)
tests := []struct {
id int // 测试id
input1 string // 输入值
input2 string // 输入值
expected string // 期望值
}{
{1, "2020-08-05 13:14:15", "2020-08-05 13:14:15", "방금"},
{2, "2020-08-05 13:14:15", "2021-08-05 13:14:15", "1 년전"},
{3, "2020-08-05 13:14:15", "2019-08-05 13:14:15", "1 년후"},
{4, "2020-08-05 13:14:15", "2030-08-05 13:14:15", "10 년전"},
{5, "2020-08-05 13:14:15", "2010-08-05 13:14:15", "10 년후"},
{6, "2020-08-05 13:14:15", "2020-09-05 13:14:15", "1 개월전"},
{7, "2020-08-05 13:14:15", "2020-07-05 13:14:15", "1 개월후"},
{8, "2020-08-05 13:14:15", "2021-06-05 13:14:15", "10 개월전"},
{9, "2020-08-05 13:14:15", "2019-10-05 13:14:15", "10 개월후"},
{10, "2020-08-05 13:14:15", "2020-08-06 13:14:15", "1 일전"},
{11, "2020-08-05 13:14:15", "2020-08-04 13:14:15", "1 일후"},
{12, "2020-08-05 13:14:15", "2020-08-15 13:14:15", "1 주전"},
{13, "2020-08-05 13:14:15", "2020-07-26 13:14:15", "1 주후"},
{14, "2020-08-05 13:14:15", "2020-08-05 14:14:15", "1 시간전"},
{15, "2020-08-05 13:14:15", "2020-08-05 12:14:15", "1 시간후"},
{16, "2020-08-05 13:14:15", "2020-08-05 23:14:15", "10 시간전"},
{17, "2020-08-05 13:14:15", "2020-08-05 03:14:15", "10 시간후"},
{18, "2020-08-05 13:14:15", "2020-08-05 13:15:15", "1 분전"},
{19, "2020-08-05 13:14:15", "2020-08-05 13:13:15", "1 분후"},
{20, "2020-08-05 13:14:15", "2020-08-05 13:24:15", "10 분전"},
{21, "2020-08-05 13:14:15", "2020-08-05 13:04:15", "10 분후"},
{22, "2020-08-05 13:14:15", "2020-08-05 13:14:16", "1 초전"},
{23, "2020-08-05 13:14:15", "2020-08-05 13:14:14", "1 초후"},
{24, "2020-08-05 13:14:15", "2020-08-05 13:14:25", "10 초전"},
{25, "2020-08-05 13:14:15", "2020-08-05 13:14:05", "10 초후"},
}
for _, test := range tests {
c1 := Parse(test.input1)
c2 := Parse(test.input2)
assert.Nil(c1.Error)
assert.Nil(c2.Error)
assert.Equal(test.expected, c1.SetLocale(korean).DiffForHumans(c2), "Current test id is "+strconv.Itoa(test.id))
}
}