croner 4.0.2

Fully-featured, lightweight, and efficient Rust library designed for parsing and evaluating cron patterns
Documentation
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
// OCPS Compliance Test Suite
//
// This file contains a separate test suite for verifying compliance
// with the Open Cron Pattern Specification (OCPS) 1.4 draft.
//
// Specification Reference: github.com/open-source-cron/ocsp
//
// Each module in this suite corresponds to a specific version of the OCPS,
// allowing for targeted testing of features as they were introduced.

#![cfg(any(feature = "chrono", feature = "jiff"))]

use croner::parser::CronParser;
use croner::Cron;
use std::str::FromStr;

/// Helper function to parse with a specific configuration.
fn custom_parse(pattern: &str, dom_and_dow: bool) -> Result<Cron, croner::errors::CronError> {
    CronParser::builder()
        .dom_and_dow(dom_and_dow)
        .build()
        .parse(pattern)
}

#[cfg(test)]
mod ocps_1_0_tests {
    use super::*;

    #[test]
    fn test_5_field_baseline() {
        assert!(
            Cron::from_str("15 10 1 10 *").is_ok(),
            "Should parse a 5-field pattern."
        );
    }

    #[test]
    fn test_special_chars_wildcard_list_range_step() {
        assert!(
            Cron::from_str("*/15 0-4,8-12 * JAN-MAR,DEC MON-FRI").is_ok(),
            "Should handle *, /, -, and , correctly."
        );
    }

    #[cfg(feature = "chrono")]
    #[test]
    fn chrono_test_logical_or_for_date_fields() {
        use chrono::{Local, TimeZone};

        let cron = Cron::from_str("0 12 1 * MON").unwrap();
        let first_of_month = Local.with_ymd_and_hms(2025, 7, 1, 12, 0, 0).unwrap();
        let a_monday = Local.with_ymd_and_hms(2025, 7, 14, 12, 0, 0).unwrap();

        assert!(cron.is_time_matching(&first_of_month).unwrap());
        assert!(cron.is_time_matching(&a_monday).unwrap());
    }

    #[cfg(feature = "jiff")]
    #[test]
    fn jiff_test_logical_or_for_date_fields() {
        use jiff::civil::date;

        let cron = Cron::from_str("0 12 1 * MON").unwrap();
        let first_of_month: jiff::civil::DateTime = date(2025, 7, 1).at(12, 0, 0, 0);
        let a_monday: jiff::civil::DateTime = date(2025, 7, 14).at(12, 0, 0, 0);

        assert!(cron.is_time_matching(&first_of_month).unwrap());
        assert!(cron.is_time_matching(&a_monday).unwrap());
    }
}

#[cfg(test)]
mod ocps_1_1_tests {
    use super::*;

    #[test]
    fn test_nicknames() {
        assert_eq!(
            custom_parse("@yearly", false)
                .unwrap()
                .pattern
                .to_string()
                .to_uppercase(),
            "0 0 1 1 *"
        );
        assert_eq!(
            custom_parse("@monthly", false)
                .unwrap()
                .pattern
                .to_string()
                .to_uppercase(),
            "0 0 1 * *"
        );
        assert_eq!(
            custom_parse("@weekly", false)
                .unwrap()
                .pattern
                .to_string()
                .to_uppercase(),
            "0 0 * * 0"
        );
        assert_eq!(
            custom_parse("@daily", false)
                .unwrap()
                .pattern
                .to_string()
                .to_uppercase(),
            "0 0 * * *"
        );
        assert_eq!(
            custom_parse("@hourly", false)
                .unwrap()
                .pattern
                .to_string()
                .to_uppercase(),
            "0 * * * *"
        );
    }

    #[test]
    #[ignore] // Ignored until @reboot is implemented
    fn test_reboot_nickname() {
        // The parser should accept @reboot without crashing.
        // A call to find_next_occurrence could then return a specific error if not supported at runtime.
        assert!(custom_parse("@reboot", false).is_ok());
    }
}

#[cfg(test)]
mod ocps_1_2_tests {
    use super::*;

    #[test]
    fn test_6_field_with_seconds() {
        let cron = custom_parse("30 15 10 1 10 *", false).unwrap();
        assert!(cron.pattern.seconds.is_bit_set(30, 1).unwrap());
        assert!(!cron.pattern.seconds.is_bit_set(0, 1).unwrap());
    }

