-
Notifications
You must be signed in to change notification settings - Fork 6
/
cron_test.go
100 lines (91 loc) · 2.56 KB
/
cron_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
package cron
import (
"errors"
"fmt"
"testing"
)
var (
testLocales = map[LocaleType][]localeTestCase{
Locale_cs: cs_TestCases(),
Locale_da: da_TestCases(),
Locale_de: de_TestCases(),
Locale_en: en_TestCases(),
Locale_es: es_TestCases(),
Locale_fa: fa_TestCases(),
Locale_fi: fi_TestCases(),
Locale_fr: fr_TestCases(),
Locale_he: he_TestCases(),
Locale_it: it_TestCases(),
Locale_ja: ja_TestCases(),
Locale_ko: ko_TestCases(),
Locale_nb: nb_TestCases(),
Locale_nl: nl_TestCases(),
Locale_pl: pl_TestCases(),
Locale_pt_BR: pt_BR_TestCases(),
Locale_ru: ru_TestCases(),
Locale_ro: ro_TestCases(),
Locale_sk: sk_TestCases(),
Locale_sl: sl_TestCases(),
Locale_sv: sv_TestCases(),
Locale_sw: sw_TestCases(),
Locale_tr: tr_TestCases(),
Locale_uk: uk_TestCases(),
Locale_zh_CN: zh_CN_TestCases(),
Locale_zh_TW: zh_TW_TestCases(),
}
)
func TestExpressionDescriptor_ToDescription(t *testing.T) {
for loc, localeTestCases := range testLocales {
t.Run(fmt.Sprintf("%s_%d_case(s)", loc, len(localeTestCases)), func(t *testing.T) {
for i, tc := range localeTestCases {
exprDesc, err := NewDescriptor(
Verbose(tc.isVerbose),
DayOfWeekStartsAtOne(tc.isDOWStartsAtOne),
Use24HourTimeFormat(tc.is24HourTimeFormat),
SetLocales(loc),
)
if err != nil {
t.Errorf("failed to create expression descriptor: %s", err)
return
}
gotDesc, err := exprDesc.ToDescription(tc.inExpr, loc)
if tc.outErr != nil {
if err == nil {
t.Errorf("%d. %s: expected error, got nil", i, tc.name)
return
}
if !errors.Is(err, tc.outErr) {
t.Errorf("%d. %s: expected '%v' error, got '%v'", i, tc.name, tc.outErr, err)
return
}
if gotDesc != tc.outDesc && gotDesc != "" {
t.Errorf("%d. %s: expected return empty string when error, got '%v'", i, tc.name, gotDesc)
return
}
return
}
if gotDesc != tc.outDesc {
t.Errorf("%d. %s: expected '%v', got '%v'", i, tc.name, tc.outDesc, gotDesc)
return
}
}
})
}
}
var _desc string
func BenchmarkExpressionDescriptor_ToDescription(b *testing.B) {
b.StopTimer()
exprDesc, err := NewDescriptor(SetLocales(Locale_en))
if err != nil {
b.Errorf("failed to init expression descriptor: %s", err)
return
}
expr := "0/5 1,5,10,15 */2 L JAN-OCT 1-5/2 2000-2050/10"
b.StartTimer()
for i := 0; i < b.N; i++ {
_desc, err = exprDesc.ToDescription(expr, Locale_en)
if err != nil {
b.Fatalf("expected nil, got error: %s", err)
}
}
}