Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Scripts/format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Go to the repository root (one level up from Scripts)
REPO_ROOT="$(dirname "$SCRIPT_DIR")"

# Run swift format with --in-place to fix formatting issues
swift format --in-place --recursive \
"$REPO_ROOT/Packages/" \
"$REPO_ROOT/Sources/" \
"$REPO_ROOT/Tests/"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Array {
/// - elementGenerator: A closure that generates array elements.
public init<ErrorType>(
count: Int,
elementGenerator: () throws(ErrorType) -> Element
elementGenerator: () throws(ErrorType) -> Element,
) throws(ErrorType) where ErrorType: Error {
try self.init(count: count) { (_) throws(ErrorType) in
try elementGenerator()
Expand All @@ -31,7 +31,7 @@ extension Array {
/// generated.
public init<ErrorType>(
count: Int,
elementGenerator: (Int) throws(ErrorType) -> Element
elementGenerator: (Int) throws(ErrorType) -> Element,
) throws(ErrorType) where ErrorType: Error {
self.init()
reserveCapacity(count)
Expand All @@ -56,7 +56,7 @@ extension Dictionary {
/// - keyPairGenerator: A closure that generates key-value pairs.
public init<ErrorType>(
count: Int,
keyPairGenerator: () throws(ErrorType) -> (Key, Value)
keyPairGenerator: () throws(ErrorType) -> (Key, Value),
) throws(ErrorType) where ErrorType: Error {
self.init(minimumCapacity: count)

Expand All @@ -79,7 +79,7 @@ extension Set {
/// - elementGenerator: A closure that generates set elements.
public init<ErrorType>(
count: Int,
elementGenerator: () throws(ErrorType) -> Element
elementGenerator: () throws(ErrorType) -> Element,
) throws(ErrorType) where ErrorType: Error {
self.init(minimumCapacity: count)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension BinaryFloatingPoint where RawSignificand: FixedWidthInteger {
/// - generator: The random number generator to use when creating the new random value.
public static func randomPrintable(
in range: Range<Self>,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> Self {
let subdivisions = 256

Expand All @@ -49,7 +49,7 @@ extension BinaryFloatingPoint where RawSignificand: FixedWidthInteger {
/// - generator: The random number generator to use when creating the new random value.
public static func randomPrintable(
in range: ClosedRange<Self>,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> Self {
let subdivisions = 256

Expand Down
8 changes: 4 additions & 4 deletions Sources/DevTesting/Random Value Generation/Date+Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ extension Date {
/// - Returns: A random date within the bounds of range.
public static func random(
in range: Range<Date>,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> Date {
let lowerBound = range.lowerBound.timeIntervalSinceReferenceDate
let upperBound = range.upperBound.timeIntervalSinceReferenceDate
return Date(
timeIntervalSinceReferenceDate: .randomPrintable(
in: lowerBound ..< upperBound,
using: &generator
using: &generator,
)
)
}
Expand All @@ -37,14 +37,14 @@ extension Date {
/// - Returns: A random date within the bounds of range.
public static func random(
in range: ClosedRange<Date>,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> Date {
let lowerBound = range.lowerBound.timeIntervalSinceReferenceDate
let upperBound = range.upperBound.timeIntervalSinceReferenceDate
return Date(
timeIntervalSinceReferenceDate: .randomPrintable(
in: lowerBound ... upperBound,
using: &generator
using: &generator,
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extension Optional {
/// - generator: The random number generator to use when creating the new random optional.
public static func random(
_ value: @autoclosure () -> Wrapped,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> Self {
return Bool.random(using: &generator) ? value() : nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ extension RandomValueGenerating {
public mutating func randomData(count: Int? = nil) -> Data {
return Data.random(
count: count ?? randomInt(in: 16 ... 128),
using: &randomNumberGenerator
using: &randomNumberGenerator,
)
}

Expand Down Expand Up @@ -191,7 +191,7 @@ extension RandomValueGenerating {
/// - range: The half-open range in which to create a random value.
public mutating func random<FloatingPoint>(
_ type: FloatingPoint.Type,
in range: Range<FloatingPoint>
in range: Range<FloatingPoint>,
) -> FloatingPoint
where FloatingPoint: BinaryFloatingPoint, FloatingPoint.RawSignificand: FixedWidthInteger {
return FloatingPoint.randomPrintable(in: range, using: &randomNumberGenerator)
Expand All @@ -217,7 +217,7 @@ extension RandomValueGenerating {
/// - range: The closed range in which to create a random value.
public mutating func random<FloatingPoint>(
_ type: FloatingPoint.Type,
in range: ClosedRange<FloatingPoint>
in range: ClosedRange<FloatingPoint>,
) -> FloatingPoint
where FloatingPoint: BinaryFloatingPoint, FloatingPoint.RawSignificand: FixedWidthInteger {
return FloatingPoint.randomPrintable(in: range, using: &randomNumberGenerator)
Expand All @@ -243,7 +243,7 @@ extension RandomValueGenerating {
/// - range: The half-open range in which to create a random value.
public mutating func random<Integer>(
_ type: Integer.Type,
in range: Range<Integer>
in range: Range<Integer>,
) -> Integer
where Integer: FixedWidthInteger {
return Integer.random(in: range, using: &randomNumberGenerator)
Expand All @@ -269,7 +269,7 @@ extension RandomValueGenerating {
/// - range: The closed range in which to create a random value.
public mutating func random<Integer>(
_ type: Integer.Type,
in range: ClosedRange<Integer>
in range: ClosedRange<Integer>,
) -> Integer
where Integer: FixedWidthInteger {
return Integer.random(in: range, using: &randomNumberGenerator)
Expand Down Expand Up @@ -310,7 +310,7 @@ extension RandomValueGenerating {
public mutating func randomAlphanumericString(count: Int? = nil) -> String {
return String.randomAlphanumeric(
count: count ?? Int.random(in: 5 ... 10, using: &randomNumberGenerator),
using: &randomNumberGenerator
using: &randomNumberGenerator,
)
}

Expand All @@ -324,7 +324,7 @@ extension RandomValueGenerating {
public mutating func randomBasicLatinString(count: Int? = nil) -> String {
return String.randomBasicLatin(
count: count ?? Int.random(in: 5 ... 10, using: &randomNumberGenerator),
using: &randomNumberGenerator
using: &randomNumberGenerator,
)
}

Expand All @@ -339,12 +339,12 @@ extension RandomValueGenerating {
/// chosen.
public mutating func randomString(
withCharactersFrom characters: some Collection<Character>,
count: Int? = nil
count: Int? = nil,
) -> String {
return String.random(
withCharactersFrom: characters,
count: count ?? Int.random(in: 5 ... 10, using: &randomNumberGenerator),
using: &randomNumberGenerator
using: &randomNumberGenerator,
)
}

Expand All @@ -370,12 +370,12 @@ extension RandomValueGenerating {
/// include query items or not.
public mutating func randomURL(
includeFragment: Bool? = nil,
includeQueryItems: Bool? = nil
includeQueryItems: Bool? = nil,
) -> URL {
return URL.random(
includeFragment: includeFragment,
includeQueryItems: includeQueryItems,
using: &randomNumberGenerator
using: &randomNumberGenerator,
)
}

Expand All @@ -391,12 +391,12 @@ extension RandomValueGenerating {
/// include query items or not.
public mutating func randomURLComponents(
includeFragment: Bool? = nil,
includeQueryItems: Bool? = nil
includeQueryItems: Bool? = nil,
) -> URLComponents {
return URLComponents.random(
includeFragment: includeFragment,
includeQueryItems: includeQueryItems,
using: &randomNumberGenerator
using: &randomNumberGenerator,
)
}

Expand Down
12 changes: 6 additions & 6 deletions Sources/DevTesting/Random Value Generation/String+Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension String {
public static func random(
withCharactersFrom characters: some Collection<Character>,
count: Int,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> String {
precondition(!characters.isEmpty || count == 0, "count must be 0 if characters is empty")
guard count > 0 else {
Expand All @@ -39,14 +39,14 @@ extension String {
/// - generator: The random number generator to use when creating the new random string.
public static func randomAlphanumeric(
count: Int,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> String {
return random(
withCharactersFrom: characters(
fromUnicodeScalarRanges: 0x30 ... 0x39, 0x41 ... 0x5a, 0x61 ... 0x7a
fromUnicodeScalarRanges: 0x30 ... 0x39, 0x41 ... 0x5a, 0x61 ... 0x7a,
),
count: count,
using: &generator
using: &generator,
)
}

Expand All @@ -65,12 +65,12 @@ extension String {
/// - generator: The random number generator to use when creating the new random string.
public static func randomBasicLatin(
count: Int,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> String {
return random(
withCharactersFrom: characters(fromUnicodeScalarRanges: 0x20 ... 0x7e),
count: count,
using: &generator
using: &generator,
)
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/DevTesting/Random Value Generation/URL+Random.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ extension URL {
public static func random(
includeFragment: Bool? = nil,
includeQueryItems: Bool? = nil,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> URL {
return URLComponents.random(
includeFragment: includeFragment,
includeQueryItems: includeQueryItems,
using: &generator
using: &generator,
).url!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension URLComponents {
public static func random(
includeFragment: Bool? = nil,
includeQueryItems: Bool? = nil,
using generator: inout some RandomNumberGenerator
using generator: inout some RandomNumberGenerator,
) -> URLComponents {
var urlComponents = URLComponents()

Expand All @@ -47,7 +47,7 @@ extension URLComponents {
let pathComponents = Array(count: Int.random(in: 1 ... 5, using: &generator)) {
String.randomAlphanumeric(
count: Int.random(in: 1 ... 5, using: &generator),
using: &generator
using: &generator,
)
}
urlComponents.path = "/\(pathComponents.joined(separator: "/"))"
Expand All @@ -56,7 +56,7 @@ extension URLComponents {
if includeFragment ?? Bool.random(using: &generator) {
urlComponents.fragment = String.randomAlphanumeric(
count: Int.random(in: 3 ... 5, using: &generator),
using: &generator
using: &generator,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ extension URLQueryItem {
return URLQueryItem(
name: .randomAlphanumeric(
count: Int.random(in: 3 ... 10, using: &generator),
using: &generator
using: &generator,
),
value: Int.random(in: 0 ..< 10, using: &generator) == 0
? nil
: .randomAlphanumeric(
count: Int.random(in: 3 ... 10, using: &generator),
using: &generator
)
using: &generator,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension UUID {
return UUID(
uuid: (
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], modifiedByte6, bytes[7],
modifiedByte8, bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]
modifiedByte8, bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15],
)
)
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/DevTesting/Stubbing/Stub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ public final class ThrowingStub<Arguments, ReturnType, ErrorType> where ErrorTyp
/// - resultQueue: A queue of call results to use. If empty, `defaultResult` is used.
public init(
defaultResult: Result<ReturnType, ErrorType>,
resultQueue: [Result<ReturnType, ErrorType>] = []
resultQueue: [Result<ReturnType, ErrorType>] = [],
) {
self.mutableProperties = .init(
uncheckedState: .init(
defaultResult: defaultResult,
resultQueue: resultQueue
resultQueue: resultQueue,
)
)
}
Expand Down Expand Up @@ -146,7 +146,7 @@ extension ThrowingStub {
/// - resultQueue: A queue of call results to use. If empty, `defaultResult` is used.
public convenience init(
defaultReturnValue: ReturnType,
resultQueue: [Result<ReturnType, ErrorType>] = []
resultQueue: [Result<ReturnType, ErrorType>] = [],
) {
self.init(defaultResult: .success(defaultReturnValue), resultQueue: resultQueue)
}
Expand All @@ -159,7 +159,7 @@ extension ThrowingStub {
/// - resultQueue: A queue of call results to use. If empty, `defaultResult` is used.
public convenience init(
defaultError: ErrorType,
resultQueue: [Result<ReturnType, ErrorType>] = []
resultQueue: [Result<ReturnType, ErrorType>] = [],
) {
self.init(defaultResult: .failure(defaultError), resultQueue: resultQueue)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ extension ThrowingStub where ReturnType == Void {
public convenience init(defaultError: ErrorType?, errorQueue: [ErrorType?] = []) {
self.init(
defaultResult: defaultError.map(Result.failure(_:)) ?? .success(()),
resultQueue: errorQueue.map { $0.map(Result.failure(_:)) ?? .success(()) }
resultQueue: errorQueue.map { $0.map(Result.failure(_:)) ?? .success(()) },
)
}

Expand Down Expand Up @@ -273,7 +273,7 @@ extension ThrowingStub where ErrorType == Never {
public convenience init(defaultReturnValue: ReturnType, returnValueQueue: [ReturnType]) {
self.init(
defaultResult: .success(defaultReturnValue),
resultQueue: returnValueQueue.map(Result.success(_:))
resultQueue: returnValueQueue.map(Result.success(_:)),
)
}

Expand Down
Loading
Loading