diff --git a/Source/Constraint.swift b/Source/Constraint.swift index 2491c7b..0bfce79 100644 --- a/Source/Constraint.swift +++ b/Source/Constraint.swift @@ -82,7 +82,7 @@ public class Constraint { // get layout to attribute let layoutToAttribute: NSLayoutAttribute #if os(iOS) || os(tvOS) - if layoutToAttributes.count > 1 { + if layoutToAttributes.count > 0 { if self.from.attributes == .edges && self.to.attributes == .margins { switch layoutFromAttribute { case .left: @@ -109,11 +109,11 @@ public class Constraint { default: fatalError() } + } else if self.from.attributes == self.to.attributes { + layoutToAttribute = layoutFromAttribute } else { layoutToAttribute = layoutToAttributes[0] } - } else if layoutToAttributes.count == 1 { - layoutToAttribute = layoutToAttributes[0] } else { layoutToAttribute = layoutFromAttribute } diff --git a/Tests/Tests.swift b/Tests/Tests.swift index 5c37c95..1896d8d 100644 --- a/Tests/Tests.swift +++ b/Tests/Tests.swift @@ -441,6 +441,28 @@ class SnapKitTests: XCTestCase { } + func testEdgesToEdges() { + var fromAttributes = Set() + var toAttributes = Set() + + let view = View() + self.container.addSubview(view) + + view.snp.remakeConstraints { (make) -> Void in + make.edges.equalTo(self.container.snp.edges) + } + + XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints") + + for constraint in (container.snp_constraints as! [NSLayoutConstraint]) { + fromAttributes.insert(constraint.firstAttribute) + toAttributes.insert(constraint.secondAttribute) + } + + XCTAssert(fromAttributes == [.top, .left, .bottom, .right]) + XCTAssert(toAttributes == [.top, .left, .bottom, .right]) + } + func testLayoutGuideConstraints() { let vc = UIViewController() vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))