Skip to content

Commit 486a881

Browse files
author
Baris Sencan
committed
Merge pull request #3 from isair/feature/proper-tests
Test Entire API
2 parents 41a5b21 + 8d98f19 commit 486a881

File tree

10 files changed

+252
-21
lines changed

10 files changed

+252
-21
lines changed

ManualLayout.xcodeproj/project.pbxproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F67BC091A9D43FE00347483 /* FastAccessTests.swift */; };
1011
5F875C581A9BC8BF003CACDD /* Enums.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C571A9BC8BF003CACDD /* Enums.swift */; };
1112
5F875C5B1A9BCBB2003CACDD /* UIView+ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */; };
1213
5F875C5F1A9BD55D003CACDD /* ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */; };
13-
5F875C651A9BE2D3003CACDD /* UIViewProxyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C641A9BE2D3003CACDD /* UIViewProxyTests.swift */; };
14+
5F875C651A9BE2D3003CACDD /* UIViewManualLayoutTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C641A9BE2D3003CACDD /* UIViewManualLayoutTests.swift */; };
1415
5F875C691A9BE99F003CACDD /* CALayer+FastAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C681A9BE99F003CACDD /* CALayer+FastAccess.swift */; };
1516
5F875C6D1A9BFC7E003CACDD /* UIView+FastAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C6C1A9BFC7E003CACDD /* UIView+FastAccess.swift */; };
1617
5F875C6F1A9BFE01003CACDD /* CALayer+ManualLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F875C6E1A9BFE01003CACDD /* CALayer+ManualLayout.swift */; };
@@ -30,10 +31,11 @@
3031
/* End PBXContainerItemProxy section */
3132

