Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ExpressibleByArrayLiteral conformance of _TinyArray to the declaring module #157

Merged
merged 3 commits into from
Dec 5, 2023
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
2 changes: 1 addition & 1 deletion Sources/X509/CryptographicMessageSyntax/CMSSignature.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//===----------------------------------------------------------------------===//

import SwiftASN1
#if canImport(Darwin)
#if canImport(Darwin) || swift(>=5.9.1)
import Foundation
#else
@preconcurrency import Foundation
Expand Down
2 changes: 1 addition & 1 deletion Sources/X509/OCSP/OCSPPolicy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import SwiftASN1
import Crypto
#if canImport(Darwin)
#if canImport(Darwin) || swift(>=5.9.1)
import Foundation
#else
@preconcurrency import Foundation
Expand Down
14 changes: 14 additions & 0 deletions Sources/_CertificateInternals/_TinyArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ extension _TinyArray: Equatable where Element: Equatable {}
extension _TinyArray: Hashable where Element: Hashable {}
extension _TinyArray: Sendable where Element: Sendable {}

extension _TinyArray: ExpressibleByArrayLiteral {
@inlinable
public init(arrayLiteral elements: Element...) {
switch elements.count {
case 0:
self = .init()
case 1:
self = .init(CollectionOfOne(elements[0]))
default:
self = .init(elements)
}
}
}

extension _TinyArray: RandomAccessCollection {
public typealias Element = Element

Expand Down
17 changes: 9 additions & 8 deletions Tests/CertificateInternalsTests/TinyArrayTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ final class TinyArrayTests: XCTestCase {
XCTAssertEqual(Array(_TinyArray<Int>([1, 2, 3, 4, 5])), [1, 2, 3, 4, 5])
}

func testExpressibleByArrayLiteral() {
XCTAssertEqual(Array([] as _TinyArray<Int>), [])
XCTAssertEqual(Array([1] as _TinyArray<Int>), [1])
XCTAssertEqual(Array([1, 2] as _TinyArray<Int>), [1, 2])
XCTAssertEqual(Array([1, 2, 3] as _TinyArray<Int>), [1, 2, 3])
XCTAssertEqual(Array([1, 2, 3, 4] as _TinyArray<Int>), [1, 2, 3, 4])
XCTAssertEqual(Array([1, 2, 3, 4, 5] as _TinyArray<Int>), [1, 2, 3, 4, 5])
}

func testAppend() {
assertEqual([1]) { array in
array.append(1)
Expand Down Expand Up @@ -339,11 +348,3 @@ final class TinyArrayTests: XCTestCase {
)
}
}

extension _TinyArray: ExpressibleByArrayLiteral {
public typealias ArrayLiteralElement = Element

public init(arrayLiteral elements: Element...) {
self.init(elements)
}
}
2 changes: 1 addition & 1 deletion Tests/X509Tests/OCSPPolicyVerifierTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import XCTest
import Crypto
import SwiftASN1
@testable import X509
#if canImport(Darwin)
#if canImport(Darwin) || swift(>=5.9.1)
import Foundation
#else
@preconcurrency import Foundation
Expand Down