    #[test]
    fn test_7_field_with_year() {
        let cron = custom_parse("0 0 12 1 1 * 2025", false).unwrap();
        assert!(cron.pattern.years.is_bit_set(2025, 1).unwrap());
    }
}

#[cfg(test)]
mod ocps_1_3_tests {
    use super::*;

    #[cfg(feature = "chrono")]
    mod chrono_tests {
        use super::*;
        use chrono::{Datelike, Local, TimeZone};

        #[test]
        fn test_last_day_of_month() {
        let cron = Cron::from_str("0 0 L * *").unwrap();
        let last_of_july = Local.with_ymd_and_hms(2025, 7, 31, 0, 0, 0).unwrap();
        let not_last_of_july = Local.with_ymd_and_hms(2025, 7, 30, 0, 0, 0).unwrap();
        assert!(cron.is_time_matching(&last_of_july).unwrap());
        assert!(!cron.is_time_matching(&not_last_of_july).unwrap());
    }

    #[test]
    fn test_last_weekday_of_month() {
        // The last Friday in July 2025 is the 25th.
        let cron = Cron::from_str("0 0 * * 5L").unwrap();
        let last_friday = Local.with_ymd_and_hms(2025, 7, 25, 0, 0, 0).unwrap();
        let not_last_friday = Local.with_ymd_and_hms(2025, 7, 18, 0, 0, 0).unwrap();
        assert!(cron.is_time_matching(&last_friday).unwrap());
        assert!(!cron.is_time_matching(&not_last_friday).unwrap());
    }

    #[test]
    fn test_nth_weekday_of_month() {
        // The second Tuesday in July 2025 is the 8th.
        let cron = Cron::from_str("0 0 * * 2#2").unwrap();
        let second_tuesday = Local.with_ymd_and_hms(2025, 7, 8, 0, 0, 0).unwrap();
        let first_tuesday = Local.with_ymd_and_hms(2025, 7, 1, 0, 0, 0).unwrap();
        assert!(cron.is_time_matching(&second_tuesday).unwrap());
        assert!(!cron.is_time_matching(&first_tuesday).unwrap());
    }

    #[test]
    fn test_closest_weekday() {
        // July 5th, 2025 is a Saturday. The closest weekday is Friday the 4th.
        let cron = Cron::from_str("0 0 5W 7 *").unwrap();
        let closest_weekday = Local.with_ymd_and_hms(2025, 7, 4, 0, 0, 0).unwrap();
        assert!(cron.is_time_matching(&closest_weekday).unwrap());
    }

    #[test]
    fn test_last_weekday_lw() {
        // Test LW (last weekday of the month)
        let cron = Cron::from_str("0 0 LW * *").unwrap();

        // February 2025: last day is 28 (Friday), last weekday is 28 (Friday)
        let feb_last_weekday = Local.with_ymd_and_hms(2025, 2, 28, 0, 0, 0).unwrap();
        assert!(
            cron.is_time_matching(&feb_last_weekday).unwrap(),
            "Should match Feb 28 (Friday) as last weekday"
        );

        // August 2025: last day is 31 (Sunday), last weekday is 29 (Friday)
        let aug_last_weekday = Local.with_ymd_and_hms(2025, 8, 29, 0, 0, 0).unwrap();
        assert!(
            cron.is_time_matching(&aug_last_weekday).unwrap(),
            "Should match Aug 29 (Friday) as last weekday"
        );

        // August 2025: 31st is Sunday, should NOT match
        let aug_31 = Local.with_ymd_and_hms(2025, 8, 31, 0, 0, 0).unwrap();
        assert!(
            !cron.is_time_matching(&aug_31).unwrap(),
            "Should NOT match Aug 31 (Sunday)"
        );

        // November 2025: last day is 30 (Sunday), last weekday is 28 (Friday)
        let nov_last_weekday = Local.with_ymd_and_hms(2025, 11, 28, 0, 0, 0).unwrap();
        assert!(
            cron.is_time_matching(&nov_last_weekday).unwrap(),
            "Should match Nov 28 (Friday) as last weekday"
        );

        // November 2025: 30th is Sunday, should NOT match
        let nov_30 = Local.with_ymd_and_hms(2025, 11, 30, 0, 0, 0).unwrap();
        assert!(
            !cron.is_time_matching(&nov_30).unwrap(),
            "Should NOT match Nov 30 (Sunday)"
        );
    }

    #[test]
    fn test_31w_only_triggers_if_31st_exists() {
        // Test that 31W only triggers if the 31st is present in the current month
        let cron = Cron::from_str("0 0 31W * *").unwrap();

        // January 2025: has 31 days, 31st is Friday, so 31W should match Jan 31
        let jan_31 = Local.with_ymd_and_hms(2025, 1, 31, 0, 0, 0).unwrap();
        assert!(
            cron.is_time_matching(&jan_31).unwrap(),
            "Should match Jan 31 (Friday)"
        );

        // February 2025: has only 28 days, 31W should NOT trigger in February at all
        let feb_28 = Local.with_ymd_and_hms(2025, 2, 28, 0, 0, 0).unwrap();
        assert!(
            !cron.is_time_matching(&feb_28).unwrap(),
            "Should NOT match in February (no 31st)"
        );

        // April 2025: has only 30 days, 31W should NOT trigger in April at all
        let apr_30 = Local.with_ymd_and_hms(2025, 4, 30, 0, 0, 0).unwrap();
        assert!(
            !cron.is_time_matching(&apr_30).unwrap(),
            "Should NOT match in April (no 31st)"
        );

        // May 2025: has 31 days, 31st is Saturday, so 31W should match May 30 (Friday)
        let may_30 = Local.with_ymd_and_hms(2025, 5, 30, 0, 0, 0).unwrap();
        assert!(
            cron.is_time_matching(&may_30).unwrap(),
            "Should match May 30 (Friday) for 31W"
        );

        // August 2025: has 31 days, 31st is Sunday, so 31W should match Aug 29 (Friday)
        let aug_29 = Local.with_ymd_and_hms(2025, 8, 29, 0, 0, 0).unwrap();
        assert!(
            cron.is_time_matching(&aug_29).unwrap(),
            "Should match Aug 29 (Friday) for 31W"
        );
    }

    #[test]
    fn test_lw_find_next_occurrences() {
        // Test that LW correctly finds the last weekday of each month
        let cron = Cron::from_str("0 0 LW * *").expect("Failed to parse LW pattern");

        // Start from Jan 1, 2025
        let start_date = Local.with_ymd_and_hms(2025, 1, 1, 0, 0, 0).unwrap();

        // Expected last weekdays for each month in 2025
        let expected = vec![
            (2025, 1, 31),  // January 31 (Friday)
            (2025, 2, 28),  // February 28 (Friday)
            (2025, 3, 31),  // March 31 (Monday)
            (2025, 4, 30),  // April 30 (Wednesday)
            (2025, 5, 30),  // May 30 (Friday)
            (2025, 6, 30),  // June 30 (Monday)
            (2025, 7, 31),  // July 31 (Thursday)
            (2025, 8, 29),  // August 29 (Friday) - 31st is Sunday
            (2025, 9, 30),  // September 30 (Tuesday)
            (2025, 10, 31), // October 31 (Friday)
            (2025, 11, 28), // November 28 (Friday) - 30th is Sunday
            (2025, 12, 31), // December 31 (Wednesday)
        ];

        let mut current = start_date;
        for (i, (year, month, day)) in expected.iter().enumerate() {
            match cron.find_next_occurrence(&current, false) {
                Ok(next) => {
                    assert_eq!(next.year(), *year, "Year mismatch at index {}", i);
                    assert_eq!(next.month(), *month, "Month mismatch at index {}", i);
                    assert_eq!(next.day(), *day, "Day mismatch at index {}", i);
                    current = next;
                }
                Err(e) => panic!("Error finding occurrence at index {}: {:?}", i, e),
            }
        }
    } // closes test_lw_find_next_occurrences
    } // closes chrono_tests

    #[cfg(feature = "jiff")]
    mod jiff_tests {
        use super::*;
        use jiff::civil::date;

