@@ -547,7 +547,7 @@ void main() {
547
547
expect (initial.firstDayOfMonth, expected);
548
548
});
549
549
550
- group ('last day of month' , (){
550
+ group ('last day of month' , () {
551
551
test ('last day of month' , () {
552
552
final initial = DateTime (2022 , 5 , 20 );
553
553
final expected = DateTime (2022 , 5 , 31 );
@@ -580,95 +580,67 @@ void main() {
580
580
});
581
581
});
582
582
583
- group (
584
- 'clamp' ,
585
- () {
586
- group (
587
- 'returns max when before it' ,
588
- () {
589
- final it = DateTime (2022 , DateTime .october, 15 );
590
- final min = DateTime (2022 , DateTime .september, 1 );
591
- final max = DateTime (2022 , DateTime .september, 30 );
592
- test (
593
- 'when it has a value for min' ,
594
- () {
595
- expect (it.clamp (min: min, max: max), equals (max));
596
- },
597
- );
598
- test (
599
- 'when it does not have a value for min' ,
600
- () {
601
- expect (it.clamp (max: max), equals (max));
602
- },
603
- );
604
- },
605
- );
606
- group (
607
- 'returns min when after it' ,
608
- () {
609
- final it = DateTime (2022 , DateTime .august, 21 );
610
- final min = DateTime (2022 , DateTime .september, 15 );
611
- final max = DateTime (2022 , DateTime .september, 30 );
612
- test (
613
- 'when it has a value for max' ,
614
- () {
615
- expect (it.clamp (min: min, max: max), equals (min));
616
- },
617
- );
618
- test (
619
- 'when it does not have a value for max' ,
620
- () {
621
- expect (it.clamp (min: min), equals (min));
622
- },
623
- );
624
- },
625
- );
626
- group (
627
- 'returns it' ,
628
- () {
629
- final it = DateTime (2022 , DateTime .september, 1 );
630
- final min = DateTime (2022 , DateTime .august, 1 );
631
- final max = DateTime (2022 , DateTime .september, 30 );
632
- test (
633
- 'when both min and max are null' ,
634
- () {
635
- expect (it.clamp (), equals (it));
636
- },
637
- );
638
- test (
639
- 'when is longer than min and max is null' ,
640
- () {
641
- expect (it.clamp (min: min), equals (it));
642
- },
643
- );
644
- test (
645
- 'when is shorter than max and min is null' ,
646
- () {
647
- expect (it.clamp (max: max), equals (it));
648
- },
649
- );
650
- test (
651
- 'when is longer than min and shorter than max' ,
652
- () {
653
- expect (it.clamp (min: min, max: max), equals (it));
654
- },
655
- );
656
- },
657
- );
658
- test (
659
- 'asserts that min should be before max' ,
660
- () {
661
- final it = DateTime (2022 , DateTime .september, 1 );
662
- final min = DateTime (2022 , DateTime .september, 30 );
663
- final max = DateTime (2022 , DateTime .august, 1 );
664
- expect (
665
- () => it.clamp (min: min, max: max),
666
- throwsA (isA <AssertionError >()),
667
- );
668
- },
669
- );
670
- },
671
- );
583
+ group ('clamp' , () {
584
+ group ('returns max when before it' , () {
585
+ final it = DateTime (2022 , DateTime .october, 15 );
586
+ final min = DateTime (2022 , DateTime .september, 1 );
587
+ final max = DateTime (2022 , DateTime .september, 30 );
588
+
589
+ test ('when it has a value for min' , () {
590
+ expect (it.clamp (min: min, max: max), equals (max));
591
+ });
592
+
593
+ test ('when it does not have a value for min' , () {
594
+ expect (it.clamp (max: max), equals (max));
595
+ });
596
+ });
597
+
598
+ group ('returns min when after it' , () {
599
+ final it = DateTime (2022 , DateTime .august, 21 );
600
+ final min = DateTime (2022 , DateTime .september, 15 );
601
+ final max = DateTime (2022 , DateTime .september, 30 );
602
+
603
+ test ('when it has a value for max' , () {
604
+ expect (it.clamp (min: min, max: max), equals (min));
605
+ });
606
+
607
+ test ('when it does not have a value for max' , () {
608
+ expect (it.clamp (min: min), equals (min));
609
+ });
610
+ });
611
+
612
+ group ('returns it' , () {
613
+ final it = DateTime (2022 , DateTime .september, 1 );
614
+ final min = DateTime (2022 , DateTime .august, 1 );
615
+ final max = DateTime (2022 , DateTime .september, 30 );
616
+
617
+ test ('when both min and max are null' , () {
618
+ expect (it.clamp (), equals (it));
619
+ });
620
+
621
+ test ('when is longer than min and max is null' , () {
622
+ expect (it.clamp (min: min), equals (it));
623
+ });
624
+
625
+ test ('when is shorter than max and min is null' , () {
626
+ expect (it.clamp (max: max), equals (it));
627
+ });
628
+
629
+ test ('when is longer than min and shorter than max' , () {
630
+ expect (it.clamp (min: min, max: max), equals (it));
631
+ });
632
+ });
633
+
634
+ test ('asserts that min should be before max' , () {
635
+ final it = DateTime (2022 , DateTime .september, 1 );
636
+ final min = DateTime (2022 , DateTime .september, 30 );
637
+ final max = DateTime (2022 , DateTime .august, 1 );
638
+ expect (
639
+ () => it.clamp (min: min, max: max),
640
+ throwsA (isA <AssertionError >()),
641
+ );
642
+ });
643
+ });
672
644
});
673
645
674
646
group ('Duration' , () {
@@ -705,94 +677,66 @@ void main() {
705
677
expect (extraTime >= 0 , true );
706
678
});
707
679
708
- group (
709
- 'clamp' ,
710
- () {
711
- group (
712
- 'returns max when shorter than it' ,
713
- () {
714
- final it = Duration (days: 10 , hours: 12 );
715
- final min = Duration (days: 5 );
716
- final max = Duration (days: 10 );
717
- test (
718
- 'when it has a value for min' ,
719
- () {
720
- expect (it.clamp (min: min, max: max), equals (max));
721
- },
722
- );
723
- test (
724
- 'when it does not have a value for min' ,
725
- () {
726
- expect (it.clamp (max: max), equals (max));
727
- },
728
- );
729
- },
730
- );
731
- group (
732
- 'returns min when longer than it' ,
733
- () {
734
- final it = Duration (hours: 18 );
735
- final min = Duration (days: 5 );
736
- final max = Duration (days: 10 );
737
- test (
738
- 'when it has a value for max' ,
739
- () {
740
- expect (it.clamp (min: min, max: max), equals (min));
741
- },
742
- );
743
- test (
744
- 'when it does not have a value for max' ,
745
- () {
746
- expect (it.clamp (min: min), equals (min));
747
- },
748
- );
749
- },
750
- );
751
- group (
752
- 'returns it' ,
753
- () {
754
- final it = Duration (days: 0 );
755
- final min = Duration (days: - 5 );
756
- final max = Duration (days: 5 );
757
- test (
758
- 'when both min and max are null' ,
759
- () {
760
- expect (it.clamp (), equals (it));
761
- },
762
- );
763
- test (
764
- 'when is longer than min and max is null' ,
765
- () {
766
- expect (it.clamp (min: min), equals (it));
767
- },
768
- );
769
- test (
770
- 'when is shorter than max and min is null' ,
771
- () {
772
- expect (it.clamp (max: max), equals (it));
773
- },
774
- );
775
- test (
776
- 'when is longer than min and shorter than max' ,
777
- () {
778
- expect (it.clamp (min: min, max: max), equals (it));
779
- },
780
- );
781
- },
782
- );
783
- test (
784
- 'asserts that min should be shorter than max' ,
785
- () {
786
- final it = Duration (days: - 0 );
787
- final min = Duration (days: 5 );
788
- final max = Duration (days: - 5 );
789
- expect (
790
- () => it.clamp (min: min, max: max),
791
- throwsA (isA <AssertionError >()),
792
- );
793
- },
794
- );
795
- },
796
- );
680
+ group ('clamp' , () {
681
+ group ('returns max when shorter than it' , () {
682
+ final it = Duration (days: 10 , hours: 12 );
683
+ final min = Duration (days: 5 );
684
+ final max = Duration (days: 10 );
685
+
686
+ test ('when it has a value for min' , () {
687
+ expect (it.clamp (min: min, max: max), equals (max));
688
+ });
689
+
690
+ test ('when it does not have a value for min' , () {
691
+ expect (it.clamp (max: max), equals (max));
692
+ });
693
+ });
694
+
695
+ group ('returns min when longer than it' , () {
696
+ final it = Duration (hours: 18 );
697
+ final min = Duration (days: 5 );
698
+ final max = Duration (days: 10 );
699
+
700
+ test ('when it has a value for max' , () {
701
+ expect (it.clamp (min: min, max: max), equals (min));
702
+ });
703
+
704
+ test ('when it does not have a value for max' , () {
705
+ expect (it.clamp (min: min), equals (min));
706
+ });
707
+ });
708
+
709
+ group ('returns it' , () {
710
+ final it = Duration (days: 0 );
711
+ final min = Duration (days: - 5 );
712
+ final max = Duration (days: 5 );
713
+
714
+ test ('when both min and max are null' , () {
715
+ expect (it.clamp (), equals (it));
716
+ });
717
+
718
+ test ('when is longer than min and max is null' , () {
719
+ expect (it.clamp (min: min), equals (it));
720
+ });
721
+
722
+ test ('when is shorter than max and min is null' , () {
723
+ expect (it.clamp (max: max), equals (it));
724
+ });
725
+
726
+ test ('when is longer than min and shorter than max' , () {
727
+ expect (it.clamp (min: min, max: max), equals (it));
728
+ });
729
+ });
730
+
731
+ test ('asserts that min should be shorter than max' , () {
732
+ final it = Duration (days: - 0 );
733
+ final min = Duration (days: 5 );
734
+ final max = Duration (days: - 5 );
735
+ expect (
736
+ () => it.clamp (min: min, max: max),
737
+ throwsA (isA <AssertionError >()),
738
+ );
739
+ });
740
+ });
797
741
});
798
742
}
0 commit comments