|
|
@@ -413,6 +413,90 @@ class SnapKitTests: XCTestCase {
|
|
|
XCTAssertEqual(constraints[3].constant, -25, "Should be -25")
|
|
|
}
|
|
|
|
|
|
+ #if os(iOS) || os(tvOS)
|
|
|
+ @available(iOS 11.0, tvOS 11.0, *)
|
|
|
+ func testConstraintDirectionalInsetsAsImpliedEqualToConstraints() {
|
|
|
+ let view = View()
|
|
|
+ self.container.addSubview(view)
|
|
|
+
|
|
|
+ view.snp.makeConstraints { (make) -> Void in
|
|
|
+ make.top.leading.bottom.trailing.equalTo(self.container).inset(ConstraintDirectionalInsets(top: 25, leading: 25, bottom: 25, trailing: 25))
|
|
|
+ }
|
|
|
+
|
|
|
+ XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
|
|
|
+
|
|
|
+
|
|
|
+ let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.firstAttribute.rawValue < $1.firstAttribute.rawValue }
|
|
|
+
|
|
|
+ let verify: (NSLayoutConstraint, NSLayoutConstraint.Attribute, CGFloat) -> Void = { constraint, attribute, constant in
|
|
|
+ XCTAssertEqual(constraint.firstAttribute, attribute, "First attribute \(constraint.firstAttribute.rawValue) is not \(attribute.rawValue)")
|
|
|
+ XCTAssertEqual(constraint.secondAttribute, attribute, "Second attribute \(constraint.secondAttribute.rawValue) is not \(attribute.rawValue)")
|
|
|
+ XCTAssertEqual(constraint.constant, constant, "Attribute \(attribute.rawValue) should have constant \(constant)")
|
|
|
+ }
|
|
|
+
|
|
|
+ verify(constraints[0], .top, 25)
|
|
|
+ verify(constraints[1], .bottom, -25)
|
|
|
+ verify(constraints[2], .leading, 25)
|
|
|
+ verify(constraints[3], .trailing, -25)
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #if os(iOS) || os(tvOS)
|
|
|
+ @available(iOS 11.0, tvOS 11.0, *)
|
|
|
+ func testConstraintDirectionalInsetsAsConstraintsConstant() {
|
|
|
+ let view = View()
|
|
|
+ self.container.addSubview(view)
|
|
|
+
|
|
|
+ view.snp.makeConstraints { (make) -> Void in
|
|
|
+ make.top.leading.bottom.trailing.equalTo(self.container).inset(ConstraintDirectionalInsets(top: 25, leading: 25, bottom: 25, trailing: 25))
|
|
|
+ }
|
|
|
+
|
|
|
+ XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
|
|
|
+
|
|
|
+
|
|
|
+ let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.firstAttribute.rawValue < $1.firstAttribute.rawValue }
|
|
|
+
|
|
|
+ let verify: (NSLayoutConstraint, NSLayoutConstraint.Attribute, CGFloat) -> Void = { constraint, attribute, constant in
|
|
|
+ XCTAssertEqual(constraint.firstAttribute, attribute, "First attribute \(constraint.firstAttribute.rawValue) is not \(attribute.rawValue)")
|
|
|
+ XCTAssertEqual(constraint.secondAttribute, attribute, "Second attribute \(constraint.secondAttribute.rawValue) is not \(attribute.rawValue)")
|
|
|
+ XCTAssertEqual(constraint.constant, constant, "Attribute \(attribute.rawValue) should have constant \(constant)")
|
|
|
+ }
|
|
|
+
|
|
|
+ verify(constraints[0], .top, 25)
|
|
|
+ verify(constraints[1], .bottom, -25)
|
|
|
+ verify(constraints[2], .leading, 25)
|
|
|
+ verify(constraints[3], .trailing, -25)
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
+ #if os(iOS) || os(tvOS)
|
|
|
+ @available(iOS 11.0, tvOS 11.0, *)
|
|
|
+ func testConstraintDirectionalInsetsFallBackForNonDirectionalConstraints() {
|
|
|
+ let view = View()
|
|
|
+ self.container.addSubview(view)
|
|
|
+
|
|
|
+ view.snp.makeConstraints { (make) -> Void in
|
|
|
+ make.edges.equalTo(self.container).inset(ConstraintDirectionalInsets(top: 25, leading: 25, bottom: 25, trailing: 25))
|
|
|
+ }
|
|
|
+
|
|
|
+ XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
|
|
|
+
|
|
|
+
|
|
|
+ let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.firstAttribute.rawValue < $1.firstAttribute.rawValue }
|
|
|
+
|
|
|
+ let verify: (NSLayoutConstraint, NSLayoutConstraint.Attribute, CGFloat) -> Void = { constraint, attribute, constant in
|
|
|
+ XCTAssertEqual(constraint.firstAttribute, attribute, "First attribute \(constraint.firstAttribute.rawValue) is not \(attribute.rawValue)")
|
|
|
+ XCTAssertEqual(constraint.secondAttribute, attribute, "Second attribute \(constraint.secondAttribute.rawValue) is not \(attribute.rawValue)")
|
|
|
+ XCTAssertEqual(constraint.constant, constant, "Attribute \(attribute.rawValue) should have constant \(constant)")
|
|
|
+ }
|
|
|
+
|
|
|
+ verify(constraints[0], .left, 25)
|
|
|
+ verify(constraints[1], .right, -25)
|
|
|
+ verify(constraints[2], .top, 25)
|
|
|
+ verify(constraints[3], .bottom, -25)
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
func testSizeConstraints() {
|
|
|
let view = View()
|
|
|
self.container.addSubview(view)
|