SnapKit/Tests/SnapKitTests/Tests.swift

772 lines
29 KiB
Swift
Raw Normal View History

#if os(iOS) || os(tvOS)
2014-07-25 12:24:17 +08:00
import UIKit
2015-03-24 06:39:41 +08:00
typealias View = UIView
extension View {
2016-09-20 11:12:30 +08:00
var snp_constraints: [AnyObject] {
return self.constraints
.filter { $0 is LayoutConstraint }
.filter { $0.isActive }
}
2015-03-24 06:39:41 +08:00
}
#else
import AppKit
typealias View = NSView
extension View {
2016-09-20 11:12:30 +08:00
var snp_constraints: [AnyObject] {
return self.constraints
.filter { $0 is LayoutConstraint }
.filter { $0.isActive }
}
2015-03-24 06:39:41 +08:00
}
#endif
2014-06-06 11:42:44 +08:00
import XCTest
@testable import SnapKit
2014-06-06 11:42:44 +08:00
2015-04-15 19:07:50 +08:00
class SnapKitTests: XCTestCase {
2014-06-06 11:42:44 +08:00
2015-03-24 06:39:41 +08:00
let container = View()
2014-06-06 11:42:44 +08:00
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testMakeConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
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)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
v2.snp.makeConstraints { (make) -> Void in
make.edges.equalTo(v1)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed")
}
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
func testHorizontalVerticalEdges() {
let v1 = View()
self.container.addSubview(v1)
v1.snp.makeConstraints { (make) -> Void in
make.verticalEdges.equalToSuperview()
make.horizontalEdges.equalToSuperview()
return
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed")
XCTAssertTrue(container.constraints.count == 4)
XCTAssertTrue(container.constraints.allSatisfy { $0.firstItem === v1 && $0.secondItem === v1.superview })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .left && $0.secondAttribute == .left })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .right && $0.secondAttribute == .right })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .top && $0.secondAttribute == .top })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .bottom && $0.secondAttribute == .bottom })
}
func testHorizontalVerticalDirectionalEdges() {
let v1 = View()
self.container.addSubview(v1)
v1.snp.makeConstraints { (make) -> Void in
make.directionalVerticalEdges.equalToSuperview()
make.directionalHorizontalEdges.equalToSuperview()
return
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed")
XCTAssertTrue(container.constraints.count == 4)
XCTAssertTrue(container.constraints.allSatisfy { $0.firstItem === v1 && $0.secondItem === v1.superview })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .leading && $0.secondAttribute == .leading })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .trailing && $0.secondAttribute == .trailing })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .top && $0.secondAttribute == .top })
XCTAssertNotNil(container.constraints.first { $0.firstAttribute == .bottom && $0.secondAttribute == .bottom })
}
func testGuideMakeConstraints() {
guard #available(iOS 9.0, OSX 10.11, *) else { return }
let v1 = View()
let g1 = ConstraintLayoutGuide()
self.container.addSubview(v1)
self.container.addLayoutGuide(g1)
v1.snp.makeConstraints { (make) -> Void in
make.top.equalTo(g1).offset(50)
make.left.equalTo(g1.snp.top).offset(50)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
g1.snp.makeConstraints { (make) -> Void in
make.edges.equalTo(v1)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed")
}
2016-08-16 19:24:51 +08:00
func testMakeImpliedSuperviewConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
v1.snp.makeConstraints { (make) -> Void in
make.top.equalTo(50.0)
make.left.equalTo(50.0)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
v2.snp.makeConstraints { (make) -> Void in
make.edges.equalTo(v1)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 6, "Should have 6 constraints installed")
}
func testUpdateConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
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)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
v1.snp.updateConstraints { (make) -> Void in
make.top.equalTo(v2.snp.top).offset(15)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should still have 2 constraints installed")
}
func testRemakeConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
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)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints installed")
v1.snp.remakeConstraints { (make) -> Void in
make.edges.equalTo(v2)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed")
}
func testRemoveConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
v1.snp.makeConstraints { (make) -> Void in
2016-09-20 11:12:30 +08:00
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")
2016-09-20 11:12:30 +08:00
print(self.container.snp_constraints)
v1.snp.removeConstraints()
2016-09-20 11:12:30 +08:00
print(self.container.snp_constraints)
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
}
func testPrepareConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
let constraints = v1.snp.prepareConstraints { (make) -> Void in
make.edges.equalTo(v2)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
for constraint in constraints {
constraint.activate()
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed")
for constraint in constraints {
constraint.deactivate()
}
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
}
func testReactivateConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
let constraints = v1.snp.prepareConstraints { (make) -> Void in
make.edges.equalTo(v2)
return
}
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
for constraint in constraints {
constraint.activate()
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints installed")
for constraint in constraints {
constraint.deactivate()
}
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints installed")
}
func testActivateDeactivateConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
var c1: Constraint? = nil
var c2: Constraint? = nil
v1.snp.prepareConstraints { (make) -> Void in
c1 = make.top.equalTo(v2.snp.top).offset(50).constraint
c2 = make.left.equalTo(v2.snp.top).offset(50).constraint
return
}
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints")
c1?.activate()
c2?.activate()
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
c1?.deactivate()
c2?.deactivate()
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints")
c1?.activate()
c2?.activate()
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
}
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
func testSetIsActivatedConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
var c1: Constraint? = nil
var c2: Constraint? = nil
v1.snp.prepareConstraints { (make) -> Void in
c1 = make.top.equalTo(v2.snp.top).offset(50).constraint
c2 = make.left.equalTo(v2.snp.top).offset(50).constraint
return
}
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints")
c1?.isActive = true
c2?.isActive = false
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
c1?.isActive = true
c2?.isActive = true
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
c1?.isActive = false
c2?.isActive = false
XCTAssertEqual(self.container.snp_constraints.count, 0, "Should have 0 constraints")
}
2016-08-06 19:24:43 +08:00
func testEdgeConstraints() {
let view = View()
self.container.addSubview(view)
view.snp.makeConstraints { (make) -> Void in
make.edges.equalTo(self.container).offset(50.0)
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
let constraints = self.container.snp_constraints as! [NSLayoutConstraint]
XCTAssertEqual(constraints[0].constant, 50, "Should be 50")
XCTAssertEqual(constraints[1].constant, 50, "Should be 50")
XCTAssertEqual(constraints[2].constant, 50, "Should be 50")
XCTAssertEqual(constraints[3].constant, 50, "Should be 50")
}
2016-09-01 20:54:18 +08:00
func testUpdateReferencedConstraints() {
let v1 = View()
let v2 = View()
self.container.addSubview(v1)
self.container.addSubview(v2)
var c1: Constraint! = nil
var c2: Constraint! = nil
v1.snp.makeConstraints { (make) -> Void in
2016-09-01 20:57:40 +08:00
c1 = make.top.equalTo(v2).offset(50).constraint
c2 = make.bottom.equalTo(v2).offset(25).constraint
2016-09-01 20:54:18 +08:00
return
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
2016-09-01 20:57:40 +08:00
let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant }
2016-09-01 20:54:18 +08:00
2016-09-01 20:57:40 +08:00
XCTAssertEqual(constraints[0].constant, 50, "Should be 50")
XCTAssertEqual(constraints[1].constant, 25, "Should be 25")
2016-09-01 20:54:18 +08:00
c1.update(offset: 15)
c2.update(offset: 20)
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
2016-09-01 20:57:40 +08:00
XCTAssertEqual(constraints[0].constant, 15, "Should be 15")
XCTAssertEqual(constraints[1].constant, 20, "Should be 20")
c1.update(inset: 15)
c2.update(inset: 20)
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
XCTAssertEqual(constraints[0].constant, 15, "Should be 15")
XCTAssertEqual(constraints[1].constant, -20, "Should be -20")
2016-09-01 20:54:18 +08:00
}
func testInsetsAsConstraintsConstant() {
let view = View()
self.container.addSubview(view)
view.snp.makeConstraints { (make) -> Void in
make.edges.equalTo(self.container).inset(50.0)
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant }
XCTAssertEqual(constraints[0].constant, 50, "Should be 50")
XCTAssertEqual(constraints[1].constant, 50, "Should be 50")
XCTAssertEqual(constraints[2].constant, -50, "Should be -50")
XCTAssertEqual(constraints[3].constant, -50, "Should be -50")
}
2016-09-01 21:39:08 +08:00
func testConstraintInsetsAsImpliedEqualToConstraints() {
2016-09-01 20:54:18 +08:00
let view = View()
self.container.addSubview(view)
view.snp.makeConstraints { (make) -> Void in
2016-09-01 21:39:08 +08:00
make.edges.equalTo(ConstraintInsets(top: 25, left: 25, bottom: 25, right: 25))
2016-09-01 20:54:18 +08:00
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant }
XCTAssertEqual(constraints[0].constant, 25, "Should be 25")
XCTAssertEqual(constraints[1].constant, 25, "Should be 25")
XCTAssertEqual(constraints[2].constant, -25, "Should be -25")
XCTAssertEqual(constraints[3].constant, -25, "Should be -25")
}
2016-09-01 21:39:08 +08:00
func testConstraintInsetsAsConstraintsConstant() {
2016-09-01 20:54:18 +08:00
let view = View()
self.container.addSubview(view)
view.snp.makeConstraints { (make) -> Void in
2016-09-01 21:39:08 +08:00
make.edges.equalTo(self.container).inset(ConstraintInsets(top: 25, left: 25, bottom: 25, right: 25))
2016-09-01 20:54:18 +08:00
}
XCTAssertEqual(self.container.snp_constraints.count, 4, "Should have 4 constraints")
let constraints = (self.container.snp_constraints as! [NSLayoutConstraint]).sorted { $0.constant > $1.constant }
XCTAssertEqual(constraints[0].constant, 25, "Should be 25")
XCTAssertEqual(constraints[1].constant, 25, "Should be 25")
XCTAssertEqual(constraints[2].constant, -25, "Should be -25")
XCTAssertEqual(constraints[3].constant, -25, "Should be -25")
}
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
#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)
view.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: 50, height: 50))
make.left.top.equalTo(self.container)
}
XCTAssertEqual(view.snp_constraints.count, 2, "Should have 2 constraints")
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
let constraints = view.snp_constraints as! [NSLayoutConstraint]
// no guarantee which order the constraints are in, but we should test their couple
let widthHeight = (LayoutAttribute.width.rawValue, LayoutAttribute.height.rawValue)
let heightWidth = (widthHeight.1, widthHeight.0)
let firstSecond = (constraints[0].firstAttribute.rawValue, constraints[1].firstAttribute.rawValue)
// constraint values are correct in either width, height or height, width order
XCTAssertTrue(firstSecond == widthHeight || firstSecond == heightWidth, "2 contraint values should match")
XCTAssertEqual(constraints[0].constant, 50, "Should be 50")
XCTAssertEqual(constraints[1].constant, 50, "Should be 50")
}
2016-08-06 19:24:43 +08:00
func testCenterConstraints() {
let view = View()
self.container.addSubview(view)
view.snp.makeConstraints { (make) -> Void in
make.center.equalTo(self.container).offset(50.0)
}
XCTAssertEqual(self.container.snp_constraints.count, 2, "Should have 2 constraints")
if let constraints = self.container.snp_constraints as? [NSLayoutConstraint], constraints.count > 0 {
2016-08-06 19:24:43 +08:00
XCTAssertEqual(constraints[0].constant, 50, "Should be 50")
XCTAssertEqual(constraints[1].constant, 50, "Should be 50")
}
2016-08-06 19:24:43 +08:00
}
func testConstraintIdentifier() {
let identifier = "Test-Identifier"
let view = View()
self.container.addSubview(view)
view.snp.makeConstraints { (make) -> Void in
make.top.equalTo(self.container.snp.top).labeled(identifier)
}
let constraints = container.snp_constraints as! [NSLayoutConstraint]
XCTAssertEqual(constraints[0].identifier, identifier, "Identifier should be 'Test'")
}
2016-09-20 11:12:30 +08:00
func testEdgesToEdges() {
var fromAttributes = Set<LayoutAttribute>()
var toAttributes = Set<LayoutAttribute>()
let view = View()
self.container.addSubview(view)
view.snp.remakeConstraints { (make) -> Void in
2016-09-20 11:12:30 +08:00
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])
2016-09-20 11:12:30 +08:00
XCTAssert(toAttributes == [.top, .left, .bottom, .right])
}
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
func testDirectionalEdgesToDirectionalEdges() {
var fromAttributes = Set<LayoutAttribute>()
var toAttributes = Set<LayoutAttribute>()
let view = View()
self.container.addSubview(view)
view.snp.remakeConstraints { (make) -> Void in
make.directionalEdges.equalTo(self.container.snp.directionalEdges)
}
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, .leading, .bottom, .trailing])
XCTAssert(toAttributes == [.top, .leading, .bottom, .trailing])
}
2016-09-20 11:12:30 +08:00
#if os(iOS) || os(tvOS)
func testEdgesToMargins() {
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
var fromAttributes = Set<LayoutAttribute>()
var toAttributes = Set<LayoutAttribute>()
2016-09-20 11:12:30 +08:00
let view = View()
self.container.addSubview(view)
view.snp.remakeConstraints { (make) -> Void in
2016-09-20 11:12:30 +08:00
make.edges.equalTo(self.container.snp.margins)
}
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)
}
2016-09-20 11:12:30 +08:00
XCTAssert(fromAttributes == [.top, .left, .bottom, .right])
XCTAssert(toAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin])
2016-09-20 11:12:30 +08:00
fromAttributes.removeAll()
toAttributes.removeAll()
view.snp.remakeConstraints { (make) -> Void in
2016-09-20 11:12:30 +08:00
make.margins.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(toAttributes == [.top, .left, .bottom, .right])
2016-09-20 11:12:30 +08:00
XCTAssert(fromAttributes == [.topMargin, .leftMargin, .bottomMargin, .rightMargin])
}
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
func testDirectionalEdgesToDirectionalMargins() {
var fromAttributes = Set<LayoutAttribute>()
var toAttributes = Set<LayoutAttribute>()
let view = View()
self.container.addSubview(view)
view.snp.remakeConstraints { (make) -> Void in
make.directionalEdges.equalTo(self.container.snp.directionalMargins)
}
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, .leading, .bottom, .trailing])
XCTAssert(toAttributes == [.topMargin, .leadingMargin, .bottomMargin, .trailingMargin])
fromAttributes.removeAll()
toAttributes.removeAll()
view.snp.remakeConstraints { (make) -> Void in
make.directionalMargins.equalTo(self.container.snp.directionalEdges)
}
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(toAttributes == [.top, .leading, .bottom, .trailing])
XCTAssert(fromAttributes == [.topMargin, .leadingMargin, .bottomMargin, .trailingMargin])
}
2016-09-01 21:39:08 +08:00
func testLayoutGuideConstraints() {
let vc = UIViewController()
vc.view = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300))
vc.view.addSubview(self.container)
self.container.snp.makeConstraints { (make) -> Void in
2016-09-20 11:12:30 +08:00
make.top.equalTo(vc.topLayoutGuide.snp.bottom)
make.bottom.equalTo(vc.bottomLayoutGuide.snp.top)
2016-09-01 21:39:08 +08:00
}
2016-09-10 12:40:55 +08:00
2016-09-20 11:12:30 +08:00
XCTAssertEqual(vc.view.snp_constraints.count, 2, "Should have 2 constraints installed")
2016-09-01 21:39:08 +08:00
}
#endif
2016-09-20 13:08:30 +08:00
func testCanSetLabel() {
self.container.snp.setLabel("Hello World")
Feature/release 5.6 (#746) * Add support for UILayoutPriority as priority target. (#466) * Add support for UILayoutPriority as priority target. * Fixed for tvOS * Add update(priority: ConstraintPriority) method (#467) * Add update(priority: ConstraintPriority) method * Fix copy-paste error * Add Swift Package Manager support (#501) * Swift4.2 (#516) * make ConstraintAttributes conform to ExpressibleByIntegerLiteral (#520) * Adds 'constraint.isActive = bool' to Constraint (#496) * delegate identical 'constraint creation' code to 'prepareConstraints' * adds 'set(isActivated:)' method to call appropriate 'activate/deactivate' based on bool cleans up about 30 lines of if foo { activate } else { deactivate } code in my app * instead of 'set(isActivated:)', use 'isActive = value' * Add swift version to podspec * Update podspec * Update podspec * Update project to get rid of Migration Warning (#547) * Update Swift Language version to 4.2 under build settings (#551) * Update swift language version to 4.2 in build settings * Update podspec * Remove Swift Version file * Remove Package.swift, SnapKit is not SwiftPM compatible anyways * Update Podspec * Update version in Podspec * Support swift 5.0 (#570) * Update swift version 5.0 * Remove needless access control * Fix misused "Available" annotations * Support @unknown default * Support swift 5.0 in test code * Update podspec * Update travis CI * Code review by @freak4pc * Add constraint for Swift version * Fix build failed * [EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574) * @sashabelonogov Update LayoutConstraint == operator to support iOS 10 and higher changes * Simplify return statement of the LayoutConstraint == operator * Fix incorrect behavior of inset with center and baseline anchors (#569) * Fix insets adjusting center attributes incorrectly * Fix insets adjusting baseline attributes incorrectly * Add back Package.swift for SwiftPM compatibility (#559) reverts 477fffae4c37386285f78511ff4120f1f5324ff8 * Update podspec * Update min target versions * Update min target versions * Update README.md * Update README.md * Revert "[EXC_BAD_ACCESS] Update LayoutConstraint == operator to support iOS 10 and higher changes (#574)" (#593) This reverts commit bc2b0b93320513eb747b3baf6332c05bacc067b4. * Update Podspec * Bump min version requirements * Fix layout constraint comparison * Fix equality check for iOS * Adds support for NSDirectionalEdgeInsets as an inset constant (#594) * Make ConstraintViewDSL content priorities nonmutating (#586) * Adds two new compositions – DirectionalEdges and DirectionalMargins (#595) * WIP * Add directional margins * Whitespace * Add Playground Sample (#608) * added updates to Package.swift so it can be imported with Xcode 11 (#615) * Revert #574 * Update Podspec * Add background color to quick start box in README.md (#619) * add-dimensional-edges: add ConstraintItems horizontalEdges, verticalEdges, directionalHorizontalEdges and directionalVerticalEdges as convenience items to express left+right, top+bottom or leading+trailing (#637) * Update deprecations to allow Xcode to auto-fixup. (#634) * Migrate to Xcode 11 and updated travis.yml (#629) * Migrate to Xcode 11 and updated travis.yml * Travis to support Xcode 11 * project.pbxproj: Update to recommended settings. (#627) * Add test assert to unit test testCanSetLabel. (#625) * Add back support for OS X 10.11 (#645) * Use << for ConstraintAttributes options (#659) * Use << for ConstraintAttributes options * iPhone 6s is not supported by the latest Xcode * Add method getting constraint with closure to ConstraintMakerRelatable (#663) * add ConstraintMakerRelatable extension * fix fatalError message Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> * Xcode 12 and SwiftPM enhancements * Update README to include SPM installation notes (#673) * Fix typo * Remove duplicate file * xcodeproject configuration enhancement for localization (#584) Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> * Updates to project files * Dynamic Product (#710) This PR adds a dynamic product to SnapKit. Having a dynamic product is important in modular project structures; multiple packages may be using SnapKit, and this allows that support without the end-user have to wrap SnapKit in their own package that exposes it and using that package in lieu of SnapKit. * Fix warning about `class` (#714) * Added Example-iOS.xcdodeproj and fixed examples (#707) * Update README.md, add missing Migration Guides section (#721) * Make ConstraintMaker.item public (#693) * Typo source directory in Podspec (#738) Source directory has been renamed in 18608ead653bfe1e05e3d1f6fb6d34f62cec49bd * Release 5.6 * Update urls in readme * Update podspec version Co-authored-by: Benjamin Chrobot <benjamin.blair.chrobot@gmail.com> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: Mauro Vime Castillo <mvimeapps@gmail.com> Co-authored-by: o( ̄へ ̄)o <guzhenhuaGitHub@users.noreply.github.com> Co-authored-by: Colin T.A. Gray <colinta@gmail.com> Co-authored-by: Shai Mishali <freak4pc@gmail.com> Co-authored-by: Ibrahim Koteish <ikteish@yahoo.com> Co-authored-by: Jungwon An <kawoou@kawoou.kr> Co-authored-by: Alexander Belonogov <sashabelonogov@gmail.com> Co-authored-by: Christian Schnorr <christian.schnorr@me.com> Co-authored-by: Josh Converse <josh.converse@gmail.com> Co-authored-by: Vitalii Budnik <nekrich@users.noreply.github.com> Co-authored-by: Shiva Huang <shiva.tw@gmail.com> Co-authored-by: Max Cobb <5754073+maxxfrazer@users.noreply.github.com> Co-authored-by: Liam Elmore <32336260+iosmo@users.noreply.github.com> Co-authored-by: Sven Driemecker <sven.dr@gmx.de> Co-authored-by: Alex Simpson <alexandersimpson94@gmail.com> Co-authored-by: pushp1989 <54930194+pushp1989@users.noreply.github.com> Co-authored-by: Ben Yohay <ben@lightricks.com> Co-authored-by: Natascha Fadeeva <nataschafadeeva@aol.de> Co-authored-by: Wang, Chi <patr0nus@users.noreply.github.com> Co-authored-by: Roman Podymov <podymfrombryansk@yandex.ru> Co-authored-by: wotjd <wotjd971102@gmail.com> Co-authored-by: Jimi <jimi-hpcnt@hpcnt.com> Co-authored-by: Samuel Eshun <samueleshun15@gmail.com> Co-authored-by: Amr Elghadban <amr.elghadban@gmail.com> Co-authored-by: AmrAngry <c_amr.elghadban@smartdubai.ae> Co-authored-by: Hesham Salman <iron-ham@github.com> Co-authored-by: Mr. Ming <minglq.9@gmail.com> Co-authored-by: Teameh <tiemevanveen@hotmail.com> Co-authored-by: Josip Rezić <josip.rezic@hotmail.com> Co-authored-by: Rhett Tuan <devindwan@gmail.com> Co-authored-by: Damien Debin <ddebin@users.noreply.github.com> Co-authored-by: Robert Payne <robertjpayne@Roberts-MacBook-Pro.local>
2022-04-13 12:06:06 +08:00
XCTAssertEqual(self.container.snp.label(), "Hello World")
2016-09-20 13:08:30 +08:00
}
func testPriorityShortcuts() {
let view = View()
self.container.addSubview(view)
view.snp.remakeConstraints { make in
make.left.equalTo(1000.0).priority(.required)
}
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.required.value)
view.snp.remakeConstraints { make in
make.left.equalTo(1000.0).priority(.low)
}
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value)
view.snp.remakeConstraints { make in
make.left.equalTo(1000.0).priority(ConstraintPriority.low.value + 1)
}
XCTAssertEqual(self.container.snp_constraints.count, 1, "Should have 1 constraint")
XCTAssertEqual(self.container.snp_constraints.first?.priority, ConstraintPriority.low.value + 1)
}
func testPriorityStride() {
let highPriority: ConstraintPriority = .high
2017-06-12 18:12:07 +08:00
let higherPriority: ConstraintPriority = ConstraintPriority.high.advanced(by: 1)
XCTAssertEqual(higherPriority.value, highPriority.value + 1)
}
2014-06-06 11:42:44 +08:00
}