        #[test]
        fn test_last_day_of_month() {
            let cron = Cron::from_str("0 0 L * *").unwrap();
            let last_of_july: jiff::civil::DateTime = date(2025, 7, 31).at(0, 0, 0, 0);
            let not_last_of_july: jiff::civil::DateTime = date(2025, 7, 30).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&last_of_july).unwrap());
            assert!(!cron.is_time_matching(&not_last_of_july).unwrap());
        }

        #[test]
        fn test_last_weekday_of_month() {
            let cron = Cron::from_str("0 0 * * 5L").unwrap();
            let last_friday: jiff::civil::DateTime = date(2025, 7, 25).at(0, 0, 0, 0);
            let not_last_friday: jiff::civil::DateTime = date(2025, 7, 18).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&last_friday).unwrap());
            assert!(!cron.is_time_matching(&not_last_friday).unwrap());
        }

        #[test]
        fn test_nth_weekday_of_month() {
            let cron = Cron::from_str("0 0 * * 2#2").unwrap();
            let second_tuesday: jiff::civil::DateTime = date(2025, 7, 8).at(0, 0, 0, 0);
            let first_tuesday: jiff::civil::DateTime = date(2025, 7, 1).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&second_tuesday).unwrap());
            assert!(!cron.is_time_matching(&first_tuesday).unwrap());
        }

        #[test]
        fn test_closest_weekday() {
            let cron = Cron::from_str("0 0 5W 7 *").unwrap();
            let closest_weekday: jiff::civil::DateTime = date(2025, 7, 4).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&closest_weekday).unwrap());
        }

        #[test]
        fn test_last_weekday_lw() {
            let cron = Cron::from_str("0 0 LW * *").unwrap();
            let feb_last: jiff::civil::DateTime = date(2025, 2, 28).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&feb_last).unwrap(), "Feb 28 (Friday) as last weekday");
            let aug_last: jiff::civil::DateTime = date(2025, 8, 29).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&aug_last).unwrap(), "Aug 29 (Friday) as last weekday");
            let aug_31: jiff::civil::DateTime = date(2025, 8, 31).at(0, 0, 0, 0);
            assert!(!cron.is_time_matching(&aug_31).unwrap(), "Should NOT match Aug 31 (Sunday)");
            let nov_last: jiff::civil::DateTime = date(2025, 11, 28).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&nov_last).unwrap(), "Nov 28 (Friday) as last weekday");
            let nov_30: jiff::civil::DateTime = date(2025, 11, 30).at(0, 0, 0, 0);
            assert!(!cron.is_time_matching(&nov_30).unwrap(), "Should NOT match Nov 30 (Sunday)");
        }

        #[test]
        fn test_31w_only_triggers_if_31st_exists() {
            let cron = Cron::from_str("0 0 31W * *").unwrap();
            let jan_31: jiff::civil::DateTime = date(2025, 1, 31).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&jan_31).unwrap(), "Should match Jan 31 (Friday)");
            let feb_28: jiff::civil::DateTime = date(2025, 2, 28).at(0, 0, 0, 0);
            assert!(!cron.is_time_matching(&feb_28).unwrap(), "Should NOT match in February");
            let apr_30: jiff::civil::DateTime = date(2025, 4, 30).at(0, 0, 0, 0);
            assert!(!cron.is_time_matching(&apr_30).unwrap(), "Should NOT match in April");
            let may_30: jiff::civil::DateTime = date(2025, 5, 30).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&may_30).unwrap(), "Should match May 30 for 31W");
            let aug_29: jiff::civil::DateTime = date(2025, 8, 29).at(0, 0, 0, 0);
            assert!(cron.is_time_matching(&aug_29).unwrap(), "Should match Aug 29 for 31W");
        }

        #[test]
        fn test_lw_find_next_occurrences() {
            use jiff::civil::DateTime as CivilDateTime;

            let cron = Cron::from_str("0 0 LW * *").expect("Failed to parse LW pattern");
            let start_date: CivilDateTime = date(2025, 1, 1).at(0, 0, 0, 0);
            let expected = vec![
                (2025, 1, 31), (2025, 2, 28), (2025, 3, 31), (2025, 4, 30),
                (2025, 5, 30), (2025, 6, 30), (2025, 7, 31), (2025, 8, 29),
                (2025, 9, 30), (2025, 10, 31), (2025, 11, 28), (2025, 12, 31),
            ];
            let mut current = start_date;
            for (i, (year, month, day)) in expected.iter().enumerate() {
                match cron.find_next_occurrence(&current, false) {
                    Ok(next) => {
                        assert_eq!(next.year(), *year, "Year mismatch at index {i}");
                        assert_eq!(next.month(), *month, "Month mismatch at index {i}");
                        assert_eq!(next.day(), *day, "Day mismatch at index {i}");
                        current = next;
                    }
                    Err(e) => panic!("Error finding occurrence at index {i}: {e:?}"),
                }
            }
        }
    } // closes jiff_tests
} // closes ocps_1_3_tests

#[cfg(test)]
mod ocps_1_4_tests {
    use super::*;

    #[test]
    fn test_question_mark_is_alias_for_wildcard() {
        let cron_star = Cron::from_str("0 0 1 * *").unwrap();
        let cron_q = Cron::from_str("0 0 1 * ?").unwrap();
        assert_eq!(cron_star, cron_q);
    }

