diff --git a/Cartography.xcodeproj/project.pbxproj b/Cartography.xcodeproj/project.pbxproj index 367f849..78084dc 100644 --- a/Cartography.xcodeproj/project.pbxproj +++ b/Cartography.xcodeproj/project.pbxproj @@ -8,8 +8,8 @@ /* Begin PBXBuildFile section */ 54143E4E1A93991D00208182 /* Distribute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5467916E1A93962000DC9BF7 /* Distribute.swift */; }; - 54143E511A939D7000208182 /* DistributeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54143E4F1A939D6000208182 /* DistributeTests.swift */; }; - 54143E521A939D7100208182 /* DistributeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54143E4F1A939D6000208182 /* DistributeTests.swift */; }; + 54143E511A939D7000208182 /* DistributeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54143E4F1A939D6000208182 /* DistributeSpec.swift */; }; + 54143E521A939D7100208182 /* DistributeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 54143E4F1A939D6000208182 /* DistributeSpec.swift */; }; 543250CD1A8131F100BE7581 /* TypesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 543250CB1A8112D700BE7581 /* TypesTests.swift */; }; 543250CE1A8131F200BE7581 /* TypesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 543250CB1A8112D700BE7581 /* TypesTests.swift */; }; 5435B8BF1AD8612C00B805F1 /* Nimble.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5435B8B41AD8610300B805F1 /* Nimble.framework */; }; @@ -142,7 +142,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 54143E4F1A939D6000208182 /* DistributeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DistributeTests.swift; sourceTree = ""; }; + 54143E4F1A939D6000208182 /* DistributeSpec.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DistributeSpec.swift; sourceTree = ""; }; 543250CB1A8112D700BE7581 /* TypesTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypesTests.swift; sourceTree = ""; }; 5435B8B41AD8610300B805F1 /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Nimble.framework; sourceTree = ""; }; 5435B8B51AD8610300B805F1 /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = Quick.framework; sourceTree = ""; }; @@ -320,7 +320,7 @@ 54BF29B11A934ECF0066ED10 /* AlignSpec.swift */, 54A388981A7663AC003945B7 /* ConstraintGroupSpec.swift */, 54C96A23195063CD000CDD27 /* DimensionSpec.swift */, - 54143E4F1A939D6000208182 /* DistributeTests.swift */, + 54143E4F1A939D6000208182 /* DistributeSpec.swift */, 545F858E1953235F00791F75 /* EdgesTests.swift */, 546E9E921950A87600B16707 /* EdgeTests.swift */, 545F35831ACDFF6C00B57E98 /* MemoryLeakTests.swift */, @@ -552,7 +552,7 @@ 54DE2B9F1ABE2BC5004D62D8 /* TestView.swift in Sources */, 54FA3A441951A9730094B82A /* SizeTests.swift in Sources */, 54BF29B31A934F240066ED10 /* AlignSpec.swift in Sources */, - 54143E511A939D7000208182 /* DistributeTests.swift in Sources */, + 54143E511A939D7000208182 /* DistributeSpec.swift in Sources */, 54FA3A3E1951A3750094B82A /* PointTests.swift in Sources */, 545F858F1953235F00791F75 /* EdgesTests.swift in Sources */, 54FA3A381950FD8E0094B82A /* OperatorTests.swift in Sources */, @@ -601,7 +601,7 @@ 54DE2BA01ABE2BC5004D62D8 /* TestView.swift in Sources */, BBAC6D1C1A22A8F400E8A3E2 /* ViewHierarchyTests.swift in Sources */, 54BF29B41A934F250066ED10 /* AlignSpec.swift in Sources */, - 54143E521A939D7100208182 /* DistributeTests.swift in Sources */, + 54143E521A939D7100208182 /* DistributeSpec.swift in Sources */, 543250CE1A8131F200BE7581 /* TypesTests.swift in Sources */, BBAC6D1A1A22A8EE00E8A3E2 /* ViewUtils.swift in Sources */, 54F6A860195C213F00313D24 /* PointTests.swift in Sources */, diff --git a/CartographyTests/DistributeSpec.swift b/CartographyTests/DistributeSpec.swift new file mode 100644 index 0000000..274c1b5 --- /dev/null +++ b/CartographyTests/DistributeSpec.swift @@ -0,0 +1,79 @@ +import Cartography + +import Nimble +import Quick + +class DistributeSpec: QuickSpec { + override func spec() { + var superview: View! + var viewA: View! + var viewB: View! + var viewC: View! + + beforeEach { + superview = TestView(frame: CGRectMake(0, 0, 400, 400)) + + viewA = TestView(frame: CGRectZero) + superview.addSubview(viewA) + + viewB = TestView(frame: CGRectZero) + superview.addSubview(viewB) + + viewC = TestView(frame: CGRectZero) + superview.addSubview(viewC) + + constrain(viewA, viewB, viewC) { viewA, viewB, viewC in + viewA.width == 100 + viewA.height == 100 + + viewA.top == viewA.superview!.top + viewA.left == viewA.superview!.left + + viewA.size == viewB.size + viewA.size == viewC.size + } + } + + describe("from left to right") { + beforeEach { + layout(viewA, viewB, viewC) { viewA, viewB, viewC in + align(centerY: viewA, viewB, viewC) + distribute(by: 10, leftToRight: viewA, viewB, viewC) + } + } + + it("should distribute the views") { + expect(viewA.frame.minX).to(equal( 0)) + expect(viewB.frame.minX).to(equal(110)) + expect(viewC.frame.minX).to(equal(220)) + } + + it("should disable translating autoresizing masks into constraints") { + expect(viewA.car_translatesAutoresizingMaskIntoConstraints).to(beFalse()) + expect(viewB.car_translatesAutoresizingMaskIntoConstraints).to(beFalse()) + expect(viewC.car_translatesAutoresizingMaskIntoConstraints).to(beFalse()) + } + } + + describe("vertically") { + beforeEach { + layout(viewA, viewB, viewC) { viewA, viewB, viewC in + align(centerX: viewA, viewB, viewC) + distribute(by: 10, vertically: viewA, viewB, viewC) + } + } + + it("should distribute the views") { + expect(viewA.frame.minY).to(equal( 0)) + expect(viewB.frame.minY).to(equal(110)) + expect(viewC.frame.minY).to(equal(220)) + } + + it("should disable translating autoresizing masks into constraints") { + expect(viewA.car_translatesAutoresizingMaskIntoConstraints).to(beFalse()) + expect(viewB.car_translatesAutoresizingMaskIntoConstraints).to(beFalse()) + expect(viewC.car_translatesAutoresizingMaskIntoConstraints).to(beFalse()) + } + } + } +} diff --git a/CartographyTests/DistributeTests.swift b/CartographyTests/DistributeTests.swift deleted file mode 100644 index 742bf57..0000000 --- a/CartographyTests/DistributeTests.swift +++ /dev/null @@ -1,86 +0,0 @@ -// -// DistributeTests.swift -// Cartography -// -// Created by Robert Böhnke on 17/02/15. -// Copyright (c) 2015 Robert Böhnke. All rights reserved. -// - -import Cartography -import XCTest - -class DistributeTests: XCTestCase { - var superview: View! - var viewA: View! - var viewB: View! - var viewC: View! - - override func setUp() { - superview = TestView(frame: CGRectMake(0, 0, 400, 400)) - - viewA = TestView(frame: CGRectZero) - superview.addSubview(viewA) - - viewB = TestView(frame: CGRectZero) - superview.addSubview(viewB) - - viewC = TestView(frame: CGRectZero) - superview.addSubview(viewC) - - constrain(viewA, viewB, viewC) { viewA, viewB, viewC in - viewA.width == 100 - viewA.height == 100 - - viewA.top == viewA.superview!.top - viewA.left == viewA.superview!.left - - viewA.size == viewB.size - viewA.size == viewC.size - } - } - - func testDistributeHorizontally() { - layout(viewA, viewB, viewC) { viewA, viewB, viewC in - align(centerY: viewA, viewB, viewC) - distribute(by: 10, horizontally: viewA, viewB, viewC) - } - - XCTAssertEqual(viewA.frame, CGRect(x: 0, y: 0, width: 100, height: 100), "It should distribute the views") - XCTAssertEqual(viewB.frame, CGRect(x: 110, y: 0, width: 100, height: 100), "It should distribute the views") - XCTAssertEqual(viewC.frame, CGRect(x: 220, y: 0, width: 100, height: 100), "It should distribute the views") - - XCTAssertFalse(viewA.car_translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(viewB.car_translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(viewC.car_translatesAutoresizingMaskIntoConstraints) - } - - func testDistributeLeftToRight() { - layout(viewA, viewB, viewC) { viewA, viewB, viewC in - align(centerY: viewA, viewB, viewC) - distribute(by: 10, leftToRight: viewA, viewB, viewC) - } - - XCTAssertEqual(viewA.frame, CGRect(x: 0, y: 0, width: 100, height: 100), "It should distribute the views") - XCTAssertEqual(viewB.frame, CGRect(x: 110, y: 0, width: 100, height: 100), "It should distribute the views") - XCTAssertEqual(viewC.frame, CGRect(x: 220, y: 0, width: 100, height: 100), "It should distribute the views") - - XCTAssertFalse(viewA.car_translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(viewB.car_translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(viewC.car_translatesAutoresizingMaskIntoConstraints) - } - - func testDistributeVertically() { - layout(viewA, viewB, viewC) { viewA, viewB, viewC in - align(centerX: viewA, viewB, viewC) - distribute(by: 10, vertically: viewA, viewB, viewC) - } - - XCTAssertEqual(viewA.frame, CGRect(x: 0, y: 0, width: 100, height: 100), "It should distribute the views") - XCTAssertEqual(viewB.frame, CGRect(x: 0, y: 110, width: 100, height: 100), "It should distribute the views") - XCTAssertEqual(viewC.frame, CGRect(x: 0, y: 220, width: 100, height: 100), "It should distribute the views") - - XCTAssertFalse(viewA.car_translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(viewB.car_translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(viewC.car_translatesAutoresizingMaskIntoConstraints) - } -}