From b22fa0237bcc342b8e05fe93872c715ccdce9427 Mon Sep 17 00:00:00 2001 From: Sacha DSO Date: Sun, 22 Sep 2024 19:36:12 -1000 Subject: [PATCH 01/14] 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 02/14] 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 03/14] 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 04/14] 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 05/14] 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 06/14] 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 07/14] 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 08/14] 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 09/14] 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 10/14] 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 11/14] 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 12/14] 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 13/14] 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 14/14] 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