Skip to content

Commit 8f7a188

Browse files
committed
Changes following PR comments
1 parent 62fffcd commit 8f7a188

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

Sources/Impl/PinLayout+Coordinates.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ extension PinLayout {
328328
}
329329

330330
internal func validateWidth(_ width: CGFloat, context: Context) -> Bool {
331-
guard width.isNormal && width >= 0 else {
331+
guard width >= 0, width.isFinite else {
332332
warnWontBeApplied("the width (\(width)) must be greater than or equal to zero.", context)
333333
return false
334334
}
@@ -337,15 +337,15 @@ extension PinLayout {
337337
}
338338

339339
internal func validateComputedWidth(_ width: CGFloat?) -> Bool {
340-
if let width = width, !width.isNormal || width < 0 {
340+
if let width = width, !width.isFinite || width < 0 {
341341
return false
342342
} else {
343343
return true
344344
}
345345
}
346346

347347
internal func validateHeight(_ height: CGFloat, context: Context) -> Bool {
348-
guard height.isNormal && height >= 0 else {
348+
guard height >= 0, height.isFinite else {
349349
warnWontBeApplied("the height (\(height)) must be greater than or equal to zero.", context)
350350
return false
351351
}
@@ -354,7 +354,7 @@ extension PinLayout {
354354
}
355355

356356
internal func validateComputedHeight(_ height: CGFloat?) -> Bool {
357-
if let height = height, !height.isNormal || height < 0 {
357+
if let height = height, !height.isFinite || height < 0 {
358358
return false
359359
} else {
360360
return true

Tests/Common/AdjustSizeSpec.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ class AdjustSizeSpec: QuickSpec {
115115
expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 50.0, height: 60.0)))
116116
}
117117

118+
it("should accept a width of 0") {
119+
aView.pin.width(0)
120+
expect(Pin.lastWarningText).to(beNil())
121+
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 0.0, height: 60.0)))
122+
}
123+
118124
it("should warn about negative width value") {
119125
aView.pin.width(-2)
120126
expect(Pin.lastWarningText).to(contain(["width", "won't be applied", "the width", "must be greater than or equal to zero"]))
@@ -127,11 +133,23 @@ class AdjustSizeSpec: QuickSpec {
127133
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
128134
}
129135

136+
it("should warn about -NaN width value") {
137+
aView.pin.width(-CGFloat.nan)
138+
expect(Pin.lastWarningText).to(contain(["width", "nan", "won't be applied", "the width", "must be greater than or equal to zero"]))
139+
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
140+
}
141+
130142
it("should warn about infinity width value") {
131143
aView.pin.width(CGFloat.infinity)
132144
expect(Pin.lastWarningText).to(contain(["width", "inf", "won't be applied", "the width", "must be greater than or equal to zero"]))
133145
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
134146
}
147+
148+
it("should warn about -infinity width value") {
149+
aView.pin.width(-CGFloat.infinity)
150+
expect(Pin.lastWarningText).to(contain(["width", "inf", "won't be applied", "the width", "must be greater than or equal to zero"]))
151+
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
152+
}
135153
}
136154

137155
describe("the result of the height(...) methods") {
@@ -166,6 +184,12 @@ class AdjustSizeSpec: QuickSpec {
166184
expect(aView.frame).to(equal(CGRect(x: 140.0, y: 100.0, width: 100.0, height: 30.0)))
167185
}
168186

187+
it("should accept a height of 0") {
188+
aView.pin.height(0)
189+
expect(Pin.lastWarningText).to(beNil())
190+
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 0.0)))
191+
}
192+
169193
it("should warn about negative height value") {
170194
aView.pin.height(-2)
171195
expect(Pin.lastWarningText).to(contain(["height", "won't be applied", "the height", "must be greater than or equal to zero"]))
@@ -178,11 +202,23 @@ class AdjustSizeSpec: QuickSpec {
178202
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
179203
}
180204

205+
it("should warn about -NaN height value") {
206+
aView.pin.height(-CGFloat.nan)
207+
expect(Pin.lastWarningText).to(contain(["height", "nan", "won't be applied", "the height", "must be greater than or equal to zero"]))
208+
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
209+
}
210+
181211
it("should warn about infinity height value") {
182212
aView.pin.height(CGFloat.infinity)
183213
expect(Pin.lastWarningText).to(contain(["height", "inf", "won't be applied", "the height", "must be greater than or equal to zero"]))
184214
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
185215
}
216+
217+
it("should warn about -infinity height value") {
218+
aView.pin.height(-CGFloat.infinity)
219+
expect(Pin.lastWarningText).to(contain(["height", "inf", "won't be applied", "the height", "must be greater than or equal to zero"]))
220+
expect(aView.frame).to(equal(CGRect(x: 140, y: 100.0, width: 100.0, height: 60.0)))
221+
}
186222
}
187223

188224
describe("the result of the size(...) methods") {

0 commit comments

Comments
 (0)