10
10
*
11
11
*/
12
12
13
- package cronexpr_test
13
+ package cronexpr
14
14
15
15
/******************************************************************************/
16
16
17
17
import (
18
18
"testing"
19
19
"time"
20
-
21
- "github.com/gorhill/cronexpr"
22
20
)
23
21
24
22
/******************************************************************************/
@@ -203,9 +201,9 @@ func TestExpressions(t *testing.T) {
203
201
for _ , test := range crontests {
204
202
for _ , times := range test .times {
205
203
from , _ := time .Parse ("2006-01-02 15:04:05" , times .from )
206
- expr , err := cronexpr . Parse (test .expr )
204
+ expr , err := Parse (test .expr )
207
205
if err != nil {
208
- t .Errorf (`cronexpr. Parse("%s") returned "%s"` , test .expr , err .Error ())
206
+ t .Errorf (`Parse("%s") returned "%s"` , test .expr , err .Error ())
209
207
}
210
208
next := expr .Next (from )
211
209
nextstr := next .Format (test .layout )
@@ -220,17 +218,17 @@ func TestExpressions(t *testing.T) {
220
218
221
219
func TestZero (t * testing.T ) {
222
220
from , _ := time .Parse ("2006-01-02" , "2013-08-31" )
223
- next := cronexpr . MustParse ("* * * * * 1980" ).Next (from )
221
+ next := MustParse ("* * * * * 1980" ).Next (from )
224
222
if next .IsZero () == false {
225
223
t .Error (`("* * * * * 1980").Next("2013-08-31").IsZero() returned 'false', expected 'true'` )
226
224
}
227
225
228
- next = cronexpr . MustParse ("* * * * * 2050" ).Next (from )
226
+ next = MustParse ("* * * * * 2050" ).Next (from )
229
227
if next .IsZero () == true {
230
228
t .Error (`("* * * * * 2050").Next("2013-08-31").IsZero() returned 'true', expected 'false'` )
231
229
}
232
230
233
- next = cronexpr . MustParse ("* * * * * 2099" ).Next (time.Time {})
231
+ next = MustParse ("* * * * * 2099" ).Next (time.Time {})
234
232
if next .IsZero () == false {
235
233
t .Error (`("* * * * * 2014").Next(time.Time{}).IsZero() returned 'true', expected 'false'` )
236
234
}
@@ -247,7 +245,7 @@ func TestNextN(t *testing.T) {
247
245
"Sat, 29 Nov 2014 00:00:00" ,
248
246
}
249
247
from , _ := time .Parse ("2006-01-02 15:04:05" , "2013-09-02 08:44:30" )
250
- result := cronexpr . MustParse ("0 0 * * 6#5" ).NextN (from , uint (len (expected )))
248
+ result := MustParse ("0 0 * * 6#5" ).NextN (from , uint (len (expected )))
251
249
if len (result ) != len (expected ) {
252
250
t .Errorf (`MustParse("0 0 * * 6#5").NextN("2013-09-02 08:44:30", 5):\n"` )
253
251
t .Errorf (` Expected %d returned time values but got %d instead` , len (expected ), len (result ))
@@ -270,38 +268,38 @@ func TestNextN_every5min(t *testing.T) {
270
268
"Mon, 2 Sep 2013 09:05:00" ,
271
269
}
272
270
from , _ := time .Parse ("2006-01-02 15:04:05" , "2013-09-02 08:44:32" )
273
- result := cronexpr . MustParse ("*/5 * * * *" ).NextN (from , uint (len (expected )))
271
+ result := MustParse ("*/5 * * * *" ).NextN (from , uint (len (expected )))
274
272
if len (result ) != len (expected ) {
275
273
t .Errorf (`MustParse("*/5 * * * *").NextN("2013-09-02 08:44:30", 5):\n"` )
276
274
t .Errorf (` Expected %d returned time values but got %d instead` , len (expected ), len (result ))
277
275
}
278
276
for i , next := range result {
279
277
nextStr := next .Format ("Mon, 2 Jan 2006 15:04:05" )
280
278
if nextStr != expected [i ] {
281
- t .Errorf (`MustParse("*/5 * * * *").NextN("2013-09-02 08:44:30", 5):\n"` )
279
+ t .Errorf (`MustParse("*/5 * * * *").NextN("2013-09-02 08:44:30", 5):\n"` )
282
280
t .Errorf (` result[%d]: expected "%s" but got "%s"` , i , expected [i ], nextStr )
283
281
}
284
282
}
285
283
}
286
284
287
285
// Issue: https://github.com/gorhill/cronexpr/issues/16
288
- func TestInterval_Interval60Issue (t * testing.T ){
289
- _ , err := cronexpr . Parse ("*/60 * * * * *" )
286
+ func TestInterval_Interval60Issue (t * testing.T ) {
287
+ _ , err := Parse ("*/60 * * * * *" )
290
288
if err == nil {
291
289
t .Errorf ("parsing with interval 60 should return err" )
292
290
}
293
291
294
- _ , err = cronexpr . Parse ("*/61 * * * * *" )
292
+ _ , err = Parse ("*/61 * * * * *" )
295
293
if err == nil {
296
294
t .Errorf ("parsing with interval 61 should return err" )
297
295
}
298
296
299
- _ , err = cronexpr . Parse ("2/60 * * * * *" )
297
+ _ , err = Parse ("2/60 * * * * *" )
300
298
if err == nil {
301
299
t .Errorf ("parsing with interval 60 should return err" )
302
300
}
303
301
304
- _ , err = cronexpr . Parse ("2-20/61 * * * * *" )
302
+ _ , err = Parse ("2-20/61 * * * * *" )
305
303
if err == nil {
306
304
t .Errorf ("parsing with interval 60 should return err" )
307
305
}
@@ -322,14 +320,14 @@ var benchmarkExpressionsLen = len(benchmarkExpressions)
322
320
323
321
func BenchmarkParse (b * testing.B ) {
324
322
for i := 0 ; i < b .N ; i ++ {
325
- _ = cronexpr . MustParse (benchmarkExpressions [i % benchmarkExpressionsLen ])
323
+ _ = MustParse (benchmarkExpressions [i % benchmarkExpressionsLen ])
326
324
}
327
325
}
328
326
329
327
func BenchmarkNext (b * testing.B ) {
330
- exprs := make ([]* cronexpr. Expression , benchmarkExpressionsLen )
328
+ exprs := make ([]* Expression , benchmarkExpressionsLen )
331
329
for i := 0 ; i < benchmarkExpressionsLen ; i ++ {
332
- exprs [i ] = cronexpr . MustParse (benchmarkExpressions [i ])
330
+ exprs [i ] = MustParse (benchmarkExpressions [i ])
333
331
}
334
332
from := time .Now ()
335
333
b .ResetTimer ()
0 commit comments