Skip to content

Commit

Permalink
better swift 6 compiler conditionals (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
sliemeobn authored Dec 8, 2024
1 parent b78de8c commit e884367
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/Elementary/ServerSupport/SendOnceBox.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if swift(>=6.0) && !hasFeature(Embedded)
#if compiler(>=6.0) && !hasFeature(Embedded)
import Synchronization

@available(macOS 15.0, *)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Elementary/ServerSupport/SendableAnyHTMLBox.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public struct _SendableAnyHTMLBox: Sendable {

enum Storage {
case sendable(any HTML & Sendable)
#if swift(>=6.0)
#if compiler(>=6.0)
// NOTE: protocol can be removed when macOS 15 is the minimum
case sendOnceBox(any SendOnceBoxing<any HTML>)
#endif
Expand All @@ -18,14 +18,14 @@ public struct _SendableAnyHTMLBox: Sendable {
storage = .sendable(html)
}

#if swift(>=6.0)
#if compiler(>=6.0)
@available(macOS 15, *)
public init(_ html: sending any HTML) {
storage = .sendOnceBox(SendOnceBox(html))
}
#endif

#if swift(>=6.0)
#if compiler(>=6.0)
public consuming func tryTake() -> sending (any HTML)? {
switch storage {
case let .sendable(html):
Expand Down
9 changes: 6 additions & 3 deletions Tests/ElementaryTests/SendableAnyHTMLBox.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Elementary
import XCTest

@available(macOS 15.0, *)
final class SendOnceHTMLValueTests: XCTestCase {
func testHoldsSendableValue() {
let html = div { "Hello, World!" }
Expand All @@ -10,8 +9,12 @@ final class SendOnceHTMLValueTests: XCTestCase {
XCTAssertNotNil(box.tryTake())
}

#if swift(>=6.0)
func testHoldsNonSendable() {
#if compiler(>=6.0)
func testHoldsNonSendable() throws {
guard #available(macOS 15.0, *) else {
throw XCTSkip("Requires macOS 15.0")
}

let html = MyComponent()
let box = _SendableAnyHTMLBox(html)
XCTAssertNotNil(box.tryTake())
Expand Down

0 comments on commit e884367

Please sign in to comment.