Skip to content

Commit

Permalink
Merge pull request #363 from mapierce/xcode-16-fixes
Browse files Browse the repository at this point in the history
Xcode 16 support
  • Loading branch information
spaluchiewicz authored Sep 2, 2024
2 parents d0f1bd4 + 723dbb9 commit 3672eea
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 116 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ on:
- master
jobs:
SwiftyMocky-Tests:
runs-on: macos-11
runs-on: macos-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2
- name: Set Xcode version
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '13.2.1'
xcode-version: '15.4'
- name: Prepare for tests
run: |
rake pods
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftyMocky/Mock.swifttemplate
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ class Helpers {
}
static func extractGenericsList(_ associatedTypes: [String]?) -> [String] {
return associatedTypes?.flatMap {
split($0, byFirstOccurenceOf: " where ").0.replacingOccurrences(of: " ", with: "").characters.split(separator: ":").map(String.init).first
split($0, byFirstOccurenceOf: " where ").0.replacingOccurrences(of: " ", with: "").split(separator: ":").map(String.init).first
}.map { "\($0)" } ?? []
}
static func extractGenericTypesModifier(_ associatedTypes: [String]?) -> String {
Expand All @@ -253,9 +253,9 @@ class Helpers {
guard let all = associatedTypes else { return "" }
let constraints = all.flatMap { t -> String? in
let splitted = split(t, byFirstOccurenceOf: " where ")
let constraint = splitted.0.replacingOccurrences(of: " ", with: "").characters.split(separator: ":").map(String.init)
let constraint = splitted.0.replacingOccurrences(of: " ", with: "").split(separator: ":").map(String.init)
guard constraint.count == 2 else { return nil }
let adopts = constraint[1].characters.split(separator: ",").map(String.init)
let adopts = constraint[1].split(separator: ",").map(String.init)
var mapped = adopts.map { "\(constraint[0]): \($0)" }
if !splitted.1.isEmpty {
mapped.append(splitted.1)
Expand Down Expand Up @@ -1146,7 +1146,7 @@ class MethodWrapper {
genPart.removeFirst()
genPart.removeLast()

let parts = genPart.replacingOccurrences(of: " ", with: "").characters.split(separator: ",").map(String.init)
let parts = genPart.replacingOccurrences(of: " ", with: "").split(separator: ",").map(String.init)
return parts.map { stripGenPart(part: $0) }
}

Expand All @@ -1161,7 +1161,7 @@ class MethodWrapper {
genPart.removeFirst()
genPart.removeLast()

let parts = genPart.replacingOccurrences(of: " ", with: "").characters.split(separator: ",").map(String.init)
let parts = genPart.replacingOccurrences(of: " ", with: "").split(separator: ",").map(String.init)
return parts.filter {
let components = $0.components(separatedBy: ":")
return (components.count == 2 || !filterSingle) && generics.contains(components[0])
Expand All @@ -1183,7 +1183,7 @@ class MethodWrapper {
}

private func stripGenPart(part: String) -> String {
return part.characters.split(separator: ":").map(String.init).first!
return part.split(separator: ":").map(String.init).first!
}

private func returnTypeStripped(_ method: SourceryRuntime.Method, type: Bool = false) -> String {
Expand Down
64 changes: 0 additions & 64 deletions Sources/SwiftyMocky/Parameter+Literals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,6 @@ import Foundation

// MARK: - ExpressibleByStringLiteral

extension Optional:
ExpressibleByStringLiteral,
ExpressibleByExtendedGraphemeClusterLiteral,
ExpressibleByUnicodeScalarLiteral
where Wrapped: ExpressibleByStringLiteral
{
public typealias StringLiteralType = Wrapped.StringLiteralType
public typealias ExtendedGraphemeClusterLiteralType = Wrapped.ExtendedGraphemeClusterLiteralType
public typealias UnicodeScalarLiteralType = Wrapped.UnicodeScalarLiteralType

public init(stringLiteral value: StringLiteralType) {
self = .some(Wrapped.init(stringLiteral: value))
}

public init(extendedGraphemeClusterLiteral value: ExtendedGraphemeClusterLiteralType) {
self = .some(Wrapped.init(extendedGraphemeClusterLiteral: value))
}

public init(unicodeScalarLiteral value: UnicodeScalarLiteralType) {
self = .some(Wrapped.init(unicodeScalarLiteral: value))
}
}

extension Parameter:
ExpressibleByStringLiteral,
ExpressibleByExtendedGraphemeClusterLiteral,
Expand Down Expand Up @@ -58,14 +35,6 @@ extension Parameter: ExpressibleByNilLiteral where ValueType: ExpressibleByNilLi

// MARK: - ExpressibleByIntegerLiteral

extension Optional: ExpressibleByIntegerLiteral where Wrapped: ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = Wrapped.IntegerLiteralType

public init(integerLiteral value: IntegerLiteralType) {
self = .some(Wrapped.init(integerLiteral: value))
}
}

extension Parameter: ExpressibleByIntegerLiteral where ValueType: ExpressibleByIntegerLiteral {
public typealias IntegerLiteralType = ValueType.IntegerLiteralType

Expand All @@ -76,14 +45,6 @@ extension Parameter: ExpressibleByIntegerLiteral where ValueType: ExpressibleByI

// MARK: - ExpressibleByBooleanLiteral

extension Optional: ExpressibleByBooleanLiteral where Wrapped: ExpressibleByBooleanLiteral {
public typealias BooleanLiteralType = Wrapped.BooleanLiteralType

public init(booleanLiteral value: BooleanLiteralType) {
self = .some(Wrapped.init(booleanLiteral: value))
}
}

extension Parameter: ExpressibleByBooleanLiteral where ValueType: ExpressibleByBooleanLiteral {
public typealias BooleanLiteralType = ValueType.BooleanLiteralType

Expand All @@ -94,14 +55,6 @@ extension Parameter: ExpressibleByBooleanLiteral where ValueType: ExpressibleByB

// MARK: - ExpressibleByFloatLiteral

extension Optional: ExpressibleByFloatLiteral where Wrapped: ExpressibleByFloatLiteral {
public typealias FloatLiteralType = Wrapped.FloatLiteralType

public init(floatLiteral value: FloatLiteralType) {
self = .some(Wrapped.init(floatLiteral: value))
}
}

extension Parameter: ExpressibleByFloatLiteral where ValueType: ExpressibleByFloatLiteral {
public typealias FloatLiteralType = ValueType.FloatLiteralType

Expand All @@ -126,14 +79,6 @@ private extension ExpressibleByArrayLiteral where ArrayLiteralElement: Hashable
}
}

extension Optional: ExpressibleByArrayLiteral where Wrapped: ExpressibleByArrayLiteral {
public typealias ArrayLiteralElement = Wrapped.ArrayLiteralElement

public init(arrayLiteral elements: ArrayLiteralElement...) {
self = .some(Wrapped.init(elements))
}
}

extension Parameter: ExpressibleByArrayLiteral where ValueType: ExpressibleByArrayLiteral {
public typealias ArrayLiteralElement = ValueType.ArrayLiteralElement

Expand All @@ -151,15 +96,6 @@ private extension ExpressibleByDictionaryLiteral where Key: Hashable {
}
}

extension Optional: ExpressibleByDictionaryLiteral where Wrapped: ExpressibleByDictionaryLiteral, Wrapped.Key: Hashable {
public typealias Key = Wrapped.Key
public typealias Value = Wrapped.Value

public init(dictionaryLiteral elements: (Key, Value)...) {
self = .some(Wrapped.init(elements))
}
}

extension Parameter: ExpressibleByDictionaryLiteral where ValueType: ExpressibleByDictionaryLiteral, ValueType.Key: Hashable {
public typealias Key = ValueType.Key
public typealias Value = ValueType.Value
Expand Down
12 changes: 6 additions & 6 deletions Sources/SwiftyPrototype/Prototype.swifttemplate
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class Helpers {
}
static func extractGenericsList(_ associatedTypes: [String]?) -> [String] {
return associatedTypes?.flatMap {
split($0, byFirstOccurenceOf: " where ").0.replacingOccurrences(of: " ", with: "").characters.split(separator: ":").map(String.init).first
split($0, byFirstOccurenceOf: " where ").0.replacingOccurrences(of: " ", with: "").split(separator: ":").map(String.init).first
}.map { "\($0)" } ?? []
}
static func extractGenericTypesModifier(_ associatedTypes: [String]?) -> String {
Expand All @@ -252,9 +252,9 @@ class Helpers {
guard let all = associatedTypes else { return "" }
let constraints = all.flatMap { t -> String? in
let splitted = split(t, byFirstOccurenceOf: " where ")
let constraint = splitted.0.replacingOccurrences(of: " ", with: "").characters.split(separator: ":").map(String.init)
let constraint = splitted.0.replacingOccurrences(of: " ", with: "").split(separator: ":").map(String.init)
guard constraint.count == 2 else { return nil }
let adopts = constraint[1].characters.split(separator: ",").map(String.init)
let adopts = constraint[1].split(separator: ",").map(String.init)
var mapped = adopts.map { "\(constraint[0]): \($0)" }
if !splitted.1.isEmpty {
mapped.append(splitted.1)
Expand Down Expand Up @@ -1145,7 +1145,7 @@ class MethodWrapper {
genPart.removeFirst()
genPart.removeLast()

let parts = genPart.replacingOccurrences(of: " ", with: "").characters.split(separator: ",").map(String.init)
let parts = genPart.replacingOccurrences(of: " ", with: "").split(separator: ",").map(String.init)
return parts.map { stripGenPart(part: $0) }
}

Expand All @@ -1160,7 +1160,7 @@ class MethodWrapper {
genPart.removeFirst()
genPart.removeLast()

let parts = genPart.replacingOccurrences(of: " ", with: "").characters.split(separator: ",").map(String.init)
let parts = genPart.replacingOccurrences(of: " ", with: "").split(separator: ",").map(String.init)
return parts.filter {
let components = $0.components(separatedBy: ":")
return (components.count == 2 || !filterSingle) && generics.contains(components[0])
Expand All @@ -1182,7 +1182,7 @@ class MethodWrapper {
}

private func stripGenPart(part: String) -> String {
return part.characters.split(separator: ":").map(String.init).first!
return part.split(separator: ":").map(String.init).first!
}

private func returnTypeStripped(_ method: SourceryRuntime.Method, type: Bool = false) -> String {
Expand Down
60 changes: 30 additions & 30 deletions SwiftyMocky-Tests/Shared/Other/ExpressibleByLiteralsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ class ExpressibleByLiteralsTests: XCTestCase {

// Optional
Given(mock, .methodWithOtionalStringParameter(p: .any, willReturn: 0))
Given(mock, .methodWithOtionalStringParameter(p: "a", willReturn: 1))
Given(mock, .methodWithOtionalStringParameter(p: "b", willReturn: 2))
Given(mock, .methodWithOtionalStringParameter(p: .value("a"), willReturn: 1))
Given(mock, .methodWithOtionalStringParameter(p: .value("b"), willReturn: 2))
Given(mock, .methodWithOtionalStringParameter(p: nil, willReturn: 3))

XCTAssertEqual(mock.methodWithOtionalStringParameter(p: "a"), 1)
XCTAssertEqual(mock.methodWithOtionalStringParameter(p: "b"), 2)
XCTAssertEqual(mock.methodWithOtionalStringParameter(p: "c"), 0)
XCTAssertEqual(mock.methodWithOtionalStringParameter(p: nil), 3)

Verify(mock, .methodWithOtionalStringParameter(p: "a"))
Verify(mock, .methodWithOtionalStringParameter(p: "b"))
Verify(mock, .methodWithOtionalStringParameter(p: "c"))
Verify(mock, .methodWithOtionalStringParameter(p: .value("a")))
Verify(mock, .methodWithOtionalStringParameter(p: .value("b")))
Verify(mock, .methodWithOtionalStringParameter(p: .value("c")))
Verify(mock, .methodWithOtionalStringParameter(p: nil))
Verify(mock, .never, .methodWithOtionalStringParameter(p: "d"))
Verify(mock, .never, .methodWithOtionalStringParameter(p: .value("d")))
Verify(mock, 4, .methodWithOtionalStringParameter(p: .any))

// Custom
Expand All @@ -83,8 +83,8 @@ class ExpressibleByLiteralsTests: XCTestCase {

// Custom Optional
Given(mock, .methodWithCustomOptionalStringParameter(p: .any, willReturn: 0))
Given(mock, .methodWithCustomOptionalStringParameter(p: "a", willReturn: 1))
Given(mock, .methodWithCustomOptionalStringParameter(p: "b", willReturn: 2))
Given(mock, .methodWithCustomOptionalStringParameter(p: .value("a"), willReturn: 1))
Given(mock, .methodWithCustomOptionalStringParameter(p: .value("b"), willReturn: 2))
Given(mock, .methodWithCustomOptionalStringParameter(p: nil, willReturn: 3))

XCTAssertEqual(mock.methodWithCustomOptionalStringParameter(p: CustomString.a), 1)
Expand All @@ -93,11 +93,11 @@ class ExpressibleByLiteralsTests: XCTestCase {
XCTAssertEqual(mock.methodWithCustomOptionalStringParameter(p: nil), 3)

Verify(mock, 1, .methodWithCustomOptionalStringParameter(p: .value(CustomString.a)))
Verify(mock, 1, .methodWithCustomOptionalStringParameter(p: "a"))
Verify(mock, .methodWithCustomOptionalStringParameter(p: "b"))
Verify(mock, .methodWithCustomOptionalStringParameter(p: "c"))
Verify(mock, 1, .methodWithCustomOptionalStringParameter(p: .value("a")))
Verify(mock, .methodWithCustomOptionalStringParameter(p: .value("b")))
Verify(mock, .methodWithCustomOptionalStringParameter(p: .value("c")))
Verify(mock, .methodWithCustomOptionalStringParameter(p: nil))
Verify(mock, .never, .methodWithCustomOptionalStringParameter(p: "d"))
Verify(mock, .never, .methodWithCustomOptionalStringParameter(p: .value("d")))

Verify(mock, 4, .methodWithCustomOptionalStringParameter(p: .any))
}
Expand All @@ -121,8 +121,8 @@ class ExpressibleByLiteralsTests: XCTestCase {

// Custom Optional
Given(mock, .methodWithCustomOptionalIntParameter(p: .any, willReturn: 0))
Given(mock, .methodWithCustomOptionalIntParameter(p: 1, willReturn: 1))
Given(mock, .methodWithCustomOptionalIntParameter(p: 2, willReturn: 2))
Given(mock, .methodWithCustomOptionalIntParameter(p: .value(1), willReturn: 1))
Given(mock, .methodWithCustomOptionalIntParameter(p: .value(2), willReturn: 2))
Given(mock, .methodWithCustomOptionalIntParameter(p: nil, willReturn: 3))

XCTAssertEqual(mock.methodWithCustomOptionalIntParameter(p: CustomInt.value(1)), 1)
Expand All @@ -131,9 +131,9 @@ class ExpressibleByLiteralsTests: XCTestCase {
XCTAssertEqual(mock.methodWithCustomOptionalIntParameter(p: nil), 3)

Verify(mock, 1, .methodWithCustomOptionalIntParameter(p: .value(CustomInt.zero)))
Verify(mock, 1, .methodWithCustomOptionalIntParameter(p: 1))
Verify(mock, .methodWithCustomOptionalIntParameter(p: 2))
Verify(mock, .methodWithCustomOptionalIntParameter(p: 0))
Verify(mock, 1, .methodWithCustomOptionalIntParameter(p: .value(1)))
Verify(mock, .methodWithCustomOptionalIntParameter(p: .value(2)))
Verify(mock, .methodWithCustomOptionalIntParameter(p: .value(0)))
Verify(mock, .methodWithCustomOptionalIntParameter(p: nil))
Verify(mock, .never, .methodWithCustomOptionalIntParameter(p: .value(CustomInt.value(15))))

Expand All @@ -145,17 +145,17 @@ class ExpressibleByLiteralsTests: XCTestCase {

Given(mock, .methodWithBool(p: .any, willReturn: 0))
Given(mock, .methodWithBool(p: nil, willReturn: -1))
Given(mock, .methodWithBool(p: true, willReturn: 2))
Given(mock, .methodWithBool(p: false, willReturn: 1))
Given(mock, .methodWithBool(p: .value(true), willReturn: 2))
Given(mock, .methodWithBool(p: .value(false), willReturn: 1))

XCTAssertEqual(mock.methodWithBool(p: nil), -1)
XCTAssertEqual(mock.methodWithBool(p: true), 2)
XCTAssertEqual(mock.methodWithBool(p: false), 1)

Verify(mock, 1, .methodWithBool(p: nil))
Verify(mock, 1, .methodWithBool(p: .value(nil)))
Verify(mock, 1, .methodWithBool(p: true))
Verify(mock, 1, .methodWithBool(p: false))
Verify(mock, 1, .methodWithBool(p: .value(true)))
Verify(mock, 1, .methodWithBool(p: .value(false)))
Verify(mock, 3, .methodWithBool(p: .any))
Verify(mock, 2, .methodWithBool(p: .notNil))
}
Expand All @@ -165,8 +165,8 @@ class ExpressibleByLiteralsTests: XCTestCase {

Given(mock, .methodWithFloat(p: .any, willReturn: 0))
Given(mock, .methodWithFloat(p: nil, willReturn: -1))
Given(mock, .methodWithFloat(p: 1.0, willReturn: 1))
Given(mock, .methodWithFloat(p: 2, willReturn: 2))
Given(mock, .methodWithFloat(p: .value(1.0), willReturn: 1))
Given(mock, .methodWithFloat(p: .value(2), willReturn: 2))

XCTAssertEqual(mock.methodWithFloat(p: nil), -1)
XCTAssertEqual(mock.methodWithFloat(p: 1.0000001), 0)
Expand All @@ -177,8 +177,8 @@ class ExpressibleByLiteralsTests: XCTestCase {

Given(mock, .methodWithDouble(p: .any, willReturn: 0))
Given(mock, .methodWithDouble(p: nil, willReturn: -1))
Given(mock, .methodWithDouble(p: 1.0, willReturn: 1))
Given(mock, .methodWithDouble(p: 2, willReturn: 2))
Given(mock, .methodWithDouble(p: .value(1.0), willReturn: 1))
Given(mock, .methodWithDouble(p: .value(2), willReturn: 2))

XCTAssertEqual(mock.methodWithDouble(p: nil), -1)
XCTAssertEqual(mock.methodWithDouble(p: 1.0000001), 0)
Expand Down Expand Up @@ -224,8 +224,8 @@ class ExpressibleByLiteralsTests: XCTestCase {
Verify(mock, .once, .methodWithSetOfInt(p: [2,3,4]))

Given(mock, .methodWithOptionalSetOfInt(p: .any, willReturn: 0))
Given(mock, .methodWithOptionalSetOfInt(p: [0,1,2], willReturn: 1))
Given(mock, .methodWithOptionalSetOfInt(p: [2,3,4], willReturn: 2))
Given(mock, .methodWithOptionalSetOfInt(p: .value([0,1,2]), willReturn: 1))
Given(mock, .methodWithOptionalSetOfInt(p: .value([2,3,4]), willReturn: 2))
Given(mock, .methodWithOptionalSetOfInt(p: nil, willReturn: 3))

XCTAssertEqual(mock.methodWithOptionalSetOfInt(p: [0,1]), 0)
Expand All @@ -234,9 +234,9 @@ class ExpressibleByLiteralsTests: XCTestCase {
XCTAssertEqual(mock.methodWithOptionalSetOfInt(p: nil), 3)

Verify(mock, 4, .methodWithOptionalSetOfInt(p: .any))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: [0,1]))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: [0,1,2]))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: [2,3,4]))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: .value([0,1])))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: .value([0,1,2])))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: .value([2,3,4])))
Verify(mock, .once, .methodWithOptionalSetOfInt(p: nil))
}

Expand Down
4 changes: 2 additions & 2 deletions SwiftyMocky-Tests/Shared/Other/SimpleSequencingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SimpleSequencingTests: XCTestCase {

Given(mock, .simpleMehtodThatReturns(optionalParam: .any, willReturn: nil), .wrap)
Given(mock, .simpleMehtodThatReturns(optionalParam: nil, willReturn: "a","b"), .drop)
Given(mock, .simpleMehtodThatReturns(optionalParam: "z", willReturn: "z","z","z"), .drop)
Given(mock, .simpleMehtodThatReturns(optionalParam: .value("z"), willReturn: "z","z","z"), .drop)

XCTAssertEqual(mock.simpleMehtodThatReturns(optionalParam: nil), "a")
XCTAssertEqual(mock.simpleMehtodThatReturns(optionalParam: "q"), nil)
Expand All @@ -171,7 +171,7 @@ class SimpleSequencingTests: XCTestCase {
func test_mixed_policy_when_inverted() {
let mock = SimpleProtocolWithMethodsMock(sequencing: .inWritingOrder)

Given(mock, .simpleMehtodThatReturns(optionalParam: "z", willReturn: "z","z","z"), .drop)
Given(mock, .simpleMehtodThatReturns(optionalParam: .value("z"), willReturn: "z","z","z"), .drop)
Given(mock, .simpleMehtodThatReturns(optionalParam: nil, willReturn: "a","b"), .drop)
Given(mock, .simpleMehtodThatReturns(optionalParam: .any, willReturn: nil), .wrap)

Expand Down
Loading

0 comments on commit 3672eea

Please sign in to comment.