diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 7784c59..ab057e0 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -9,14 +9,14 @@ jobs: strategy: matrix: destination: ['platform=iOS Simulator,OS=13.1,name=iPhone 8'] - xcode: ['/Applications/Xcode_11.1.app/Contents/Developer'] + xcode: ['/Applications/Xcode_11.6.app/Contents/Developer'] steps: - uses: actions/checkout@v1 # Github Actions' machines do in fact have recent versions of Xcode, # but you may have to explicitly switch to them. We explicitly want # to use Xcode 11, so we use xcode-select to switch to it. - name: Switch to Xcode 11 - run: sudo xcode-select --switch /Applications/Xcode_11.1.app + run: sudo xcode-select --switch /Applications/Xcode_11.6.app # Since we want to be running our tests from Xcode, we need to # generate an .xcodeproj file. Luckly, Swift Package Manager has # build in functionality to do so. diff --git a/.gitignore b/.gitignore index 043dffd..cb39884 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /*.xcodeproj xcuserdata/ build +*.resolved \ No newline at end of file diff --git a/Package.swift b/Package.swift index db925b9..e15a42c 100644 --- a/Package.swift +++ b/Package.swift @@ -14,13 +14,16 @@ let package = Package( dependencies: [ // Dependencies declare other packages that this package depends on. // .package(url: /* package url */, from: "1.0.0"), + .package(url: "https://github.com/0xLeif/Later", from: "0.3.0") ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "SwiftUIKit", - dependencies: []), + dependencies: [ + "Later" + ]), .testTarget( name: "SwiftUIKitTests", dependencies: ["SwiftUIKit"]), diff --git a/Sources/SwiftUIKit/Containers/HStack.swift b/Sources/SwiftUIKit/Containers/HStack.swift index 65804b9..d887537 100644 --- a/Sources/SwiftUIKit/Containers/HStack.swift +++ b/Sources/SwiftUIKit/Containers/HStack.swift @@ -6,12 +6,26 @@ // import UIKit +import Later /// Horizontal StackView @available(iOS 9.0, *) public class HStack: UIView { + deinit { + views.resign() + } + + private var spacing: Float + private var padding: Float + private var alignment: UIStackView.Alignment + private var distribution: UIStackView.Distribution /// The views that the HStack contains - public var views: [UIView] = [] + public lazy var views = Contract<[UIView]>(initialValue: []) + .onChange { [weak self] (views) in + Later.main { + self?.draw(views: views ?? []) + } + } /// Create a HStack /// - Parameters: @@ -25,14 +39,13 @@ public class HStack: UIView { alignment: UIStackView.Alignment = .fill, distribution: UIStackView.Distribution = .fill, _ closure: () -> [UIView]) { - views = closure() + self.spacing = spacing + self.padding = padding + self.alignment = alignment + self.distribution = distribution super.init(frame: .zero) - - hstack(withSpacing: spacing, - padding: padding, - alignment: alignment, - distribution: distribution, - closure) + views.value = closure() + draw(views: views.value ?? []) } /// Create a HStack that accepts an array of UIView? @@ -47,18 +60,26 @@ public class HStack: UIView { alignment: UIStackView.Alignment = .fill, distribution: UIStackView.Distribution = .fill, _ closure: () -> [UIView?]) { - views = closure() - .compactMap { $0 } + self.spacing = spacing + self.padding = padding + self.alignment = alignment + self.distribution = distribution super.init(frame: .zero) - - hstack(withSpacing: spacing, - padding: padding, - alignment: alignment, - distribution: distribution) - { views } + views.value = closure() + .compactMap { $0 } + draw(views: views.value ?? []) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + internal func draw(views: [UIView]) { + clear() + .hstack(withSpacing: spacing, + padding: padding, + alignment: alignment, + distribution: distribution) + { views } + } } diff --git a/Sources/SwiftUIKit/Containers/VStack.swift b/Sources/SwiftUIKit/Containers/VStack.swift index 9ec00d5..54bb19a 100644 --- a/Sources/SwiftUIKit/Containers/VStack.swift +++ b/Sources/SwiftUIKit/Containers/VStack.swift @@ -6,12 +6,26 @@ // import UIKit +import Later /// Vertical StackView @available(iOS 9.0, *) public class VStack: UIView { + deinit { + views.resign() + } + + private var spacing: Float + private var padding: Float + private var alignment: UIStackView.Alignment + private var distribution: UIStackView.Distribution /// The views that the VStack contains - public var views: [UIView] = [] + public lazy var views = Contract<[UIView]>() + .onChange { [weak self] (views) in + Later.main { + self?.draw(views: views ?? []) + } + } /// Create a VStack /// - Parameters: @@ -25,14 +39,13 @@ public class VStack: UIView { alignment: UIStackView.Alignment = .fill, distribution: UIStackView.Distribution = .fill, _ closure: () -> [UIView]) { - views = closure() + self.spacing = spacing + self.padding = padding + self.alignment = alignment + self.distribution = distribution super.init(frame: .zero) - - vstack(withSpacing: spacing, - padding: padding, - alignment: alignment, - distribution: distribution, - closure) + views.value = closure() + draw(views: views.value ?? []) } /// Create a VStack that accepts an array of UIView? @@ -47,18 +60,26 @@ public class VStack: UIView { alignment: UIStackView.Alignment = .fill, distribution: UIStackView.Distribution = .fill, _ closure: () -> [UIView?]) { - views = closure() - .compactMap { $0 } + self.spacing = spacing + self.padding = padding + self.alignment = alignment + self.distribution = distribution super.init(frame: .zero) - - vstack(withSpacing: spacing, - padding: padding, - alignment: alignment, - distribution: distribution) - { views } + views.value = closure() + .compactMap { $0 } + draw(views: views.value ?? []) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } + + internal func draw(views: [UIView]) { + clear() + .vstack(withSpacing: spacing, + padding: padding, + alignment: alignment, + distribution: distribution) + { views } + } } diff --git a/Sources/SwiftUIKit/Extensions/UIAppearance+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UIAppearance+SwiftUIKit.swift new file mode 100644 index 0000000..07b25ef --- /dev/null +++ b/Sources/SwiftUIKit/Extensions/UIAppearance+SwiftUIKit.swift @@ -0,0 +1,18 @@ +// +// UIAppearance+SwiftUIKit.swift +// +// +// Created by Zach Eriksen on 8/25/20. +// + +import UIKit +import Later + +@available(iOS 9.0, *) +public extension UIAppearance where Self: UIView { + func contract(_ closure: (Self) -> Contract) -> ContractView { + ContractView(view: self) { view in + closure(view) + } + } +} diff --git a/Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift new file mode 100644 index 0000000..ac1c28a --- /dev/null +++ b/Sources/SwiftUIKit/Extensions/UILabel+SwiftUIKit.swift @@ -0,0 +1,24 @@ +// +// UILabel+SwiftUIKit.swift +// SwiftUIKit +// +// Created by Zach Eriksen on 7/7/20. +// + +import UIKit + +public extension UILabel { + @discardableResult + func text(color: UIColor?) -> Self { + textColor = color + + return self + } + + @discardableResult + func text(_ value: String?) -> Self { + text = value + + return self + } +} diff --git a/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift index 06a6043..d458de4 100644 --- a/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift +++ b/Sources/SwiftUIKit/Extensions/UITextField+SwiftUIKit.swift @@ -14,4 +14,11 @@ public extension UITextField { return self } + + @discardableResult + func text(_ value: String?) -> Self { + text = value + + return self + } } diff --git a/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift b/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift index 41f3b14..c788848 100644 --- a/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift +++ b/Sources/SwiftUIKit/Extensions/UITextView+SwiftUIKit.swift @@ -15,6 +15,13 @@ public extension UITextView { return self } + @discardableResult + func text(_ value: String?) -> Self { + text = value + + return self + } + @discardableResult func tint(color: UIColor?) -> Self { tintColor = color diff --git a/Sources/SwiftUIKit/Extensions/UIView+Later.swift b/Sources/SwiftUIKit/Extensions/UIView+Later.swift new file mode 100644 index 0000000..9b43ae6 --- /dev/null +++ b/Sources/SwiftUIKit/Extensions/UIView+Later.swift @@ -0,0 +1,87 @@ +// +// UIView+Later.swift +// SwiftUIKit +// +// Created by Zach Eriksen on 8/26/20. +// + +import UIKit +import Later + +@available(iOS 9.0, *) +public extension UIView { + static func later(_ laterView: (Later.Type) -> LaterValue) -> UIView { + let view = UIView() + + view.center { + LoadingView() + .start() + } + + laterView(Later.self) + .whenSuccess { embeddedView in + Later.main { + view.clear() + .embed { + embeddedView + } + } + + } + + return view + } + + static func later(centeredLoadingView: UIView, + withSize size: CGSize? = nil, + _ laterView: (Later.Type) -> LaterValue) -> UIView { + + let view = UIView() + + view.center { + centeredLoadingView + .configure { + if let size = size { + $0.frame(height: Float(size.height), + width: Float(size.width)) + } + } + } + + laterView(Later.self) + .whenSuccess { embeddedView in + Later.main { + view.clear() + .embed { + embeddedView + } + } + + } + + return view + } + + static func later(embeddedLoadingView: UIView, + withPadding padding: Float = 0, + _ laterView: (Later.Type) -> LaterValue) -> UIView { + let view = UIView() + + view.embed(withPadding: padding) { + embeddedLoadingView + } + + laterView(Later.self) + .whenSuccess { embeddedView in + Later.main { + view.clear() + .embed { + embeddedView + } + } + + } + + return view + } +} diff --git a/Sources/SwiftUIKit/Views/Button.swift b/Sources/SwiftUIKit/Views/Button.swift index dba3077..d6ae60f 100644 --- a/Sources/SwiftUIKit/Views/Button.swift +++ b/Sources/SwiftUIKit/Views/Button.swift @@ -9,13 +9,13 @@ import UIKit @available(iOS 9.0, *) public class Button: UIButton { - private var action: () -> Void + private var action: (() -> Void)? public init(_ title: String, titleColor: UIColor? = nil, backgroundColor: UIColor? = nil, forEvent event: UIControl.Event = .touchUpInside, - _ action: @escaping () -> Void) { + _ action: (() -> Void)? = nil) { self.action = action super.init(frame: .zero) @@ -27,7 +27,7 @@ public class Button: UIButton { accessibility(label: title, traits: .button) } - public init(_ action: @escaping () -> Void, + public init(action: (() -> Void)? = nil, forEvent event: UIControl.Event = .touchUpInside, _ closure: () -> UIView) { self.action = action @@ -41,11 +41,18 @@ public class Button: UIButton { self.addTarget(self, action: #selector(handleButtonTap), for: event) } + @discardableResult + public func setAction(_ action: (() -> Void)?) -> Self { + self.action = action + + return self + } + required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } @objc private func handleButtonTap() { - action() + action?() } } diff --git a/Sources/SwiftUIKit/Views/ContractView.swift b/Sources/SwiftUIKit/Views/ContractView.swift new file mode 100644 index 0000000..99885af --- /dev/null +++ b/Sources/SwiftUIKit/Views/ContractView.swift @@ -0,0 +1,30 @@ +// +// ContractView.swift +// +// +// Created by Zach Eriksen on 8/25/20. +// + +import UIKit +import Later + +@available(iOS 9.0, *) +public class ContractView: UIView where View: UIView { + public var contract: Contract? + + public init(view: View, _ closure: (View) -> Contract) { + super.init(frame: .zero) + + self.contract = closure(view) + + embed { + view + } + + contract?.value = contract?.value + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/Sources/SwiftUIKit/Views/NavButton.swift b/Sources/SwiftUIKit/Views/NavButton.swift index 71590c4..67eca07 100644 --- a/Sources/SwiftUIKit/Views/NavButton.swift +++ b/Sources/SwiftUIKit/Views/NavButton.swift @@ -40,7 +40,7 @@ public class NavButton: Button { self.destination = destination self.style = style - super.init({ + super.init(action: { tapHandler?() Navigate.shared.go(destination(), style: style) diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift deleted file mode 100644 index 714cbb4..0000000 --- a/Tests/LinuxMain.swift +++ /dev/null @@ -1,7 +0,0 @@ -import XCTest - -import SwiftUIKitTests - -var tests = [XCTestCaseEntry]() -tests += SwiftUIKitTests.allTests() -XCTMain(tests) diff --git a/Tests/SwiftUIKitTests/ADA/BasicADATests.swift b/Tests/SwiftUIKitTests/ADA/BasicADATests.swift index 4eadd75..02c55f4 100644 --- a/Tests/SwiftUIKitTests/ADA/BasicADATests.swift +++ b/Tests/SwiftUIKitTests/ADA/BasicADATests.swift @@ -20,18 +20,18 @@ final class BasicADATests: XCTestCase { .padding() .debug() - assert(label.accessibilityLabel == "SomeString") - assert(label.accessibilityIdentifier == "SomeID") - assert(label.accessibilityTraits == .staticText) + XCTAssertEqual(label.accessibilityLabel, "SomeString") + XCTAssertEqual(label.accessibilityIdentifier, "SomeID") + XCTAssertEqual(label.accessibilityTraits, .staticText) } func testButtonADA() { let button = Button("SomeString") { print("Hello") } .accessibility(label: nil) - assert(button.accessibilityLabel == "SomeString") - assert(button.accessibilityIdentifier == nil) - assert(button.accessibilityTraits == .button) + XCTAssertEqual(button.accessibilityLabel, "SomeString") + XCTAssertEqual(button.accessibilityIdentifier, nil) + XCTAssertEqual(button.accessibilityTraits, .button) } func testComplexViewADA() { @@ -49,15 +49,9 @@ final class BasicADATests: XCTestCase { let accessibilityLabels = ["Hello World", "Ipsum"] - assert(view.allSubviews.compactMap { $0.accessibilityLabel } == accessibilityLabels) - assert(view.accessibilityIdentifier == "mainView") - assert(view.accessibilityTraits == .none) - assert(view.shouldGroupAccessibilityChildren == false) + XCTAssertEqual(view.allSubviews.compactMap { $0.accessibilityLabel }, accessibilityLabels) + XCTAssertEqual(view.accessibilityIdentifier, "mainView") + XCTAssertEqual(view.accessibilityTraits, .none) + XCTAssertEqual(view.shouldGroupAccessibilityChildren, false) } - - static var allTests = [ - ("testLabelADA", testLabelADA), - ("testButtonADA", testButtonADA), - ("testComplexViewADA", testComplexViewADA) - ] } diff --git a/Tests/SwiftUIKitTests/Core/BasicSwiftUIKitTests.swift b/Tests/SwiftUIKitTests/Core/BasicSwiftUIKitTests.swift index 655dc4f..dfa2698 100644 --- a/Tests/SwiftUIKitTests/Core/BasicSwiftUIKitTests.swift +++ b/Tests/SwiftUIKitTests/Core/BasicSwiftUIKitTests.swift @@ -7,6 +7,7 @@ import Foundation import XCTest +import Later @testable import SwiftUIKit @available(iOS 10.0, *) @@ -17,8 +18,8 @@ final class BasicSwiftUIKitTests: XCTestCase { let view = UIView() XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 0) - XCTAssert(view.constraints.count == 0) + XCTAssertEqual(view.allSubviews.count, 0) + XCTAssertEqual(view.constraints.count, 0) } func testEmbedView() { @@ -37,8 +38,8 @@ final class BasicSwiftUIKitTests: XCTestCase { let topConstraint = view.topConstraints.first XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 1) - XCTAssert(view.constraints.count == 4) + XCTAssertEqual(view.allSubviews.count, 1) + XCTAssertEqual(view.constraints.count, 4) XCTAssertEqual(leadingConstraint?.constant, 0) XCTAssertEqual(bottomConstraint?.constant, 0) XCTAssertEqual(trailingConstraint?.constant, 0) @@ -46,7 +47,7 @@ final class BasicSwiftUIKitTests: XCTestCase { view.update(padding: 16) - XCTAssert(view.constraints.count == 4) + XCTAssertEqual(view.constraints.count, 4) XCTAssertEqual(leadingConstraint?.constant, 16) XCTAssertEqual(bottomConstraint?.constant, -16) XCTAssertEqual(trailingConstraint?.constant, -16) @@ -68,8 +69,8 @@ final class BasicSwiftUIKitTests: XCTestCase { let constraint = view.leadingConstraints.first XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 1) - XCTAssert(view.constraints.count == 1) + XCTAssertEqual(view.allSubviews.count, 1) + XCTAssertEqual(view.constraints.count, 1) XCTAssertEqual(constraint?.constant, 16) view.update(padding: .leading(8)) @@ -96,15 +97,15 @@ final class BasicSwiftUIKitTests: XCTestCase { let bottomConstraint = view.bottomConstraints.first XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 1) - XCTAssert(view.constraints.count == 2) + XCTAssertEqual(view.allSubviews.count, 1) + XCTAssertEqual(view.constraints.count, 2) XCTAssertEqual(leadingConstraint?.constant, 16) XCTAssertEqual(bottomConstraint?.constant, -16) view.update(padding: .leading(8)) view.update(padding: .bottom(32)) - XCTAssert(view.constraints.count == 2) + XCTAssertEqual(view.constraints.count, 2) XCTAssertEqual(leadingConstraint?.constant, 8) XCTAssertEqual(bottomConstraint?.constant, -32) } @@ -128,15 +129,15 @@ final class BasicSwiftUIKitTests: XCTestCase { let trailingConstraint = view.trailingConstraints.first XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 1) - XCTAssert(view.constraints.count == 3) + XCTAssertEqual(view.allSubviews.count, 1) + XCTAssertEqual(view.constraints.count, 3) XCTAssertEqual(leadingConstraint?.constant, 16) XCTAssertEqual(bottomConstraint?.constant, -16) XCTAssertEqual(trailingConstraint?.constant, -16) view.update(padding: [.leading(32), .trailing(32), .bottom(32)]) - XCTAssert(view.constraints.count == 3) + XCTAssertEqual(view.constraints.count, 3) XCTAssertEqual(leadingConstraint?.constant, 32) XCTAssertEqual(bottomConstraint?.constant, -32) XCTAssertEqual(trailingConstraint?.constant, -32) @@ -163,8 +164,8 @@ final class BasicSwiftUIKitTests: XCTestCase { let topConstraint = view.topConstraints.first XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 1) - XCTAssert(view.constraints.count == 4) + XCTAssertEqual(view.allSubviews.count, 1) + XCTAssertEqual(view.constraints.count, 4) XCTAssertEqual(leadingConstraint?.constant, 16) XCTAssertEqual(bottomConstraint?.constant, -16) XCTAssertEqual(trailingConstraint?.constant, -16) @@ -172,7 +173,7 @@ final class BasicSwiftUIKitTests: XCTestCase { view.update(padding: 32) - XCTAssert(view.constraints.count == 4) + XCTAssertEqual(view.constraints.count, 4) XCTAssertEqual(leadingConstraint?.constant, 32) XCTAssertEqual(bottomConstraint?.constant, -32) XCTAssertEqual(trailingConstraint?.constant, -32) @@ -192,8 +193,8 @@ final class BasicSwiftUIKitTests: XCTestCase { } XCTAssertNil(view.backgroundColor) - XCTAssert(view.allSubviews.count == 2) - XCTAssert(view.constraints.count == 4) + XCTAssertEqual(view.allSubviews.count, 2) + XCTAssertEqual(view.constraints.count, 4) } func testVStackView() { @@ -207,7 +208,46 @@ final class BasicSwiftUIKitTests: XCTestCase { } XCTAssert(stack.subviews.first.map { type(of: $0) } == UIStackView.self) - XCTAssert(stack.allSubviews.count == 2) + XCTAssertEqual(stack.allSubviews.count, 2) + XCTAssertEqual(stack.views.value?.count, 1) + } + + func testVStackViewAppend_one() { + + let viewToEmbed = UIView() + + let stack = VStack { + [ + viewToEmbed + ] + } + + stack.views.value?.append(UIView()) + + stack.draw(views: stack.views.value ?? []) + + XCTAssert(stack.subviews.first.map { type(of: $0) } == UIStackView.self) + XCTAssertEqual(stack.allSubviews.count, 3) + XCTAssertEqual(stack.views.value?.count, 2) + } + + func testVStackViewAppend_five() { + + let viewToEmbed = UIView() + + let stack = VStack { + [ + viewToEmbed + ] + } + + stack.views.value? += (0 ... 4).map { Label("\($0)") } + + stack.draw(views: stack.views.value ?? []) + + XCTAssert(stack.subviews.first.map { type(of: $0) } == UIStackView.self) + XCTAssertEqual(stack.allSubviews.count, 7) + XCTAssertEqual(stack.views.value?.count, 6) } func testHStackView() { @@ -221,7 +261,45 @@ final class BasicSwiftUIKitTests: XCTestCase { } XCTAssert(stack.subviews.first.map { type(of: $0) } == UIStackView.self) - XCTAssert(stack.allSubviews.count == 2) + XCTAssertEqual(stack.allSubviews.count, 2) + XCTAssertEqual(stack.views.value?.count, 1) + } + + func testHStackViewAppend_one() { + + let viewToEmbed = UIView() + + let stack = VStack { + [ + viewToEmbed + ] + } + + stack.views.value?.append(UIView()) + + stack.draw(views: stack.views.value ?? []) + + XCTAssert(stack.subviews.first.map { type(of: $0) } == UIStackView.self) + XCTAssertEqual(stack.allSubviews.count, 3) + XCTAssertEqual(stack.views.value?.count, 2) + } + + func testHStackViewAppend_five() { + let viewToEmbed = UIView() + + let stack = VStack { + [ + viewToEmbed + ] + } + + stack.views.value? += (0 ... 4).map { Label("\($0)") } + + stack.draw(views: stack.views.value ?? []) + + XCTAssert(stack.subviews.first.map { type(of: $0) } == UIStackView.self) + XCTAssertEqual(stack.allSubviews.count, 7) + XCTAssertEqual(stack.views.value?.count, 6) } func testZStackView() { @@ -234,14 +312,14 @@ final class BasicSwiftUIKitTests: XCTestCase { ] } - XCTAssert(stack.allSubviews.count == 1) + XCTAssertEqual(stack.allSubviews.count, 1) } func testPaddingView() { let view = UIView().padding() - XCTAssert(view.allSubviews.count == 1) + XCTAssertEqual(view.allSubviews.count, 1) } func testConfigureView() { @@ -258,14 +336,14 @@ final class BasicSwiftUIKitTests: XCTestCase { .hide(if: true) .clipsToBounds(true) - XCTAssert(view.backgroundColor == .blue) - XCTAssert(view.isHidden == true) - XCTAssert(view.tintColor == .green) - XCTAssert(view.clipsToBounds == true) + XCTAssertEqual(view.backgroundColor, .blue) + XCTAssertEqual(view.isHidden, true) + XCTAssertEqual(view.tintColor, .green) + XCTAssertEqual(view.clipsToBounds, true) - XCTAssert(view.backgroundColor == otherView.backgroundColor) - XCTAssert(view.isHidden == otherView.isHidden) - XCTAssert(view.clipsToBounds == otherView.clipsToBounds) + XCTAssertEqual(view.backgroundColor, otherView.backgroundColor) + XCTAssertEqual(view.isHidden, otherView.isHidden) + XCTAssertEqual(view.clipsToBounds, otherView.clipsToBounds) } func testLayerView() { @@ -281,12 +359,12 @@ final class BasicSwiftUIKitTests: XCTestCase { let otherView = UIView() .layer(cornerRadius: 8) - XCTAssert(view.layer.borderColor == UIColor.blue.cgColor) - XCTAssert(view.layer.borderWidth == 3) - XCTAssert(view.layer.cornerRadius == 8) - XCTAssert(view.layer.masksToBounds == true) + XCTAssertEqual(view.layer.borderColor, UIColor.blue.cgColor) + XCTAssertEqual(view.layer.borderWidth, 3) + XCTAssertEqual(view.layer.cornerRadius, 8) + XCTAssertEqual(view.layer.masksToBounds, true) - XCTAssert(view.layer.cornerRadius == otherView.layer.cornerRadius) + XCTAssertEqual(view.layer.cornerRadius, otherView.layer.cornerRadius) } func testClearView() { @@ -320,15 +398,18 @@ final class BasicSwiftUIKitTests: XCTestCase { } } - // Will fail unless... - // === (iOS >= 13) === - XCTAssert(switchView.allSubviews.count == 8, "switchView.allSubviews.count == \(switchView.allSubviews.count)") - XCTAssert(uiSwitchView.allSubviews.count == 8, "uiSwitchView.allSubviews.count == \(uiSwitchView.allSubviews.count)") - XCTAssert(view.allSubviews.count == 12, "view.allSubviews.count == \(view.allSubviews.count)") - XCTAssert(otherView.allSubviews.count == 12, "otherView.allSubviews.count == \(otherView.allSubviews.count)") - // === (End) === + /** Will fail unless... + === (iOS >= 13) === + */ + XCTAssertEqual(switchView.allSubviews.count, 8) + XCTAssertEqual(uiSwitchView.allSubviews.count, 8) + XCTAssertEqual(view.allSubviews.count, 12) + XCTAssertEqual(otherView.allSubviews.count, 12) + /** + === (End) === + */ - XCTAssert(viewWithoutSwitch.allSubviews.count == 3, "viewWithoutSwitch.allSubviews.count == \(viewWithoutSwitch.allSubviews.count)") + XCTAssertEqual(viewWithoutSwitch.allSubviews.count, 3) switchView.clear() uiSwitchView.clear() @@ -337,12 +418,12 @@ final class BasicSwiftUIKitTests: XCTestCase { otherView.clear() viewWithoutSwitch.clear() - XCTAssert(switchView.allSubviews.count == 0) - XCTAssert(uiSwitchView.allSubviews.count == 0) + XCTAssertEqual(switchView.allSubviews.count, 0) + XCTAssertEqual(uiSwitchView.allSubviews.count, 0) - XCTAssert(view.allSubviews.count == 0) - XCTAssert(otherView.allSubviews.count == 0) - XCTAssert(viewWithoutSwitch.allSubviews.count == 0) + XCTAssertEqual(view.allSubviews.count, 0) + XCTAssertEqual(otherView.allSubviews.count, 0) + XCTAssertEqual(viewWithoutSwitch.allSubviews.count, 0) } func testLayoutConstraint() { @@ -363,21 +444,7 @@ final class BasicSwiftUIKitTests: XCTestCase { ] } - XCTAssert(innerView.constraints.count == 2) - XCTAssert(stack.constraints.count == 2) + XCTAssertEqual(innerView.constraints.count, 2) + XCTAssertEqual(stack.constraints.count, 2) } - - static var allTests = [ - ("testDefaultView", testDefaultView), - ("testEmbedViews", testEmbedViews), - ("testEmbedView", testEmbedView), - ("testVStackView", testVStackView), - ("testHStackView", testHStackView), - ("testZStackView", testZStackView), - ("testPaddingView", testPaddingView), - ("testConfigureView", testConfigureView), - ("testLayerView", testLayerView), - ("testClearView", testClearView), - ("testLayoutConstraint", testLayoutConstraint) - ] } diff --git a/Tests/SwiftUIKitTests/NSAttributedString/NSMutableAttributedStringTests.swift b/Tests/SwiftUIKitTests/NSAttributedString/NSMutableAttributedStringTests.swift index 4dcb440..2e76072 100644 --- a/Tests/SwiftUIKitTests/NSAttributedString/NSMutableAttributedStringTests.swift +++ b/Tests/SwiftUIKitTests/NSAttributedString/NSMutableAttributedStringTests.swift @@ -74,9 +74,4 @@ final class NSMutableAttributedStringTests: XCTestCase { XCTAssert(!(applyLabel.text?.isEmpty ?? true)) XCTAssert(!(applyLabel.accessibilityLabel?.isEmpty ?? true)) } - - static var allTests = [ - ("testAttributedString", testAttributedString), - ("testApplyLabel", testApplyLabel) - ] } diff --git a/Tests/SwiftUIKitTests/XCTestManifests.swift b/Tests/SwiftUIKitTests/XCTestManifests.swift deleted file mode 100644 index 30c9364..0000000 --- a/Tests/SwiftUIKitTests/XCTestManifests.swift +++ /dev/null @@ -1,11 +0,0 @@ -import XCTest - -#if !canImport(ObjectiveC) -public func allTests() -> [XCTestCaseEntry] { - return [ - testCase(BasicSwiftUIKitTests.allTests), - testCase(BasicADATests.allTests), - testCase(NSMutableAttributedStringTests.allTests), - ] -} -#endif