@@ -44,20 +44,21 @@ class PinEdgesSpec: QuickSpec {
4444 viewController = UIViewController ( )
4545
4646 rootView = BasicView ( text: " " , color: . white)
47- rootView. frame = CGRect ( x: 0 , y: 0 , width: 400 , height: 400 )
4847 viewController. view. addSubview ( rootView)
4948
5049 aView = BasicView ( text: " View A " , color: UIColor . red. withAlphaComponent ( 0.5 ) )
51- aView. frame = CGRect ( x: 140 , y: 100 , width: 200 , height: 100 )
5250 rootView. addSubview ( aView)
5351
5452 bView = BasicView ( text: " View B " , color: UIColor . blue. withAlphaComponent ( 0.5 ) )
55- bView. frame = CGRect ( x: 160 , y: 120 , width: 110 , height: 80 )
5653 rootView. addSubview ( bView)
5754
5855 bViewChild = BasicView ( text: " View B Child " , color: UIColor . blue. withAlphaComponent ( 0.7 ) )
59- bViewChild. frame = CGRect ( x: 40 , y: 10 , width: 60 , height: 20 )
6056 bView. addSubview ( bViewChild)
57+
58+ rootView. frame = CGRect ( x: 0 , y: 0 , width: 400 , height: 400 )
59+ aView. frame = CGRect ( x: 140 , y: 100 , width: 200 , height: 100 )
60+ bView. frame = CGRect ( x: 160 , y: 120 , width: 110 , height: 80 )
61+ bViewChild. frame = CGRect ( x: 40 , y: 10 , width: 60 , height: 20 )
6162 }
6263
6364 //
@@ -456,62 +457,113 @@ class PinEdgesSpec: QuickSpec {
456457 }
457458
458459 //
459- // all / horizontall / vertically
460+ // all()
460461 //
461- describe ( " the result of bottom(... ) " ) {
462+ describe ( " the result of all( ) " ) {
462463 it ( " should adjust the aView " ) {
463464 aView. pin. all ( )
464- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 300 .0, width: 200 .0, height: 100 .0) ) )
465+ expect ( aView. frame) . to ( equal ( CGRect ( x: 0.0 , y: 0 .0, width: 400 .0, height: 400 .0) ) )
465466 }
466467
467468 it ( " should adjust the aView " ) {
468- aView. pin. bottom ( 0 )
469- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 300 .0, width: 200 .0, height: 100 .0) ) )
469+ aView. pin. all ( ) . margin ( 10 )
470+ expect ( aView. frame) . to ( equal ( CGRect ( x: 10.0 , y: 10 .0, width: 380 .0, height: 380 .0) ) )
470471 }
471472
472- it ( " should have the same position without or with a 0 parameter value " ) {
473- aView. pin. bottom ( )
474- let noParameterFrame = aView. frame
475-
476- aView. pin. bottom ( 0 )
477- expect ( aView. frame) . to ( equal ( noParameterFrame) )
473+ it ( " should adjust the bViewChild " ) {
474+ bViewChild. pin. all ( )
475+ expect ( bViewChild. frame) . to ( equal ( CGRect ( x: 0.0 , y: 0.0 , width: 110.0 , height: 80.0 ) ) )
478476 }
479477
478+ it ( " should adjust the bViewChild " ) {
479+ bViewChild. pin. all ( ) . margin ( 10 )
480+ expect ( bViewChild. frame) . to ( equal ( CGRect ( x: 10.0 , y: 10.0 , width: 90.0 , height: 60.0 ) ) )
481+ }
482+
483+ it ( " should warn " ) {
484+ aView. pin. top ( 20 ) . all ( )
485+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " all() top coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
486+ }
487+ it ( " should warn " ) {
488+ aView. pin. left ( 20 ) . all ( )
489+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " all() left coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
490+ }
491+ it ( " should warn " ) {
492+ aView. pin. right ( 20 ) . all ( )
493+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " all() right coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
494+ }
495+
496+ it ( " should warn " ) {
497+ aView. pin. bottom ( 20 ) . all ( )
498+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " all() bottom coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
499+ }
500+ }
501+
502+ //
503+ // horizontally()
504+ //
505+ describe ( " the result of horizontally() " ) {
480506 it ( " should adjust the aView " ) {
481- aView. pin. bottom ( - 20 )
482- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 320 .0, width: 200 .0, height: 100.0 ) ) )
507+ aView. pin. horizontally ( )
508+ expect ( aView. frame) . to ( equal ( CGRect ( x: 0.0 , y: 100 .0, width: 400 .0, height: 100.0 ) ) )
483509 }
484510
485511 it ( " should adjust the aView " ) {
486- aView. pin. top ( ) . bottom ( - 20 )
487- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 0 .0, width: 200 .0, height: 420 .0) ) )
512+ aView. pin. horizontally ( ) . margin ( 10 )
513+ expect ( aView. frame) . to ( equal ( CGRect ( x: 10.0 , y: 100 .0, width: 380 .0, height: 100 .0) ) )
488514 }
489515
490- it ( " should warns that the view is not added to any view " ) {
491- let unAttachedView = UIView ( frame: CGRect ( x: 10 , y: 10 , width: 10 , height: 10 ) )
492- unAttachedView. pin. bottom ( 20 % )
493-
494- expect ( unAttachedView. frame) . to ( equal ( CGRect ( x: 10 , y: 10 , width: 10 , height: 10 ) ) )
516+ it ( " should adjust the bViewChild " ) {
517+ bViewChild. pin. horizontally ( )
518+ expect ( bViewChild. frame) . to ( equal ( CGRect ( x: 0.0 , y: 10.0 , width: 110.0 , height: 20.0 ) ) )
519+ }
520+
521+ it ( " should adjust the bViewChild " ) {
522+ bViewChild. pin. horizontally ( ) . margin ( 10 )
523+ expect ( bViewChild. frame) . to ( equal ( CGRect ( x: 10.0 , y: 10.0 , width: 90.0 , height: 20.0 ) ) )
495524 }
496525
526+ it ( " should warn " ) {
527+ aView. pin. left ( 20 ) . horizontally ( )
528+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " horizontally() left coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
529+ }
530+ it ( " should warn " ) {
531+ aView. pin. right ( 20 ) . horizontally ( )
532+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " horizontally() right coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
533+ }
534+ }
535+
536+ //
537+ // vertically()
538+ //
539+ describe ( " the result of vertically() " ) {
497540 it ( " should adjust the aView " ) {
498- aView. pin. bottom ( 20 % )
499- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 220 .0, width: 200.0 , height: 100 .0) ) )
541+ aView. pin. vertically ( )
542+ expect ( aView. frame) . to ( equal ( CGRect ( x: 140.0 , y: 0 .0, width: 200.0 , height: 400 .0) ) )
500543 }
501544
502545 it ( " should adjust the aView " ) {
503- aView. pin. top ( ) . bottom ( 20 % )
504- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 0 .0, width: 200.0 , height: 320 .0) ) )
546+ aView. pin. vertically ( ) . margin ( 10 )
547+ expect ( aView. frame) . to ( equal ( CGRect ( x: 140.0 , y: 10 .0, width: 200.0 , height: 380 .0) ) )
505548 }
506549
507- it ( " should adjust the aView " ) {
508- aView . pin. bottom ( - 20 % )
509- expect ( aView . frame) . to ( equal ( CGRect ( x: 140 , y: 380 .0, width: 200 .0, height: 100 .0) ) )
550+ it ( " should adjust the bViewChild " ) {
551+ bViewChild . pin. vertically ( )
552+ expect ( bViewChild . frame) . to ( equal ( CGRect ( x: 40.0 , y: 0 .0, width: 60 .0, height: 80 .0) ) )
510553 }
511554
512- it ( " should adjust the aView " ) {
513- aView. pin. top ( ) . bottom ( - 20 % )
514- expect ( aView. frame) . to ( equal ( CGRect ( x: 140 , y: 0.0 , width: 200.0 , height: 480.0 ) ) )
555+ it ( " should adjust the bViewChild " ) {
556+ bViewChild. pin. vertically ( ) . margin ( 10 )
557+ expect ( bViewChild. frame) . to ( equal ( CGRect ( x: 40.0 , y: 10.0 , width: 60.0 , height: 60.0 ) ) )
558+ }
559+
560+ it ( " should warn " ) {
561+ aView. pin. top ( 20 ) . vertically ( )
562+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " vertically() top coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
563+ }
564+ it ( " should warn " ) {
565+ aView. pin. bottom ( 20 ) . vertically ( )
566+ expect ( _pinlayoutUnitTestLastWarning) . to ( contain ( [ " vertically() bottom coordinate " , " won't be applied " , " already been set to 20.0 " ] ) )
515567 }
516568 }
517569 }
0 commit comments