17
17
Utc ,
18
18
} ,
19
19
chrono_tz:: Tz ,
20
- proptest:: {
21
- arbitrary:: any,
22
- prop_compose,
23
- proptest,
24
- } ,
25
20
std:: {
26
21
fmt:: Display ,
27
22
str:: FromStr ,
42
37
} ,
43
38
} ;
44
39
45
-
46
40
/// Helper time value representing 24:00:00 as 00:00:00 minus 1
47
41
/// nanosecond (underflowing to 23:59:59.999(...) ). While chrono
48
42
/// has this value internally exposed as NaiveTime::MAX, it is not
@@ -51,7 +45,6 @@ const MAX_TIME_INSTANT: NaiveTime = NaiveTime::MIN
51
45
. overflowing_sub_signed ( Duration :: nanoseconds ( 1 ) )
52
46
. 0 ;
53
47
54
-
55
48
#[ derive( Clone , Debug , Eq , PartialEq ) ]
56
49
pub struct MarketSchedule {
57
50
pub timezone : Tz ,
@@ -154,7 +147,6 @@ impl From<LegacySchedule> for MarketSchedule {
154
147
}
155
148
}
156
149
157
-
158
150
#[ derive( Clone , Debug , Eq , PartialEq ) ]
159
151
pub struct HolidayDaySchedule {
160
152
pub month : u32 ,
@@ -198,7 +190,6 @@ impl Display for HolidayDaySchedule {
198
190
}
199
191
}
200
192
201
-
202
193
#[ derive( Clone , Debug , Eq , PartialEq , Copy ) ]
203
194
pub enum ScheduleDayKind {
204
195
Open ,
@@ -286,6 +277,11 @@ mod tests {
286
277
use {
287
278
super :: * ,
288
279
chrono:: NaiveDateTime ,
280
+ proptest:: {
281
+ arbitrary:: any,
282
+ prop_compose,
283
+ proptest,
284
+ } ,
289
285
} ;
290
286
291
287
#[ test]
@@ -478,98 +474,98 @@ mod tests {
478
474
479
475
Ok ( ( ) )
480
476
}
481
- }
482
477
483
- prop_compose ! {
484
- fn schedule_day_kind( ) (
485
- r in any:: <u8 >( ) ,
486
- t1 in any:: <u32 >( ) ,
487
- t2 in any:: <u32 >( ) ,
488
- ) -> ScheduleDayKind {
489
- match r % 3 {
490
- 0 => ScheduleDayKind :: Open ,
491
- 1 => ScheduleDayKind :: Closed ,
492
- _ => ScheduleDayKind :: TimeRange (
493
- NaiveTime :: from_hms_opt( t1 % 24 , t1 / 24 % 60 , 0 ) . unwrap( ) ,
494
- NaiveTime :: from_hms_opt( t2 % 24 , t2 / 24 % 60 , 0 ) . unwrap( ) ,
495
- ) ,
478
+ prop_compose ! {
479
+ fn schedule_day_kind( ) (
480
+ r in any:: <u8 >( ) ,
481
+ t1 in any:: <u32 >( ) ,
482
+ t2 in any:: <u32 >( ) ,
483
+ ) -> ScheduleDayKind {
484
+ match r % 3 {
485
+ 0 => ScheduleDayKind :: Open ,
486
+ 1 => ScheduleDayKind :: Closed ,
487
+ _ => ScheduleDayKind :: TimeRange (
488
+ NaiveTime :: from_hms_opt( t1 % 24 , t1 / 24 % 60 , 0 ) . unwrap( ) ,
489
+ NaiveTime :: from_hms_opt( t2 % 24 , t2 / 24 % 60 , 0 ) . unwrap( ) ,
490
+ ) ,
491
+ }
496
492
}
497
493
}
498
- }
499
494
500
- prop_compose ! {
501
- fn holiday_day_schedule( ) (
502
- m in 1 ..=12u32 ,
503
- d in 1 ..=31u32 ,
504
- s in schedule_day_kind( ) ,
505
- ) -> HolidayDaySchedule {
506
- HolidayDaySchedule {
507
- month: m,
508
- day: d,
509
- kind: s,
495
+ prop_compose ! {
496
+ fn holiday_day_schedule( ) (
497
+ m in 1 ..=12u32 ,
498
+ d in 1 ..=31u32 ,
499
+ s in schedule_day_kind( ) ,
500
+ ) -> HolidayDaySchedule {
501
+ HolidayDaySchedule {
502
+ month: m,
503
+ day: d,
504
+ kind: s,
505
+ }
510
506
}
511
507
}
512
- }
513
508
514
- prop_compose ! {
515
- fn market_schedule( ) (
516
- tz in proptest:: sample:: select( vec![
517
- Tz :: UTC ,
518
- Tz :: America__New_York ,
519
- Tz :: America__Los_Angeles ,
520
- Tz :: America__Chicago ,
521
- Tz :: Singapore ,
522
- Tz :: Australia__Sydney ,
523
- ] ) ,
524
- weekly_schedule in proptest:: collection:: vec( schedule_day_kind( ) , 7 ..=7 ) ,
525
- holidays in proptest:: collection:: vec( holiday_day_schedule( ) , 0 ..12 ) ,
526
- ) -> MarketSchedule {
527
- MarketSchedule {
528
- timezone: tz,
529
- weekly_schedule,
530
- holidays,
509
+ prop_compose ! {
510
+ fn market_schedule( ) (
511
+ tz in proptest:: sample:: select( vec![
512
+ Tz :: UTC ,
513
+ Tz :: America__New_York ,
514
+ Tz :: America__Los_Angeles ,
515
+ Tz :: America__Chicago ,
516
+ Tz :: Singapore ,
517
+ Tz :: Australia__Sydney ,
518
+ ] ) ,
519
+ weekly_schedule in proptest:: collection:: vec( schedule_day_kind( ) , 7 ..=7 ) ,
520
+ holidays in proptest:: collection:: vec( holiday_day_schedule( ) , 0 ..12 ) ,
521
+ ) -> MarketSchedule {
522
+ MarketSchedule {
523
+ timezone: tz,
524
+ weekly_schedule,
525
+ holidays,
526
+ }
531
527
}
532
528
}
533
- }
534
529
535
- // Matches C or O or hhmm-hhmm with 24-hour time
536
- const VALID_SCHEDULE_DAY_KIND_REGEX : & str =
537
- "C|O|([01][1-9]|2[0-3])([0-5][0-9])-([01][1-9]|2[0-3])([0-5][0-9])" ;
530
+ // Matches C or O or hhmm-hhmm with 24-hour time
531
+ const VALID_SCHEDULE_DAY_KIND_REGEX : & str =
532
+ "C|O|([01][1-9]|2[0-3])([0-5][0-9])-([01][1-9]|2[0-3])([0-5][0-9])" ;
538
533
539
- // Matches MMDD with MM and DD being 01-12 and 01-31 respectively
540
- const VALID_MONTH_DAY_REGEX : & str = "(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" ;
534
+ // Matches MMDD with MM and DD being 01-12 and 01-31 respectively
535
+ const VALID_MONTH_DAY_REGEX : & str = "(0[1-9]|1[0-2])(0[1-9]|[12][0-9]|3[01])" ;
541
536
542
- proptest ! (
543
- #[ test]
544
- fn doesnt_crash( s in "\\ PC*" ) {
545
- _ = s. parse:: <MarketSchedule >( ) ;
546
- _ = s. parse:: <HolidayDaySchedule >( ) ;
547
- _ = s. parse:: <ScheduleDayKind >( ) ;
548
- }
537
+ proptest ! (
538
+ #[ test]
539
+ fn doesnt_crash( s in "\\ PC*" ) {
540
+ _ = s. parse:: <MarketSchedule >( ) ;
541
+ _ = s. parse:: <HolidayDaySchedule >( ) ;
542
+ _ = s. parse:: <ScheduleDayKind >( ) ;
543
+ }
549
544
550
- #[ test]
551
- fn parse_valid_schedule_day_kind( s in VALID_SCHEDULE_DAY_KIND_REGEX ) {
552
- assert!( s. parse:: <ScheduleDayKind >( ) . is_ok( ) ) ;
553
- }
545
+ #[ test]
546
+ fn parse_valid_schedule_day_kind( s in VALID_SCHEDULE_DAY_KIND_REGEX ) {
547
+ assert!( s. parse:: <ScheduleDayKind >( ) . is_ok( ) ) ;
548
+ }
554
549
555
- #[ test]
556
- fn test_valid_schedule_day_kind( s in schedule_day_kind( ) ) {
557
- assert_eq!( s, s. to_string( ) . parse:: <ScheduleDayKind >( ) . unwrap( ) ) ;
558
- }
550
+ #[ test]
551
+ fn test_valid_schedule_day_kind( s in schedule_day_kind( ) ) {
552
+ assert_eq!( s, s. to_string( ) . parse:: <ScheduleDayKind >( ) . unwrap( ) ) ;
553
+ }
559
554
560
- #[ test]
561
- fn parse_valid_holiday_day_schedule( s in VALID_SCHEDULE_DAY_KIND_REGEX , d in VALID_MONTH_DAY_REGEX ) {
562
- let valid_holiday_day = format!( "{}/{}" , d, s) ;
563
- assert!( valid_holiday_day. parse:: <HolidayDaySchedule >( ) . is_ok( ) ) ;
564
- }
555
+ #[ test]
556
+ fn parse_valid_holiday_day_schedule( s in VALID_SCHEDULE_DAY_KIND_REGEX , d in VALID_MONTH_DAY_REGEX ) {
557
+ let valid_holiday_day = format!( "{}/{}" , d, s) ;
558
+ assert!( valid_holiday_day. parse:: <HolidayDaySchedule >( ) . is_ok( ) ) ;
559
+ }
565
560
566
- #[ test]
567
- fn test_valid_holiday_day_schedule( s in holiday_day_schedule( ) ) {
568
- assert_eq!( s, s. to_string( ) . parse:: <HolidayDaySchedule >( ) . unwrap( ) ) ;
569
- }
561
+ #[ test]
562
+ fn test_valid_holiday_day_schedule( s in holiday_day_schedule( ) ) {
563
+ assert_eq!( s, s. to_string( ) . parse:: <HolidayDaySchedule >( ) . unwrap( ) ) ;
564
+ }
570
565
571
- #[ test]
572
- fn test_valid_market_schedule( s in market_schedule( ) ) {
573
- assert_eq!( s, s. to_string( ) . parse:: <MarketSchedule >( ) . unwrap( ) ) ;
574
- }
575
- ) ;
566
+ #[ test]
567
+ fn test_valid_market_schedule( s in market_schedule( ) ) {
568
+ assert_eq!( s, s. to_string( ) . parse:: <MarketSchedule >( ) . unwrap( ) ) ;
569
+ }
570
+ ) ;
571
+ }
0 commit comments