Skip to content
This repository has been archived by the owner on Sep 15, 2019. It is now read-only.

Commit

Permalink
Merge c17a1e5 into b818c70
Browse files Browse the repository at this point in the history
  • Loading branch information
sp71 committed Apr 2, 2017
2 parents b818c70 + c17a1e5 commit 7c1427e
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 32 deletions.
34 changes: 12 additions & 22 deletions Example/SnapLayout.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
/* Begin PBXBuildFile section */
05D8B3621E8E1F7F00E5819A /* SnapConfigTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D8B3611E8E1F7F00E5819A /* SnapConfigTests.swift */; };
05D8B3641E8E1FAE00E5819A /* SnapManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05D8B3631E8E1FAE00E5819A /* SnapManagerTests.swift */; };
1903337A84AAE47EB8FAD934 /* Pods_SnapLayout_ExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF111A53420B9650C1DF7D5 /* Pods_SnapLayout_ExampleTests.framework */; };
5ABBFC5A61D891256E312103 /* Pods_SnapLayout_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C4411399DDCCAE9D04770720 /* Pods_SnapLayout_Example.framework */; };
05FA916D1E919EE90033BC64 /* SnapLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 05FA916C1E919EE90033BC64 /* SnapLayoutTests.swift */; };
16620983C7FD6063E77C3842 /* Pods_SnapLayout_ExampleTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C8E67D8280A8CA43B58D9B0 /* Pods_SnapLayout_ExampleTests.framework */; };
607FACD61AFB9204008FA782 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD51AFB9204008FA782 /* AppDelegate.swift */; };
607FACD81AFB9204008FA782 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 607FACD71AFB9204008FA782 /* ViewController.swift */; };
607FACDD1AFB9204008FA782 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDC1AFB9204008FA782 /* Images.xcassets */; };
607FACE01AFB9204008FA782 /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 607FACDE1AFB9204008FA782 /* LaunchScreen.xib */; };
C5916DD918499AC040716CAE /* Pods_SnapLayout_Example.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6E8455DE81A33BC7EDDE58E6 /* Pods_SnapLayout_Example.framework */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -28,48 +29,42 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
05D8B3431E8E1B4000E5819A /* SnapLayout.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SnapLayout.framework; path = "Pods/../build/Debug-iphoneos/SnapLayout/SnapLayout.framework"; sourceTree = "<group>"; };
05D8B3571E8E1D7C00E5819A /* SnapLayout_ExampleTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SnapLayout_ExampleTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
05D8B35B1E8E1D7C00E5819A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
05D8B3611E8E1F7F00E5819A /* SnapConfigTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapConfigTests.swift; sourceTree = "<group>"; };
05D8B3631E8E1FAE00E5819A /* SnapManagerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapManagerTests.swift; sourceTree = "<group>"; };
05FA916C1E919EE90033BC64 /* SnapLayoutTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SnapLayoutTests.swift; sourceTree = "<group>"; };
1C8E67D8280A8CA43B58D9B0 /* Pods_SnapLayout_ExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapLayout_ExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
286255A2AE6D51660F5C7B63 /* Pods-SnapLayout_ExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_ExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_ExampleTests/Pods-SnapLayout_ExampleTests.release.xcconfig"; sourceTree = "<group>"; };
2C9EFFE12017367D906EA542 /* Pods-SnapLayout_ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_ExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_ExampleTests/Pods-SnapLayout_ExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
39BF416F85D73A58E0759C5A /* Pods-SnapLayout_Example-SnapLayout_ExampleTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_Example-SnapLayout_ExampleTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_Example-SnapLayout_ExampleTests/Pods-SnapLayout_Example-SnapLayout_ExampleTests.debug.xcconfig"; sourceTree = "<group>"; };
3AF111A53420B9650C1DF7D5 /* Pods_SnapLayout_ExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapLayout_ExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
4C9147F394BD9B0020A19460 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; lineEnding = 0; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = "<none>"; };
5D24B25AC0181DDD97F376C0 /* Pods_SnapLayout_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapLayout_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD01AFB9204008FA782 /* SnapLayout_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SnapLayout_Example.app; sourceTree = BUILT_PRODUCTS_DIR; };
607FACD41AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACD51AFB9204008FA782 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
607FACD71AFB9204008FA782 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
607FACDC1AFB9204008FA782 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
607FACDF1AFB9204008FA782 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = "<group>"; };
630EA847B7E2C05C27DF4671 /* Pods-SnapLayout_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_Tests/Pods-SnapLayout_Tests.debug.xcconfig"; sourceTree = "<group>"; };
6E8455DE81A33BC7EDDE58E6 /* Pods_SnapLayout_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapLayout_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
7CC5E256D0B6B8AB75218628 /* SnapLayout.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; lineEnding = 0; name = SnapLayout.podspec; path = ../SnapLayout.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = "<none>"; };
81249413C533FA3C633F8B09 /* Pods-SnapLayout_Example.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_Example.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_Example/Pods-SnapLayout_Example.release.xcconfig"; sourceTree = "<group>"; };
83DD46CF64EC537739968A0D /* Pods-SnapLayout_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_Example/Pods-SnapLayout_Example.debug.xcconfig"; sourceTree = "<group>"; };
9FE2FE590678BB0D7C3AE9D5 /* Pods_SnapLayout_Example_SnapLayout_ExampleTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapLayout_Example_SnapLayout_ExampleTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
C4411399DDCCAE9D04770720 /* Pods_SnapLayout_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SnapLayout_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
CF6C903DE4EA30D1C820E7C5 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; lineEnding = 0; name = README.md; path = ../README.md; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.markdown; };
D26389D625F6CC2DE5BE5F5B /* Pods-SnapLayout_Example-SnapLayout_ExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_Example-SnapLayout_ExampleTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_Example-SnapLayout_ExampleTests/Pods-SnapLayout_Example-SnapLayout_ExampleTests.release.xcconfig"; sourceTree = "<group>"; };
FF5E1BCF564DE8261F019A1C /* Pods-SnapLayout_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapLayout_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnapLayout_Tests/Pods-SnapLayout_Tests.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
05D8B3541E8E1D7C00E5819A /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
1903337A84AAE47EB8FAD934 /* Pods_SnapLayout_ExampleTests.framework in Frameworks */,
16620983C7FD6063E77C3842 /* Pods_SnapLayout_ExampleTests.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
607FACCD1AFB9204008FA782 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
5ABBFC5A61D891256E312103 /* Pods_SnapLayout_Example.framework in Frameworks */,
C5916DD918499AC040716CAE /* Pods_SnapLayout_Example.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -81,6 +76,7 @@
children = (
05D8B3611E8E1F7F00E5819A /* SnapConfigTests.swift */,
05D8B3631E8E1FAE00E5819A /* SnapManagerTests.swift */,
05FA916C1E919EE90033BC64 /* SnapLayoutTests.swift */,
05D8B35B1E8E1D7C00E5819A /* Info.plist */,
);
path = SnapLayout_ExampleTests;
Expand All @@ -91,10 +87,6 @@
children = (
83DD46CF64EC537739968A0D /* Pods-SnapLayout_Example.debug.xcconfig */,
81249413C533FA3C633F8B09 /* Pods-SnapLayout_Example.release.xcconfig */,
630EA847B7E2C05C27DF4671 /* Pods-SnapLayout_Tests.debug.xcconfig */,
FF5E1BCF564DE8261F019A1C /* Pods-SnapLayout_Tests.release.xcconfig */,
39BF416F85D73A58E0759C5A /* Pods-SnapLayout_Example-SnapLayout_ExampleTests.debug.xcconfig */,
D26389D625F6CC2DE5BE5F5B /* Pods-SnapLayout_Example-SnapLayout_ExampleTests.release.xcconfig */,
2C9EFFE12017367D906EA542 /* Pods-SnapLayout_ExampleTests.debug.xcconfig */,
286255A2AE6D51660F5C7B63 /* Pods-SnapLayout_ExampleTests.release.xcconfig */,
);
Expand Down Expand Up @@ -156,11 +148,8 @@
B26703EFE7205943E8D7FD25 /* Frameworks */ = {
isa = PBXGroup;
children = (
05D8B3431E8E1B4000E5819A /* SnapLayout.framework */,
C4411399DDCCAE9D04770720 /* Pods_SnapLayout_Example.framework */,
5D24B25AC0181DDD97F376C0 /* Pods_SnapLayout_Tests.framework */,
9FE2FE590678BB0D7C3AE9D5 /* Pods_SnapLayout_Example_SnapLayout_ExampleTests.framework */,
3AF111A53420B9650C1DF7D5 /* Pods_SnapLayout_ExampleTests.framework */,
6E8455DE81A33BC7EDDE58E6 /* Pods_SnapLayout_Example.framework */,
1C8E67D8280A8CA43B58D9B0 /* Pods_SnapLayout_ExampleTests.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -369,6 +358,7 @@
files = (
05D8B3641E8E1FAE00E5819A /* SnapManagerTests.swift in Sources */,
05D8B3621E8E1F7F00E5819A /* SnapConfigTests.swift in Sources */,
05FA916D1E919EE90033BC64 /* SnapLayoutTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
164 changes: 164 additions & 0 deletions Example/SnapLayout_ExampleTests/SnapLayoutTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//
// SnapLayoutTests.swift
// SnapLayout
//
// Created by Satinder Singh on 4/2/17.
// Copyright © 2017 CocoaPods. All rights reserved.
//

import UIKit
import XCTest
import SnapLayout

class SnapLayoutTests: XCTestCase {

/// Tests Snap Layout where no constraints were applied.
func testSnapInActiveError() {
let childView = UIView()
let superview = UIView()
superview.addSubview(childView)
let snapManager = childView.snap()
XCTAssertEqual(childView.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertNil(snapManager.top)
XCTAssertNil(snapManager.leading)
XCTAssertNil(snapManager.bottom)
XCTAssertNil(snapManager.trailing)
XCTAssertNil(snapManager.width)
XCTAssertNil(snapManager.height)
XCTAssertNil(snapManager.centerX)
XCTAssertNil(snapManager.centerY)
}

/// Tests Snap Width method
func testSnapWidth() {
let view1 = UIView()
let view2 = UIView()
let containerView = UIView()
containerView.addSubview(view1)
containerView.addSubview(view2)
let snapManager = view1.snapWidth(to: view2, multiplier: 0.5)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertEqual(view2.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNotNil(snapManager.width)
XCTAssertEqual(snapManager.width!.isActive, true)
XCTAssertEqual(snapManager.width!.constant, 0)
XCTAssertEqual(snapManager.width!.multiplier, 0.5)
}

/// Tests Snap Width where constraint was not applied
func testsSnapWidthError() {
let view1 = UIView()
let snapManager = view1.snapWidth(multiplier: 0.5)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNil(snapManager.width)
}

/// Tets Snap Height method
func testSnapHeight() {
let view1 = UIView()
let view2 = UIView()
let containerView = UIView()
containerView.addSubview(view1)
containerView.addSubview(view2)
let snapManager = view1.snapHeight(to: view2, multiplier: 0.5)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertEqual(view2.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNotNil(snapManager.height)
XCTAssertEqual(snapManager.height!.isActive, true)
XCTAssertEqual(snapManager.height!.constant, 0)
XCTAssertEqual(snapManager.height!.multiplier, 0.5)
}

/// Tests Snap Height where constraint was not applied
func testsSnapHeightError() {
let view1 = UIView()
let snapManager = view1.snapHeight(multiplier: 0.5)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNil(snapManager.height)
}

/// Tests Snap Size method
func testSnapSize() {
let size = CGSize(width: 30, height: 40)
let view1 = UIView()
let snapManager = view1.snapSize(size: size)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertNotNil(snapManager.width)
XCTAssertNotNil(snapManager.height)
XCTAssertEqual(snapManager.width!.isActive, true)
XCTAssertEqual(snapManager.height!.isActive, true)
XCTAssertEqual(snapManager.width!.constant, size.width)
XCTAssertEqual(snapManager.height!.constant, size.height)
XCTAssertEqual(snapManager.width!.multiplier, 1.0)
XCTAssertEqual(snapManager.height!.multiplier, 1.0)
}

/// Tests Snap Trailing View
func testSnapTrailingView() {
let trailingConstant = CGFloat(8)
let view1 = UIView()
let view2 = UIView()
let containerView = UIView()
containerView.addSubview(view1)
containerView.addSubview(view2)
let snapManager = view1.snap(trailingView: view2, constant: trailingConstant)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertEqual(view2.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNotNil(snapManager.trailing)
XCTAssertEqual(snapManager.trailing!.isActive, true)
XCTAssertEqual(snapManager.trailing!.constant, trailingConstant)
XCTAssertEqual(snapManager.trailing!.multiplier, 1.0)
}

/// Tests Snap Leading View
func testSnapLeadingView() {
let leadingConstant = CGFloat(8)
let view1 = UIView()
let view2 = UIView()
let containerView = UIView()
containerView.addSubview(view1)
containerView.addSubview(view2)
let snapManager = view1.snap(leadingView: view2, constant: leadingConstant)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertEqual(view2.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNotNil(snapManager.leading)
XCTAssertEqual(snapManager.leading!.isActive, true)
XCTAssertEqual(snapManager.leading!.constant, leadingConstant)
XCTAssertEqual(snapManager.leading!.multiplier, 1.0)
}

/// Tests Snap Bottom View
func testSnapBottomView() {
let bottomConstant = CGFloat(8)
let view1 = UIView()
let view2 = UIView()
let containerView = UIView()
containerView.addSubview(view1)
containerView.addSubview(view2)
let snapManager = view1.snap(bottomView: view2, constant: bottomConstant)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertEqual(view2.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNotNil(snapManager.bottom)
XCTAssertEqual(snapManager.bottom!.isActive, true)
XCTAssertEqual(snapManager.bottom!.constant, bottomConstant)
XCTAssertEqual(snapManager.bottom!.multiplier, 1.0)
}

/// Tests Snap Trailing View
func testSnapTopView() {
let topConstant = CGFloat(8)
let view1 = UIView()
let view2 = UIView()
let containerView = UIView()
containerView.addSubview(view1)
containerView.addSubview(view2)
let snapManager = view1.snap(topView: view2, constant: topConstant)
XCTAssertEqual(view1.translatesAutoresizingMaskIntoConstraints, false)
XCTAssertEqual(view2.translatesAutoresizingMaskIntoConstraints, true)
XCTAssertNotNil(snapManager.top)
XCTAssertEqual(snapManager.top!.isActive, true)
XCTAssertEqual(snapManager.top!.constant, topConstant)
XCTAssertEqual(snapManager.top!.multiplier, 1.0)
}

}
Loading

0 comments on commit 7c1427e

Please sign in to comment.