3233
/* Begin PBXFileReference section */
34+
5F67BC091A9D43FE00347483 /* FastAccessTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FastAccessTests.swift; sourceTree = "<group>"; };
3335
5F875C571A9BC8BF003CACDD /* Enums.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Enums.swift; sourceTree = "<group>"; };
3436
5F875C5A1A9BCBB2003CACDD /* UIView+ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+ManualLayout.swift"; sourceTree = "<group>"; };
3537
5F875C5E1A9BD55D003CACDD /* ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManualLayout.swift; sourceTree = "<group>"; };
36-
5F875C641A9BE2D3003CACDD /* UIViewProxyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewProxyTests.swift; sourceTree = "<group>"; };
38+
5F875C641A9BE2D3003CACDD /* UIViewManualLayoutTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIViewManualLayoutTests.swift; sourceTree = "<group>"; };
3739
5F875C681A9BE99F003CACDD /* CALayer+FastAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CALayer+FastAccess.swift"; sourceTree = "<group>"; };
3840
5F875C6C1A9BFC7E003CACDD /* UIView+FastAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIView+FastAccess.swift"; sourceTree = "<group>"; };
3941
5F875C6E1A9BFE01003CACDD /* CALayer+ManualLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CALayer+ManualLayout.swift"; sourceTree = "<group>"; };
@@ -108,8 +110,9 @@
108110
5FB4CBF81A9BBE7500C2FB4F /* ManualLayoutTests */ = {
109111
isa = PBXGroup;
110112
children = (
113+
5F67BC091A9D43FE00347483 /* FastAccessTests.swift */,
111114
5FB4CBFB1A9BBE7500C2FB4F /* ManualLayoutTests.swift */,
112-
5F875C641A9BE2D3003CACDD /* UIViewProxyTests.swift */,
115+
5F875C641A9BE2D3003CACDD /* UIViewManualLayoutTests.swift */,
113116
5FB4CBF91A9BBE7500C2FB4F /* Supporting Files */,
114117
);
115118
path = ManualLayoutTests;
@@ -243,7 +246,8 @@
243246
isa = PBXSourcesBuildPhase;
244247
buildActionMask = 2147483647;
245248
files = (
246-
5F875C651A9BE2D3003CACDD /* UIViewProxyTests.swift in Sources */,
249+
5F875C651A9BE2D3003CACDD /* UIViewManualLayoutTests.swift in Sources */,
250+
5F67BC0A1A9D43FE00347483 /* FastAccessTests.swift in Sources */,
247251
5FB4CBFC1A9BBE7500C2FB4F /* ManualLayoutTests.swift in Sources */,
248252
);
249253
runOnlyForDeploymentPostprocessing = 0;

ManualLayout/CALayer+FastAccess.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010

1111
public extension CALayer {
1212

ManualLayout/CALayer+ManualLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010

1111
public extension CALayer {
1212

ManualLayout/Enums.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
10-
119
public enum ManualLayoutDimension {
1210
case X, Y
1311
}

ManualLayout/ManualLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010

1111
public struct ManualLayout {
1212

ManualLayout/UIView+FastAccess.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010

1111
// I wish there was an easier way to do this in Swift.
1212
public extension UIView {

ManualLayout/UIView+ManualLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010

1111
// Proxy CALayer+ManualLayout methods for UIView.
1212
public extension UIView {
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
//
2+
// FastAccessTests.swift
3+
// ManualLayout
4+
//
5+
// Created by Baris Sencan on 24/02/15.
6+
// Copyright (c) 2015 Baris Sencan. All rights reserved.
7+
//
8+
9+
import UIKit
10+
import XCTest
11+
import ManualLayout
12+
13+
class FastAccessTests: XCTestCase {
14+
let view = UIView(frame: CGRectZero)
15+
let defaultFrame = CGRect(x: 1, y: 3, width: 6, height: 8)
16+
17+
override func setUp() {
18+
view.frame = defaultFrame
19+
}
20+
21+
func testOrigin() {
22+
let newOrigin = CGPoint(x: 10, y: 10)
23+
view.origin = newOrigin
24+
XCTAssertEqual(
25+
view.frame.origin,
26+
newOrigin,
27+
"origin changes should modify frame origin")
28+
XCTAssertEqual(
29+
view.frame.size,
30+
defaultFrame.size,
31+
"origin changes should not modify frame size")
32+
}
33+
34+
func testX() {
35+
view.x = 10
36+
XCTAssertEqual(
37+
view.frame.origin,
38+
CGPoint(x: 10, y: defaultFrame.origin.y),
39+
"x changes should just modify frame x")
40+
XCTAssertEqual(
41+
view.frame.size,
42+
defaultFrame.size,
43+
"x changes should not modify frame size")
44+
}
45+
46+
func testY() {
47+
view.y = 10
48+
XCTAssertEqual(
49+
view.frame.origin,
50+
CGPoint(x: defaultFrame.origin.x, y: 10),
51+
"y changes should just modify frame y")
52+
XCTAssertEqual(
53+
view.frame.size,
54+
defaultFrame.size,
55+
"y changes should not modify frame size")
56+
}
57+
58+
func testCenter() {
59+
view.layer.center = CGPoint(x: 10, y: 10)
60+
XCTAssertEqual(
61+
view.frame.origin,
62+
CGPoint(x: 7, y: 6),
63+
"center changes should center frame")
64+
XCTAssertEqual(
65+
view.frame.size,
66+
defaultFrame.size,
67+
"center changes should not modify frame size")
68+
}
69+
70+
func testCenterX() {
71+
view.centerX = 10
72+
XCTAssertEqual(
73+
view.frame.origin,
74+
CGPoint(x: 7, y: defaultFrame.origin.y),
75+
"centerX changes should center frame")
76+
XCTAssertEqual(
77+
view.frame.size,
78+
defaultFrame.size,
79+
"centerX changes should not modify frame size")
80+
}
81+
82+
func testCenterY() {
83+
view.centerY = 10
84+
XCTAssertEqual(
85+
view.frame.origin,
86+
CGPoint(x: defaultFrame.origin.x, y: 6),
87+
"centerY changes should center frame")
88+
XCTAssertEqual(
89+
view.frame.size,
90+
defaultFrame.size,
91+
"centerY changes should not modify frame size")
92+
}
93+
94+
func testSize() {
95+
view.size = CGSizeZero
96+
XCTAssertEqual(
97+
view.frame.origin,
98+
defaultFrame.origin,
99+
"size changes should not modify frame origin")
100+
XCTAssertEqual(
101+
view.frame.size,
102+
CGSizeZero,
103+
"size changes should modify frame size")
104+
}
105+
106+
func testWidth() {
107+
view.width = 10
108+
XCTAssertEqual(
109+
view.frame.origin,
110+
defaultFrame.origin,
111+
"width changes should not modify frame origin")
112+
XCTAssertEqual(
113+
view.frame.size,
114+
CGSize(width: 10, height: defaultFrame.size.height),
115+
"width changes should just modify frame width")
116+
}
117+
118+
func testHeight() {
119+
view.height = 10
120+
XCTAssertEqual(
121+
view.frame.origin,
122+
defaultFrame.origin,
123+
"height changes should not modify frame origin")
124+
XCTAssertEqual(
125+
view.frame.size,
126+
CGSize(width: defaultFrame.size.width, height: 10),
127+
"height changes should just modify frame height")
128+
}
129+
130+
func testTop() {
131+
view.top = 10
132+
XCTAssertEqual(
133+
view.frame.origin,
134+
CGPoint(x: defaultFrame.origin.x, y: 10),
135+
"top changes should just modify frame y")
136+
XCTAssertEqual(
137+
view.frame.size,
138+
defaultFrame.size,
139+
"top changes should not modify frame size")
140+
}
141+
142+
func testRight() {
143+
view.right = 10
144+
XCTAssertEqual(
145+
view.frame.origin,
146+
CGPoint(x: 10 - defaultFrame.size.width, y: defaultFrame.origin.y),
147+
"right changes should just modify frame x")
148+
XCTAssertEqual(
149+
view.frame.size,
150+
defaultFrame.size,
151+
"right changes should not modify frame size")
152+
}
153+
154+
func testBottom() {
155+
view.bottom = 10
156+
XCTAssertEqual(
157+
view.frame.origin,
158+
CGPoint(x: defaultFrame.origin.x, y: 10 - defaultFrame.size.height),
159+
"bottom changes should just modify frame y")
160+
XCTAssertEqual(
161+
view.frame.size,
162+
defaultFrame.size,
163+
"bottom changes should not modify frame size")
164+
}
165+
166+
func testLeft() {
167+
view.left = 10
168+
XCTAssertEqual(
169+
view.frame.origin,
170+
CGPoint(x: 10, y: defaultFrame.origin.y),
171+
"left changes should just modify frame x")
172+
XCTAssertEqual(
173+
view.frame.size,
174+
defaultFrame.size,
175+
"left changes should not modify frame size")
176+
}
177+
178+
func testTop2() {
179+
view.top2 = 5
180+
XCTAssertEqual(
181+
view.frame.origin,
182+
CGPoint(x: defaultFrame.origin.x, y: 5),
183+
"top2 changes without a swap should just modify frame y")
184+
XCTAssertEqual(
185+
view.frame.size,
186+
CGSize(width: defaultFrame.size.width, height: 6),
187+
"top2 changes without a swap should modify frame size")
188+
// TODO: Test swap behavior.
189+
}
190+
191+
func testRight2() {
192+
view.right2 = 5
193+
XCTAssertEqual(
194+
view.frame.origin,
195+
defaultFrame.origin,
196+
"right2 changes without a swap should not modify frame origin")
197+
XCTAssertEqual(
198+
view.frame.size,
199+
CGSize(width: 4, height: defaultFrame.size.height),
200+
"right2 changes without a swap should modify frame size")
201+
// TODO: Test swap behavior.
202+
}
203+
204+
func testBottom2() {
205+
view.bottom2 = 5
206+
XCTAssertEqual(
207+
view.frame.origin,
208+
defaultFrame.origin,
209+
"bottom2 changes without a swap should not modify frame origin")
210+
XCTAssertEqual(
211+
view.frame.size,
212+
CGSize(width: defaultFrame.size.width, height: 2),
213+
"bottom2 changes without a swap should modify frame size")
214+
// TODO: Test swap behavior.
215+
}
216+
217+
func testLeft2() {
218+
view.left2 = 5
219+
XCTAssertEqual(
220+
view.frame.origin,
221+
CGPoint(x: 5, y: defaultFrame.origin.y),
222+
"left2 changes without a swap should just modify frame x")
223+
XCTAssertEqual(
224+
view.frame.size,
225+
CGSize(width: 2, height: defaultFrame.size.height),
226+
"left2 changes without a swap should modify frame size")
227+
// TODO: Test swap behavior.
228+
}
229+
}

ManualLayoutTests/ManualLayoutTests.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import XCTest
1111
import ManualLayout
1212

1313
internal class ManualLayoutTests: XCTestCase {
14-
let otherRect = CGRect (x: 10, y: 20, width: 100, height: 100)
14+
let otherRect = CGRect(x: 10, y: 20, width: 100, height: 100)
1515
let rect = CGRect(x: 0, y: 0, width: 10, height: 10)
1616

1717
func testGetOriginForCenteringRect() {
18-
let origin = ManualLayout.getOriginForCenteringRect(rect, inRect: otherRect)
19-
XCTAssertEqual(origin, CGPoint(x: 55, y: 65), "origin should be at (55, 65)")
18+
let o = ManualLayout.getOriginForCenteringRect(rect, inRect: otherRect)
19+
XCTAssertEqual(o, CGPoint(x: 55, y: 65), "o should equal center point")
2020
}
2121

2222
func testGetPositionForCenteringRect() {
23-
let positionX = ManualLayout.getPositionForCenteringRect(rect, dimension: .X, inRect: otherRect)
24-
XCTAssertEqual(positionX, CGFloat(55), "x position should be 55")
25-
let positionY = ManualLayout.getPositionForCenteringRect(rect, dimension: .Y, inRect: otherRect)
26-
XCTAssertEqual(positionY, CGFloat(65), "y position should be 65")
23+
let x = ManualLayout.getPositionForCenteringRect(rect, dimension: .X, inRect: otherRect)
24+
XCTAssert(x == 55, "x should be in center")
25+
let y = ManualLayout.getPositionForCenteringRect(rect, dimension: .Y, inRect: otherRect)
26+
XCTAssert(y == 65, "y should be in center")
2727
}
2828
}

ManualLayoutTests/UIViewProxyTests.swift renamed to ManualLayoutTests/UIViewManualLayoutTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
//
2-
// UIViewProxyTests.swift
2+
// UIViewManualLayoutTests.swift
33
// ManualLayout
44
//
55
// Created by Baris Sencan on 23/02/15.
66
// Copyright (c) 2015 Baris Sencan. All rights reserved.
77
//
88

9-
import Foundation
9+
import UIKit
1010
import XCTest
1111
import ManualLayout
1212

13-
class UIViewProxyTests: XCTestCase {
13+
class UIViewManualLayoutTests: XCTestCase {
1414
let containerView = UIView(frame: CGRectZero)
1515
let view = UIView(frame: CGRectZero)
1616

0 commit comments

Comments
 (0)