Skip to content
Permalink
Browse files

Update Tests to Swift 5

  • Loading branch information...
freak4pc authored and kzaher committed Apr 6, 2019
1 parent 9a39952 commit c3c74ed675262c1c010c6dcd41091397b4a85600
@@ -17,13 +17,8 @@ import XCTest
#else
import UIKit
typealias View = UIView
#if swift(>=4.2)
let topLayoutAttribute = NSLayoutConstraint.Attribute.top
let equalLayoutRelation = NSLayoutConstraint.Relation.equal
#else
let topLayoutAttribute = NSLayoutAttribute.top
let equalLayoutRelation = NSLayoutRelation.equal
#endif
let topLayoutAttribute = NSLayoutConstraint.Attribute.top
let equalLayoutRelation = NSLayoutConstraint.Relation.equal
#endif

final class NSLayoutConstraintTest : RxTest {
@@ -46,11 +46,8 @@ extension NSTextFieldTests {
name: NSControl.textDidChangeNotification,
object: textField,
userInfo: ["NSFieldEditor" : NSText()])
#if swift(>=4.2)
textField.delegate?.controlTextDidChange?(notification)
#else
(textField.delegate as! NSObject).controlTextDidChange(notification)
#endif

textField.delegate?.controlTextDidChange?(notification)

XCTAssertTrue(rxDidChange)
XCTAssertTrue(delegate.didChange)
@@ -64,13 +61,8 @@ extension NSTextFieldTests {
fileprivate final class TextFieldDelegate: NSObject, NSTextFieldDelegate {

var didChange = false
#if swift(>=4.2)

func controlTextDidChange(_ notification: Notification) {
didChange = true
}
#else
override func controlTextDidChange(_ notification: Notification) {
didChange = true
}
#endif
}
@@ -88,9 +88,9 @@ enum ObjectRuntimeChange : Hashable {
}

extension ObjectRuntimeChange {
var hashValue: Int {
func hash(into hasher: inout Hasher) {
// who cares, this is not performance critical
return 0
hasher.combine(0)
}

var isClassChange: Bool {
@@ -11,8 +11,6 @@ import RxSwift
import RxCocoa
import RxBlocking



final class SentMessageTest: RxTest {
var testClosure: () -> Void = { }

@@ -1197,8 +1195,8 @@ extension SentMessageTest {
expectedResult: NSValue(nonretainedObject: object))
_testMessageRecordedAndAllCallsAreMade(#selector(SentMessageTestBase_shared.justCalledClass(toSay:)), sendMessage: { x in NSValue(nonretainedObject: x.justCalledClass(toSay: type(of: object))) }, expectedResult: NSValue(nonretainedObject: type(of: object)))
_testMessageRecordedAndAllCallsAreMade(#selector(SentMessageTestBase_shared.justCalledClosure(toSay:)),
sendMessage: { x in "\(x.justCalledClosure(toSay: closure))" },
expectedResult: "\(closure)")
sendMessage: { x in "\(String(describing: x.justCalledClosure(toSay: closure)))" },
expectedResult: "\(String(describing: closure))")
_testMessageRecordedAndAllCallsAreMade(#selector(SentMessageTestBase_shared.justCalledChar(toSay:)),
sendMessage: { x in x.justCalledChar(toSay: 3)},
expectedResult: 3)
@@ -1252,8 +1250,8 @@ extension SentMessageTest {

_testMessageRecordedAndAllCallsAreMade(#selector(SentMessageTestBase_shared.voidJustCalledObject(toSay:)), sendMessage: { x in x.voidJustCalledObject(toSay: object); return NSValue(nonretainedObject: object) }, expectedResult: NSValue(nonretainedObject: object))
_testMessageRecordedAndAllCallsAreMade(#selector(SentMessageTestBase_shared.voidJustCalledClosure(toSay:)),
sendMessage: { x in x.voidJustCalledClosure(toSay: closure); return "\(closure)" },
expectedResult: "\(closure)")
sendMessage: { x in x.voidJustCalledClosure(toSay: closure); return "\(String(describing: closure))" },
expectedResult: "\(String(describing: closure))")
_testMessageRecordedAndAllCallsAreMade(#selector(SentMessageTestBase_shared.voidJustCalledChar(toSay:)),
sendMessage: { x in x.voidJustCalledChar(toSay: 3); return 3 },
expectedResult: 3)
@@ -139,11 +139,7 @@ final class UICollectionViewTests : RxTest {
})

let testSupplementaryView = UICollectionReusableView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
#if swift(>=4.2)
let testElementKind = UICollectionView.elementKindSectionHeader
#else
let testElementKind = UICollectionElementKindSectionHeader
#endif
let testElementKind = UICollectionView.elementKindSectionHeader
let testIndexPath = IndexPath(row: 1, section: 0)
collectionView.delegate!.collectionView!(collectionView, willDisplaySupplementaryView: testSupplementaryView, forElementKind: testElementKind, at: testIndexPath)

@@ -193,11 +189,7 @@ final class UICollectionViewTests : RxTest {
})

let testSupplementaryView = UICollectionReusableView(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
#if swift(>=4.2)
let testElementKind = UICollectionView.elementKindSectionHeader
#else
let testElementKind = UICollectionElementKindSectionHeader
#endif
let testElementKind = UICollectionView.elementKindSectionHeader
let testIndexPath = IndexPath(row: 1, section: 0)
collectionView.delegate!.collectionView!(collectionView, didEndDisplayingSupplementaryView: testSupplementaryView, forElementOfKind: testElementKind, at: testIndexPath)

@@ -163,7 +163,7 @@ extension UIControlTests {
}

fileprivate extension UIControl {
func forceSendActions(for: UIControlEvents) {
func forceSendActions(for: UIControl.Event) {
for target in self.allTargets {
for selector in self.actions(forTarget: target, forControlEvent: `for`) ?? [] {
(target.base as! NSObject).perform(NSSelectorFromString(selector), with: self)
@@ -661,7 +661,7 @@ extension UITableViewTests {
XCTAssertTrue(tableView.dataSource!.responds(to: #selector(UITableViewDataSource.tableView(_:commit:forRowAt:))))
XCTAssertArraysEqual(setDataSources, [tableView.dataSource, nil, tableView.dataSource] as [UITableViewDataSource?]) { $0 === $1 }

let deleteEditingStyle: NSNumber = NSNumber(value: UITableViewCellEditingStyle.delete.rawValue)
let deleteEditingStyle: NSNumber = NSNumber(value: UITableViewCell.EditingStyle.delete.rawValue)
let indexPath: NSIndexPath = NSIndexPath(item: 0, section: 0)
XCTAssertEqual(firstEvents, [] as [Arguments]) { $0 == $1 }
XCTAssertEqual(secondEvents, [] as [Arguments]) { $0 == $1 }
@@ -718,7 +718,7 @@ extension UITableViewTests {
XCTAssertTrue(tableView.dataSource!.responds(to: #selector(UITableViewDataSource.tableView(_:commit:forRowAt:))))
XCTAssertArraysEqual(setDataSources, [tableView.dataSource, nil, tableView.dataSource] as [UITableViewDataSource?]) { $0 === $1 }

let deleteEditingStyle: NSNumber = NSNumber(value: UITableViewCellEditingStyle.delete.rawValue)
let deleteEditingStyle: NSNumber = NSNumber(value: UITableViewCell.EditingStyle.delete.rawValue)
let indexPath: NSIndexPath = NSIndexPath(item: 0, section: 0)
XCTAssertEqual(firstEvents, [] as [Arguments]) { $0 == $1 }
XCTAssertEqual(secondEvents, [] as [Arguments]) { $0 == $1 }
@@ -750,15 +750,15 @@ extension UITableViewTests {
}

@objc final class TableViewDataSourceThatImplementsCommitForRowAt: NSObject, UITableViewDataSource {
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
arc4random_stir()
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 0
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
return UITableViewCell()
}
}
@@ -558,18 +558,6 @@ extension CompletableTest {
}
}

#if swift(>=4.2)
#if !compiler(>=5.0)
extension Never: Equatable {

}
#endif
#else
extension Never: Equatable {

}
#endif

public func == (lhs: Never, rhs: Never) -> Bool {
fatalError()
}
@@ -103,11 +103,8 @@ extension RxTest {
if self.startResourceCount < Resources.total {
// main schedulers need to finish work
print("Waiting for resource cleanup ...")
#if swift(>=4.2)
let mode = RunLoop.Mode.default
#else
let mode = RunLoopMode.defaultRunLoopMode
#endif
let mode = RunLoop.Mode.default

RunLoop.current.run(mode: mode, before: Date(timeIntervalSinceNow: 0.05))
}
else {
@@ -23,7 +23,7 @@ func XCTAssertErrorEqual(_ lhs: Swift.Error, _ rhs: Swift.Error, file: StaticStr
}

func XCTAssertThrowsErrorEqual<T>(_ expression: @autoclosure () throws -> T, _ expectedError: Error, file: StaticString = #file, line: UInt = #line) {
XCTAssertThrowsError(expression, file: file, line: line) { actualError in
XCTAssertThrowsError(try expression(), file: file, line: line) { actualError in
XCTAssertErrorEqual(actualError, expectedError, file: file, line: line)
}
}

0 comments on commit c3c74ed

Please sign in to comment.
You can’t perform that action at this time.