@@ -663,6 +663,40 @@ final class LayoutTests: XCTestCase {
663
663
}
664
664
}
665
665
666
+ func testEqualAttributesWithViews_givenEmptyArray( ) {
667
+
668
+ // GIVEN
669
+
670
+ let superview : UIView = . init( )
671
+ let view1 : UIView = . init( )
672
+ let view2 : UIView = . init( )
673
+ let layout : Layout = superview. layout ( ) . addItems ( view1, view2)
674
+
675
+ // WHEN
676
+
677
+ layout. equal ( . top, [ ] )
678
+
679
+ // THEN
680
+
681
+ expect ( layout. constraints) . to ( beEmpty ( ) )
682
+
683
+ // WHEN
684
+
685
+ layout. equal ( . top, [ view1] )
686
+
687
+ // THEN
688
+
689
+ expect ( layout. constraints) . to ( beEmpty ( ) )
690
+
691
+ // WHEN
692
+
693
+ layout. equal ( . top, [ view1, view2] )
694
+
695
+ // THEN
696
+
697
+ expect ( layout. constraints. count) == 1
698
+ }
699
+
666
700
func testEqualSizeWithViews( ) {
667
701
668
702
// GIVEN
@@ -721,6 +755,32 @@ final class LayoutTests: XCTestCase {
721
755
}
722
756
}
723
757
758
+ func testCenterViewBetweenLeadingAndTrailingPriority_givenNilSuperview( ) {
759
+
760
+ // GIVEN
761
+
762
+ var superview : UIView ? = . init( )
763
+ let view : UIView = . init( )
764
+ let siblingView : UIView = . init( )
765
+ let layout : Layout = superview!. layout ( ) . addItems ( view, siblingView)
766
+ let leadingAnchor : NSLayoutXAxisAnchor = siblingView. trailing
767
+ let trailingAnchor : NSLayoutXAxisAnchor = superview!. trailing
768
+
769
+ // THEN
770
+
771
+ expect ( layout. center ( view, between: leadingAnchor, and: trailingAnchor) ) === layout
772
+ expect ( layout. constraints. count) == 3
773
+
774
+ // WHEN
775
+
776
+ superview = nil
777
+
778
+ // THEN
779
+
780
+ expect ( layout. center ( view, between: leadingAnchor, and: trailingAnchor) ) === layout
781
+ expect ( layout. constraints. count) == 3
782
+ }
783
+
724
784
func testCenterViewBetweenTopAndBottomPriority( ) {
725
785
726
786
// GIVEN
@@ -755,6 +815,32 @@ final class LayoutTests: XCTestCase {
755
815
}
756
816
}
757
817
818
+ func testCenterViewBetweenTopAndBottomPriority_givenNilSuperview( ) {
819
+
820
+ // GIVEN
821
+
822
+ var superview : UIView ? = . init( )
823
+ let view : UIView = . init( )
824
+ let siblingView : UIView = . init( )
825
+ let layout : Layout = superview!. layout ( ) . addItems ( view, siblingView)
826
+ let topAnchor : NSLayoutYAxisAnchor = siblingView. bottom
827
+ let bottomAnchor : NSLayoutYAxisAnchor = superview!. bottom
828
+
829
+ // THEN
830
+
831
+ expect ( layout. center ( view, between: topAnchor, and: bottomAnchor) ) === layout
832
+ expect ( layout. constraints. count) == 3
833
+
834
+ // WHEN
835
+
836
+ superview = nil
837
+
838
+ // THEN
839
+
840
+ expect ( layout. center ( view, between: topAnchor, and: bottomAnchor) ) === layout
841
+ expect ( layout. constraints. count) == 3
842
+ }
843
+
758
844
// MARK: - Stack
759
845
760
846
func testHorizontalViewsSpacingDirectionPriorityAlignment( ) {
@@ -848,6 +934,40 @@ final class LayoutTests: XCTestCase {
848
934
}
849
935
}
850
936
937
+ func testHorizontalViewsSpacingDirectionPriorityAlignment_givenEmptyArray( ) {
938
+
939
+ // GIVEN
940
+
941
+ let superview : UIView = . init( )
942
+ let view1 : UIView = . init( )
943
+ let view2 : UIView = . init( )
944
+ let layout : Layout = superview. layout ( ) . addItems ( view1, view2)
945
+
946
+ // WHEN
947
+
948
+ layout. horizontal ( [ ] )
949
+
950
+ // THEN
951
+
952
+ expect ( layout. constraints) . to ( beEmpty ( ) )
953
+
954
+ // WHEN
955
+
956
+ layout. horizontal ( [ view1] )
957
+
958
+ // THEN
959
+
960
+ expect ( layout. constraints) . to ( beEmpty ( ) )
961
+
962
+ // WHEN
963
+
964
+ layout. horizontal ( [ view1, view2] )
965
+
966
+ // THEN
967
+
968
+ expect ( layout. constraints. count) == 1
969
+ }
970
+
851
971
func testVerticalViewsSpacingPriorityAlignment( ) {
852
972
853
973
// GIVEN
@@ -916,6 +1036,40 @@ final class LayoutTests: XCTestCase {
916
1036
}
917
1037
}
918
1038
1039
+ func testVerticalViewsSpacingPriorityAlignment_givenEmptyArray( ) {
1040
+
1041
+ // GIVEN
1042
+
1043
+ let superview : UIView = . init( )
1044
+ let view1 : UIView = . init( )
1045
+ let view2 : UIView = . init( )
1046
+ let layout : Layout = superview. layout ( ) . addItems ( view1, view2)
1047
+
1048
+ // WHEN
1049
+
1050
+ layout. vertical ( [ ] )
1051
+
1052
+ // THEN
1053
+
1054
+ expect ( layout. constraints) . to ( beEmpty ( ) )
1055
+
1056
+ // WHEN
1057
+
1058
+ layout. vertical ( [ view1] )
1059
+
1060
+ // THEN
1061
+
1062
+ expect ( layout. constraints) . to ( beEmpty ( ) )
1063
+
1064
+ // WHEN
1065
+
1066
+ layout. vertical ( [ view1, view2] )
1067
+
1068
+ // THEN
1069
+
1070
+ expect ( layout. constraints. count) == 1
1071
+ }
1072
+
919
1073
// MARK: - Visual Format Language
920
1074
921
1075
func testHorizontalWithFormatMetricsOptions_givenDefaults( ) {
0 commit comments