Robert Payne 9 سال پیش
والد
کامیت
505ed036a0
1فایلهای تغییر یافته به همراه38 افزوده شده و 26 حذف شده
  1. 38 26
      Tests/Tests.swift

+ 38 - 26
Tests/Tests.swift

@@ -2,13 +2,21 @@
 import UIKit
 typealias View = UIView
 extension View {
-    var snp_constraints: [AnyObject] { return self.constraints }
+    var snp_constraints: [AnyObject] {
+        return self.constraints
+            .filter { $0 is LayoutConstraint }
+            .filter { $0.isActive }
+    }
 }
 #else
 import AppKit
 typealias View = NSView
 extension View {
-    var snp_constraints: [AnyObject] { return self.constraints }
+    var snp_constraints: [AnyObject] {
+        return self.constraints
+            .filter { $0 is LayoutConstraint }
+            .filter { $0.isActive }
+    }
 }
 #endif
 
@@ -128,15 +136,19 @@ class SnapKitTests: XCTestCase {
         self.container.addSubview(v2)
         
         v1.snp.makeConstraints { (make) -> Void in
-            make.top.equalTo(v2.snp.top).offset(50)
-            make.left.equalTo(v2.snp.top).offset(50)
+            make.top.equalTo(v2).offset(50)
+            make.left.equalTo(v2).offset(50)
             return
         }
         
         XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
         
+        print(self.container.snp_constraints)
+        
         v1.snp.removeConstraints()
         
+        print(self.container.snp_constraints)
+        
         XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
         
     }
@@ -400,8 +412,7 @@ class SnapKitTests: XCTestCase {
         XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'")
     }
     
-    #if os(iOS) || os(tvOS)
-    func testEdgesToMargins() {
+    func testEdgesToEdges() {
         var fromAttributes = Set<NSLayoutAttribute>()
         var toAttributes = Set<NSLayoutAttribute>()
         
@@ -409,7 +420,7 @@ class SnapKitTests: XCTestCase {
         self.container.addSubview(view)
         
         view.snp.remakeConstraints { (make) -> Void in
-            make.edges.equalTo(self.container.snp.margins)
+            make.edges.equalTo(self.container.snp.edges)
         }
         
         XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
@@ -420,13 +431,19 @@ class SnapKitTests: XCTestCase {
         }
         
         XCTAssert(fromAttributes == [.top, .left, .bottom, .right])
-        XCTAssert(toAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin])
+        XCTAssert(toAttributes == [.top, .left, .bottom, .right])
+    }
+    
+    #if os(iOS) || os(tvOS)
+    func testEdgesToMargins() {
+        var fromAttributes = Set<NSLayoutAttribute>()
+        var toAttributes = Set<NSLayoutAttribute>()
         
-        fromAttributes.removeAll()
-        toAttributes.removeAll()
+        let view = View()
+        self.container.addSubview(view)
         
         view.snp.remakeConstraints { (make) -> Void in
-            make.margins.equalTo(self.container.snp.edges)
+            make.edges.equalTo(self.container.snp.margins)
         }
         
         XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
@@ -436,20 +453,14 @@ class SnapKitTests: XCTestCase {
             toAttributes.insert(constraint.secondAttribute)
         }
         
-        XCTAssert(toAttributes == [.top, .left, .bottom, .right])
-        XCTAssert(fromAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin])
-        
-    }
-    
-    func testEdgesToEdges() {
-        var fromAttributes = Set<NSLayoutAttribute>()
-        var toAttributes = Set<NSLayoutAttribute>()
+        XCTAssert(fromAttributes == [.top, .left, .bottom, .right])
+        XCTAssert(toAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin])
         
-        let view = View()
-        self.container.addSubview(view)
+        fromAttributes.removeAll()
+        toAttributes.removeAll()
         
         view.snp.remakeConstraints { (make) -> Void in
-            make.edges.equalTo(self.container.snp.edges)
+            make.margins.equalTo(self.container.snp.edges)
         }
         
         XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
@@ -459,8 +470,9 @@ class SnapKitTests: XCTestCase {
             toAttributes.insert(constraint.secondAttribute)
         }
         
-        XCTAssert(fromAttributes == [.top, .left, .bottom, .right])
         XCTAssert(toAttributes == [.top, .left, .bottom, .right])
+        XCTAssert(fromAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin])
+        
     }
     
     func testLayoutGuideConstraints() {
@@ -470,11 +482,11 @@ class SnapKitTests: XCTestCase {
         vc.view.addSubview(self.container)
         
         self.container.snp.makeConstraints { (make) -> Void in
-        make.top.equalTo(vc.topLayoutGuide.snp.bottom)
-        make.bottom.equalTo(vc.bottomLayoutGuide.snp.top)
+            make.top.equalTo(vc.topLayoutGuide.snp.bottom)
+            make.bottom.equalTo(vc.bottomLayoutGuide.snp.top)
         }
          
-        XCTAssertEqual(vc.view.snp_constraints.count, 6, "Should have 6 constraints installed")
+        XCTAssertEqual(vc.view.snp_constraints.count, 2, "Should have 2 constraints installed")
     }
     #endif