mirror of https://github.com/SnapKit/SnapKit
Fix tests
This commit is contained in:
parent
5c7ede844a
commit
505ed036a0
|
@ -2,13 +2,21 @@
|
||||||
import UIKit
|
import UIKit
|
||||||
typealias View = UIView
|
typealias View = UIView
|
||||||
extension View {
|
extension View {
|
||||||
var snp_constraints: [AnyObject] { return self.constraints }
|
var snp_constraints: [AnyObject] {
|
||||||
|
return self.constraints
|
||||||
|
.filter { $0 is LayoutConstraint }
|
||||||
|
.filter { $0.isActive }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
import AppKit
|
import AppKit
|
||||||
typealias View = NSView
|
typealias View = NSView
|
||||||
extension View {
|
extension View {
|
||||||
var snp_constraints: [AnyObject] { return self.constraints }
|
var snp_constraints: [AnyObject] {
|
||||||
|
return self.constraints
|
||||||
|
.filter { $0 is LayoutConstraint }
|
||||||
|
.filter { $0.isActive }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -128,15 +136,19 @@ class SnapKitTests: XCTestCase {
|
||||||
self.container.addSubview(v2)
|
self.container.addSubview(v2)
|
||||||
|
|
||||||
v1.snp.makeConstraints { (make) -> Void in
|
v1.snp.makeConstraints { (make) -> Void in
|
||||||
make.top.equalTo(v2.snp.top).offset(50)
|
make.top.equalTo(v2).offset(50)
|
||||||
make.left.equalTo(v2.snp.top).offset(50)
|
make.left.equalTo(v2).offset(50)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
|
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
|
||||||
|
|
||||||
|
print(self.container.snp_constraints)
|
||||||
|
|
||||||
v1.snp.removeConstraints()
|
v1.snp.removeConstraints()
|
||||||
|
|
||||||
|
print(self.container.snp_constraints)
|
||||||
|
|
||||||
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
|
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -400,6 +412,28 @@ class SnapKitTests: XCTestCase {
|
||||||
XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'")
|
XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testEdgesToEdges() {
|
||||||
|
var fromAttributes = Set<NSLayoutAttribute>()
|
||||||
|
var toAttributes = Set<NSLayoutAttribute>()
|
||||||
|
|
||||||
|
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])
|
||||||
|
}
|
||||||
|
|
||||||
#if os(iOS) || os(tvOS)
|
#if os(iOS) || os(tvOS)
|
||||||
func testEdgesToMargins() {
|
func testEdgesToMargins() {
|
||||||
var fromAttributes = Set<NSLayoutAttribute>()
|
var fromAttributes = Set<NSLayoutAttribute>()
|
||||||
|
@ -441,28 +475,6 @@ class SnapKitTests: XCTestCase {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func testEdgesToEdges() {
|
|
||||||
var fromAttributes = Set<NSLayoutAttribute>()
|
|
||||||
var toAttributes = Set<NSLayoutAttribute>()
|
|
||||||
|
|
||||||
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() {
|
func testLayoutGuideConstraints() {
|
||||||
let vc = UIViewController()
|
let vc = UIViewController()
|
||||||
vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
|
vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
|
||||||
|
@ -474,7 +486,7 @@ class SnapKitTests: XCTestCase {
|
||||||
make.bottom.equalTo(vc.bottomLayoutGuide.snp.top)
|
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
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue