From 090ffddd48f2f64f5c17a74f0cc61fe9387d71a5 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Tue, 5 Mar 2024 21:45:04 -1000 Subject: [PATCH 01/27] Bumps to Swift 5.9 --- Package.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index 3c751a8..c46de15 100644 --- a/Package.swift +++ b/Package.swift @@ -1,10 +1,13 @@ -// swift-tools-version:5.3 +// swift-tools-version:5.9 import PackageDescription let package = Package( name: "Stevia", - platforms: [.iOS(.v9), .tvOS(.v10)], + platforms: [ + .iOS(.v12), + .tvOS(.v12) + ], products: [.library(name: "Stevia", targets: ["Stevia"])], targets: [ .target(name: "Stevia", path: "Sources", resources: [.copy("PrivacyInfo.xcprivacy")]), From 05234054a0c6435412243b6b8b969256126799fb Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Fri, 20 Sep 2024 07:50:00 -1000 Subject: [PATCH 02/27] WIP: Migrates main project to Swift 6 --- Package.swift | 2 +- Sources/Stevia/Stevia+Alignment.swift | 68 +++++++++++----------- Sources/Stevia/Stevia+Baselines.swift | 8 +-- Sources/Stevia/Stevia+Constraints.swift | 2 +- Sources/Stevia/Stevia+DoubleDash.swift | 40 ++++++------- Sources/Stevia/Stevia+Equation.swift | 28 ++++----- Sources/Stevia/Stevia+FlexibleMargin.swift | 8 +-- Sources/Stevia/Stevia+GetConstraint.swift | 2 +- Sources/Stevia/Stevia+LayoutAnchors.swift | 4 +- Sources/Stevia/Stevia+Notifications.swift | 2 +- Sources/Stevia/Stevia+Operators.swift | 38 ++++++------ Sources/Stevia/Stevia+Size.swift | 26 ++++----- 12 files changed, 114 insertions(+), 114 deletions(-) diff --git a/Package.swift b/Package.swift index c46de15..6e87d56 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.9 +// swift-tools-version:6.0 import PackageDescription diff --git a/Sources/Stevia/Stevia+Alignment.swift b/Sources/Stevia/Stevia+Alignment.swift index 0a8c226..d20d92d 100644 --- a/Sources/Stevia/Stevia+Alignment.swift +++ b/Sources/Stevia/Stevia+Alignment.swift @@ -25,13 +25,13 @@ import UIKit */ @discardableResult -public func align(horizontally views: UIView...) -> [UIView] { +@MainActor public func align(horizontally views: UIView...) -> [UIView] { return align(horizontally: views) } @available(*, deprecated, renamed: "align(horizontally:)") @discardableResult -public func alignHorizontally(_ views: UIView...) -> [UIView] { +@MainActor public func alignHorizontally(_ views: UIView...) -> [UIView] { return align(horizontally: views) } @@ -51,14 +51,14 @@ public func alignHorizontally(_ views: UIView...) -> [UIView] { */ @discardableResult -public func align(horizontally views: [UIView]) -> [UIView] { +@MainActor public func align(horizontally views: [UIView]) -> [UIView] { align(.horizontal, views: views) return views } @available(*, deprecated, renamed: "align(horizontally:)") @discardableResult -public func alignHorizontally(_ views: [UIView]) -> [UIView] { +@MainActor public func alignHorizontally(_ views: [UIView]) -> [UIView] { align(.horizontal, views: views) return views } @@ -73,12 +73,12 @@ public func alignHorizontally(_ views: [UIView]) -> [UIView] { - Returns: The array of views, enabling chaining, */ -public func align(vertically views: UIView...) { +@MainActor public func align(vertically views: UIView...) { align(vertically: views) } @available(*, deprecated, renamed: "align(vertically:)") -public func alignVertically(_ views: UIView...) { +@MainActor public func alignVertically(_ views: UIView...) { align(vertically: views) } @@ -92,12 +92,12 @@ public func alignVertically(_ views: UIView...) { - Returns: The array of views, enabling chaining, */ -public func align(vertically views: [UIView]) { +@MainActor public func align(vertically views: [UIView]) { align(.vertical, views: views) } @available(*, deprecated, renamed: "align(vertically:)") -public func alignVertically(_ views: [UIView]) { +@MainActor public func alignVertically(_ views: [UIView]) { align(.vertical, views: views) } @@ -108,7 +108,7 @@ public func alignVertically(_ views: [UIView]) { alignCenter(button, with:image) ``` */ -public func alignCenter(_ v1: UIView, with v2: UIView) { +@MainActor public func alignCenter(_ v1: UIView, with v2: UIView) { alignHorizontally(v1, with: v2) alignVertically(v1, with: v2) } @@ -121,7 +121,7 @@ public func alignCenter(_ v1: UIView, with v2: UIView) { ``` */ -public func alignHorizontally(_ v1: UIView, with v2: UIView, offset: Double = 0) { +@MainActor public func alignHorizontally(_ v1: UIView, with v2: UIView, offset: Double = 0) { align(.horizontal, v1: v1, with: v2, offset: offset) } @@ -133,11 +133,11 @@ public func alignHorizontally(_ v1: UIView, with v2: UIView, offset: Double = 0) ``` */ -public func alignVertically(_ v1: UIView, with v2: UIView, offset: Double = 0) { +@MainActor public func alignVertically(_ v1: UIView, with v2: UIView, offset: Double = 0) { align(.vertical, v1: v1, with: v2, offset: offset) } -private func align(_ axis: NSLayoutConstraint.Axis, views: [UIView]) { +@MainActor private func align(_ axis: NSLayoutConstraint.Axis, views: [UIView]) { for (i, v) in views.enumerated() where views.count > i+1 { let v2 = views[i+1] if axis == .horizontal { @@ -148,7 +148,7 @@ private func align(_ axis: NSLayoutConstraint.Axis, views: [UIView]) { } } -func align(_ axis: NSLayoutConstraint.Axis, v1: UIView, with v2: UIView, offset: Double) { +@MainActor func align(_ axis: NSLayoutConstraint.Axis, v1: UIView, with v2: UIView, offset: Double) { if let spv = v1.superview { let center: NSLayoutConstraint.Attribute = axis == .horizontal ? .centerY : .centerX let c = constraint(item: v1, attribute: center, toItem: v2, constant: offset) @@ -174,13 +174,13 @@ func align(_ axis: NSLayoutConstraint.Axis, v1: UIView, with v2: UIView, offset: */ @discardableResult -public func align(tops views: UIView...) -> [UIView] { +@MainActor public func align(tops views: UIView...) -> [UIView] { return align(tops: views) } @available(*, deprecated, renamed: "align(tops:)") @discardableResult -public func alignTops(_ views: UIView...) -> [UIView] { +@MainActor public func alignTops(_ views: UIView...) -> [UIView] { return align(tops: views) } @@ -200,14 +200,14 @@ public func alignTops(_ views: UIView...) -> [UIView] { */ @discardableResult -public func align(tops views: [UIView]) -> [UIView] { +@MainActor public func align(tops views: [UIView]) -> [UIView] { align(.top, views: views) return views } @available(*, deprecated, renamed: "align(tops:)") @discardableResult -public func alignTops(_ views: [UIView]) -> [UIView] { +@MainActor public func alignTops(_ views: [UIView]) -> [UIView] { align(.top, views: views) return views } @@ -228,13 +228,13 @@ public func alignTops(_ views: [UIView]) -> [UIView] { */ @discardableResult -public func align(bottoms views: UIView...) -> [UIView] { +@MainActor public func align(bottoms views: UIView...) -> [UIView] { return align(bottoms: views) } @available(*, deprecated, renamed: "align(bottoms:)") @discardableResult -public func alignBottoms(_ views: UIView...) -> [UIView] { +@MainActor public func alignBottoms(_ views: UIView...) -> [UIView] { return align(bottoms: views) } @@ -254,14 +254,14 @@ public func alignBottoms(_ views: UIView...) -> [UIView] { */ @discardableResult -public func align(bottoms views: [UIView]) -> [UIView] { +@MainActor public func align(bottoms views: [UIView]) -> [UIView] { align(.bottom, views: views) return views } @available(*, deprecated, renamed: "align(bottoms:)") @discardableResult -public func alignBottoms(_ views: [UIView]) -> [UIView] { +@MainActor public func alignBottoms(_ views: [UIView]) -> [UIView] { align(.bottom, views: views) return views } @@ -277,13 +277,13 @@ public func alignBottoms(_ views: [UIView]) -> [UIView] { */ @discardableResult -public func align(lefts views: UIView...) -> [UIView] { +@MainActor public func align(lefts views: UIView...) -> [UIView] { return align(lefts: views) } @available(*, deprecated, renamed: "align(lefts:)") @discardableResult -public func alignLefts(_ views: UIView...) -> [UIView] { +@MainActor public func alignLefts(_ views: UIView...) -> [UIView] { return align(lefts: views) } @@ -298,14 +298,14 @@ public func alignLefts(_ views: UIView...) -> [UIView] { */ @discardableResult -public func align(lefts views: [UIView]) -> [UIView] { +@MainActor public func align(lefts views: [UIView]) -> [UIView] { align(.left, views: views) return views } @available(*, deprecated, renamed: "align(lefts:)") @discardableResult -public func alignLefts(_ views: [UIView]) -> [UIView] { +@MainActor public func alignLefts(_ views: [UIView]) -> [UIView] { align(.left, views: views) return views } @@ -321,13 +321,13 @@ public func alignLefts(_ views: [UIView]) -> [UIView] { */ @discardableResult -public func align(rights views: UIView...) -> [UIView] { +@MainActor public func align(rights views: UIView...) -> [UIView] { return align(rights: views) } @available(*, deprecated, renamed: "align(rights:)") @discardableResult -public func alignRights(_ views: UIView...) -> [UIView] { +@MainActor public func alignRights(_ views: UIView...) -> [UIView] { return align(rights: views) } @@ -342,14 +342,14 @@ public func alignRights(_ views: UIView...) -> [UIView] { */ @discardableResult -public func align(rights views: [UIView]) -> [UIView] { +@MainActor public func align(rights views: [UIView]) -> [UIView] { align(.right, views: views) return views } @available(*, deprecated, renamed: "align(rights:)") @discardableResult -public func alignRights(_ views: [UIView]) -> [UIView] { +@MainActor public func alignRights(_ views: [UIView]) -> [UIView] { align(.right, views: views) return views } @@ -365,7 +365,7 @@ align(leadings: [label,field,button]) */ @discardableResult -public func align(leadings views: [UIView]) -> [UIView] { +@MainActor public func align(leadings views: [UIView]) -> [UIView] { align(.leading, views: views) return views } @@ -381,7 +381,7 @@ align(leadings: label,field,button) */ @discardableResult -public func align(leadings views: UIView...) -> [UIView] { +@MainActor public func align(leadings views: UIView...) -> [UIView] { align(.leading, views: views) return views } @@ -397,7 +397,7 @@ align(trailing: [label,field,button]) */ @discardableResult -public func align(trailings views: [UIView]) -> [UIView] { +@MainActor public func align(trailings views: [UIView]) -> [UIView] { align(.trailing, views: views) return views } @@ -413,13 +413,13 @@ align(trailing: label,field,button) */ @discardableResult -public func align(trailings views: UIView...) -> [UIView] { +@MainActor public func align(trailings views: UIView...) -> [UIView] { align(.trailing, views: views) return views } @discardableResult -public func align(_ attribute: NSLayoutConstraint.Attribute, views: [UIView]) -> [UIView] { +@MainActor public func align(_ attribute: NSLayoutConstraint.Attribute, views: [UIView]) -> [UIView] { for (i, v) in views.enumerated() where views.count > i+1 { let v2 = views[i+1] if let spv = v.superview { diff --git a/Sources/Stevia/Stevia+Baselines.swift b/Sources/Stevia/Stevia+Baselines.swift index 419dfcd..4e956bd 100644 --- a/Sources/Stevia/Stevia+Baselines.swift +++ b/Sources/Stevia/Stevia+Baselines.swift @@ -25,12 +25,12 @@ import UIKit */ @discardableResult -public func align(lastBaselines views: UIView...) -> [UIView] { +@MainActor public func align(lastBaselines views: UIView...) -> [UIView] { return align(lastBaselines: views) } @discardableResult -public func align(lastBaselines views: [UIView]) -> [UIView] { +@MainActor public func align(lastBaselines views: [UIView]) -> [UIView] { for (i, v) in views.enumerated() where views.count > i+1 { let v2 = views[i+1] if #available(iOS 9.0, *) { @@ -59,12 +59,12 @@ public func align(lastBaselines views: [UIView]) -> [UIView] { */ @discardableResult -public func align(firstBaselines views: UIView...) -> [UIView] { +@MainActor public func align(firstBaselines views: UIView...) -> [UIView] { return align(firstBaselines: views) } @discardableResult -public func align(firstBaselines views: [UIView]) -> [UIView] { +@MainActor public func align(firstBaselines views: [UIView]) -> [UIView] { for (i, v) in views.enumerated() where views.count > i+1 { let v2 = views[i+1] if #available(iOS 9.0, *) { diff --git a/Sources/Stevia/Stevia+Constraints.swift b/Sources/Stevia/Stevia+Constraints.swift index 3559911..eac541d 100644 --- a/Sources/Stevia/Stevia+Constraints.swift +++ b/Sources/Stevia/Stevia+Constraints.swift @@ -69,7 +69,7 @@ public extension UIView { - Returns: The NSLayoutConstraint created. */ -func constraint(item view1: AnyObject, +@MainActor func constraint(item view1: AnyObject, attribute attr1: NSLayoutConstraint.Attribute, relatedBy: NSLayoutConstraint.Relation = .equal, toItem view2: AnyObject? = nil, diff --git a/Sources/Stevia/Stevia+DoubleDash.swift b/Sources/Stevia/Stevia+DoubleDash.swift index b323907..c84032e 100644 --- a/Sources/Stevia/Stevia+DoubleDash.swift +++ b/Sources/Stevia/Stevia+DoubleDash.swift @@ -26,27 +26,27 @@ public func -- (left: UIView, right: Int) -> PartialConstraint { } @discardableResult -public func -- (left: SideConstraint, right: UIView) -> UIView { +@MainActor public func -- (left: SideConstraint, right: UIView) -> UIView { return left-right } @discardableResult -public func -- (left: [UIView], right: SideConstraint) -> [UIView] { +@MainActor public func -- (left: [UIView], right: SideConstraint) -> [UIView] { return left-right } @discardableResult -public func -- (left: UIView, right: SideConstraint) -> UIView { +@MainActor public func -- (left: UIView, right: SideConstraint) -> UIView { return left-right } @discardableResult -public func -- (left: PartialConstraint, right: UIView) -> [UIView] { +@MainActor public func -- (left: PartialConstraint, right: UIView) -> [UIView] { return left-right } @discardableResult -public func -- (left: UIView, right: UIView) -> [UIView] { +@MainActor public func -- (left: UIView, right: UIView) -> [UIView] { return left-right } @@ -66,7 +66,7 @@ public func -- (left: [UIView], right: Int) -> PartialConstraint { } @discardableResult -public func -- (left: [UIView], right: UIView) -> [UIView] { +@MainActor public func -- (left: [UIView], right: UIView) -> [UIView] { return left-right } @@ -98,22 +98,22 @@ public func -- (left: [UIView], } @discardableResult -public func -- (left: PartialFlexibleConstraint, right: UIView) -> [UIView] { +@MainActor public func -- (left: PartialFlexibleConstraint, right: UIView) -> [UIView] { return left-right } @discardableResult -public func -- (left: SteviaLeftFlexibleMargin, right: UIView) -> UIView { +@MainActor public func -- (left: SteviaLeftFlexibleMargin, right: UIView) -> UIView { return left-right } @discardableResult -public func -- (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { +@MainActor public func -- (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { return left-right } @discardableResult -public func -- (left: [UIView], right: SteviaRightFlexibleMargin) -> [UIView] { +@MainActor public func -- (left: [UIView], right: SteviaRightFlexibleMargin) -> [UIView] { return left-right } #endif @@ -141,27 +141,27 @@ public func ⁃ (left: UIView, right: Int) -> PartialConstraint { } @discardableResult -public func ⁃ (left: SideConstraint, right: UIView) -> UIView { +@MainActor public func ⁃ (left: SideConstraint, right: UIView) -> UIView { return left-right } @discardableResult -public func ⁃ (left: [UIView], right: SideConstraint) -> [UIView] { +@MainActor public func ⁃ (left: [UIView], right: SideConstraint) -> [UIView] { return left-right } @discardableResult -public func ⁃ (left: UIView, right: SideConstraint) -> UIView { +@MainActor public func ⁃ (left: UIView, right: SideConstraint) -> UIView { return left-right } @discardableResult -public func ⁃ (left: PartialConstraint, right: UIView) -> [UIView] { +@MainActor public func ⁃ (left: PartialConstraint, right: UIView) -> [UIView] { return left-right } @discardableResult -public func ⁃ (left: UIView, right: UIView) -> [UIView] { +@MainActor public func ⁃ (left: UIView, right: UIView) -> [UIView] { return left-right } @@ -181,7 +181,7 @@ public func ⁃ (left: [UIView], right: Int) -> PartialConstraint { } @discardableResult -public func ⁃ (left: [UIView], right: UIView) -> [UIView] { +@MainActor public func ⁃ (left: [UIView], right: UIView) -> [UIView] { return left-right } @@ -213,22 +213,22 @@ public func ⁃ (left: [UIView], } @discardableResult -public func ⁃ (left: PartialFlexibleConstraint, right: UIView) -> [UIView] { +@MainActor public func ⁃ (left: PartialFlexibleConstraint, right: UIView) -> [UIView] { return left-right } @discardableResult -public func ⁃ (left: SteviaLeftFlexibleMargin, right: UIView) -> UIView { +@MainActor public func ⁃ (left: SteviaLeftFlexibleMargin, right: UIView) -> UIView { return left-right } @discardableResult -public func ⁃ (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { +@MainActor public func ⁃ (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { return left-right } @discardableResult -public func ⁃ (left: [UIView], right: SteviaRightFlexibleMargin) -> [UIView] { +@MainActor public func ⁃ (left: [UIView], right: SteviaRightFlexibleMargin) -> [UIView] { return left-right } #endif diff --git a/Sources/Stevia/Stevia+Equation.swift b/Sources/Stevia/Stevia+Equation.swift index 9a35b15..6083f84 100644 --- a/Sources/Stevia/Stevia+Equation.swift +++ b/Sources/Stevia/Stevia+Equation.swift @@ -84,7 +84,7 @@ public extension UIView { // MARK: - Equations of type v.P == v'.P' + X @discardableResult -public func == (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstraint { +@MainActor public func == (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstraint { let constant = right.constant ?? left.constant ?? 0 let multiplier = right.multiplier ?? left.multiplier ?? 1 @@ -138,7 +138,7 @@ public func == (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstr return NSLayoutConstraint() } -func commonParent(with viewA: UIView, and viewB: UIView) -> UIView? { +@MainActor func commonParent(with viewA: UIView, and viewB: UIView) -> UIView? { // Both views should have a superview guard viewA.superview != nil && viewB.superview != nil else { @@ -158,16 +158,16 @@ func commonParent(with viewA: UIView, and viewB: UIView) -> UIView? { } @discardableResult -public func >= (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstraint { +@MainActor public func >= (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstraint { return applyRelation(left: left, right: right, relateBy: .greaterThanOrEqual) } @discardableResult -public func <= (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstraint { +@MainActor public func <= (left: SteviaAttribute, right: SteviaAttribute) -> NSLayoutConstraint { return applyRelation(left: left, right: right, relateBy: .lessThanOrEqual) } -private func applyRelation(left: SteviaAttribute, right: SteviaAttribute, relateBy: NSLayoutConstraint.Relation) -> NSLayoutConstraint { +@MainActor private func applyRelation(left: SteviaAttribute, right: SteviaAttribute, relateBy: NSLayoutConstraint.Relation) -> NSLayoutConstraint { let constant = right.constant ?? 0 let multiplier = right.multiplier ?? 1 if let spv = left.view.superview { @@ -262,7 +262,7 @@ public func % (left: Int, right: SteviaAttribute) -> SteviaAttribute { // MARK: - Equations of type v.P == X @discardableResult -public func == (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { +@MainActor public func == (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { if let spv = left.view.superview { var toItem: UIView? = spv var constant = right @@ -281,17 +281,17 @@ public func == (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { } @discardableResult -public func == (left: SteviaAttribute, right: CGFloat) -> NSLayoutConstraint { +@MainActor public func == (left: SteviaAttribute, right: CGFloat) -> NSLayoutConstraint { left == Double(right) } @discardableResult -public func == (left: SteviaAttribute, right: Int) -> NSLayoutConstraint { +@MainActor public func == (left: SteviaAttribute, right: Int) -> NSLayoutConstraint { left == Double(right) } @discardableResult -public func >= (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { +@MainActor public func >= (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { if let spv = left.view.superview { var toItem: UIView? = spv var constant = right @@ -311,17 +311,17 @@ public func >= (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { } @discardableResult -public func >= (left: SteviaAttribute, right: CGFloat) -> NSLayoutConstraint { +@MainActor public func >= (left: SteviaAttribute, right: CGFloat) -> NSLayoutConstraint { left >= Double(right) } @discardableResult -public func >= (left: SteviaAttribute, right: Int) -> NSLayoutConstraint { +@MainActor public func >= (left: SteviaAttribute, right: Int) -> NSLayoutConstraint { left >= Double(right) } @discardableResult -public func <= (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { +@MainActor public func <= (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { if let spv = left.view.superview { var toItem: UIView? = spv var constant = right @@ -341,12 +341,12 @@ public func <= (left: SteviaAttribute, right: Double) -> NSLayoutConstraint { } @discardableResult -public func <= (left: SteviaAttribute, right: CGFloat) -> NSLayoutConstraint { +@MainActor public func <= (left: SteviaAttribute, right: CGFloat) -> NSLayoutConstraint { left <= Double(right) } @discardableResult -public func <= (left: SteviaAttribute, right: Int) -> NSLayoutConstraint { +@MainActor public func <= (left: SteviaAttribute, right: Int) -> NSLayoutConstraint { left <= Double(right) } #endif diff --git a/Sources/Stevia/Stevia+FlexibleMargin.swift b/Sources/Stevia/Stevia+FlexibleMargin.swift index bfc3215..7116fc3 100644 --- a/Sources/Stevia/Stevia+FlexibleMargin.swift +++ b/Sources/Stevia/Stevia+FlexibleMargin.swift @@ -65,7 +65,7 @@ public func - (left: [UIView], } @discardableResult -public func - (left: PartialFlexibleConstraint, right: UIView) -> [UIView] { +@MainActor public func - (left: PartialFlexibleConstraint, right: UIView) -> [UIView] { if let views = left.views { if let spv = right.superview { let c = constraint(item: right, attribute: .leading, @@ -99,7 +99,7 @@ public prefix func |- (fm: SteviaFlexibleMargin) -> SteviaLeftFlexibleMargin { } @discardableResult -public func - (left: SteviaLeftFlexibleMargin, right: UIView) -> UIView { +@MainActor public func - (left: SteviaLeftFlexibleMargin, right: UIView) -> UIView { if let spv = right.superview { let c = constraint(item: right, attribute: .leading, relatedBy: left.fm.relation, toItem: spv, @@ -122,7 +122,7 @@ public postfix func -| (fm: SteviaFlexibleMargin) -> SteviaRightFlexibleMargin { } @discardableResult -public func - (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { +@MainActor public func - (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { if let spv = left.superview { let c = constraint(item: spv, attribute: .trailing, relatedBy: right.fm.relation, toItem: left, @@ -134,7 +134,7 @@ public func - (left: UIView, right: SteviaRightFlexibleMargin) -> UIView { } @discardableResult -public func - (left: [UIView], right: SteviaRightFlexibleMargin) -> [UIView] { +@MainActor public func - (left: [UIView], right: SteviaRightFlexibleMargin) -> [UIView] { if let spv = left.last!.superview { let c = constraint(item: spv, attribute: .trailing, relatedBy: right.fm.relation, diff --git a/Sources/Stevia/Stevia+GetConstraint.swift b/Sources/Stevia/Stevia+GetConstraint.swift index 4cf6a69..52556ab 100644 --- a/Sources/Stevia/Stevia+GetConstraint.swift +++ b/Sources/Stevia/Stevia+GetConstraint.swift @@ -171,7 +171,7 @@ public extension UIView { } } -func constraintForView(_ v: UIView, attribute: NSLayoutConstraint.Attribute) -> NSLayoutConstraint? { +@MainActor func constraintForView(_ v: UIView, attribute: NSLayoutConstraint.Attribute) -> NSLayoutConstraint? { func lookForConstraint(in view: UIView?) -> NSLayoutConstraint? { guard let constraints = view?.constraints else { diff --git a/Sources/Stevia/Stevia+LayoutAnchors.swift b/Sources/Stevia/Stevia+LayoutAnchors.swift index 2bf5d70..4990d9a 100644 --- a/Sources/Stevia/Stevia+LayoutAnchors.swift +++ b/Sources/Stevia/Stevia+LayoutAnchors.swift @@ -69,7 +69,7 @@ public extension UILayoutGuide { @available(iOS 9.0, *) @discardableResult -public func == (left: SteviaAttribute, right: SteviaLayoutYAxisAnchor) -> NSLayoutConstraint { +@MainActor public func == (left: SteviaAttribute, right: SteviaLayoutYAxisAnchor) -> NSLayoutConstraint { var constraint = NSLayoutConstraint() @@ -91,7 +91,7 @@ public func == (left: SteviaAttribute, right: SteviaLayoutYAxisAnchor) -> NSLayo @available(iOS 9.0, *) @discardableResult -public func == (left: SteviaAttribute, right: SteviaLayoutXAxisAnchor) -> NSLayoutConstraint { +@MainActor public func == (left: SteviaAttribute, right: SteviaLayoutXAxisAnchor) -> NSLayoutConstraint { var constraint = NSLayoutConstraint() diff --git a/Sources/Stevia/Stevia+Notifications.swift b/Sources/Stevia/Stevia+Notifications.swift index 1bc88fd..ff1e2c3 100644 --- a/Sources/Stevia/Stevia+Notifications.swift +++ b/Sources/Stevia/Stevia+Notifications.swift @@ -11,7 +11,7 @@ import UIKit public extension NSObject { - func on(_ event: String, _ callback:@escaping () -> Void) { + func on(_ event: String, _ callback:@escaping @Sendable() -> Void) { _ = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: event), object: nil, queue: nil) { _ in diff --git a/Sources/Stevia/Stevia+Operators.swift b/Sources/Stevia/Stevia+Operators.swift index 3ecc5e7..e4a11c1 100644 --- a/Sources/Stevia/Stevia+Operators.swift +++ b/Sources/Stevia/Stevia+Operators.swift @@ -11,13 +11,13 @@ import UIKit prefix operator | @discardableResult -public prefix func | (p: UIView) -> UIView { +@MainActor public prefix func | (p: UIView) -> UIView { p.leading(0) } postfix operator | @discardableResult -public postfix func | (p: UIView) -> UIView { +@MainActor public postfix func | (p: UIView) -> UIView { p.trailing(0) } @@ -28,48 +28,48 @@ precedencegroup HeightPrecedence { } @discardableResult -public func ~ (left: UIView, right: Double) -> UIView { +@MainActor public func ~ (left: UIView, right: Double) -> UIView { left.height(right) } @discardableResult -public func ~ (left: UIView, right: CGFloat) -> UIView { +@MainActor public func ~ (left: UIView, right: CGFloat) -> UIView { left ~ Double(right) } @discardableResult -public func ~ (left: UIView, right: Int) -> UIView { +@MainActor public func ~ (left: UIView, right: Int) -> UIView { left ~ Double(right) } @discardableResult -public func ~ (left: UIView, right: SteviaPercentage) -> UIView { +@MainActor public func ~ (left: UIView, right: SteviaPercentage) -> UIView { left.height(right) } @discardableResult -public func ~ (left: UIView, right: SteviaFlexibleMargin) -> UIView { +@MainActor public func ~ (left: UIView, right: SteviaFlexibleMargin) -> UIView { left.height(right) } @discardableResult -public func ~ (left: [UIView], right: Double) -> [UIView] { +@MainActor public func ~ (left: [UIView], right: Double) -> [UIView] { for l in left { l.height(right) } return left } @discardableResult -public func ~ (left: [UIView], right: CGFloat) -> [UIView] { +@MainActor public func ~ (left: [UIView], right: CGFloat) -> [UIView] { left ~ Double(right) } @discardableResult -public func ~ (left: [UIView], right: Int) -> [UIView] { +@MainActor public func ~ (left: [UIView], right: Int) -> [UIView] { left ~ Double(right) } @discardableResult -public func ~ (left: [UIView], right: SteviaFlexibleMargin) -> [UIView] { +@MainActor public func ~ (left: [UIView], right: SteviaFlexibleMargin) -> [UIView] { for l in left { l.height(right) } return left } @@ -93,7 +93,7 @@ public prefix func |- (p: Int) -> SideConstraint { } @discardableResult -public prefix func |- (v: UIView) -> UIView { +@MainActor public prefix func |- (v: UIView) -> UIView { v.leading(8) } @@ -116,7 +116,7 @@ public postfix func -| (p: Int) -> SideConstraint { } @discardableResult -public postfix func -| (v: UIView) -> UIView { +@MainActor public postfix func -| (v: UIView) -> UIView { v.trailing(8) } @@ -151,7 +151,7 @@ public func - (left: UIView, right: Int) -> PartialConstraint { // Side Constraints @discardableResult -public func - (left: SideConstraint, right: UIView) -> UIView { +@MainActor public func - (left: SideConstraint, right: UIView) -> UIView { if let spv = right.superview { let c = constraint(item: right, attribute: .leading, toItem: spv, attribute: .leading, @@ -162,7 +162,7 @@ public func - (left: SideConstraint, right: UIView) -> UIView { } @discardableResult -public func - (left: [UIView], right: SideConstraint) -> [UIView] { +@MainActor public func - (left: [UIView], right: SideConstraint) -> [UIView] { let lastView = left[left.count-1] if let spv = lastView.superview { let c = constraint(item: lastView, attribute: .trailing, @@ -174,7 +174,7 @@ public func - (left: [UIView], right: SideConstraint) -> [UIView] { } @discardableResult -public func - (left: UIView, right: SideConstraint) -> UIView { +@MainActor public func - (left: UIView, right: SideConstraint) -> UIView { if let spv = left.superview { let c = constraint(item: left, attribute: .trailing, toItem: spv, attribute: .trailing, @@ -185,7 +185,7 @@ public func - (left: UIView, right: SideConstraint) -> UIView { } @discardableResult -public func - (left: PartialConstraint, right: UIView) -> [UIView] { +@MainActor public func - (left: PartialConstraint, right: UIView) -> [UIView] { if let views = left.views { if let spv = right.superview { let lastView = views[views.count-1] @@ -209,7 +209,7 @@ public func - (left: PartialConstraint, right: UIView) -> [UIView] { } @discardableResult -public func - (left: UIView, right: UIView) -> [UIView] { +@MainActor public func - (left: UIView, right: UIView) -> [UIView] { if let spv = left.superview { let c = constraint(item: right, attribute: .leading, toItem: left, attribute: .trailing, @@ -239,7 +239,7 @@ public func - (left: [UIView], right: Int) -> PartialConstraint { @discardableResult -public func - (left: [UIView], right: UIView) -> [UIView] { +@MainActor public func - (left: [UIView], right: UIView) -> [UIView] { let lastView = left[left.count-1] if let spv = lastView.superview { let c = constraint(item: lastView, attribute: .trailing, diff --git a/Sources/Stevia/Stevia+Size.swift b/Sources/Stevia/Stevia+Size.swift index 24fd2d5..9746acb 100644 --- a/Sources/Stevia/Stevia+Size.swift +++ b/Sources/Stevia/Stevia+Size.swift @@ -268,13 +268,13 @@ public extension UIView { */ @discardableResult -public func equal(sizes views: UIView...) -> [UIView] { +@MainActor public func equal(sizes views: UIView...) -> [UIView] { return equal(sizes: views) } @available(*, deprecated, renamed:"equal(sizes:)") @discardableResult -public func equalSizes(_ views: UIView...) -> [UIView] { +@MainActor public func equalSizes(_ views: UIView...) -> [UIView] { return equal(sizes: views) } @@ -289,7 +289,7 @@ public func equalSizes(_ views: UIView...) -> [UIView] { */ @discardableResult -public func equal(sizes views: [UIView]) -> [UIView] { +@MainActor public func equal(sizes views: [UIView]) -> [UIView] { equal(heights: views) equal(widths: views) return views @@ -297,7 +297,7 @@ public func equal(sizes views: [UIView]) -> [UIView] { @available(*, deprecated, renamed:"equal(sizes:)") @discardableResult -public func equalSizes(_ views: [UIView]) -> [UIView] { +@MainActor public func equalSizes(_ views: [UIView]) -> [UIView] { equal(heights: views) equal(widths: views) return views @@ -314,13 +314,13 @@ public func equalSizes(_ views: [UIView]) -> [UIView] { */ @discardableResult -public func equal(widths views: UIView...) -> [UIView] { +@MainActor public func equal(widths views: UIView...) -> [UIView] { return equal(widths: views) } @available(*, deprecated, renamed:"equal(widths:)") @discardableResult -public func equalWidths(_ views: UIView...) -> [UIView] { +@MainActor public func equalWidths(_ views: UIView...) -> [UIView] { return equal(widths: views) } @@ -335,14 +335,14 @@ public func equalWidths(_ views: UIView...) -> [UIView] { */ @discardableResult -public func equal(widths views: [UIView]) -> [UIView] { +@MainActor public func equal(widths views: [UIView]) -> [UIView] { equal(.width, views: views) return views } @available(*, deprecated, renamed:"equal(widths:)") @discardableResult -public func equalWidths(_ views: [UIView]) -> [UIView] { +@MainActor public func equalWidths(_ views: [UIView]) -> [UIView] { equal(.width, views: views) return views } @@ -358,13 +358,13 @@ public func equalWidths(_ views: [UIView]) -> [UIView] { */ @discardableResult -public func equal(heights views: UIView...) -> [UIView] { +@MainActor public func equal(heights views: UIView...) -> [UIView] { return equal(heights: views) } @available(*, deprecated, renamed:"equal(heights:)") @discardableResult -public func equalHeights(_ views: UIView...) -> [UIView] { +@MainActor public func equalHeights(_ views: UIView...) -> [UIView] { return equal(heights: views) } @@ -379,19 +379,19 @@ public func equalHeights(_ views: UIView...) -> [UIView] { */ @discardableResult -public func equal(heights views: [UIView]) -> [UIView] { +@MainActor public func equal(heights views: [UIView]) -> [UIView] { equal(.height, views: views) return views } @available(*, deprecated, renamed:"equal(heights:)") @discardableResult -public func equalHeights(_ views: [UIView]) -> [UIView] { +@MainActor public func equalHeights(_ views: [UIView]) -> [UIView] { equal(.height, views: views) return views } -private func equal(_ attribute: NSLayoutConstraint.Attribute, views: [UIView]) { +@MainActor private func equal(_ attribute: NSLayoutConstraint.Attribute, views: [UIView]) { var previousView: UIView? for v in views { if let pv = previousView { From c3ecd9b35c6b45a02be539e2fd0696323ee43022 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Fri, 20 Sep 2024 07:59:38 -1000 Subject: [PATCH 03/27] WIP: Fixes unit tests --- Tests/SteviaTests/BaselineTests.swift | 6 +++-- Tests/SteviaTests/CenterTests.swift | 6 ++--- Tests/SteviaTests/ContentTests.swift | 25 +++++++++++---------- Tests/SteviaTests/EquationTests.swift | 6 ++--- Tests/SteviaTests/FillTests.swift | 6 ++--- Tests/SteviaTests/FlexibleMarginTests.swift | 6 ++--- Tests/SteviaTests/FullLayoutTests.swift | 6 ++--- Tests/SteviaTests/GetConstraintsTests.swift | 22 +++++++++--------- Tests/SteviaTests/HierarchyTests.swift | 2 +- Tests/SteviaTests/LayoutTests.swift | 6 ++--- Tests/SteviaTests/PositionTests.swift | 6 ++--- Tests/SteviaTests/SizeTests.swift | 16 ++++++++++--- Tests/SteviaTests/StyleTests.swift | 2 +- 13 files changed, 64 insertions(+), 51 deletions(-) diff --git a/Tests/SteviaTests/BaselineTests.swift b/Tests/SteviaTests/BaselineTests.swift index 1213b92..35c5dcf 100644 --- a/Tests/SteviaTests/BaselineTests.swift +++ b/Tests/SteviaTests/BaselineTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class BaselineTests: XCTestCase { +@MainActor class BaselineTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var label1 = UILabel() var label2 = UILabel() - override func setUp() { + override func setUp() async throws { win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler @@ -29,6 +29,8 @@ class BaselineTests: XCTestCase { } } + + func testAlignLastBaselines() { label1.top(100) align(lastBaselines: label1, label2) diff --git a/Tests/SteviaTests/CenterTests.swift b/Tests/SteviaTests/CenterTests.swift index cadf6ce..e08537a 100644 --- a/Tests/SteviaTests/CenterTests.swift +++ b/Tests/SteviaTests/CenterTests.swift @@ -10,14 +10,14 @@ import XCTest let magicalIphoneXShift = 0.17 -class CenterTests: XCTestCase { +@MainActor class CenterTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// try await super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/ContentTests.swift b/Tests/SteviaTests/ContentTests.swift index 5eeb8f4..aaaebf2 100644 --- a/Tests/SteviaTests/ContentTests.swift +++ b/Tests/SteviaTests/ContentTests.swift @@ -12,11 +12,11 @@ import Stevia let title = "TitleTest" -class UIButtonContentTests: XCTestCase { +@MainActor class UIButtonContentTests: XCTestCase { var button = UIButton() - override func setUp() { - super.setUp() + override func setUp() async throws { +// button = UIButton() } @@ -41,11 +41,12 @@ class UIButtonContentTests: XCTestCase { } } -class UILabelContentTests: XCTestCase { + +@MainActor class UILabelContentTests: XCTestCase { var label = UILabel() - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() label = UILabel() } @@ -64,11 +65,11 @@ class UILabelContentTests: XCTestCase { } } -class UITextFieldContentTests: XCTestCase { +@MainActor class UITextFieldContentTests: XCTestCase { var textField = UITextField() - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() textField = UITextField() } @@ -82,11 +83,11 @@ class UITextFieldContentTests: XCTestCase { } } -class UIImageViewContentTests: XCTestCase { +@MainActor class UIImageViewContentTests: XCTestCase { var imageView = UIImageView() - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() imageView = UIImageView() } diff --git a/Tests/SteviaTests/EquationTests.swift b/Tests/SteviaTests/EquationTests.swift index 4c67fa6..5c1eff0 100644 --- a/Tests/SteviaTests/EquationTests.swift +++ b/Tests/SteviaTests/EquationTests.swift @@ -9,13 +9,13 @@ import XCTest import Stevia -class EquationTests: XCTestCase { +@MainActor class EquationTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/FillTests.swift b/Tests/SteviaTests/FillTests.swift index ad81541..38311eb 100644 --- a/Tests/SteviaTests/FillTests.swift +++ b/Tests/SteviaTests/FillTests.swift @@ -10,12 +10,12 @@ import XCTest import Stevia -class FillTests: XCTestCase { +@MainActor class FillTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/FlexibleMarginTests.swift b/Tests/SteviaTests/FlexibleMarginTests.swift index f3f2684..246a67b 100644 --- a/Tests/SteviaTests/FlexibleMarginTests.swift +++ b/Tests/SteviaTests/FlexibleMarginTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class FlexibleMarginTests: XCTestCase { +@MainActor class FlexibleMarginTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/FullLayoutTests.swift b/Tests/SteviaTests/FullLayoutTests.swift index 2696041..006e01d 100644 --- a/Tests/SteviaTests/FullLayoutTests.swift +++ b/Tests/SteviaTests/FullLayoutTests.swift @@ -53,14 +53,14 @@ class TestView: UIView { } } -class FullLayoutTests: XCTestCase { +@MainActor class FullLayoutTests: XCTestCase { var win: UIWindow! var vc: UIViewController! var v: TestView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) vc = UIViewController()///TestVC() win.rootViewController = vc diff --git a/Tests/SteviaTests/GetConstraintsTests.swift b/Tests/SteviaTests/GetConstraintsTests.swift index 2a33b2f..8b59410 100644 --- a/Tests/SteviaTests/GetConstraintsTests.swift +++ b/Tests/SteviaTests/GetConstraintsTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class GetConstraintsTests: XCTestCase { +@MainActor class GetConstraintsTests: XCTestCase { var v: UIView! var spv: UIView! - override func setUp() { - spv = UIView() - v = UIView() + override func setUp() async throws { + spv = await UIView() + v = await UIView() spv.subviews { v! } } @@ -68,7 +68,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetBottomConstraint() { + @MainActor func testCanGetBottomConstraint() { XCTAssertNil(v.bottomConstraint) v.bottom(145) let c = v.bottomConstraint @@ -84,7 +84,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetHeightConstraint() { + @MainActor func testCanGetHeightConstraint() { XCTAssertNil(v.heightConstraint) v.height(35) let c = v.heightConstraint @@ -100,7 +100,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetWidthConstraint() { + @MainActor func testCanGetWidthConstraint() { XCTAssertNil(v.widthConstraint) v.width(51) let c = v.widthConstraint @@ -116,7 +116,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetTrailingConstraint() { + @MainActor func testCanGetTrailingConstraint() { XCTAssertNil(v.trailingConstraint) v.trailingAnchor.constraint(equalTo: spv.trailingAnchor, constant: 104).isActive = true let c = v.trailingConstraint @@ -132,7 +132,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetLeadingonstraint() { + @MainActor func testCanGetLeadingonstraint() { XCTAssertNil(v.leadingConstraint) v.leadingAnchor.constraint(equalTo: spv.leadingAnchor, constant: 73).isActive = true let c = v.leadingConstraint @@ -148,7 +148,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetCenterXConstraint() { + @MainActor func testCanGetCenterXConstraint() { XCTAssertNil(v.centerXConstraint) v.CenterX == spv.CenterX + 27 let c = v.centerXConstraint @@ -164,7 +164,7 @@ class GetConstraintsTests: XCTestCase { XCTAssertEqual(c?.isActive, true) } - func testCanGetCenterYConstraint() { + @MainActor func testCanGetCenterYConstraint() { XCTAssertNil(v.centerYConstraint) v.CenterY == spv.CenterY - 32 let c = v.centerYConstraint diff --git a/Tests/SteviaTests/HierarchyTests.swift b/Tests/SteviaTests/HierarchyTests.swift index 38fbd0f..db0573e 100644 --- a/Tests/SteviaTests/HierarchyTests.swift +++ b/Tests/SteviaTests/HierarchyTests.swift @@ -9,7 +9,7 @@ import XCTest import Stevia -class HierarchyTests: XCTestCase { +@MainActor class HierarchyTests: XCTestCase { override func setUp() { super.setUp() diff --git a/Tests/SteviaTests/LayoutTests.swift b/Tests/SteviaTests/LayoutTests.swift index 77a0628..2a3bf42 100644 --- a/Tests/SteviaTests/LayoutTests.swift +++ b/Tests/SteviaTests/LayoutTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class LayoutTests: XCTestCase { +@MainActor class LayoutTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/PositionTests.swift b/Tests/SteviaTests/PositionTests.swift index e20af41..a98aaf9 100644 --- a/Tests/SteviaTests/PositionTests.swift +++ b/Tests/SteviaTests/PositionTests.swift @@ -9,14 +9,14 @@ import XCTest import Stevia -class PositionTests: XCTestCase { +@MainActor class PositionTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// super.setUp() win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/SizeTests.swift b/Tests/SteviaTests/SizeTests.swift index b1b6fef..0ad681d 100644 --- a/Tests/SteviaTests/SizeTests.swift +++ b/Tests/SteviaTests/SizeTests.swift @@ -9,14 +9,24 @@ import XCTest import Stevia -class SizeTests: XCTestCase { +@MainActor class SizeTests: XCTestCase { var win: UIWindow! var ctrler: UIViewController! var v: UIView! - override func setUp() { - super.setUp() + override func setUp() async throws { +// try await super.setUp() + win = UIWindow(frame: UIScreen.main.bounds) + ctrler = UIViewController() + win.rootViewController = ctrler + v = UIView() + ctrler.view.subviews { + v! + } + } + + func uiSetUp() { win = UIWindow(frame: UIScreen.main.bounds) ctrler = UIViewController() win.rootViewController = ctrler diff --git a/Tests/SteviaTests/StyleTests.swift b/Tests/SteviaTests/StyleTests.swift index 326b2ec..6c7a173 100644 --- a/Tests/SteviaTests/StyleTests.swift +++ b/Tests/SteviaTests/StyleTests.swift @@ -9,7 +9,7 @@ import XCTest import Stevia -class StyleTests: XCTestCase { +@MainActor class StyleTests: XCTestCase { func styleView(_ view: UIView) { view.backgroundColor = UIColor.yellow From ff8b1f186ec4e1719f854177d101b57b9bdc310d Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sat, 21 Sep 2024 17:24:51 -1000 Subject: [PATCH 04/27] Update swift.yml --- .github/workflows/swift.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 2d93658..5645dcd 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -1,10 +1,13 @@ +# This workflow will build a Swift project +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift + name: Swift on: push: - branches: [ master ] + branches: [ "master" ] pull_request: - branches: [ master ] + branches: [ "master" ] jobs: build: @@ -12,8 +15,8 @@ jobs: runs-on: macos-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Build - run: swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator" -# - name: Run tests -# run: swift test -v + run: swift build -v + - name: Run tests + run: swift test -v From bb81748c13046f46fb1c3228eea8d00fad1d4e94 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sat, 21 Sep 2024 17:40:11 -1000 Subject: [PATCH 05/27] Update README.md Swift version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3c17a8e..ab4ac68 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ ![Stevia](https://raw.githubusercontent.com/s4cha/Stevia/master/banner.png) [![Documentation](https://img.shields.io/badge/Read_the-Docs-67ad5c.svg)](https://freshos.github.io/SteviaDocs/) -[![Language: Swift 2, 3, 4 and 5](https://img.shields.io/badge/language-swift%205-f48041.svg?style=flat)](https://developer.apple.com/swift) +[![Language: Swift 2, 3, 4, 5 and 6](https://img.shields.io/badge/language-swift%206-f48041.svg?style=flat)](https://developer.apple.com/swift) ![Platform: iOS 8+](https://img.shields.io/badge/platform-iOS%20|%20tvOS-blue.svg?style=flat) [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) [![CocoaPods compatible](https://img.shields.io/badge/Cocoapods-compatible-4BC51D.svg?style=flat)](https://cocoapods.org/pods/SteviaLayout) From c065867840d221ba002bf9ccd75fa5f33a696268 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sat, 21 Sep 2024 17:41:02 -1000 Subject: [PATCH 06/27] Update README.md removes legacy package managers badges --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index ab4ac68..f1b2ba5 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ [![Documentation](https://img.shields.io/badge/Read_the-Docs-67ad5c.svg)](https://freshos.github.io/SteviaDocs/) [![Language: Swift 2, 3, 4, 5 and 6](https://img.shields.io/badge/language-swift%206-f48041.svg?style=flat)](https://developer.apple.com/swift) ![Platform: iOS 8+](https://img.shields.io/badge/platform-iOS%20|%20tvOS-blue.svg?style=flat) -[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage) -[![CocoaPods compatible](https://img.shields.io/badge/Cocoapods-compatible-4BC51D.svg?style=flat)](https://cocoapods.org/pods/SteviaLayout) ![Swift](https://github.com/freshOS/Stevia/workflows/Swift/badge.svg) [![Build Status](https://app.bitrise.io/app/4478e29045c5f12e/status.svg?token=pti6g-HVKBUPv9mIR3baIw)](https://app.bitrise.io/app/4478e29045c5f12e) [![codebeat badge](https://codebeat.co/badges/5b81e292-552c-4cf1-9ccc-89d333ec8b79)](https://codebeat.co/projects/github-com-freshos-stevia-master) From b22fa0237bcc342b8e05fe93872c715ccdce9427 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 19:36:12 -1000 Subject: [PATCH 07/27] Migrates StyleTests to Testing --- Tests/SteviaTests/StyleTests.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Tests/SteviaTests/StyleTests.swift b/Tests/SteviaTests/StyleTests.swift index 6c7a173..ec4b1f2 100644 --- a/Tests/SteviaTests/StyleTests.swift +++ b/Tests/SteviaTests/StyleTests.swift @@ -6,10 +6,12 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class StyleTests: XCTestCase { +@Suite +@MainActor struct StyleTests { func styleView(_ view: UIView) { view.backgroundColor = UIColor.yellow @@ -19,7 +21,8 @@ import Stevia label.textColor = UIColor.yellow } - func testStyle() { + @Test + func canCallStyle() { let label = UILabel() label.style(styleLabel).style(styleView) @@ -28,13 +31,13 @@ import Stevia let view: UIView = label view.style(styleView) - XCTAssertEqual(view.backgroundColor, UIColor.yellow) - XCTAssertEqual(label.textColor, UIColor.yellow) + #expect(view.backgroundColor == UIColor.yellow) + #expect(label.textColor == UIColor.yellow) //check type deduction label.style { (label) -> () in label.textColor = UIColor.blue } - XCTAssertEqual(label.textColor, UIColor.blue) + #expect(label.textColor == UIColor.blue) } } From 01dbd8a40b0894adc4321ee7ba8d108a087afe75 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 19:36:34 -1000 Subject: [PATCH 08/27] Migrates HierarchyTests to Testing --- Tests/SteviaTests/HierarchyTests.swift | 115 +++++++++++++------------ 1 file changed, 58 insertions(+), 57 deletions(-) diff --git a/Tests/SteviaTests/HierarchyTests.swift b/Tests/SteviaTests/HierarchyTests.swift index db0573e..ad4ef33 100644 --- a/Tests/SteviaTests/HierarchyTests.swift +++ b/Tests/SteviaTests/HierarchyTests.swift @@ -6,20 +6,16 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class HierarchyTests: XCTestCase { +@Suite +@MainActor +struct HierarchyTests { - override func setUp() { - super.setUp() - } - - override func tearDown() { - super.tearDown() - } - - func testLegacySv() { + @Test + func legacySv() { let view = UIView() let v1 = UIView() let v2 = UIView() @@ -27,14 +23,15 @@ import Stevia v1, v2 ) - XCTAssertEqual(view.subviews.count, 2) - XCTAssertTrue(view.subviews.contains(v1)) - XCTAssertTrue(view.subviews.contains(v2)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) + #expect(view.subviews.count == 2) + #expect(view.subviews.contains(v1)) + #expect(view.subviews.contains(v2)) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) } - func testLegacyTableViewCellSV() { + @Test + func legacyTableViewCellSV() { let cell = UITableViewCell() let v1 = UIView() let v2 = UIView() @@ -42,14 +39,15 @@ import Stevia v1, v2 ) - XCTAssertEqual(cell.contentView.subviews.count, 2) - XCTAssertTrue(cell.contentView.subviews.contains(v1)) - XCTAssertTrue(cell.contentView.subviews.contains(v2)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) + #expect(cell.contentView.subviews.count == 2) + #expect(cell.contentView.subviews.contains(v1)) + #expect(cell.contentView.subviews.contains(v2)) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) } - func testLegacyCollectionViewCellSV() { + @Test + func legacyCollectionViewCellSV() { let cell = UICollectionViewCell() let v1 = UIView() let v2 = UIView() @@ -57,16 +55,17 @@ import Stevia v1, v2 ) - XCTAssertEqual(cell.contentView.subviews.count, 2) - XCTAssertTrue(cell.contentView.subviews.contains(v1)) - XCTAssertTrue(cell.contentView.subviews.contains(v2)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) + #expect(cell.contentView.subviews.count == 2) + #expect(cell.contentView.subviews.contains(v1)) + #expect(cell.contentView.subviews.contains(v2)) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) } // Function Builders version - func testSubviews() { + @Test + func subviews() { let view = UIView() let v1 = UIView() let v2 = UIView() @@ -74,14 +73,15 @@ import Stevia v1 v2 } - XCTAssertEqual(view.subviews.count, 2) - XCTAssertTrue(view.subviews.contains(v1)) - XCTAssertTrue(view.subviews.contains(v2)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) + #expect(view.subviews.count == 2) + #expect(view.subviews.contains(v1)) + #expect(view.subviews.contains(v2)) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) } - func testTableViewCellSubviews() { + @Test + func tableViewCellSubviews() { let cell = UITableViewCell() let v1 = UIView() let v2 = UIView() @@ -90,14 +90,14 @@ import Stevia v2 } - - XCTAssertEqual(cell.contentView.subviews.count, 2) - XCTAssertTrue(cell.contentView.subviews.contains(v1)) - XCTAssertTrue(cell.contentView.subviews.contains(v2)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) + #expect(cell.contentView.subviews.count == 2) + #expect(cell.contentView.subviews.contains(v1)) + #expect(cell.contentView.subviews.contains(v2)) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) } + @Test func testCollectionViewCellSubviews() { let cell = UICollectionViewCell() let v1 = UIView() @@ -106,13 +106,14 @@ import Stevia v1 v2 } - XCTAssertEqual(cell.contentView.subviews.count, 2) - XCTAssertTrue(cell.contentView.subviews.contains(v1)) - XCTAssertTrue(cell.contentView.subviews.contains(v2)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) + #expect(cell.contentView.subviews.count == 2) + #expect(cell.contentView.subviews.contains(v1)) + #expect(cell.contentView.subviews.contains(v2)) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) } - + + @Test func testSubviewsCanBeNested() { let view = UIView() let v1 = UIView() @@ -126,16 +127,16 @@ import Stevia } v2 } - XCTAssertEqual(view.subviews.count, 2) - XCTAssertTrue(view.subviews.contains(v1)) - XCTAssertTrue(view.subviews.contains(v2)) - XCTAssertEqual(v1.subviews.count, 2) - XCTAssertTrue(v1.subviews.contains(v3)) - XCTAssertTrue(v1.subviews.contains(v4)) + #expect(view.subviews.count == 2) + #expect(view.subviews.contains(v1)) + #expect(view.subviews.contains(v2)) + #expect(v1.subviews.count == 2) + #expect(v1.subviews.contains(v3)) + #expect(v1.subviews.contains(v4)) - XCTAssertFalse(v1.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v2.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v3.translatesAutoresizingMaskIntoConstraints) - XCTAssertFalse(v4.translatesAutoresizingMaskIntoConstraints) + #expect(v1.translatesAutoresizingMaskIntoConstraints == false) + #expect(v2.translatesAutoresizingMaskIntoConstraints == false) + #expect(v3.translatesAutoresizingMaskIntoConstraints == false) + #expect(v4.translatesAutoresizingMaskIntoConstraints == false) } } From 743ddebd9667ddc728d381c71c2ebf7aad83b7f3 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 19:38:30 -1000 Subject: [PATCH 09/27] Migrates GetConstraintTests to Testing --- Tests/SteviaTests/GetConstraintsTests.swift | 277 ++++++++++---------- 1 file changed, 138 insertions(+), 139 deletions(-) diff --git a/Tests/SteviaTests/GetConstraintsTests.swift b/Tests/SteviaTests/GetConstraintsTests.swift index 8b59410..6ff5c68 100644 --- a/Tests/SteviaTests/GetConstraintsTests.swift +++ b/Tests/SteviaTests/GetConstraintsTests.swift @@ -6,178 +6,177 @@ // Copyright © 2017 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class GetConstraintsTests: XCTestCase { +@Suite +@MainActor struct GetConstraintsTests { - var v: UIView! - var spv: UIView! + let v = UIView() + let spv = UIView() - override func setUp() async throws { - spv = await UIView() - v = await UIView() - spv.subviews { v! } + init() { + spv.subviews { v } } - func testCanGetLeftConstraint() { - XCTAssertNil(v.leftConstraint) + @Test + func canGetLeftConstraint() throws { + #expect(v.leftConstraint == nil) v.left(10) - let c = v.leftConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 10) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .left) - XCTAssertEqual(c?.secondAttribute, .left) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.leftConstraint) + #expect(c.constant == 10) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .left) + #expect(c.secondAttribute == .left) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - func testCanGetRightConstraint() { - XCTAssertNil(v.rightConstraint) + @Test + func canGetRightConstraint() throws { + #expect(v.rightConstraint == nil) v.right(42) - let c = v.rightConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, -42) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .right) - XCTAssertEqual(c?.secondAttribute, .right) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.rightConstraint) + #expect(c.constant == -42) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .right) + #expect(c.secondAttribute == .right) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - func testCanGetTopConstraint() { - XCTAssertNil(v.topConstraint) + @Test + func canGetTopConstraint() throws { + #expect(v.topConstraint == nil) v.top(23) - let c = v.topConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 23) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .top) - XCTAssertEqual(c?.secondAttribute, .top) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.topConstraint) + #expect(c.constant == 23) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .top) + #expect(c.secondAttribute == .top) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - @MainActor func testCanGetBottomConstraint() { - XCTAssertNil(v.bottomConstraint) + @Test + func testCanGetBottomConstraint() throws { + #expect(v.bottomConstraint == nil) v.bottom(145) - let c = v.bottomConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, -145) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .bottom) - XCTAssertEqual(c?.secondAttribute, .bottom) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.bottomConstraint) + #expect(c.constant == -145) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .bottom) + #expect(c.secondAttribute == .bottom) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - @MainActor func testCanGetHeightConstraint() { - XCTAssertNil(v.heightConstraint) + @Test + func testCanGetHeightConstraint() throws { + #expect(v.heightConstraint == nil) v.height(35) - let c = v.heightConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 35) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertNil(c?.secondItem) - XCTAssertEqual(c?.firstAttribute, .height) - XCTAssertEqual(c?.secondAttribute, .notAnAttribute) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.heightConstraint) + #expect(c.constant == 35) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem == nil) + #expect(c.firstAttribute == .height) + #expect(c.secondAttribute == .notAnAttribute) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - @MainActor func testCanGetWidthConstraint() { - XCTAssertNil(v.widthConstraint) + @Test + func canGetWidthConstraint() throws { + #expect(v.widthConstraint == nil) v.width(51) - let c = v.widthConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 51) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertNil(c?.secondItem) - XCTAssertEqual(c?.firstAttribute, .width) - XCTAssertEqual(c?.secondAttribute, .notAnAttribute) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.widthConstraint) + #expect(c.constant == 51) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem == nil) + #expect(c.firstAttribute == .width) + #expect(c.secondAttribute == .notAnAttribute) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - @MainActor func testCanGetTrailingConstraint() { - XCTAssertNil(v.trailingConstraint) + @Test + func canGetTrailingConstraint() throws { + #expect(v.trailingConstraint == nil) v.trailingAnchor.constraint(equalTo: spv.trailingAnchor, constant: 104).isActive = true - let c = v.trailingConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 104) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .trailing) - XCTAssertEqual(c?.secondAttribute, .trailing) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 1000) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.trailingConstraint) + #expect(c.constant == 104) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .trailing) + #expect(c.secondAttribute == .trailing) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 1000) + #expect(c.isActive) } - @MainActor func testCanGetLeadingonstraint() { - XCTAssertNil(v.leadingConstraint) + @Test + func canGetLeadingonstraint() throws { + #expect(v.leadingConstraint == nil) v.leadingAnchor.constraint(equalTo: spv.leadingAnchor, constant: 73).isActive = true - let c = v.leadingConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 73) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .leading) - XCTAssertEqual(c?.secondAttribute, .leading) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 1000) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.leadingConstraint) + #expect(c.constant == 73) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .leading) + #expect(c.secondAttribute == .leading) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 1000) + #expect(c.isActive) } - @MainActor func testCanGetCenterXConstraint() { - XCTAssertNil(v.centerXConstraint) + @Test + func canGetCenterXConstraint() throws { + #expect(v.centerXConstraint == nil) v.CenterX == spv.CenterX + 27 - let c = v.centerXConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, 27) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .centerX) - XCTAssertEqual(c?.secondAttribute, .centerX) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.centerXConstraint) + #expect(c.constant == 27) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .centerX) + #expect(c.secondAttribute == .centerX) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - @MainActor func testCanGetCenterYConstraint() { - XCTAssertNil(v.centerYConstraint) + @Test + func canGetCenterYConstraint() throws { + #expect(v.centerYConstraint == nil) v.CenterY == spv.CenterY - 32 - let c = v.centerYConstraint - XCTAssertNotNil(c) - XCTAssertEqual(c?.constant, -32) - XCTAssertEqual(c?.firstItem as? UIView, v) - XCTAssertEqual(c?.secondItem as? UIView, spv) - XCTAssertEqual(c?.firstAttribute, .centerY) - XCTAssertEqual(c?.secondAttribute, .centerY) - XCTAssertEqual(c?.multiplier, 1) - XCTAssertEqual(c?.relation, .equal) - XCTAssertEqual(c?.priority.rawValue, 751) - XCTAssertEqual(c?.isActive, true) + let c = try #require(v.centerYConstraint) + #expect(c.constant == -32) + #expect(c.firstItem as? UIView == v) + #expect(c.secondItem as? UIView == spv) + #expect(c.firstAttribute == .centerY) + #expect(c.secondAttribute == .centerY) + #expect(c.multiplier == 1) + #expect(c.relation == .equal) + #expect(c.priority.rawValue == 751) + #expect(c.isActive) } - } From f1ad41d7e48ac25680a88c38835517d1b57840ee Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 19:38:53 -1000 Subject: [PATCH 10/27] Migrates BaselineTests to Testing --- Tests/SteviaTests/BaselineTests.swift | 33 ++++++++++++--------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Tests/SteviaTests/BaselineTests.swift b/Tests/SteviaTests/BaselineTests.swift index 35c5dcf..c1ef0cf 100644 --- a/Tests/SteviaTests/BaselineTests.swift +++ b/Tests/SteviaTests/BaselineTests.swift @@ -6,43 +6,40 @@ // Copyright © 2018 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import UIKit import Stevia +import Testing -@MainActor class BaselineTests: XCTestCase { +@Suite +@MainActor struct BaselineTests { - var win: UIWindow! - var ctrler: UIViewController! - var label1 = UILabel() - var label2 = UILabel() + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() + let label1 = UILabel() + let label2 = UILabel() - override func setUp() async throws { - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler - label1 = UILabel() - label2 = UILabel() - ctrler.view.subviews { label1 label2 } } - - - func testAlignLastBaselines() { + @Test + func alignLastBaselines() { label1.top(100) align(lastBaselines: label1, label2) ctrler.view.layoutIfNeeded() - XCTAssertEqual(label1.forLastBaselineLayout.frame.minY, label2.forLastBaselineLayout.frame.minY) + #expect(label1.forLastBaselineLayout.frame.minY == label2.forLastBaselineLayout.frame.minY) } - func testAlignFirstBaselines() { + @Test + func alignFirstBaselines() { label1.top(100) align(firstBaselines: label1, label2) ctrler.view.layoutIfNeeded() - XCTAssertEqual(label1.forLastBaselineLayout.frame.minY, label2.forLastBaselineLayout.frame.minY) + #expect(label1.forLastBaselineLayout.frame.minY == label2.forLastBaselineLayout.frame.minY) } } From 44d98a94f71e80590a1c2181ee2af3123f539644 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 20:00:18 -1000 Subject: [PATCH 11/27] Migrates ContentTest to Testing --- Tests/SteviaTests/ContentTests.swift | 79 ++++++++++------------------ 1 file changed, 28 insertions(+), 51 deletions(-) diff --git a/Tests/SteviaTests/ContentTests.swift b/Tests/SteviaTests/ContentTests.swift index aaaebf2..fcb8036 100644 --- a/Tests/SteviaTests/ContentTests.swift +++ b/Tests/SteviaTests/ContentTests.swift @@ -6,95 +6,72 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest - +import Testing +import UIKit import Stevia let title = "TitleTest" -@MainActor class UIButtonContentTests: XCTestCase { +@Suite +@MainActor struct UIButtonContentTests { + var button = UIButton() - override func setUp() async throws { -// + init() { button = UIButton() } - override func tearDown() { - super.tearDown() - } - + @Test func testText() { button.text(title) - XCTAssertEqual(button.currentTitle, title) - XCTAssertEqual(button.state, .normal) + #expect(button.currentTitle == title) + #expect(button.state == .normal) } + @Test func testTextKey() { button.textKey(title) - XCTAssertEqual(button.currentTitle, title) - } - - func testImage() { - button.image("foo") - //XCTAssertEqual(button.currentImage, title) + #expect(button.currentTitle == title) } } -@MainActor class UILabelContentTests: XCTestCase { - var label = UILabel() - - override func setUp() async throws { -// super.setUp() - label = UILabel() - } +@Suite +@MainActor struct UILabelContentTests { - override func tearDown() { - super.tearDown() - } + let label = UILabel() + @Test func testText() { label.text(title) - XCTAssertEqual(label.text, title) + #expect(label.text == title) } + @Test func testTextKey() { label.textKey(title) - XCTAssertEqual(label.text, title) + #expect(label.text == title) } } -@MainActor class UITextFieldContentTests: XCTestCase { - var textField = UITextField() +@Suite +@MainActor struct UITextFieldContentTests { - override func setUp() async throws { -// super.setUp() - textField = UITextField() - } - - override func tearDown() { - super.tearDown() - } + let textField = UITextField() + @Test func testPlaceholder() { textField.placeholder(title) - XCTAssertEqual(textField.placeholder, title) + #expect(textField.placeholder == title) } } -@MainActor class UIImageViewContentTests: XCTestCase { - var imageView = UIImageView() - - override func setUp() async throws { -// super.setUp() - imageView = UIImageView() - } - - override func tearDown() { - super.tearDown() - } +@Suite +@MainActor struct UIImageViewContentTests { + let imageView = UIImageView() + + @Test func testImage() { imageView.image("foo") //XCTAssertEqual(button.currentImage, title) From 33535f1037e879921e069a6b0a35d3e1adcbb687 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 20:17:23 -1000 Subject: [PATCH 12/27] Migrates EquationTests to Testing --- Tests/SteviaTests/EquationTests.swift | 187 ++++++++++++++++---------- 1 file changed, 119 insertions(+), 68 deletions(-) diff --git a/Tests/SteviaTests/EquationTests.swift b/Tests/SteviaTests/EquationTests.swift index 5c1eff0..ecd886a 100644 --- a/Tests/SteviaTests/EquationTests.swift +++ b/Tests/SteviaTests/EquationTests.swift @@ -6,445 +6,493 @@ // Copyright © 2017 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class EquationTests: XCTestCase { +@Suite +@MainActor struct EquationTests { - var win: UIWindow! - var ctrler: UIViewController! + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() - override func setUp() async throws { -// super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler } - override func tearDown() { - super.tearDown() - } - + @Test func testTopDouble() { let v = UIView() ctrler.view.subviews { v } v.Top == ctrler.view.Top + Double(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testTopCGFloat() { let v = UIView() ctrler.view.subviews { v } v.Top == ctrler.view.Top + CGFloat(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testTopInt() { let v = UIView() ctrler.view.subviews { v } v.Top == ctrler.view.Top + Int(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testTopReflexive() { let v = UIView() ctrler.view.subviews { v } ctrler.view.Top + 10 == v.Top ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testTopGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Top >= ctrler.view.Top + 10 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testTopLessThanOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Top <= ctrler.view.Top + 10 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testBottomDouble() { let v = UIView() ctrler.view.subviews { v } v.Bottom == ctrler.view.Bottom - Double(23) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testBottomCGFloat() { let v = UIView() ctrler.view.subviews { v } v.Bottom == ctrler.view.Bottom - CGFloat(23) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testBottomInt() { let v = UIView() ctrler.view.subviews { v } v.Bottom == ctrler.view.Bottom - Int(23) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testBottomReflexive() { let v = UIView() ctrler.view.subviews { v } ctrler.view.Bottom - 23 == v.Bottom ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testBottomGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Bottom >= ctrler.view.Bottom - 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testBottomLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Bottom <= ctrler.view.Bottom - 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testLeft() { let v = UIView() ctrler.view.subviews { v } v.Left == ctrler.view.Left + 72 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testLeftReflexive() { let v = UIView() ctrler.view.subviews { v } ctrler.view.Left + 72 == v.Left ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testLeftGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Left >= ctrler.view.Left + 72 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testLeftLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Left <= ctrler.view.Left + 72 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testRight() { let v = UIView() ctrler.view.subviews { v } v.Right == ctrler.view.Right - 13 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testRightReflexive() { let v = UIView() ctrler.view.subviews { v } ctrler.view.Right - 13 == v.Right ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testRightGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Right >= ctrler.view.Right - 13 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testRightLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Right >= ctrler.view.Right - 13 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testWidth() { let v = UIView() ctrler.view.subviews { v } v.Width == ctrler.view.Width - 52 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, ctrler.view.frame.width - 52) + #expect(v.frame.width == ctrler.view.frame.width - 52) } + @Test func testWidthReflexive() { let v = UIView() ctrler.view.subviews { v } ctrler.view.Width - 52 == v.Width ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, ctrler.view.frame.width - 52) + #expect(v.frame.width == ctrler.view.frame.width - 52) } + @Test func testWidthGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Width >= ctrler.view.Width - 52 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, ctrler.view.frame.width - 52) + #expect(v.frame.width == ctrler.view.frame.width - 52) } + @Test func testWidthLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Width <= ctrler.view.Width - 52 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, 0) + #expect(v.frame.width == 0) } + @Test func testHeight() { let v = UIView() ctrler.view.subviews { v } v.Height == ctrler.view.Height + 34 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, ctrler.view.frame.height + 34) + #expect(v.frame.height == ctrler.view.frame.height + 34) } + @Test func testHeightReflexive() { let v = UIView() ctrler.view.subviews { v } ctrler.view.Height + 34 == v.Height ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, ctrler.view.frame.height + 34) + #expect(v.frame.height == ctrler.view.frame.height + 34) } + @Test func testHeightGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Height >= ctrler.view.Height - 34 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, ctrler.view.frame.height - 34) + #expect(v.frame.height == ctrler.view.frame.height - 34) } + @Test func testHeightLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Height <= ctrler.view.Height - 34 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, 0) + #expect(v.frame.height == 0) } // Single Value + @Test func testSingleValueTopDouble() { let v = UIView() ctrler.view.subviews { v } v.Top == Double(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueTopCGFloat() { let v = UIView() ctrler.view.subviews { v } v.Top == CGFloat(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueTopInt() { let v = UIView() ctrler.view.subviews { v } v.Top == Int(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueTopGreaterOrEqualDouble() { let v = UIView() ctrler.view.subviews { v } v.Top >= Double(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueTopGreaterOrEqualCGFloat() { let v = UIView() ctrler.view.subviews { v } v.Top >= CGFloat(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueTopGreaterOrEqualInt() { let v = UIView() ctrler.view.subviews { v } v.Top >= Int(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueLessOrEqualDouble() { let v = UIView() ctrler.view.subviews { v } v.Top <= Double(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueLessOrEqualCGFloat() { let v = UIView() ctrler.view.subviews { v } v.Top <= CGFloat(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueLessOrEqualInt() { let v = UIView() ctrler.view.subviews { v } v.Top <= Int(10) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 10) + #expect(v.frame.origin.y == 10) } + @Test func testSingleValueBottom() { let v = UIView() ctrler.view.subviews { v } v.Bottom == 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testSingleValueBottomGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Bottom >= 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testSingleValueBottomLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Bottom <= 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - 23) + #expect(v.frame.origin.y == ctrler.view.frame.height - 23) } + @Test func testSingleValueLeft() { let v = UIView() ctrler.view.subviews { v } v.Left == 72 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testSingleValueLeftGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Left >= 72 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testSingleValueLeftLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Left <= 72 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, 72) + #expect(v.frame.origin.x == 72) } + @Test func testSingleValueRight() { let v = UIView() ctrler.view.subviews { v } v.Right == 13 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testSingleValueRightGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Right >= 13 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testSingleValueRightLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Right <= 13 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 13) + #expect(v.frame.origin.x == ctrler.view.frame.width - 13) } + @Test func testSingleValueWidth() { let v = UIView() ctrler.view.subviews { v } v.Width == 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, 23) + #expect(v.frame.width == 23) } + @Test func testSingleValueWidthGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Width >= 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, 23) + #expect(v.frame.width == 23) } + @Test func testSingleValueWidthLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.centerInContainer() // There is a bug where we need to have a x/y placement for size to be accurate. v.Width <= 23 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.width, 0) + #expect(v.frame.width == 0) } + @Test func testSingleValueHeight() { let v = UIView() ctrler.view.subviews { v } v.Height == 94 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, 94) + #expect(v.frame.height == 94) } + @Test func testSingleValueHeightGreaterOrEqual() { let v = UIView() ctrler.view.subviews { v } v.Height >= 94 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, 94) + #expect(v.frame.height == 94) } + @Test func testSingleValueHeightLessOrEqual() { let v = UIView() ctrler.view.subviews { v } v.centerInContainer() // There is a bug where we need to have a x/y placement for size to be accurate. v.Height <= 94 ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.height, 0) + #expect(v.frame.height == 0) } + @Test func testScrollView() { let scrollView = UIScrollView() let contentView = UIView() @@ -456,9 +504,10 @@ import Stevia scrollView.fillContainer() contentView.Width == ctrler.view.Width ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(contentView.frame.width, ctrler.view.frame.width) + #expect(contentView.frame.width == ctrler.view.frame.width) } + @Test func testScrollViewReflexive() { let scrollView = UIScrollView() let contentView = UIView() @@ -470,9 +519,10 @@ import Stevia scrollView.fillContainer() ctrler.view.Width == contentView.Width ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(contentView.frame.width, ctrler.view.frame.width) + #expect(contentView.frame.width == ctrler.view.frame.width) } + @Test func testDifferentViewHierarchies() { // Classic example of a field with a dropdown. let box = UIView() @@ -499,9 +549,10 @@ import Stevia ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in let absoluteFieldBottom = field.frame.origin.y + field.frame.height + box.frame.origin.y - XCTAssertEqual(absoluteFieldBottom, dropdown.frame.origin.y) + #expect(absoluteFieldBottom == dropdown.frame.origin.y) } + @Test func testDifferentViewHierarchiesReflexivity() { // Classic example of a field with a dropdown. let box = UIView() @@ -527,6 +578,6 @@ import Stevia ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in let absoluteFieldBottom = field.frame.origin.y + field.frame.height + box.frame.origin.y - XCTAssertEqual(absoluteFieldBottom, dropdown.frame.origin.y) + #expect(absoluteFieldBottom == dropdown.frame.origin.y) } } From 40c3ab4c469d635a741ad457a30e38d074e2a4b6 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 20:35:48 -1000 Subject: [PATCH 13/27] Migrates SizeTests to Testing --- Tests/SteviaTests/SizeTests.swift | 184 ++++++++++++++---------------- 1 file changed, 87 insertions(+), 97 deletions(-) diff --git a/Tests/SteviaTests/SizeTests.swift b/Tests/SteviaTests/SizeTests.swift index 0ad681d..9b6bf0a 100644 --- a/Tests/SteviaTests/SizeTests.swift +++ b/Tests/SteviaTests/SizeTests.swift @@ -6,117 +6,110 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class SizeTests: XCTestCase { +@Suite +@MainActor struct SizeTests { - var win: UIWindow! - var ctrler: UIViewController! - var v: UIView! + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() + let v = UIView() - override func setUp() async throws { -// try await super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler - v = UIView() ctrler.view.subviews { - v! + v } } - func uiSetUp() { - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() - win.rootViewController = ctrler - v = UIView() - ctrler.view.subviews { - v! - } - } - - override func tearDown() { - super.tearDown() - } - + @Test func testSizeDouble() { v.size(Double(57)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 57, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 57, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 57) + #expect(v.frame.height == 57) } + @Test func testSizeCGFloat() { v.size(CGFloat(57)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 57, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 57, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 57) + #expect(v.frame.height == 57) } + @Test func testSizeInt() { v.size(Int(57)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 57, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 57, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 57) + #expect(v.frame.height == 57) } + @Test func testWidthAndHeightDouble() { v.width(Double(36)) v.height(Double(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 36, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 23, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 36) + #expect(v.frame.height == 23) } + @Test func testWidthAndHeightCGFloat() { v.width(CGFloat(36)) v.height(CGFloat(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 36, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 23, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 36) + #expect(v.frame.height == 23) } + @Test func testWidthAndHeightInt() { v.width(Int(36)) v.height(Int(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 36, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 23, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 36) + #expect(v.frame.height == 23) } + @Test func testHeightPercentage() { v.width(100) v.height(40%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, ctrler.view.frame.height*0.4, accuracy:0.5) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + expectDelta(v.frame.height, ctrler.view.frame.height*0.4) } + @Test func testWidthPercentage() { v.height(100) v.width(87%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, ctrler.view.frame.width*0.87, accuracy: 0.5) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.height == 100) + expectDelta(v.frame.width, ctrler.view.frame.width*0.87) } + @Test func testEqualSizes() { let width = 24.0 let height = 267.0 @@ -130,10 +123,11 @@ import Stevia v1.width(width) equal(sizes: [v1, v2]) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.width, v2.frame.width, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, v2.frame.height, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.width == v2.frame.width) + #expect(v1.frame.height == v2.frame.height) } + @Test func testVariadicEqualSizes() { let width = 24.0 let height = 267.0 @@ -147,10 +141,11 @@ import Stevia v1.width(width) equal(sizes: v1, v2) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.width, v2.frame.width, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, v2.frame.height, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.width == v2.frame.width) + #expect(v1.frame.height == v2.frame.height) } + @Test func testFollwEdges() { let v1 = UIView() let v2 = UIView() @@ -166,67 +161,62 @@ import Stevia |-20-v1| ~ 32 } - ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, ctrler.view.frame.width - 20, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 32, accuracy: CGFloat(Float.ulpOfOne)) - - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - + #expect(v1.frame.origin.y == 10) + #expect(v1.frame.origin.x == 20) + #expect(v1.frame.width == ctrler.view.frame.width - 20) + #expect(v1.frame.height == 32) + + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 0) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) + v2.followEdges(v1) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v2.frame.origin.y, v1.frame.origin.y, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, v1.frame.origin.x, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, v1.frame.width, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, v1.frame.height, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == v1.frame.origin.y) + #expect(v2.frame.origin.x == v1.frame.origin.x) + #expect(v2.frame.width == v1.frame.width) + #expect(v2.frame.height == v1.frame.height) } - - + + @Test func testHeightEqualWidth() { v.heightEqualsWidth().width(85) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 85, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 85, accuracy: CGFloat(Float.ulpOfOne)) - + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 85) + #expect(v.frame.height == 85) } + @Test func testWidthEqualHeight() { v.height(192) v.heightEqualsWidth() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 192, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 192, accuracy: CGFloat(Float.ulpOfOne)) - + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 192) + #expect(v.frame.height == 192) } + @Test func testSizeOnOrphanView() { v.removeFromSuperview() v.height(80) v.width(80) - ctrler.view?.subviews { v! } - + ctrler.view?.subviews { v } + let view: UIView = ctrler.view view.layout { 0 - |v! + |v } ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.width, 80, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 80, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.width == 80) + #expect(v.frame.height == 80) } } From f73d337bba31e11a205464b28b59f493473d3ae4 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 23 Sep 2024 07:43:14 -1000 Subject: [PATCH 14/27] Migrates CenterTests to Testing --- Package.resolved | 15 +++ Package.swift | 8 +- Tests/SteviaTests/CenterTests.swift | 172 +++++++++++++--------------- 3 files changed, 102 insertions(+), 93 deletions(-) create mode 100644 Package.resolved diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..a4d4585 --- /dev/null +++ b/Package.resolved @@ -0,0 +1,15 @@ +{ + "originHash" : "0d1e08a917a619df6510ae568b5ab623f1fc22dffa644b8c590c04c4a5b086bc", + "pins" : [ + { + "identity" : "swift-numerics", + "kind" : "remoteSourceControl", + "location" : "https://github.com/apple/swift-numerics", + "state" : { + "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", + "version" : "1.0.2" + } + } + ], + "version" : 3 +} diff --git a/Package.swift b/Package.swift index 6e87d56..5959897 100644 --- a/Package.swift +++ b/Package.swift @@ -9,8 +9,14 @@ let package = Package( .tvOS(.v12) ], products: [.library(name: "Stevia", targets: ["Stevia"])], + dependencies: [ + .package(url: "https://github.com/apple/swift-numerics", from: "1.0.2"), + ], targets: [ .target(name: "Stevia", path: "Sources", resources: [.copy("PrivacyInfo.xcprivacy")]), - .testTarget(name: "SteviaTests", dependencies: ["Stevia"]), + .testTarget(name: "SteviaTests", dependencies: [ + "Stevia", + .product(name: "Numerics", package: "swift-numerics"), + ]), ] ) diff --git a/Tests/SteviaTests/CenterTests.swift b/Tests/SteviaTests/CenterTests.swift index e08537a..44529f6 100644 --- a/Tests/SteviaTests/CenterTests.swift +++ b/Tests/SteviaTests/CenterTests.swift @@ -6,149 +6,137 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import Numerics +import UIKit +import Stevia -let magicalIphoneXShift = 0.17 -@MainActor class CenterTests: XCTestCase { +@Suite +@MainActor struct CenterTests { - var win: UIWindow! - var ctrler: UIViewController! - var v: UIView! + let win = UIWindow(frame: UIScreen.main.bounds) + var ctrler = UIViewController() + var v = UIView() - override func setUp() async throws { -// try await super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler - v = UIView() - ctrler.view.subviews { v! } - - // verify view h as default values - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - + ctrler.view.subviews { v } v.size(100) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) - } - - override func tearDown() { - super.tearDown() } - func testCenterHorizontally() { + @Test + func centerHorizontally() { v.centerHorizontally() ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, - ctrler.view.frame.width/2.0 - (v.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width/2.0 - (v.frame.width/2.0))) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterHorizontallyWithOffsetDouble() { + @Test + func centerHorizontallyWithOffsetDouble() { v.centerHorizontally(offset: Double(50)) ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x - 50, - ctrler.view.frame.width/2.0 - (v.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + let val = v.frame.origin.x - 50 + #expect(isApproximatelyEqual(val, ctrler.view.frame.width/2.0 - (v.frame.width/2.0))) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterHorizontallyWithOffsetCGFloat() { + @Test + func centerHorizontallyWithOffsetCGFloat() { v.centerHorizontally(offset: CGFloat(50)) ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x - 50, - ctrler.view.frame.width/2.0 - (v.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + let val = v.frame.origin.x - 50 + #expect(isApproximatelyEqual(val, (ctrler.view.frame.width/2.0 - (v.frame.width/2.0)))) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterHorizontallyWithOffsetInt() { + @Test + func centerHorizontallyWithOffsetInt() { v.centerHorizontally(offset: Int(50)) ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x - 50, - ctrler.view.frame.width/2.0 - (v.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + let val = v.frame.origin.x - 50 + #expect(isApproximatelyEqual(val, (ctrler.view.frame.width/2.0 - (v.frame.width/2.0)))) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterVertically() { + @Test + func centerVertically() { v.centerVertically() ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, - ctrler.view.frame.height/2.0 - (v.frame.height/2.0), - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == ctrler.view.frame.height/2.0 - (v.frame.height/2.0)) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterVerticallyWithOffsetDouble() { + @Test + func centerVerticallyWithOffsetDouble() { v.centerVertically(offset: Double(50)) ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y - 50, - ctrler.view.frame.height/2.0 - (v.frame.height/2.0), - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + let val = v.frame.origin.y - 50 + #expect(isApproximatelyEqual(val, (ctrler.view.frame.height/2.0 - (v.frame.height/2.0)))) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterVerticallyWithOffsetCGFloat() { + @Test + func centerVerticallyWithOffsetCGFloat() { v.centerVertically(offset: CGFloat(50)) ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y - 50, - ctrler.view.frame.height/2.0 - (v.frame.height/2.0), - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + let val = v.frame.origin.y - 50 + #expect(isApproximatelyEqual(val, (ctrler.view.frame.height/2.0 - (v.frame.height/2.0)))) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterVerticallyWithOffsetInt() { + @Test + func centerVerticallyWithOffsetInt() { v.centerVertically(offset: Int(50)) ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y - 50, - ctrler.view.frame.height/2.0 - (v.frame.height/2.0), - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + + let val = v.frame.origin.y - 50 + #expect(isApproximatelyEqual(val, (ctrler.view.frame.height/2.0 - (v.frame.height/2.0)))) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } - func testCenterInContainer() { + @Test + func centerInContainer() { v.centerInContainer() ctrler.view.setNeedsLayout() ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, - ctrler.view.frame.height/2.0 - (v.frame.height/2.0), - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, - ctrler.view.frame.width/2.0 - (v.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + + #expect(v.frame.origin.y == ctrler.view.frame.height/2.0 - (v.frame.height/2.0)) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width/2.0 - (v.frame.width/2.0))) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) + #expect(isApproximatelyEqual(v.frame.origin.y, ctrler.view.frame.height/2.0 - (v.frame.height/2.0))) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width/2.0 - (v.frame.width/2.0))) + #expect(v.frame.height == 100) } } + +func isApproximatelyEqual(_ a: Double, _ b: Double) -> Bool { + return a.isApproximatelyEqual(to: b, absoluteTolerance: 0.2) +} From 038e894568f7d22c80dcb025cfc933af5b9a8314 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 23 Sep 2024 07:48:42 -1000 Subject: [PATCH 15/27] Migrates FillTests to Testing --- Tests/SteviaTests/FillTests.swift | 74 ++++++++++++++----------------- 1 file changed, 34 insertions(+), 40 deletions(-) diff --git a/Tests/SteviaTests/FillTests.swift b/Tests/SteviaTests/FillTests.swift index 38311eb..c6084e6 100644 --- a/Tests/SteviaTests/FillTests.swift +++ b/Tests/SteviaTests/FillTests.swift @@ -6,136 +6,130 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest - +import Testing +import UIKit import Stevia -@MainActor class FillTests: XCTestCase { - var win: UIWindow! - var ctrler: UIViewController! +@Suite +@MainActor class FillTests { + + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() - override func setUp() async throws { -// super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler } - override func tearDown() { - super.tearDown() - } - + @Test func testFillContainer() { let b = UIButton() ctrler.view.subviews { b } b.fillContainer() ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame, b.frame) + #expect(ctrler.view.frame == b.frame) } + @Test func testFillContainerWithPaddingDouble() { let padding: Double = 10.0 let b = UIButton() ctrler.view.subviews { b } b.fillContainer(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(ctrler.view.frame.width, b.frame.width + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.height == b.frame.height + CGFloat(padding) * 2) + #expect(ctrler.view.frame.width == b.frame.width + CGFloat(padding) * 2) } + @Test func testFillContainerWithPaddingCGFloat() { let padding: CGFloat = 10.0 let b = UIButton() ctrler.view.subviews { b } b.fillContainer(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(ctrler.view.frame.width, b.frame.width + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.height == b.frame.height + CGFloat(padding) * 2) + #expect(ctrler.view.frame.width == b.frame.width + CGFloat(padding) * 2) } + @Test func testFillContainerWithPaddingInt() { let padding: Int = 10 let b = UIButton() ctrler.view.subviews { b } b.fillContainer(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(ctrler.view.frame.width, b.frame.width + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.height == b.frame.height + CGFloat(padding) * 2) + #expect(ctrler.view.frame.width == b.frame.width + CGFloat(padding) * 2) } + @Test func testFillVertically() { let b = UIButton() ctrler.view.subviews { b } b.width(10) b.fillVertically() ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height) - XCTAssertEqual(10, b.frame.width) + #expect(ctrler.view.frame.height == b.frame.height) + #expect(10 == b.frame.width) } + @Test func testFillVerticallyWithPaddingDouble() { let padding: Double = 40.0 let b = UIButton() ctrler.view.subviews { b } b.fillVertically(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.height == b.frame.height + CGFloat(padding) * 2) } + @Test func testFillVerticallyWithPaddingCGFloat() { let padding: CGFloat = 30.0 let b = UIButton() ctrler.view.subviews { b } b.fillVertically(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.height == b.frame.height + CGFloat(padding) * 2) } + @Test func testFillVerticallyWithPaddingInt() { let padding: Int = 14 let b = UIButton() ctrler.view.subviews { b } b.fillVertically(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.height, b.frame.height + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.height == b.frame.height + CGFloat(padding) * 2) } + @Test func testFillHorizontallyWithPaddingDouble() { let padding: Double = 40.0 let b = UIButton() ctrler.view.subviews { b } b.fillHorizontally(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.width, b.frame.width + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.width == b.frame.width + CGFloat(padding) * 2) } + @Test func testFillHorizontallyWithPaddingCGFloat() { let padding: CGFloat = 30.0 let b = UIButton() ctrler.view.subviews { b } b.fillHorizontally(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.width, b.frame.width + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.width == b.frame.width + CGFloat(padding) * 2) } + @Test func testFillHorizontallyWithPaddingInt() { let padding: Int = 14 let b = UIButton() ctrler.view.subviews { b } b.fillHorizontally(padding: padding) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(ctrler.view.frame.width, b.frame.width + CGFloat(padding) * 2, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(ctrler.view.frame.width == b.frame.width + CGFloat(padding) * 2) } } From 9d89ef553ed203b30f7866640f65d5551cfad40a Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 23 Sep 2024 13:22:24 -1000 Subject: [PATCH 16/27] Migrates FlexibleMarginsTests to Testing --- Tests/SteviaTests/FlexibleMarginTests.swift | 353 ++++++++++---------- Tests/SteviaTests/FullLayoutTests.swift | 2 + Tests/SteviaTests/SizeTests.swift | 4 +- 3 files changed, 185 insertions(+), 174 deletions(-) diff --git a/Tests/SteviaTests/FlexibleMarginTests.swift b/Tests/SteviaTests/FlexibleMarginTests.swift index 246a67b..e8ccae5 100644 --- a/Tests/SteviaTests/FlexibleMarginTests.swift +++ b/Tests/SteviaTests/FlexibleMarginTests.swift @@ -6,287 +6,296 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class FlexibleMarginTests: XCTestCase { +@Suite +@MainActor struct FlexibleMarginTests { - var win: UIWindow! - var ctrler: UIViewController! - var v: UIView! + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() + let v = UIView() - override func setUp() async throws { -// super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler - v = UIView() - ctrler.view.subviews { v! } + ctrler.view.subviews { v } v.size(100.0) } - override func tearDown() { - super.tearDown() - } - - /// Todo stress test by pushing views - + @Test func testGreaterTopDouble() { v.top(>=Double(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterTopCGFloat() { v.top(>=CGFloat(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterTopInt() { v.top(>=Int(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterBottom() { v.bottom(>=45) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - v.frame.height - 45, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == ctrler.view.frame.height - v.frame.height - 45) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterLeft() { v.left(>=23) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterLeading() { v.leading(>=23) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterLeadingRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v.leading(>=23) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterRight() { v.right(>=74) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterTrailing() { v.trailing(>=74) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testGreaterTrailingRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v.trailing(>=74) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 74, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessTopDouble() { v.top(<=Double(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessTopCGFloat() { v.top(<=CGFloat(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessTopInt() { v.top(<=Int(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessBottom() { v.bottom(<=45) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, - ctrler.view.frame.height - v.frame.height - 45, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == ctrler.view.frame.height - v.frame.height - 45) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessLeft() { v.left(<=23) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessLeading() { v.leading(<=23) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessLeadingRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v.leading(<=23) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 23, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessLeftOperator() { |-(<=23)-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessLeftOperatorRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft |-(<=23)-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 23) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessRight() { v.right(<=74) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessTrailing() { v.trailing(<=74) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessTrailingRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v.trailing(<=74) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 74, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessRightOperator() { v-(<=74)-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLessRightOperatorRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v-(<=74)-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 74, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testMarginGreaterBetweenTwoViews() { let v1 = UIView() let v2 = UIView() v.removeFromSuperview() ctrler.view.subviews { v1; v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-(>=25)-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 35, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 35) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testMarginGreaterBetweenTwoViewsRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft let v1 = UIView() @@ -297,26 +306,27 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-(>=25)-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, ctrler.view.frame.width - 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - 10) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, ctrler.view.frame.width - v1.frame.width - 25, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - v1.frame.width - 25) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testMarginLesserBetweenTwoViews() { let v1 = UIView() let v2 = UIView() @@ -326,25 +336,26 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-(<=25)-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 35, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 35) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testMarginLesserBetweenTwoViewsRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft let v1 = UIView() @@ -355,24 +366,22 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-(<=25)-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, ctrler.view.frame.width - 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - 10) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, ctrler.view.frame.width - v1.frame.width - 25, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - v1.frame.width - 25) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } - } diff --git a/Tests/SteviaTests/FullLayoutTests.swift b/Tests/SteviaTests/FullLayoutTests.swift index 006e01d..85cee92 100644 --- a/Tests/SteviaTests/FullLayoutTests.swift +++ b/Tests/SteviaTests/FullLayoutTests.swift @@ -163,3 +163,5 @@ class TestView: UIView { XCTAssertEqual(v.view2.frame.width, v.frame.width, accuracy: CGFloat(Float.ulpOfOne)) } } + +let magicalIphoneXShift = 1.0 diff --git a/Tests/SteviaTests/SizeTests.swift b/Tests/SteviaTests/SizeTests.swift index 9b6bf0a..b468f33 100644 --- a/Tests/SteviaTests/SizeTests.swift +++ b/Tests/SteviaTests/SizeTests.swift @@ -95,7 +95,7 @@ import Stevia #expect(v.frame.origin.y == 0) #expect(v.frame.origin.x == 0) #expect(v.frame.width == 100) - expectDelta(v.frame.height, ctrler.view.frame.height*0.4) + #expect(isApproximatelyEqual(v.frame.height, ctrler.view.frame.height*0.4)) } @Test @@ -106,7 +106,7 @@ import Stevia #expect(v.frame.origin.y == 0) #expect(v.frame.origin.x == 0) #expect(v.frame.height == 100) - expectDelta(v.frame.width, ctrler.view.frame.width*0.87) + #expect(isApproximatelyEqual(v.frame.width, ctrler.view.frame.width*0.87)) } @Test From 8f9d5db647247ae36b2feaa8224cc49a43a505ad Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 23 Sep 2024 13:34:33 -1000 Subject: [PATCH 17/27] Migrates FullLayoutTests to Testing --- Tests/SteviaTests/CenterTests.swift | 2 +- Tests/SteviaTests/FullLayoutTests.swift | 133 ++++++++++-------------- 2 files changed, 55 insertions(+), 80 deletions(-) diff --git a/Tests/SteviaTests/CenterTests.swift b/Tests/SteviaTests/CenterTests.swift index 44529f6..babc74e 100644 --- a/Tests/SteviaTests/CenterTests.swift +++ b/Tests/SteviaTests/CenterTests.swift @@ -138,5 +138,5 @@ import Stevia } func isApproximatelyEqual(_ a: Double, _ b: Double) -> Bool { - return a.isApproximatelyEqual(to: b, absoluteTolerance: 0.2) + return a.isApproximatelyEqual(to: b, absoluteTolerance: 0.3) } diff --git a/Tests/SteviaTests/FullLayoutTests.swift b/Tests/SteviaTests/FullLayoutTests.swift index 85cee92..5849a4b 100644 --- a/Tests/SteviaTests/FullLayoutTests.swift +++ b/Tests/SteviaTests/FullLayoutTests.swift @@ -6,7 +6,8 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia class TestView: UIView { @@ -53,115 +54,89 @@ class TestView: UIView { } } -@MainActor class FullLayoutTests: XCTestCase { +@Suite +@MainActor class FullLayoutTests { - var win: UIWindow! - var vc: UIViewController! - var v: TestView! + let win = UIWindow(frame: UIScreen.main.bounds) + let vc = UIViewController() + let v = TestView() - override func setUp() async throws { -// super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - vc = UIViewController()///TestVC() + init() { win.rootViewController = vc - v = TestView() v.frame = vc.view.frame vc.view = v } - override func tearDown() { - super.tearDown() - } - + @Test func testFullLayout() { - XCTAssertEqual(vc.view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.width, win.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.height, win.frame.height, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(vc.view.frame.origin.x == 0) + #expect(vc.view.frame.origin.y == 0) + #expect(vc.view.frame.width == win.frame.width) + #expect(vc.view.frame.height == win.frame.height) v.layoutIfNeeded() // Email - XCTAssertEqual(v.email.frame.origin.y, 100.5, accuracy: 0.5) - XCTAssertEqual(v.email.frame.origin.x, 8, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.email.frame.width, win.frame.width - 8 - 22, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.email.frame.height, win.frame.height*0.1, accuracy: 0.5) + #expect(isApproximatelyEqual(v.email.frame.origin.y, 100.5)) + #expect(v.email.frame.origin.x == 8) + #expect(v.email.frame.width == win.frame.width - 8 - 22) + #expect(isApproximatelyEqual(v.email.frame.height, win.frame.height*0.1)) // Password - XCTAssertEqual(v.password.frame.origin.y, - v.email.frame.origin.y+v.email.frame.height + 20, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.password.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.password.frame.width, 54, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.password.frame.height, 47, accuracy: CGFloat(Float.ulpOfOne)) + #expect(isApproximatelyEqual(v.password.frame.origin.y, v.email.frame.origin.y+v.email.frame.height + 20)) + #expect(v.password.frame.origin.x == 0) + #expect(v.password.frame.width == 54) + #expect(v.password.frame.height == 47) // Password - XCTAssertEqual(v.login.frame.origin.y, - win.frame.height - v.login.frame.height - 7, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.login.frame.origin.x, - win.frame.width/2.0 - (v.login.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.login.frame.height, 99, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.login.frame.origin.y == win.frame.height - v.login.frame.height - 7) + #expect(isApproximatelyEqual(v.login.frame.origin.x, win.frame.width/2.0 - (v.login.frame.width/2.0))) + #expect(v.login.frame.height == 99) } + @Test func testFullLayoutRTL() { vc.view.semanticContentAttribute = .forceRightToLeft - XCTAssertEqual(vc.view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.width, win.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.height, win.frame.height, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(vc.view.frame.origin.x == 0) + #expect(vc.view.frame.origin.y == 0) + #expect(vc.view.frame.width == win.frame.width) + #expect(vc.view.frame.height == win.frame.height) v.layoutIfNeeded() // Email - XCTAssertEqual(v.email.frame.origin.y, 100.5, accuracy: 0.5) - XCTAssertEqual(v.email.frame.origin.x, 22, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.email.frame.width, win.frame.width - 8 - 22, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.email.frame.height, win.frame.height*0.1, accuracy: 0.5) - + #expect(isApproximatelyEqual(v.email.frame.origin.y, 100.5)) + #expect(v.email.frame.origin.x == 22) + #expect(v.email.frame.width == win.frame.width - 8 - 22) + #expect(isApproximatelyEqual(v.email.frame.height, win.frame.height*0.1)) + // Password - XCTAssertEqual(v.password.frame.origin.y, - v.email.frame.origin.y+v.email.frame.height + 20, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.password.frame.origin.x, vc.view.frame.width - 54, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.password.frame.width, 54, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.password.frame.height, 47, accuracy: CGFloat(Float.ulpOfOne)) + #expect(isApproximatelyEqual(v.password.frame.origin.y, v.email.frame.origin.y+v.email.frame.height + 20)) + #expect(v.password.frame.origin.x == vc.view.frame.width - 54) + #expect(v.password.frame.width == 54) + #expect(v.password.frame.height == 47) // Password - XCTAssertEqual(v.login.frame.origin.y, - win.frame.height - v.login.frame.height - 7, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.login.frame.origin.x, - win.frame.width/2.0 - (v.login.frame.width/2.0), - accuracy: CGFloat(magicalIphoneXShift)) - XCTAssertEqual(v.login.frame.height, 99, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.login.frame.origin.y == win.frame.height - v.login.frame.height - 7) + #expect(isApproximatelyEqual(v.login.frame.origin.x, win.frame.width/2.0 - (v.login.frame.width/2.0))) + #expect(v.login.frame.height == 99) } - + + @Test func testPercentLayout() { - XCTAssertEqual(vc.view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.width, win.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(vc.view.frame.height, win.frame.height, - accuracy: CGFloat(Float.ulpOfOne)) + #expect(vc.view.frame.origin.x == 0) + #expect(vc.view.frame.origin.y == 0) + #expect(vc.view.frame.width == win.frame.width) + #expect(vc.view.frame.height == win.frame.height) v.layoutIfNeeded() - XCTAssertEqual(v.view1.frame.origin.y, v.frame.height*0.1, accuracy: 0.5) - XCTAssertEqual(v.view1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.view1.frame.width, v.frame.width, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.view2.frame.origin.y, (v.frame.height*0.1) + 20 + (v.frame.height*0.33), accuracy: 0.5) - XCTAssertEqual(v.view2.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.view2.frame.origin.y + v.view2.frame.height, (v.frame.height*0.8), accuracy: 0.5) - XCTAssertEqual(v.view2.frame.width, v.frame.width, accuracy: CGFloat(Float.ulpOfOne)) + #expect(isApproximatelyEqual(v.view1.frame.origin.y, v.frame.height*0.1)) + #expect(v.view1.frame.origin.x == 0) + #expect(v.view1.frame.width == v.frame.width) + #expect(isApproximatelyEqual(v.view2.frame.origin.y, (v.frame.height*0.1) + 20 + (v.frame.height*0.33))) + #expect(v.view2.frame.origin.x == 0) + #expect(isApproximatelyEqual(v.view2.frame.origin.y + v.view2.frame.height, (v.frame.height*0.8))) + #expect(v.view2.frame.width == v.frame.width) } } - -let magicalIphoneXShift = 1.0 From cf866b070c7016ea1a5d07c809b8f1c70e68e599 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 23 Sep 2024 13:52:51 -1000 Subject: [PATCH 18/27] Migrates PositionTests to Testing --- Tests/SteviaTests/CenterTests.swift | 2 +- Tests/SteviaTests/HierarchyTests.swift | 50 ----- Tests/SteviaTests/PositionTests.swift | 269 +++++++++++++------------ 3 files changed, 141 insertions(+), 180 deletions(-) diff --git a/Tests/SteviaTests/CenterTests.swift b/Tests/SteviaTests/CenterTests.swift index babc74e..1b8c448 100644 --- a/Tests/SteviaTests/CenterTests.swift +++ b/Tests/SteviaTests/CenterTests.swift @@ -138,5 +138,5 @@ import Stevia } func isApproximatelyEqual(_ a: Double, _ b: Double) -> Bool { - return a.isApproximatelyEqual(to: b, absoluteTolerance: 0.3) + return a.isApproximatelyEqual(to: b, absoluteTolerance: 0.5) } diff --git a/Tests/SteviaTests/HierarchyTests.swift b/Tests/SteviaTests/HierarchyTests.swift index ad4ef33..c8d384a 100644 --- a/Tests/SteviaTests/HierarchyTests.swift +++ b/Tests/SteviaTests/HierarchyTests.swift @@ -13,56 +13,6 @@ import Stevia @Suite @MainActor struct HierarchyTests { - - @Test - func legacySv() { - let view = UIView() - let v1 = UIView() - let v2 = UIView() - view.sv( - v1, - v2 - ) - #expect(view.subviews.count == 2) - #expect(view.subviews.contains(v1)) - #expect(view.subviews.contains(v2)) - #expect(v1.translatesAutoresizingMaskIntoConstraints == false) - #expect(v2.translatesAutoresizingMaskIntoConstraints == false) - } - - @Test - func legacyTableViewCellSV() { - let cell = UITableViewCell() - let v1 = UIView() - let v2 = UIView() - cell.sv( - v1, - v2 - ) - #expect(cell.contentView.subviews.count == 2) - #expect(cell.contentView.subviews.contains(v1)) - #expect(cell.contentView.subviews.contains(v2)) - #expect(v1.translatesAutoresizingMaskIntoConstraints == false) - #expect(v2.translatesAutoresizingMaskIntoConstraints == false) - } - - @Test - func legacyCollectionViewCellSV() { - let cell = UICollectionViewCell() - let v1 = UIView() - let v2 = UIView() - cell.sv( - v1, - v2 - ) - #expect(cell.contentView.subviews.count == 2) - #expect(cell.contentView.subviews.contains(v1)) - #expect(cell.contentView.subviews.contains(v2)) - #expect(v1.translatesAutoresizingMaskIntoConstraints == false) - #expect(v2.translatesAutoresizingMaskIntoConstraints == false) - } - - // Function Builders version @Test func subviews() { diff --git a/Tests/SteviaTests/PositionTests.swift b/Tests/SteviaTests/PositionTests.swift index a98aaf9..ac9286d 100644 --- a/Tests/SteviaTests/PositionTests.swift +++ b/Tests/SteviaTests/PositionTests.swift @@ -6,271 +6,282 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class PositionTests: XCTestCase { +@Suite +@MainActor class PositionTests { - var win: UIWindow! - var ctrler: UIViewController! - var v: UIView! + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() + let v = UIView() - override func setUp() async throws { -// super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler - v = UIView() - ctrler.view.subviews { v! } + ctrler.view.subviews { v } v.size(100.0) } - - override func tearDown() { - super.tearDown() - } - + + @Test func testTopDouble() { v.top(Double(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testTopCGFloat() { v.top(CGFloat(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testTopInt() { v.top(Int(23)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 23, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 23) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testBottomDouble() { v.bottom(Double(45)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - v.frame.height - 45, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == ctrler.view.frame.height - v.frame.height - 45) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testBottomCGFloat() { v.bottom(CGFloat(45)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - v.frame.height - 45, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == ctrler.view.frame.height - v.frame.height - 45) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testBottomInt() { v.bottom(Int(45)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height - v.frame.height - 45, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == ctrler.view.frame.height - v.frame.height - 45) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLeftDouble() { v.left(Double(12)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 12, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 12) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLeftCGFloat() { v.left(CGFloat(12)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 12, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 12) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLeftInt() { v.left(Int(12)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 12, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 12) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLeadingDouble() { v.leading(Double(12)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 12, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 12) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLeadingCGFloat() { v.leading(CGFloat(12)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 12, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 12) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testLeadingInt() { v.leading(Int(12)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 12, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 12) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testRightDouble() { v.right(Double(74)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testRightCGFloat() { v.right(CGFloat(74)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testRightInt() { v.right(Int(74)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testTrailingDouble() { v.trailing(Double(74)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testTrailingCGFloat() { v.trailing(CGFloat(74)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testTrailingInt() { v.trailing(Int(74)) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 74, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 74) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentTop() { v.top(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height * (10/100) , accuracy: CGFloat(0.3)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(isApproximatelyEqual(v.frame.origin.y, ctrler.view.frame.height * 0.1)) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentBottom() { v.bottom(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, ctrler.view.frame.height * (90/100) - v.frame.height, accuracy: CGFloat(0.3)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(isApproximatelyEqual(v.frame.origin.y, ctrler.view.frame.height * 0.9 - v.frame.height)) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentLeft() { v.left(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0 , accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width * (10/100), accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width * 0.1)) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentRight() { v.right(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0 , accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width * (90/100) - v.frame.width, accuracy: CGFloat(0.2)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width * 0.9 - v.frame.width)) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentLeading() { v.leading(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0 , accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width * (10/100), accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width * 0.1)) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentTrailing() { v.trailing(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0 , accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width * (90/100) - v.frame.width, accuracy: CGFloat(0.2)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width * 0.9 - v.frame.width)) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentLeadingRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v.leading(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0 , accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width * (90/100) - v.frame.width, accuracy: CGFloat(0.2)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, (ctrler.view.frame.width * 0.9 - v.frame.width))) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } + @Test func testPercentTrailingRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v.trailing(10%) ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0 , accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width * (10/100), accuracy: CGFloat(0.1)) - XCTAssertEqual(v.frame.width, 100, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(isApproximatelyEqual(v.frame.origin.x, ctrler.view.frame.width * 0.1)) + #expect(v.frame.width == 100) + #expect(v.frame.height == 100) } } From d22d7c9f416923a8fc13a7200443c2e9d2c887d7 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Tue, 24 Sep 2024 07:08:06 -1000 Subject: [PATCH 19/27] Migrates LayoutTests to Testing --- Tests/SteviaTests/LayoutTests.swift | 779 ++++++++++++++-------------- 1 file changed, 390 insertions(+), 389 deletions(-) diff --git a/Tests/SteviaTests/LayoutTests.swift b/Tests/SteviaTests/LayoutTests.swift index 2a3bf42..f719c16 100644 --- a/Tests/SteviaTests/LayoutTests.swift +++ b/Tests/SteviaTests/LayoutTests.swift @@ -6,29 +6,23 @@ // Copyright © 2016 Sacha Durand Saint Omer. All rights reserved. // -import XCTest +import Testing +import UIKit import Stevia -@MainActor class LayoutTests: XCTestCase { +@Suite +@MainActor class LayoutTests { - var win: UIWindow! - var ctrler: UIViewController! - var v: UIView! + let win = UIWindow(frame: UIScreen.main.bounds) + let ctrler = UIViewController() + let v = UIView() - override func setUp() async throws { -// super.setUp() - win = UIWindow(frame: UIScreen.main.bounds) - ctrler = UIViewController() + init() { win.rootViewController = ctrler - v = UIView() - ctrler.view.subviews { v! } - verifyViewHasDefaultValues() - } - - override func tearDown() { - super.tearDown() + ctrler.view.subviews { v } } + @Test func testComplexLayout() { let featureA = UIView() let featureB = UIView() @@ -40,218 +34,233 @@ import Stevia //align(horizontally: |-6-feature1-2-feature2-6-|) } + @Test func testEmptyLeftMargin() { |v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testEmptyLeftMarginRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft |v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testDefaultMargin() { |-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 8, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 8) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testDefaultMarginRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft |-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 8, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - 8) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testLeftMarginDouble() { |-Double(75)-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 75, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 75) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testLeftMarginCGFloat() { |-CGFloat(75)-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 75, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 75) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testLeftMarginInt() { |-Int(75)-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 75, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 75) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testLeftMarginRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft |-75-v ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - 75, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - 75) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testEmptyRightMargin() { v| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testEmptyRightMarginRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testDefaultRightMargin() { v-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 8, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 8) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testDefaultRightMarginRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 8, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 8) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testRightMarginDouble() { v-Double(14)-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 14, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 14) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testRightMarginCGFloat() { v-CGFloat(14)-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 14, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 14) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testRightMarginInt() { v-Int(14)-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, ctrler.view.frame.width - v.frame.width - 14, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == ctrler.view.frame.width - v.frame.width - 14) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testRightMarginRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft v-14-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 14, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 14) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } + @Test func testHeightDouble() { v ~ Double(180) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 180, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == 180) } + @Test func testHeightCGFloat() { v ~ CGFloat(180) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 180, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == 180) } + @Test func testHeightInt() { v ~ Int(180) ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 180, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == 180) } + @Test func testHeightPercentageDouble() { v ~ Double(25)% ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, ctrler.view.frame.height*0.25, accuracy: 0.5) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == ctrler.view.frame.height*0.25) } + @Test func testHeightPercentageCGFloat() { v ~ CGFloat(25)% ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, ctrler.view.frame.height*0.25, accuracy: 0.5) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == ctrler.view.frame.height*0.25) } + @Test func testHeightPercentageInt() { v ~ Int(25)% ctrler.view.layoutIfNeeded() // This is needed to force auto-layout to kick-in - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, ctrler.view.frame.height*0.25, accuracy: 0.5) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == ctrler.view.frame.height*0.25) } + @Test func testMultipleHeightsAtOnceDouble() { let v1 = UIView() let v2 = UIView() @@ -263,21 +272,22 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } [v1, v2, v3] ~ Double(63) ctrler.view.layoutIfNeeded() for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 63, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 63) } } + @Test func testMultipleHeightsAtOnceCGFloat() { let v1 = UIView() let v2 = UIView() @@ -289,21 +299,22 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } [v1, v2, v3] ~ CGFloat(63) ctrler.view.layoutIfNeeded() for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 63, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 63) } } + @Test func testMultipleHeightsAtOnceInt() { let v1 = UIView() let v2 = UIView() @@ -315,21 +326,22 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } [v1, v2, v3] ~ Int(63) ctrler.view.layoutIfNeeded() for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 63, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 63) } } + @Test func testDefaultMarginBetweenTwoViews() { let v1 = UIView() let v2 = UIView() @@ -339,25 +351,26 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 18, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 18) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testDefaultMarginBetweenTwoViewsRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft let v1 = UIView() @@ -368,25 +381,26 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, ctrler.view.frame.width - 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - 10) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, ctrler.view.frame.width - 10 - 8, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - 10 - 8) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testMarginBetweenTwoViewsDouble() { let v1 = UIView() let v2 = UIView() @@ -396,25 +410,26 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } let m: Double = 52 |v1.width(10)-m-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 62, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 62) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testMarginBetweenTwoViewsCGFloat() { let v1 = UIView() let v2 = UIView() @@ -424,24 +439,24 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } let m: CGFloat = 52 |v1.width(10)-m-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 62, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 62) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } func testMarginBetweenTwoViewsInt() { @@ -453,26 +468,27 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } let m: Int = 52 |v1.width(10)-m-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 62, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 62) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } - + + @Test func testMarginBetweenTwoViewsRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft let v1 = UIView() @@ -483,24 +499,25 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(10)-52-v2 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, ctrler.view.frame.width - 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - 10) + #expect(v1.frame.width == 10) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, ctrler.view.frame.width - 10 - 52, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - 10 - 52) + #expect(v2.frame.width == 0) + #expect(v2.frame.height == 0) } + @Test func testArrayRightConstraint() { let v1 = UIView() let v2 = UIView() @@ -510,30 +527,26 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } v1-52-v2.width(10)-31-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, - ctrler.view.frame.width - 31 - v2.frame.width - 52, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, - ctrler.view.frame.width - 31 - v2.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - 31 - v2.frame.width - 52) + #expect(v1.frame.width == 0) + #expect(v1.frame.height == 0) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - 31 - v2.frame.width) + #expect(v2.frame.width == 10) + #expect(v2.frame.height == 0) } - + + @Test func testArrayRightConstraintRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft let v1 = UIView() @@ -544,25 +557,23 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } v1-52-v2.width(10)-31-| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 31 + v2.frame.width + 52, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 31, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 31 + v2.frame.width + 52) + #expect(v1.frame.width == 0) + #expect(v1.frame.height == 0) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 31) + #expect(v2.frame.width == 10) + #expect(v2.frame.height == 0) } func testDefaultMarginBetweenThreeViews() { @@ -576,32 +587,30 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } - |v1.width(20)⁃v2.width(20)⁃v3 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 28, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.x, v2.frame.origin.x + v2.frame.width + 8, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 28) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) + #expect(v3.frame.origin.y == 0) + #expect(v3.frame.origin.x == v2.frame.origin.x + v2.frame.width + 8) + #expect(v3.frame.width == 0) + #expect(v3.frame.height == 0) } + @Test func testMarginsBetweenThreeViewsDouble() { let v1 = UIView() let v2 = UIView() @@ -613,10 +622,10 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } let m1: Double = 43 @@ -624,24 +633,23 @@ import Stevia |v1.width(20)-m1-v2.width(20)-m2-v3 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, v1.frame.origin.x + v1.frame.width + 43, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.x, v2.frame.origin.x + v2.frame.width + 27, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == v1.frame.origin.x + v1.frame.width + 43) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) + #expect(v3.frame.origin.y == 0) + #expect(v3.frame.origin.x == v2.frame.origin.x + v2.frame.width + 27) + #expect(v3.frame.width == 0) + #expect(v3.frame.height == 0) } - + + @Test func testMarginsBetweenThreeViewsCGFloat() { let v1 = UIView() let v2 = UIView() @@ -653,10 +661,10 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } let m1: CGFloat = 43 @@ -664,24 +672,22 @@ import Stevia |v1.width(20)-m1-v2.width(20)-m2-v3 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, v1.frame.origin.x + v1.frame.width + 43, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.x, v2.frame.origin.x + v2.frame.width + 27, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == v1.frame.origin.x + v1.frame.width + 43) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) + #expect(v3.frame.origin.y == 0) + #expect(v3.frame.origin.x == v2.frame.origin.x + v2.frame.width + 27) + #expect(v3.frame.width == 0) + #expect(v3.frame.height == 0) } - + + @Test func testMarginsBetweenThreeViewsInt() { let v1 = UIView() let v2 = UIView() @@ -693,10 +699,10 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } let m1: Int = 43 @@ -704,22 +710,19 @@ import Stevia |v1.width(20)-m1-v2.width(20)-m2-v3 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, v1.frame.origin.x + v1.frame.width + 43, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.x, v2.frame.origin.x + v2.frame.width + 27, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == v1.frame.origin.x + v1.frame.width + 43) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) + #expect(v3.frame.origin.y == 0) + #expect(v3.frame.origin.x == v2.frame.origin.x + v2.frame.width + 27) + #expect(v3.frame.width == 0) + #expect(v3.frame.height == 0) } func testMarginsBetweenThreeViewsRTL() { @@ -734,32 +737,31 @@ import Stevia v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(20)-43-v2.width(20)-27-v3 ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, ctrler.view.frame.width - 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, ctrler.view.frame.width - v1.frame.width - 43 - v2.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.x, ctrler.view.frame.width - v1.frame.width - 43 - v2.frame.width - 27, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) - + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - 20) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) + + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - v1.frame.width - 43 - v2.frame.width) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) + #expect(v3.frame.origin.y == 0) + let val = ctrler.view.frame.width - v1.frame.width - 43 - v2.frame.width - 27 + #expect(v3.frame.origin.x == val) + #expect(v3.frame.width == 0) + #expect(v3.frame.height == 0) } - + + @Test func testSpaceBetweenTwoViews() { let v1 = UIView() let v2 = UIView() @@ -769,27 +771,27 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(20)-""-v2.width(20)| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, ctrler.view.frame.width - v2.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == ctrler.view.frame.width - v2.frame.width) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) } - + + @Test func testSpaceBetweenTwoViewsRTL() { ctrler.view.semanticContentAttribute = .forceRightToLeft let v1 = UIView() @@ -800,27 +802,27 @@ import Stevia v2 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(20)-""-v2.width(20)| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, ctrler.view.frame.width - v1.frame.width, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == ctrler.view.frame.width - v1.frame.width) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, 0, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == 0) + #expect(v2.frame.width == 20) + #expect(v2.frame.height == 0) } - + + @Test func testSpaceWithArrayOfViews() { let v1 = UIView() let v2 = UIView() @@ -828,37 +830,36 @@ import Stevia v.removeFromSuperview() ctrler.view.subviews { v1; v2; v3 } for view in ctrler.view.subviews { - XCTAssertEqual(view.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(view.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(view.frame.origin.y == 0) + #expect(view.frame.origin.x == 0) + #expect(view.frame.width == 0) + #expect(view.frame.height == 0) } |v1.width(20)-v2.width(30)-""-v3.width(10)| ctrler.view.layoutIfNeeded() - XCTAssertEqual(v1.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.width, 20, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v1.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v1.frame.origin.y == 0) + #expect(v1.frame.origin.x == 0) + #expect(v1.frame.width == 20) + #expect(v1.frame.height == 0) - XCTAssertEqual(v2.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.origin.x, v1.frame.width + 8, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.width, 30, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v2.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v2.frame.origin.y == 0) + #expect(v2.frame.origin.x == v1.frame.width + 8) + #expect(v2.frame.width == 30) + #expect(v2.frame.height == 0) - XCTAssertEqual(v3.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.origin.x, ctrler.view.frame.width - v3.frame.width, - accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.width, 10, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v3.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v3.frame.origin.y == 0) + #expect(v3.frame.origin.x == ctrler.view.frame.width - v3.frame.width) + #expect(v3.frame.width == 10) + #expect(v3.frame.height == 0) } + @Test func verifyViewHasDefaultValues() { - XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.width, 0, accuracy: CGFloat(Float.ulpOfOne)) - XCTAssertEqual(v.frame.height, 0, accuracy: CGFloat(Float.ulpOfOne)) + #expect(v.frame.origin.y == 0) + #expect(v.frame.origin.x == 0) + #expect(v.frame.width == 0) + #expect(v.frame.height == 0) } } From f8341099541879f489688ad502494d1372b7519a Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Tue, 24 Sep 2024 07:11:42 -1000 Subject: [PATCH 20/27] Removes legacy XCTest files --- Tests/LinuxMain.swift | 7 ------- Tests/SteviaTests/XCTestManifests.swift | 9 --------- 2 files changed, 16 deletions(-) delete mode 100644 Tests/LinuxMain.swift delete mode 100644 Tests/SteviaTests/XCTestManifests.swift diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index 65669b2..0000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,7 +0,0 @@ -import XCTest - -import SteviaTests - -var tests = [XCTestCaseEntry]() -tests += SteviaTests.allTests() -XCTMain(tests) diff --git a/Tests/SteviaTests/XCTestManifests.swift b/Tests/SteviaTests/XCTestManifests.swift deleted file mode 100644 index 3910b00..0000000 --- a/Tests/SteviaTests/XCTestManifests.swift +++ /dev/null @@ -1,9 +0,0 @@ -import XCTest - -#if !canImport(ObjectiveC) -public func allTests() -> [XCTestCaseEntry] { - return [ - testCase(SteviaTests.allTests), - ] -} -#endif From 2a935e2cb50663c00ef1cce2070ec11fada9e7c3 Mon Sep 17 00:00:00 2001 From: Jezreel Barbosa Date: Fri, 1 Nov 2024 20:31:41 -0400 Subject: [PATCH 21/27] Implemented aspectRatio function with SteviaPercentage --- Sources/Stevia/Stevia+Percentage.swift | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Sources/Stevia/Stevia+Percentage.swift b/Sources/Stevia/Stevia+Percentage.swift index fa0d153..907280a 100644 --- a/Sources/Stevia/Stevia+Percentage.swift +++ b/Sources/Stevia/Stevia+Percentage.swift @@ -27,6 +27,28 @@ public postfix func % (v: Int) -> SteviaPercentage { } public extension UIView { + + /** + Adds an Autolayout constraint to provide the aspect ratio for the view. + + ``` + image.aspectRatio(3/2) + image.aspectRatio(150%) + + // is equivalent to + + image.Width == image.Height * 1.5 + image.Width == 150 % image.Height + ``` + + - Returns: Itself, enabling chaining, + + */ + @discardableResult + func aspectRatio(_ p: SteviaPercentage) -> Self { + Width == p.value % Height + return self + } /** Adds an Autolayout constraint for sizing the view. From 71591609977ad27e24d52b21bd58d67ffebc25c8 Mon Sep 17 00:00:00 2001 From: Jezreel Barbosa Date: Fri, 1 Nov 2024 20:33:03 -0400 Subject: [PATCH 22/27] Implemented aspectRatio function with Double, CGFloat and Int types --- Sources/Stevia/Stevia+Size.swift | 68 +++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/Sources/Stevia/Stevia+Size.swift b/Sources/Stevia/Stevia+Size.swift index 24fd2d5..7c080e6 100644 --- a/Sources/Stevia/Stevia+Size.swift +++ b/Sources/Stevia/Stevia+Size.swift @@ -10,7 +10,73 @@ import UIKit public extension UIView { - + + /** + Adds an Autolayout constraint to provide the aspect ratio for the view. + + ``` + image.aspectRatio(3.0/2.0) + image.aspectRatio(150%) + + // is equivalent to + + image.Width == image.Height * 1.5 + image.Width == 150 % image.Height + ``` + + - Returns: Itself, enabling chaining, + + */ + @discardableResult + func aspectRatio(_ ratio: Double = 1) -> Self { + Width == Height * ratio + return self + } + + /** + Adds an Autolayout constraint to provide the aspect ratio for the view. + + ``` + image.aspectRatio(3.0/2.0) + image.aspectRatio(150%) + + // is equivalent to + + image.Width == image.Height * 1.5 + image.Width == 150 % image.Height + ``` + + - Returns: Itself, enabling chaining, + + */ + @discardableResult + func aspectRatio(_ ratio: CGFloat = 1) -> Self { + aspectRatio(Double(ratio)) + return self + } + + /** + Adds an Autolayout constraint to provide the aspect ratio for the view. + + ``` + image.aspectRatio(3.0/2.0) + image.aspectRatio(150%) + + // is equivalent to + + image.Width == image.Height * 1.5 + image.Width == 150 % image.Height + ``` + + - Returns: Itself, enabling chaining, + + */ + @discardableResult + func aspectRatio(_ ratio: Int = 1) -> Self { + aspectRatio(Double(ratio)) + return self + } + /** Adds an Autolayout constraint for sizing the view. From c1bbae28febe65e1083e1179a0f4c64a0a243a40 Mon Sep 17 00:00:00 2001 From: Jezreel Barbosa Date: Fri, 1 Nov 2024 20:33:50 -0400 Subject: [PATCH 23/27] Implemented tests for AspectRatio --- Tests/SteviaTests/SizeTests.swift | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Tests/SteviaTests/SizeTests.swift b/Tests/SteviaTests/SizeTests.swift index b1b6fef..acf1b04 100644 --- a/Tests/SteviaTests/SizeTests.swift +++ b/Tests/SteviaTests/SizeTests.swift @@ -29,6 +29,42 @@ class SizeTests: XCTestCase { override func tearDown() { super.tearDown() } + + func testAspectRatioDouble() { + v.width(150).aspectRatio(Double(3.0/2.0)) + ctrler.view.layoutIfNeeded() + XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.width, 150, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + } + + func testAspectRatioCGFloat() { + v.width(150).aspectRatio(CGFloat(3.0/2.0)) + ctrler.view.layoutIfNeeded() + XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.width, 150, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + } + + func testAspectRatioInt() { + v.width(150).aspectRatio(Int(3)) + ctrler.view.layoutIfNeeded() + XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.width, 150, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.height, 50, accuracy: CGFloat(Float.ulpOfOne)) + } + + func testAspectRatioPercentage() { + v.width(150).aspectRatio(150%) + ctrler.view.layoutIfNeeded() + XCTAssertEqual(v.frame.origin.y, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.origin.x, 0, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.width, 150, accuracy: CGFloat(Float.ulpOfOne)) + XCTAssertEqual(v.frame.height, 100, accuracy: CGFloat(Float.ulpOfOne)) + } func testSizeDouble() { v.size(Double(57)) From 04b1d3cc47782072d52abe3f00702d9259a3390d Mon Sep 17 00:00:00 2001 From: Architect <38290412+jezreelbarbosa@users.noreply.github.com> Date: Wed, 6 Nov 2024 15:45:05 -0400 Subject: [PATCH 24/27] Update SizeTests.swift --- Tests/SteviaTests/SizeTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/SteviaTests/SizeTests.swift b/Tests/SteviaTests/SizeTests.swift index fe83fcc..6d6103e 100644 --- a/Tests/SteviaTests/SizeTests.swift +++ b/Tests/SteviaTests/SizeTests.swift @@ -51,7 +51,7 @@ import Stevia #expect(v.frame.origin.y == 0) #expect(v.frame.origin.x == 0) #expect(v.frame.width == 150) - #expect(v.frame.height == 100) + #expect(v.frame.height == 50) } @Test From 234033eded7d1ca76803fe8c24311d42f5b57c30 Mon Sep 17 00:00:00 2001 From: zhangtao Date: Tue, 31 Dec 2024 11:12:45 +0800 Subject: [PATCH 25/27] Add the `SteviaLayoutConstraint` class to allow the removal of constraints added by Stevia. Introduce the `defaultPriority` customizable property to facilitate integration with Stevia, enabling the setting of higher priorities. --- Sources/Stevia/Stevia+Constraints.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Sources/Stevia/Stevia+Constraints.swift b/Sources/Stevia/Stevia+Constraints.swift index eac541d..1b863d5 100644 --- a/Sources/Stevia/Stevia+Constraints.swift +++ b/Sources/Stevia/Stevia+Constraints.swift @@ -9,6 +9,11 @@ #if canImport(UIKit) import UIKit +public class SteviaLayoutConstraint: NSLayoutConstraint { + public static defaultPriority:Float = UILayoutPriority.defaultHigh + 1 +} + + // MARK: - Shortcut public extension UIView { @@ -76,11 +81,11 @@ public extension UIView { attribute attr2: NSLayoutConstraint.Attribute? = nil, // Not an attribute?? multiplier: Double = 1, constant: Double = 0) -> NSLayoutConstraint { - let c = NSLayoutConstraint(item: view1, attribute: attr1, + let c = SteviaLayoutConstraint(item: view1, attribute: attr1, relatedBy: relatedBy, toItem: view2, attribute: ((attr2 == nil) ? attr1 : attr2! ), multiplier: CGFloat(multiplier), constant: CGFloat(constant)) - c.priority = UILayoutPriority(rawValue: UILayoutPriority.defaultHigh.rawValue + 1) + c.priority = UILayoutPriority(rawValue: SteviaLayoutConstraint.defaultPriority) return c } @@ -98,8 +103,7 @@ public extension UIView { */ var userAddedConstraints: [NSLayoutConstraint] { return constraints.filter { c in - guard let cId = c.identifier else { return true } - return !cId.contains("UIView-Encapsulated-Layout") && !cId.contains("Margin-guide-constraint") + c is SteviaLayoutConstraint } } } From 7eb652374263868ff61f6ba15e0eb3b830289485 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Mon, 6 Jan 2025 14:39:14 -1000 Subject: [PATCH 26/27] Adds missing "var" keyword --- Sources/Stevia/Stevia+Constraints.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Stevia/Stevia+Constraints.swift b/Sources/Stevia/Stevia+Constraints.swift index 1b863d5..fac2fcd 100644 --- a/Sources/Stevia/Stevia+Constraints.swift +++ b/Sources/Stevia/Stevia+Constraints.swift @@ -10,7 +10,7 @@ import UIKit public class SteviaLayoutConstraint: NSLayoutConstraint { - public static defaultPriority:Float = UILayoutPriority.defaultHigh + 1 + public static var defaultPriority: Float = UILayoutPriority.defaultHigh + 1 } From 3b2a9d5f30c01161d7431c679cb6259ca62215de Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 10 Jun 2025 19:18:42 +0200 Subject: [PATCH 27/27] fixes for iOS 26 --- Sources/Stevia/Stevia+Center.swift | 2 +- Sources/Stevia/Stevia+Constraints.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Stevia/Stevia+Center.swift b/Sources/Stevia/Stevia+Center.swift index 471ab88..7362b6d 100644 --- a/Sources/Stevia/Stevia+Center.swift +++ b/Sources/Stevia/Stevia+Center.swift @@ -24,7 +24,7 @@ public extension UIView { @discardableResult func centerInContainer() -> Self { if let spv = superview { - alignCenter(self, with: spv) + Stevia.alignCenter(self, with: spv) } return self } diff --git a/Sources/Stevia/Stevia+Constraints.swift b/Sources/Stevia/Stevia+Constraints.swift index fac2fcd..96b706d 100644 --- a/Sources/Stevia/Stevia+Constraints.swift +++ b/Sources/Stevia/Stevia+Constraints.swift @@ -10,7 +10,7 @@ import UIKit public class SteviaLayoutConstraint: NSLayoutConstraint { - public static var defaultPriority: Float = UILayoutPriority.defaultHigh + 1 + public static var defaultPriority: Float = UILayoutPriority.defaultHigh.rawValue + 1 }