    #[cfg(feature = "chrono")]
    #[test]
    fn chrono_test_and_modifier() {
        use chrono::{Local, TimeZone};

        // Should ONLY match if the 1st of the month is a Monday.
        let cron = custom_parse("0 12 1 * +MON", false).unwrap();

        // September 1st, 2025 is a Monday.
        let first_is_monday = Local.with_ymd_and_hms(2025, 9, 1, 12, 0, 0).unwrap();
        // July 1st, 2025 is a Tuesday.
        let first_is_not_monday = Local.with_ymd_and_hms(2025, 7, 1, 12, 0, 0).unwrap();

        assert!(cron.is_time_matching(&first_is_monday).unwrap());
        assert!(!cron.is_time_matching(&first_is_not_monday).unwrap());
    }

    #[cfg(feature = "jiff")]
    #[test]
    fn jiff_test_and_modifier() {
        use jiff::civil::date;

        let cron = custom_parse("0 12 1 * +MON", false).unwrap();
        let first_is_monday: jiff::civil::DateTime = date(2025, 9, 1).at(12, 0, 0, 0);
        let first_is_not_monday: jiff::civil::DateTime = date(2025, 7, 1).at(12, 0, 0, 0);

        assert!(cron.is_time_matching(&first_is_monday).unwrap());
        assert!(!cron.is_time_matching(&first_is_not_monday).unwrap());
    }

    #[cfg(feature = "chrono")]
    #[test]
    fn chrono_test_global_and_mode() {
        use chrono::{Local, TimeZone};

        let cron = custom_parse("0 12 1 * MON", true).unwrap();

        // Should ONLY match if the 1st of the month is a Monday (due to global setting).
        let first_is_monday = Local.with_ymd_and_hms(2025, 9, 1, 12, 0, 0).unwrap();
        let first_is_not_monday = Local.with_ymd_and_hms(2025, 7, 1, 12, 0, 0).unwrap();
        let a_monday_not_first = Local.with_ymd_and_hms(2025, 7, 14, 12, 0, 0).unwrap();

        assert!(cron.is_time_matching(&first_is_monday).unwrap());
        assert!(!cron.is_time_matching(&first_is_not_monday).unwrap());
        assert!(!cron.is_time_matching(&a_monday_not_first).unwrap());
    }

    #[cfg(feature = "jiff")]
    #[test]
    fn jiff_test_global_and_mode() {
        use jiff::civil::date;

        let cron = custom_parse("0 12 1 * MON", true).unwrap();
        let first_is_monday: jiff::civil::DateTime = date(2025, 9, 1).at(12, 0, 0, 0);
        let first_is_not_monday: jiff::civil::DateTime = date(2025, 7, 1).at(12, 0, 0, 0);
        let a_monday_not_first: jiff::civil::DateTime = date(2025, 7, 14).at(12, 0, 0, 0);

        assert!(cron.is_time_matching(&first_is_monday).unwrap());
        assert!(!cron.is_time_matching(&first_is_not_monday).unwrap());
        assert!(!cron.is_time_matching(&a_monday_not_first).unwrap());
    }

    #[test]
    fn test_plus_modifier_invalid_field() {
        // Using '+' in the day-of-month field should result in an error.
        let result = custom_parse("0 0 +1 * *", false);
        assert!(matches!(
            result,
            Err(croner::errors::CronError::IllegalCharacters(_))
        ));
    }

