Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Example/PinLayoutSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 46;
objectVersion = 48;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -516,7 +516,7 @@
};
};
buildConfigurationList = 249EFE3A1E64FAFE00165E39 /* Build configuration list for PBXProject "PinLayoutSample" */;
compatibilityVersion = "Xcode 3.2";
compatibilityVersion = "Xcode 8.0";
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
Expand Down
6 changes: 3 additions & 3 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PODS:
- Nimble (8.0.2)
- PinLayout (1.8.9)
- PinLayout (1.8.10)
- Quick (2.1.0)
- SwiftLint (0.35.0)

Expand All @@ -22,10 +22,10 @@ EXTERNAL SOURCES:

SPEC CHECKSUMS:
Nimble: 622629381bda1dd5678162f21f1368cec7cbba60
PinLayout: f7237c104696f409470947fee3ac82e239cac367
PinLayout: 641bc9679f73d3da35e04bb5180547cf55fd92d7
Quick: 4be43f6634acfa727dd106bdf3929ce125ffa79d
SwiftLint: 5553187048b900c91aa03552807681bb6b027846

PODFILE CHECKSUM: 9b1d14a0f41ae1e8ebc931fa3d033da6c545223e

COCOAPODS: 1.7.1
COCOAPODS: 1.7.5
16 changes: 8 additions & 8 deletions Sources/Impl/PinLayout+Coordinates.swift
Original file line number Diff line number Diff line change
Expand Up @@ -328,33 +328,33 @@ extension PinLayout {
}

internal func validateWidth(_ width: CGFloat, context: Context) -> Bool {
if width < 0 {
guard width >= 0, width.isFinite else {
warnWontBeApplied("the width (\(width)) must be greater than or equal to zero.", context)
return false
} else {
return true
}

return true
}

internal func validateComputedWidth(_ width: CGFloat?) -> Bool {
if let width = width, width < 0 {
if let width = width, !width.isFinite || width < 0 {
return false
} else {
return true
}
}

internal func validateHeight(_ height: CGFloat, context: Context) -> Bool {
if height < 0 {
guard height >= 0, height.isFinite else {
warnWontBeApplied("the height (\(height)) must be greater than or equal to zero.", context)
return false
} else {
return true
}

return true
}

internal func validateComputedHeight(_ height: CGFloat?) -> Bool {
if let height = height, height < 0 {
if let height = height, !height.isFinite || height < 0 {
return false
} else {
return true
Expand Down
72 changes: 72 additions & 0 deletions Tests/Common/AdjustSizeSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,42 @@ class AdjustSizeSpec: QuickSpec {
aView.pin.width(of: aViewChild)
expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 60.0)))
}

it("should accept a width of 0") {
aView.pin.width(0)
expect(Pin.lastWarningText).to(beNil())
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 0.0, height: 60.0)))
}

it("should warn about negative width value") {
aView.pin.width(-2)
expect(Pin.lastWarningText).to(contain(["width", "won't be applied", "the width", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about NaN width value") {
aView.pin.width(CGFloat.nan)
expect(Pin.lastWarningText).to(contain(["width", "nan", "won't be applied", "the width", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about -NaN width value") {
aView.pin.width(-CGFloat.nan)
expect(Pin.lastWarningText).to(contain(["width", "nan", "won't be applied", "the width", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about infinity width value") {
aView.pin.width(CGFloat.infinity)
expect(Pin.lastWarningText).to(contain(["width", "inf", "won't be applied", "the width", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about -infinity width value") {
aView.pin.width(-CGFloat.infinity)
expect(Pin.lastWarningText).to(contain(["width", "inf", "won't be applied", "the width", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}
}

describe("the result of the height(...) methods") {
Expand Down Expand Up @@ -147,6 +183,42 @@ class AdjustSizeSpec: QuickSpec {
aView.pin.height(of: aViewChild)
expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 30.0)))
}

it("should accept a height of 0") {
aView.pin.height(0)
expect(Pin.lastWarningText).to(beNil())
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 0.0)))
}

it("should warn about negative height value") {
aView.pin.height(-2)
expect(Pin.lastWarningText).to(contain(["height", "won't be applied", "the height", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about NaN height value") {
aView.pin.height(CGFloat.nan)
expect(Pin.lastWarningText).to(contain(["height", "nan", "won't be applied", "the height", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about -NaN height value") {
aView.pin.height(-CGFloat.nan)
expect(Pin.lastWarningText).to(contain(["height", "nan", "won't be applied", "the height", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about infinity height value") {
aView.pin.height(CGFloat.infinity)
expect(Pin.lastWarningText).to(contain(["height", "inf", "won't be applied", "the height", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}

it("should warn about -infinity height value") {
aView.pin.height(-CGFloat.infinity)
expect(Pin.lastWarningText).to(contain(["height", "inf", "won't be applied", "the height", "must be greater than or equal to zero"]))
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
}
}

describe("the result of the size(...) methods") {
Expand Down