Skip to content
Closed
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
24 changes: 24 additions & 0 deletions Sources/PropertyBased/Date+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

#if canImport(Foundation)

import Foundation

extension Calendar {
Expand Down Expand Up @@ -50,4 +51,27 @@ extension Date: @retroactive ExpressibleByStringLiteral {
}
}

#elseif canImport(FoundationEssentials)

import FoundationEssentials

extension Date: @retroactive ExpressibleByStringLiteral {
/// Create a date from a ISO8601-formatted string.
///
/// The date components are required. The time and offset components are optional.
///
/// This initializer exists as a convenience for creating date ranges. It is not recommended for use in a production environment.
///
/// - Parameter value: The string to parse.
public init(stringLiteral value: String) {
let formatter = ISO8601DateFormatter()

guard let date = formatter.date(from: value) else {
preconditionFailure("\(value) is not a valid ISO 8601 date")
}

self = date
}
}

#endif
2 changes: 1 addition & 1 deletion Sources/PropertyBased/FixedSeedTrait.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public struct FixedSeedTrait: TestTrait, TestScoping {
}

extension Trait where Self == FixedSeedTrait {
#if canImport(Foundation)
#if canImport(FoundationEssentials) || canImport(Foundation)
/// Override the seed used by all property checks within this Test.
///
/// If one of your property checks fails intermittently, apply this trait to reliably reproduce the issue.
Expand Down
6 changes: 5 additions & 1 deletion Sources/PropertyBased/Gen+Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Created by Lennard Sprong on 30/05/2025.
//

#if canImport(Foundation)
#if canImport(FoundationEssentials)
import FoundationEssentials
#elseif canImport(Foundation)
import Foundation
#endif
#if canImport(FoundationEssentials) || canImport(Foundation)

// This value is a constant, to keep test runs reproducible.
// This value may only be changed between package releases.
Expand Down
6 changes: 5 additions & 1 deletion Sources/PropertyBased/Gen+Float.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,12 @@ extension Gen where Value == Float80 {
}
#endif

#if canImport(Foundation)
#if canImport(FoundationEssentials)
import FoundationEssentials
#elseif canImport(Foundation)
import Foundation
#endif
#if canImport(FoundationEssentials) || canImport(Foundation)
extension Gen where Value == CGFloat {
/// Produces a generator of random floats within the specified range.
///
Expand Down
6 changes: 5 additions & 1 deletion Sources/PropertyBased/Shrink+Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Created by Lennard Sprong on 30/05/2025.
//

#if canImport(Foundation)
#if canImport(FoundationEssentials)
import FoundationEssentials
#elseif canImport(Foundation)
import Foundation
#endif
#if canImport(FoundationEssentials) || canImport(Foundation)

extension Shrink {
/// Shrink a TimeInterval by rounding to seconds, then minutes, then 15 minute intervals.
Expand Down
6 changes: 5 additions & 1 deletion Sources/PropertyBased/Xoshiro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ extension Xoshiro: Hashable {
}
}

#if canImport(Foundation)
#if canImport(FoundationEssentials)
import FoundationEssentials
#elseif canImport(Foundation)
import Foundation
#endif
#if canImport(FoundationEssentials) || canImport(Foundation)

extension Xoshiro: SeededRandomNumberGenerator {
public typealias Seed = String
Expand Down
9 changes: 7 additions & 2 deletions Tests/PropertyBasedTests/GenTests+Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
// Created by Lennard Sprong on 31/05/2025.
//

#if canImport(Foundation)
import Testing
#if canImport(FoundationEssentials)
import FoundationEssentials
#elseif canImport(Foundation)
import Foundation
#endif
#if canImport(FoundationEssentials) || canImport(Foundation)

import Testing
import PropertyBased

extension Calendar {
Expand Down
9 changes: 7 additions & 2 deletions Tests/PropertyBasedTests/ShrinkTests+Date.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@
// Created by Lennard Sprong on 31/05/2025.
//

#if canImport(Foundation)
import Testing
#if canImport(FoundationEssentials)
import FoundationEssentials
#elseif canImport(Foundation)
import Foundation
#endif
#if canImport(FoundationEssentials) || canImport(Foundation)

import Testing
@testable import PropertyBased

@Suite struct ShrinkDateTests {
Expand Down
Loading