    #[test]
    fn test_invalid_step_syntax_single_number() {
        // Only */Z and X-Y/Z should be allowed, not X/Z
        // Test 0/10 in minute field
        let result = Cron::from_str("0/10 * * * *");
        assert!(
            result.is_err(),
            "Pattern '0/10 * * * *' should be rejected (invalid step syntax)"
        );

        // Test 30/10 in minute field
        let result = Cron::from_str("30/10 * * * *");
        assert!(
            result.is_err(),
            "Pattern '30/10 * * * *' should be rejected (invalid step syntax)"
        );

        // Test 5/15 in hour field
        let result = Cron::from_str("* 5/15 * * *");
        assert!(
            result.is_err(),
            "Pattern '* 5/15 * * *' should be rejected (invalid step syntax)"
        );

        // Test 15/5 in day-of-month field
        let result = Cron::from_str("* * 15/5 * *");
        assert!(
            result.is_err(),
            "Pattern '* * 15/5 * *' should be rejected (invalid step syntax)"
        );

        // Test 6/2 in month field
        let result = Cron::from_str("* * * 6/2 *");
        assert!(
            result.is_err(),
            "Pattern '* * * 6/2 *' should be rejected (invalid step syntax)"
        );

        // Test 1/2 in day-of-week field
        let result = Cron::from_str("* * * * 1/2");
        assert!(
            result.is_err(),
            "Pattern '* * * * 1/2' should be rejected (invalid step syntax)"
        );

        // Test /10 in minute field (omitting starting point)
        let result = Cron::from_str("/10 * * * *");
        assert!(
            result.is_err(),
            "Pattern '/10 * * * *' should be rejected (omitting starting point)"
        );

        // Test /5 in hour field
        let result = Cron::from_str("* /5 * * *");
        assert!(
            result.is_err(),
            "Pattern '* /5 * * *' should be rejected (omitting starting point)"
        );
    }

    #[test]
    fn test_valid_step_syntax() {
        // Verify that */Z syntax is still valid
        assert!(
            Cron::from_str("*/10 * * * *").is_ok(),
            "Pattern '*/10 * * * *' should be accepted (valid wildcard step)"
        );

        // Verify that X-Y/Z syntax is still valid
        assert!(
            Cron::from_str("0-30/10 * * * *").is_ok(),
            "Pattern '0-30/10 * * * *' should be accepted (valid range step)"
        );

        assert!(
            Cron::from_str("10-50/5 * * * *").is_ok(),
            "Pattern '10-50/5 * * * *' should be accepted (valid range step)"
        );
    }

    #[test]
    fn test_sloppy_ranges_enabled() {
        // When sloppy_ranges is enabled, X/Z and /Z patterns should be accepted
        let parser = CronParser::builder().sloppy_ranges(true).build();

        // Test single number with step (0/10)
        let result = parser.parse("0/10 * * * *");
        assert!(
            result.is_ok(),
            "Pattern '0/10 * * * *' should be accepted with sloppy_ranges enabled"
        );

        // Test single number with step (30/10)
        let result = parser.parse("30/10 * * * *");
        assert!(
            result.is_ok(),
            "Pattern '30/10 * * * *' should be accepted with sloppy_ranges enabled"
        );

        // Test omitted starting point (/10)
        let result = parser.parse("/10 * * * *");
        assert!(
            result.is_ok(),
            "Pattern '/10 * * * *' should be accepted with sloppy_ranges enabled"
        );

        // Test in different fields
        let result = parser.parse("* 5/15 * * *");
        assert!(
            result.is_ok(),
            "Pattern '* 5/15 * * *' should be accepted with sloppy_ranges enabled"
        );

        let result = parser.parse("* * /5 * *");
        assert!(
            result.is_ok(),
            "Pattern '* * /5 * *' should be accepted with sloppy_ranges enabled"
        );
    }

    #[test]
    fn test_sloppy_ranges_disabled_by_default() {
        // Default parser should have sloppy_ranges disabled
        let parser = CronParser::new();

        // These should fail with default strict mode
        assert!(
            parser.parse("0/10 * * * *").is_err(),
            "Pattern '0/10 * * * *' should be rejected by default"
        );

        assert!(
            parser.parse("/10 * * * *").is_err(),
            "Pattern '/10 * * * *' should be rejected by default"
        );
    }

    #[test]
    fn test_sloppy_ranges_behavior() {
        // Test that sloppy patterns produce correct behavior
        let parser = CronParser::builder().sloppy_ranges(true).build();

        // 0/10 should match 0, 10, 20, 30, 40, 50
        let cron = parser.parse("0/10 * * * *").unwrap();
        assert!(cron.pattern.minutes.is_bit_set(0, 1).unwrap());
        assert!(cron.pattern.minutes.is_bit_set(10, 1).unwrap());
        assert!(cron.pattern.minutes.is_bit_set(20, 1).unwrap());
        assert!(!cron.pattern.minutes.is_bit_set(5, 1).unwrap());

        // /10 should match 0, 10, 20, 30, 40, 50 (same as */10)
        let cron = parser.parse("/10 * * * *").unwrap();
        assert!(cron.pattern.minutes.is_bit_set(0, 1).unwrap());
        assert!(cron.pattern.minutes.is_bit_set(10, 1).unwrap());
        assert!(cron.pattern.minutes.is_bit_set(50, 1).unwrap());
    }
}