Permalink
Browse files

converted to Swift-3

  • Loading branch information...
1 parent e083a7d commit fa2e93d6ff6e7b60ccaa6ceb8757d171ac9ae0ed @renep renep committed with Nov 17, 2016
@@ -340,24 +340,24 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
- LastUpgradeCheck = 0800;
+ LastUpgradeCheck = 0810;
ORGANIZATIONNAME = "Nikolaj Schumacher";
TargetAttributes = {
247C43331B4DD0D700F357B8 = {
CreatedOnToolsVersion = 6.4;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0810;
};
2494844719B60A56007EEA3D = {
CreatedOnToolsVersion = 6.0;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0810;
};
2496DAF019922407008C270E = {
CreatedOnToolsVersion = 6.0;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0810;
};
2496DAFB19922407008C270E = {
CreatedOnToolsVersion = 6.0;
- LastSwiftMigration = 0800;
+ LastSwiftMigration = 0810;
};
};
};
@@ -519,7 +519,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -534,15 +534,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
2494845919B60A57007EEA3D /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
@@ -563,15 +563,15 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
};
2494845A19B60A57007EEA3D /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
- "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
+ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "";
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
@@ -589,7 +589,7 @@
SDKROOT = iphoneos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
};
@@ -709,7 +709,7 @@
PRODUCT_NAME = Hamcrest;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -735,7 +735,7 @@
PRODUCT_NAME = Hamcrest;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -751,7 +751,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "de.nschum.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Debug;
};
@@ -764,7 +764,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "de.nschum.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
- SWIFT_VERSION = 2.3;
+ SWIFT_VERSION = 3.0;
};
name = Release;
};
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "0800"
+ LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
- LastUpgradeVersion = "0800"
+ LastUpgradeVersion = "0810"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
@@ -1,36 +1,40 @@
-public func equalTo<T: Equatable>(expectedValue: T) -> Matcher<T> {
+public func equalTo<T: Equatable>(_ expectedValue: T) -> Matcher<T> {
return Matcher("equal to \(expectedValue)") {$0 == expectedValue}
}
-public func closeTo(expectedValue: Double, _ delta: Double) -> Matcher<Double> {
+public func closeTo(_ expectedValue: Double, _ delta: Double) -> Matcher<Double> {
return Matcher("within \(delta) of \(expectedValue)") {
(value: Double) -> MatchResult in
let actual = abs(value - expectedValue)
return MatchResult(actual < delta, "difference of \(actual)")
}
}
-public func closeTo(expectedValue: Float, _ delta: Double) -> Matcher<Float> {
+public func closeTo(_ expectedValue: Float, _ delta: Double) -> Matcher<Float> {
let matcher = closeTo(Double(expectedValue), delta)
return Matcher(matcher.description) {matcher.matches(Double($0))}
}
-public func greaterThan<T: Comparable>(expectedValue: T) -> Matcher<T> {
+public func greaterThan<T: Comparable>(_ expectedValue: T) -> Matcher<T> {
return Matcher("greater than \(expectedValue)") {$0 > expectedValue}
}
-public func greaterThanOrEqualTo<T: Comparable>(expectedValue: T) -> Matcher<T> {
+public func greaterThanOrEqualTo<T: Comparable>(_ expectedValue: T) -> Matcher<T> {
return Matcher("greater than or equal to \(expectedValue)") {$0 >= expectedValue}
}
-public func lessThan<T: Comparable>(expectedValue: T) -> Matcher<T> {
+public func lessThan<T: Comparable>(_ expectedValue: T) -> Matcher<T> {
return Matcher("less than \(expectedValue)") {$0 < expectedValue}
}
-public func lessThanOrEqualTo<T: Comparable>(expectedValue: T) -> Matcher<T> {
+public func lessThanOrEqualTo<T: Comparable>(_ expectedValue: T) -> Matcher<T> {
return Matcher("less than or equal to \(expectedValue)") {$0 <= expectedValue}
}
-public func inInterval<T, I: IntervalType where I.Bound == T>(expectedInterval: I) -> Matcher<T> {
+public func inInterval<T>(_ expectedInterval: ClosedRange<T>) -> Matcher<T> {
return Matcher("in interval \(expectedInterval)") {expectedInterval.contains($0)}
}
+
+public func inInterval<T>(_ expectedInterval: Range<T>) -> Matcher<T> {
+ return Matcher("in interval \(expectedInterval)") {expectedInterval.contains($0)}
+}
@@ -2,7 +2,7 @@ public func anything<T>() -> Matcher<T> {
return Matcher("anything") {value in true}
}
-public func sameInstance<T: AnyObject>(expectedValue: T) -> Matcher<T> {
+public func sameInstance<T: AnyObject>(_ expectedValue: T) -> Matcher<T> {
return Matcher("same instance as \(describeAddress(expectedValue))") {
(value: T) -> MatchResult in
value === expectedValue ? .Match : .Mismatch(describeAddress(value))
@@ -11,18 +11,18 @@ public func sameInstance<T: AnyObject>(expectedValue: T) -> Matcher<T> {
// MARK: is
-public func `is`<T>(matcher: Matcher<T>) -> Matcher<T> {
+public func `is`<T>(_ matcher: Matcher<T>) -> Matcher<T> {
return Matcher("is " + matcher.description) {
(value: T) -> MatchResult in
return matcher.matches(value)
}
}
-public func isA<T: Any>(expectedType: T.Type) -> Matcher<Any> {
+public func isA<T: Any>(_ expectedType: T.Type) -> Matcher<Any> {
return `is`(instanceOf(expectedType))
}
-public func `is`<T: Equatable>(expectedValue: T) -> Matcher<T> {
+public func `is`<T: Equatable>(_ expectedValue: T) -> Matcher<T> {
return `is`(equalTo(expectedValue))
}
@@ -36,7 +36,7 @@ public func present<T>() -> Matcher<Optional<T>> {
return Matcher("present") {$0 != nil}
}
-public func presentAnd<T>(matcher: Matcher<T>) -> Matcher<Optional<T>> {
+public func presentAnd<T>(_ matcher: Matcher<T>) -> Matcher<Optional<T>> {
return Matcher("present and \(matcher.description)") {
(value: T?) -> MatchResult in
if let unwrappedValue = value {
@@ -49,16 +49,16 @@ public func presentAnd<T>(matcher: Matcher<T>) -> Matcher<Optional<T>> {
// MARK: casting
-public func instanceOf<T: Any>(expectedType: T.Type) -> Matcher<Any> {
+public func instanceOf<T: Any>(_ expectedType: T.Type) -> Matcher<Any> {
// There seems to be no way to get the type name.
return Matcher("instance of \(expectedType)") {$0 is T}
}
-public func instanceOf<T: Any>(expectedType: T.Type, and matcher: Matcher<T>) -> Matcher<Any> {
+public func instanceOf<T: Any>(_ expectedType: T.Type, and matcher: Matcher<T>) -> Matcher<Any> {
return instanceOfAnd(matcher)
}
-public func instanceOfAnd<T: Any>(matcher: Matcher<T>) -> Matcher<Any> {
+public func instanceOfAnd<T: Any>(_ matcher: Matcher<T>) -> Matcher<Any> {
return Matcher("instance of \(T.self) and \(matcher.description)") {
(value: Any) -> MatchResult in
if let value = value as? T {
@@ -67,4 +67,4 @@ public func instanceOfAnd<T: Any>(matcher: Matcher<T>) -> Matcher<Any> {
return .Mismatch("mismatched type")
}
}
-}
+}
@@ -1,66 +1,66 @@
import Foundation
-func describe<T>(value: T) -> String {
+func describe<T>(_ value: T) -> String {
if let stringArray = value as? [String] {
return joinDescriptions(stringArray.map {describe($0)})
}
if let string = value as? String {
return "\"\(string)\""
}
- return String(value)
+ return String(describing: value)
}
-func describeAddress<T: AnyObject>(object: T) -> String {
- return NSString(format: "%p", unsafeBitCast(object, Int.self)) as String
+func describeAddress<T: AnyObject>(_ object: T) -> String {
+ return NSString(format: "%p", unsafeBitCast(object, to: Int.self)) as String
}
-func describeError(error: ErrorType) -> String {
+func describeError(_ error: Error) -> String {
return "ERROR: \(error)"
}
func describeExpectedError() -> String {
return "EXPECTED ERROR"
}
-func describeExpectedError(description: String) -> String {
+func describeExpectedError(_ description: String) -> String {
return "EXPECTED ERROR: \(description)"
}
-func describeErrorMismatch<T>(error: T, _ description: String, _ mismatchDescription: String?) -> String {
+func describeErrorMismatch<T>(_ error: T, _ description: String, _ mismatchDescription: String?) -> String {
return "GOT ERROR: " + describeActualValue(error, mismatchDescription) + ", EXPECTED ERROR: \(description)"
}
-func describeMismatch<T>(value: T, _ description: String, _ mismatchDescription: String?) -> String {
+func describeMismatch<T>(_ value: T, _ description: String, _ mismatchDescription: String?) -> String {
return "GOT: " + describeActualValue(value, mismatchDescription) + ", EXPECTED: \(description)"
}
-func describeActualValue<T>(value: T, _ mismatchDescription: String?) -> String {
+func describeActualValue<T>(_ value: T, _ mismatchDescription: String?) -> String {
return describe(value) + (mismatchDescription.map{" (\($0))"} ?? "")
}
-func joinDescriptions(descriptions: [String]) -> String {
+func joinDescriptions(_ descriptions: [String]) -> String {
return joinStrings(descriptions)
}
-func joinDescriptions(descriptions: [String?]) -> String? {
+func joinDescriptions(_ descriptions: [String?]) -> String? {
let notNil = filterNotNil(descriptions)
return notNil.isEmpty ? nil : joinStrings(notNil)
}
-func joinMatcherDescriptions<S: SequenceType, T where S.Generator.Element == Matcher<T>>(matchers: S, prefix: String = "all of") -> String {
- var generator = matchers.generate()
- if let first = generator.next() where generator.next() == nil {
+func joinMatcherDescriptions<S: Sequence, T>(_ matchers: S, prefix: String = "all of") -> String where S.Iterator.Element == Matcher<T> {
+ var generator = matchers.makeIterator()
+ if let first = generator.next(), generator.next() == nil {
return first.description
} else {
return prefix + " " + joinDescriptions(matchers.map({$0.description}))
}
}
-private func joinStrings(strings: [String]) -> String {
+private func joinStrings(_ strings: [String]) -> String {
switch (strings.count) {
case 1:
return strings[0]
default:
- return "[" + strings.joinWithSeparator(", ") + "]"
+ return "[" + strings.joined(separator: ", ") + "]"
}
-}
+}
@@ -1,38 +1,38 @@
-public func hasEntry<K: Hashable, V>(keyMatcher: Matcher<K>, _ valueMatcher: Matcher<V>)
+public func hasEntry<K: Hashable, V>(_ keyMatcher: Matcher<K>, _ valueMatcher: Matcher<V>)
-> Matcher<Dictionary<K, V>> {
return Matcher("a dictionary containing [\(keyMatcher.description) -> \(valueMatcher.description)]") {
(dictionary: Dictionary<K, V>) -> Bool in
for (key, value) in dictionary {
- if keyMatcher.matches(key) && valueMatcher.matches(value) {
+ if keyMatcher.matches(key).boolValue && valueMatcher.matches(value).boolValue {
return true
}
}
return false
}
}
-public func hasEntry<K: Equatable, V: Equatable where K: Hashable>(expectedKey: K, _ expectedValue: V)
- -> Matcher<Dictionary<K, V>> {
+public func hasEntry<K: Equatable, V: Equatable>(_ expectedKey: K, _ expectedValue: V)
+ -> Matcher<Dictionary<K, V>> where K: Hashable {
return hasEntry(equalToWithoutDescription(expectedKey), equalToWithoutDescription(expectedValue))
}
-public func hasKey<K: Hashable, V>(matcher: Matcher<K>) -> Matcher<Dictionary<K, V>> {
+public func hasKey<K: Hashable, V>(_ matcher: Matcher<K>) -> Matcher<Dictionary<K, V>> {
return hasEntry(matcher, anything())
}
-public func hasKey<K, V where K: Equatable, K: Hashable>(expectedKey: K)
- -> Matcher<Dictionary<K, V>> {
+public func hasKey<K, V>(_ expectedKey: K)
+ -> Matcher<Dictionary<K, V>> where K: Equatable, K: Hashable {
return hasKey(equalToWithoutDescription(expectedKey))
}
-public func hasValue<K: Hashable, V>(matcher: Matcher<V>) -> Matcher<Dictionary<K, V>> {
+public func hasValue<K: Hashable, V>(_ matcher: Matcher<V>) -> Matcher<Dictionary<K, V>> {
return hasEntry(anything(), matcher)
}
-public func hasValue<K: Hashable, V: Equatable>(expectedValue: V) -> Matcher<Dictionary<K, V>> {
+public func hasValue<K: Hashable, V: Equatable>(_ expectedValue: V) -> Matcher<Dictionary<K, V>> {
return hasValue(equalToWithoutDescription(expectedValue))
}
Oops, something went wrong.

0 comments on commit fa2e93d

Please sign in to comment.