diff --git a/Tests/LayoutTests/Support/NimbleMatchers.swift b/Tests/LayoutTests/Support/NimbleMatchers.swift index bdc4cab7..73b99ae1 100644 --- a/Tests/LayoutTests/Support/NimbleMatchers.swift +++ b/Tests/LayoutTests/Support/NimbleMatchers.swift @@ -28,15 +28,18 @@ extension XCTestCase { // swiftlint:disable cyclomatic_complexity @MainActor - internal func match(_ expectedConstraint: NSLayoutConstraint) -> Matcher { + internal func match( + _ expectedConstraint: NSLayoutConstraint, + isActive: Bool? = nil // swiftlint:disable:this discouraged_optional_boolean + ) -> Matcher { // swiftlint:disable:next closure_body_length Matcher { expression in guard let constraint: NSLayoutConstraint = try expression.evaluate() else { return MatcherResult(status: .fail, message: .expectedTo("not be nil, got ")) } - guard constraint.isActive == expectedConstraint.isActive + guard constraint.isActive == isActive ?? expectedConstraint.isActive else { let message: String = """ - match `isActive` <\(expectedConstraint.isActive)>, \ + match `isActive` <\(isActive ?? expectedConstraint.isActive)>, \ got <\(constraint.isActive)> """ return MatcherResult(status: .fail, message: .expectedTo(message)) diff --git a/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift b/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift index bff026bf..8a26f0a2 100644 --- a/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift +++ b/Tests/LayoutTests/UIKit/UIView+AutoLayoutTests.swift @@ -47,15 +47,27 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(view.translatesAutoresizingMaskIntoConstraints) == false - expect(view.constraints[0].constant) == frame.width - expect(view.constraints[1].constant) == frame.height + expect(view.constraints.count) == 2 + expect(view.constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10), isActive: true)) + expect(view.constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20), isActive: true)) } func testConstrainingSize() { // GIVEN - let size: CGSize = .init(width: 10, height: 20) let view: UIView = .init() // THEN @@ -64,21 +76,33 @@ final class UIViewAutoLayoutTests: XCTestCase { // WHEN - view.constrainingSize(size) + view.constrainingSize(CGSize(width: 10, height: 20)) // THEN expect(view.translatesAutoresizingMaskIntoConstraints) == false - expect(view.constraints[0].constant) == size.width - expect(view.constraints[1].constant) == size.height + expect(view.constraints.count) == 2 + expect(view.constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10), isActive: true)) + expect(view.constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20), isActive: true)) } func testConstrainingWidth_givenDefaults() { // GIVEN - let width: CGFloat = 10 - let view: UIView = .init(frame: CGRect(x: 0, y: 0, width: width, height: 0)) + let view: UIView = .init(frame: CGRect(x: 0, y: 0, width: 10, height: 0)) // THEN @@ -91,14 +115,20 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(view.translatesAutoresizingMaskIntoConstraints) == false - expect(view.constraints[0].constant) == width + expect(view.constraints.count) == 1 + expect(view.constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10), isActive: true)) } func testConstrainingWidth() { // GIVEN - let width: CGFloat = 10 let view: UIView = .init() // THEN @@ -107,20 +137,26 @@ final class UIViewAutoLayoutTests: XCTestCase { // WHEN - view.constrainingWidth(width) + view.constrainingWidth(10) // THEN expect(view.translatesAutoresizingMaskIntoConstraints) == false - expect(view.constraints[0].constant) == width + expect(view.constraints.count) == 1 + expect(view.constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10), isActive: true)) } func testConstrainingHeight_givenDefaults() { // GIVEN - let height: CGFloat = 20 - let view: UIView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: height)) + let view: UIView = .init(frame: CGRect(x: 0, y: 0, width: 0, height: 20)) // THEN @@ -133,14 +169,20 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(view.translatesAutoresizingMaskIntoConstraints) == false - expect(view.constraints[0].constant) == height + expect(view.constraints.count) == 1 + expect(view.constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20), isActive: true)) } func testConstrainingHeight() { // GIVEN - let height: CGFloat = 20 let view: UIView = .init() // THEN @@ -149,12 +191,19 @@ final class UIViewAutoLayoutTests: XCTestCase { // WHEN - view.constrainingHeight(height) + view.constrainingHeight(20) // THEN expect(view.translatesAutoresizingMaskIntoConstraints) == false - expect(view.constraints[0].constant) == height + expect(view.constraints.count) == 1 + expect(view.constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20), isActive: true)) } // MARK: - Size @@ -172,22 +221,42 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(sizeConstraints1.count) == 2 - expect(sizeConstraints1[0].firstAttribute) == .width - expect(sizeConstraints1[0].constant) == 10 - expect(sizeConstraints1[1].firstAttribute) == .height - expect(sizeConstraints1[1].constant) == 20 + expect(sizeConstraints1[0]).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10))) + expect(sizeConstraints1[1]).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20))) // WHEN - let sizeConstraints2: [NSLayoutConstraint] = view.sizeConstraints(CGSize(width: 10, height: 20)) + let sizeConstraints2: [NSLayoutConstraint] = view.sizeConstraints(CGSize(width: 20, height: 40)) // THEN expect(sizeConstraints2.count) == 2 - expect(sizeConstraints2[0].firstAttribute) == .width - expect(sizeConstraints2[0].constant) == 10 - expect(sizeConstraints2[1].firstAttribute) == .height - expect(sizeConstraints2[1].constant) == 20 + expect(sizeConstraints2[0]).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20))) + expect(sizeConstraints2[1]).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 40))) } // MARK: - Width @@ -204,36 +273,41 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(widthConstraint1.relation) == .equal - expect(widthConstraint1.constant) == 10 - - // GIVEN - - let relation2: NSLayoutConstraint.Relation = .greaterThanOrEqual - let width2: CGFloat = 10 + expect(widthConstraint1).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10))) // WHEN - let widthConstraint2: NSLayoutConstraint = view.widthConstraint(is: relation2, to: width2) + let widthConstraint2: NSLayoutConstraint = view.widthConstraint(is: .greaterThanOrEqual, to: 20) // THEN - expect(widthConstraint2.relation) == relation2 - expect(widthConstraint2.constant) == width2 - - // GIVEN - - let relation3: NSLayoutConstraint.Relation = .lessThanOrEqual - let width3: CGFloat = 20 + expect(widthConstraint2).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .greaterThanOrEqual, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20))) // WHEN - let widthConstraint3: NSLayoutConstraint = view.widthConstraint(is: relation3, to: width3) + let widthConstraint3: NSLayoutConstraint = view.widthConstraint(is: .lessThanOrEqual, to: 30) // THEN - expect(widthConstraint3.relation) == relation3 - expect(widthConstraint3.constant) == width3 + expect(widthConstraint3).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .lessThanOrEqual, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 30))) } func testWidthConstraintWithConstant() { @@ -248,20 +322,27 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(widthConstraint1.relation) == .equal - expect(widthConstraint1.constant) == 10 - - // GIVEN - - let width2: CGFloat = 10 + expect(widthConstraint1).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 10))) // WHEN - let widthConstraint2: NSLayoutConstraint = view.widthConstraint(width2) + let widthConstraint2: NSLayoutConstraint = view.widthConstraint(20) // THEN - expect(widthConstraint2.constant) == width2 + expect(widthConstraint2).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20))) } // MARK: - Height @@ -278,36 +359,41 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(heightConstraint1.relation) == .equal - expect(heightConstraint1.constant) == 20 - - // GIVEN - - let relation2: NSLayoutConstraint.Relation = .greaterThanOrEqual - let height2: CGFloat = 10 + expect(heightConstraint1).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20))) // WHEN - let heightConstraint2: NSLayoutConstraint = view.heightConstraint(is: relation2, to: height2) + let heightConstraint2: NSLayoutConstraint = view.heightConstraint(is: .greaterThanOrEqual, to: 40) // THEN - expect(heightConstraint2.relation) == relation2 - expect(heightConstraint2.constant) == height2 - - // GIVEN - - let relation3: NSLayoutConstraint.Relation = .lessThanOrEqual - let height3: CGFloat = 20 + expect(heightConstraint2).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .greaterThanOrEqual, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 40))) // WHEN - let heightConstraint3: NSLayoutConstraint = view.heightConstraint(is: relation3, to: height3) + let heightConstraint3: NSLayoutConstraint = view.heightConstraint(is: .lessThanOrEqual, to: 60) // THEN - expect(heightConstraint3.relation) == relation3 - expect(heightConstraint3.constant) == height3 + expect(heightConstraint3).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .lessThanOrEqual, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 60))) } func testHeightConstraintWithConstant() { @@ -322,20 +408,27 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(heightConstraint1.relation) == .equal - expect(heightConstraint1.constant) == 20 - - // GIVEN - - let height2: CGFloat = 10 + expect(heightConstraint1).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 20))) // WHEN - let heightConstraint2: NSLayoutConstraint = view.heightConstraint(height2) + let heightConstraint2: NSLayoutConstraint = view.heightConstraint(40) // THEN - expect(heightConstraint2.constant) == height2 + expect(heightConstraint2).to(match(NSLayoutConstraint(item: view, + attribute: .height, + relatedBy: .equal, + toItem: nil, + attribute: .notAnAttribute, + multiplier: 1, + constant: 40))) } // MARK: - Square @@ -352,9 +445,13 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(constraint.firstAttribute) == .width - expect(constraint.secondAttribute) == .height - expect(constraint.relation) == .equal + expect(constraint).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: view, + attribute: .height, + multiplier: 1, + constant: 0))) } // MARK: - Aspect Ratio @@ -363,19 +460,21 @@ final class UIViewAutoLayoutTests: XCTestCase { // GIVEN - let ratio: CGFloat = 0.5 let view: UIView = .init() // WHEN - let constraint: NSLayoutConstraint = view.aspectRatioConstraint(ratio) + let constraint: NSLayoutConstraint = view.aspectRatioConstraint(0.5) // THEN - expect(constraint.firstAttribute) == .width - expect(constraint.secondAttribute) == .height - expect(constraint.relation) == .equal - expect(constraint.multiplier) == ratio + expect(constraint).to(match(NSLayoutConstraint(item: view, + attribute: .width, + relatedBy: .equal, + toItem: view, + attribute: .height, + multiplier: 0.5, + constant: 0))) } // MARK: - Equal @@ -384,17 +483,31 @@ final class UIViewAutoLayoutTests: XCTestCase { // GIVEN - let superview: UIView = .init() let view: UIView = .init() + let view1: UIView = .init() + let view2: UIView = .init() // WHEN - let constraints: [NSLayoutConstraint] = view.equalConstraints(for: .top, to: [superview]) + let constraints: [NSLayoutConstraint] = view.equalConstraints(for: .top, to: [view1, view2]) // THEN - expect(constraints.first?.firstAttribute) == .top - expect(constraints.first?.relation) == .equal + expect(constraints.count) == 2 + expect(constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: view1, + attribute: .top, + multiplier: 1, + constant: 0))) + expect(constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: view2, + attribute: .top, + multiplier: 1, + constant: 0))) } // MARK: - Center @@ -414,26 +527,42 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(constraints1.count) == 2 - expect(constraints1[0].firstAttribute) == .centerX - expect(constraints1[0].constant) == 0 - expect(constraints1[1].firstAttribute) == .centerY - expect(constraints1[1].constant) == 0 - - // GIVEN - - let offset: UIOffset = .init(horizontal: 5, vertical: 10) + expect(constraints1[0]).to(match(NSLayoutConstraint(item: view, + attribute: .centerX, + relatedBy: .equal, + toItem: superview, + attribute: .centerX, + multiplier: 1, + constant: 0))) + expect(constraints1[1]).to(match(NSLayoutConstraint(item: view, + attribute: .centerY, + relatedBy: .equal, + toItem: superview, + attribute: .centerY, + multiplier: 1, + constant: 0))) // WHEN - let constraints2: [NSLayoutConstraint] = view.centerConstraints(offset: offset) + let constraints2: [NSLayoutConstraint] = view.centerConstraints(offset: UIOffset(horizontal: 5, vertical: 10)) // THEN expect(constraints2.count) == 2 - expect(constraints2[0].firstAttribute) == .centerX - expect(constraints2[0].constant) == offset.horizontal - expect(constraints2[1].firstAttribute) == .centerY - expect(constraints2[1].constant) == offset.vertical + expect(constraints2[0]).to(match(NSLayoutConstraint(item: view, + attribute: .centerX, + relatedBy: .equal, + toItem: superview, + attribute: .centerX, + multiplier: 1, + constant: 5))) + expect(constraints2[1]).to(match(NSLayoutConstraint(item: view, + attribute: .centerY, + relatedBy: .equal, + toItem: superview, + attribute: .centerY, + multiplier: 1, + constant: 10))) } // MARK: - Attributes @@ -448,30 +577,52 @@ final class UIViewAutoLayoutTests: XCTestCase { // WHEN - let constraints1: [NSLayoutConstraint] = view.constraints(toSuperview: [.top]) + let constraints1: [NSLayoutConstraint] = view.constraints(toSuperview: [.top, .left]) // THEN - expect(constraints1.first?.firstAttribute) == .top - expect(constraints1.first?.relation) == .equal - expect(constraints1.first?.multiplier) == 1 - expect(constraints1.first?.constant) == 0 + expect(constraints1.count) == 2 + expect(constraints1[0]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: superview, + attribute: .top, + multiplier: 1, + constant: 0))) + expect(constraints1[1]).to(match(NSLayoutConstraint(item: view, + attribute: .left, + relatedBy: .equal, + toItem: superview, + attribute: .left, + multiplier: 1, + constant: 0))) // WHEN let constraints2: [NSLayoutConstraint] = view.constraints( is: .greaterThanOrEqual, - toSuperview: [.bottom], + toSuperview: [.bottom, .right], multiplier: 2, constant: 5 ) // THEN - expect(constraints2.first?.firstAttribute) == .bottom - expect(constraints2.first?.relation) == .greaterThanOrEqual - expect(constraints2.first?.multiplier) == 2 - expect(constraints2.first?.constant) == 5 + expect(constraints2.count) == 2 + expect(constraints2[0]).to(match(NSLayoutConstraint(item: view, + attribute: .bottom, + relatedBy: .greaterThanOrEqual, + toItem: superview, + attribute: .bottom, + multiplier: 2, + constant: 5))) + expect(constraints2[1]).to(match(NSLayoutConstraint(item: view, + attribute: .right, + relatedBy: .greaterThanOrEqual, + toItem: superview, + attribute: .right, + multiplier: 2, + constant: 5))) } func testConstraintForAttributeIsRelationToSuperviewMultiplierConstant_givenNilSuperview() { @@ -483,7 +634,7 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(view.constraints(toSuperview: [.top])).to(throwAssertion()) + expect(view.constraints(toSuperview: [.top, .left])).to(throwAssertion()) // WHEN @@ -491,7 +642,7 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(view.constraints(toSuperview: [.top]).count) == 1 + expect(view.constraints(toSuperview: [.top, .left])).notTo(beEmpty()) } func testConstraintForAttributeIsRelationToTargetAttributeOfTargetViewMultiplierConstant() { @@ -503,20 +654,31 @@ final class UIViewAutoLayoutTests: XCTestCase { // WHEN - let constraints1: [NSLayoutConstraint] = view.constraints(to: [.top], of: targetView) + let constraints1: [NSLayoutConstraint] = view.constraints(to: [.top, .left], of: targetView) // THEN - expect(constraints1.first?.firstAttribute) == .top - expect(constraints1.first?.relation) == .equal - expect(constraints1.first?.multiplier) == 1 - expect(constraints1.first?.constant) == 0 + expect(constraints1.count) == 2 + expect(constraints1[0]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: targetView, + attribute: .top, + multiplier: 1, + constant: 0))) + expect(constraints1[1]).to(match(NSLayoutConstraint(item: view, + attribute: .left, + relatedBy: .equal, + toItem: targetView, + attribute: .left, + multiplier: 1, + constant: 0))) // WHEN let constraints2: [NSLayoutConstraint] = view.constraints( is: .greaterThanOrEqual, - to: [.bottom], + to: [.bottom, .right], of: targetView, multiplier: 2, constant: 5 @@ -524,10 +686,21 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN - expect(constraints2.first?.firstAttribute) == .bottom - expect(constraints2.first?.relation) == .greaterThanOrEqual - expect(constraints2.first?.multiplier) == 2 - expect(constraints2.first?.constant) == 5 + expect(constraints2.count) == 2 + expect(constraints2[0]).to(match(NSLayoutConstraint(item: view, + attribute: .bottom, + relatedBy: .greaterThanOrEqual, + toItem: targetView, + attribute: .bottom, + multiplier: 2, + constant: 5))) + expect(constraints2[1]).to(match(NSLayoutConstraint(item: view, + attribute: .right, + relatedBy: .greaterThanOrEqual, + toItem: targetView, + attribute: .right, + multiplier: 2, + constant: 5))) } // MARK: - Edges @@ -547,14 +720,34 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(constraints.count) == 4 - expect(constraints[0].firstAttribute) == .left - expect(constraints[0].constant) == 0 - expect(constraints[1].firstAttribute) == .right - expect(constraints[1].constant) == 0 - expect(constraints[2].firstAttribute) == .top - expect(constraints[2].constant) == 0 - expect(constraints[3].firstAttribute) == .bottom - expect(constraints[3].constant) == 0 + expect(constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .left, + relatedBy: .equal, + toItem: superview, + attribute: .left, + multiplier: 1, + constant: 0))) + expect(constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .right, + relatedBy: .equal, + toItem: superview, + attribute: .right, + multiplier: 1, + constant: 0))) + expect(constraints[2]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: superview, + attribute: .top, + multiplier: 1, + constant: 0))) + expect(constraints[3]).to(match(NSLayoutConstraint(item: view, + attribute: .bottom, + relatedBy: .equal, + toItem: superview, + attribute: .bottom, + multiplier: 1, + constant: 0))) } func testEdgeConstraintsInset_givenInset() { @@ -573,14 +766,34 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(constraints.count) == 4 - expect(constraints[0].firstAttribute) == .left - expect(constraints[0].constant) == inset - expect(constraints[1].firstAttribute) == .right - expect(constraints[1].constant) == -inset - expect(constraints[2].firstAttribute) == .top - expect(constraints[2].constant) == inset - expect(constraints[3].firstAttribute) == .bottom - expect(constraints[3].constant) == -inset + expect(constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .left, + relatedBy: .equal, + toItem: superview, + attribute: .left, + multiplier: 1, + constant: inset))) + expect(constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .right, + relatedBy: .equal, + toItem: superview, + attribute: .right, + multiplier: 1, + constant: -inset))) + expect(constraints[2]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: superview, + attribute: .top, + multiplier: 1, + constant: inset))) + expect(constraints[3]).to(match(NSLayoutConstraint(item: view, + attribute: .bottom, + relatedBy: .equal, + toItem: superview, + attribute: .bottom, + multiplier: 1, + constant: -inset))) } func testEdgeConstraintsInsetsDirectional() { @@ -599,14 +812,34 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(constraints.count) == 4 - expect(constraints[0].firstAttribute) == .leading - expect(constraints[0].constant) == insets.leading - expect(constraints[1].firstAttribute) == .trailing - expect(constraints[1].constant) == -insets.trailing - expect(constraints[2].firstAttribute) == .top - expect(constraints[2].constant) == insets.top - expect(constraints[3].firstAttribute) == .bottom - expect(constraints[3].constant) == -insets.bottom + expect(constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .leading, + relatedBy: .equal, + toItem: superview, + attribute: .leading, + multiplier: 1, + constant: insets.leading))) + expect(constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .trailing, + relatedBy: .equal, + toItem: superview, + attribute: .trailing, + multiplier: 1, + constant: -insets.trailing))) + expect(constraints[2]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: superview, + attribute: .top, + multiplier: 1, + constant: insets.top))) + expect(constraints[3]).to(match(NSLayoutConstraint(item: view, + attribute: .bottom, + relatedBy: .equal, + toItem: superview, + attribute: .bottom, + multiplier: 1, + constant: -insets.bottom))) } func testEdgeConstraintsInsetsCanonical() { @@ -625,13 +858,33 @@ final class UIViewAutoLayoutTests: XCTestCase { // THEN expect(constraints.count) == 4 - expect(constraints[0].firstAttribute) == .left - expect(constraints[0].constant) == insets.left - expect(constraints[1].firstAttribute) == .right - expect(constraints[1].constant) == -insets.right - expect(constraints[2].firstAttribute) == .top - expect(constraints[2].constant) == insets.top - expect(constraints[3].firstAttribute) == .bottom - expect(constraints[3].constant) == -insets.bottom + expect(constraints[0]).to(match(NSLayoutConstraint(item: view, + attribute: .left, + relatedBy: .equal, + toItem: superview, + attribute: .left, + multiplier: 1, + constant: insets.left))) + expect(constraints[1]).to(match(NSLayoutConstraint(item: view, + attribute: .right, + relatedBy: .equal, + toItem: superview, + attribute: .right, + multiplier: 1, + constant: -insets.right))) + expect(constraints[2]).to(match(NSLayoutConstraint(item: view, + attribute: .top, + relatedBy: .equal, + toItem: superview, + attribute: .top, + multiplier: 1, + constant: insets.top))) + expect(constraints[3]).to(match(NSLayoutConstraint(item: view, + attribute: .bottom, + relatedBy: .equal, + toItem: superview, + attribute: .bottom, + multiplier: 1, + constant: -insets.bottom))) } }