-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from 417-72KI/linux-testable
Testable in Linux
- Loading branch information
Showing
10 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,9 @@ | |
"xcode_version": [ | ||
"14.2", | ||
"14.3.1" | ||
], | ||
"swift_version": [ | ||
"5.7", | ||
"5.8" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Sources/MultipartFormDataParser/MultipartFormDataParser.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
Tests/MultipartFormDataParserTests/Extension/URLSession+Linux.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#if canImport(FoundationNetworking) | ||
import Foundation | ||
import FoundationNetworking | ||
|
||
// `URLSession` in `FoundationNetworking` does not support `async`/`await`. | ||
extension URLSession { | ||
public func data(for request: URLRequest, delegate: (URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
let task = dataTask(with: request) { data, res, err in | ||
if let err = err { | ||
return continuation.resume(throwing: err) | ||
} | ||
if let data = data, | ||
let res = res { | ||
return continuation.resume(returning: (data, res)) | ||
} | ||
} | ||
// task.delegate = delegate | ||
task.resume() | ||
} | ||
} | ||
|
||
public func data(from url: URL, delegate: (URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse) { | ||
try await data(for: URLRequest(url: url), delegate: delegate) | ||
} | ||
|
||
public func upload(for request: URLRequest, fromFile fileURL: URL, delegate: (URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
let task = uploadTask(with: request, fromFile: fileURL) { data, res, err in | ||
if let err = err { | ||
return continuation.resume(throwing: err) | ||
} | ||
if let data = data, | ||
let res = res { | ||
return continuation.resume(returning: (data, res)) | ||
} | ||
} | ||
// task.delegate = delegate | ||
task.resume() | ||
} | ||
} | ||
|
||
public func upload(for request: URLRequest, from bodyData: Data, delegate: (URLSessionTaskDelegate)? = nil) async throws -> (Data, URLResponse) { | ||
try await withCheckedThrowingContinuation { continuation in | ||
let task = uploadTask(with: request, from: bodyData) { data, res, err in | ||
if let err = err { | ||
return continuation.resume(throwing: err) | ||
} | ||
if let data = data, | ||
let res = res { | ||
return continuation.resume(returning: (data, res)) | ||
} | ||
} | ||
// task.delegate = delegate | ||
task.resume() | ||
} | ||
} | ||
} | ||
#endif |
6 changes: 5 additions & 1 deletion
6
Tests/MultipartFormDataParserTests/Extension/XCTest+Activity.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import XCTest | ||
|
||
func runActivity<Result>(named name: String, block: () throws -> Result) rethrows -> Result { | ||
try XCTContext.runActivity(named: name) { _ in try block() } | ||
#if os(Linux) | ||
return try block() | ||
#else | ||
return try XCTContext.runActivity(named: name) { _ in try block() } | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Tests/MultipartFormDataParserTests/TestFunctions/TestFunction_URLSession.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#if os(Linux) | ||
import Foundation | ||
|
||
struct Image: Hashable { | ||
let data: Data | ||
|
||
init?(data: Data) { | ||
guard !data.isEmpty, | ||
data.prefix(2) == Data([0xFF, 0xD8]), // SOI marker | ||
data.suffix(2) == Data([0xFF, 0xD9]) // EOI marker | ||
else { | ||
print("Given data is not image.") | ||
return nil | ||
} | ||
if data.prefix(11).dropFirst(2) == Data([0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00]) { | ||
// JPEG | ||
} else { | ||
print("Given data is not an expected image format [jpg, png].") | ||
return nil | ||
} | ||
self.data = data | ||
} | ||
} | ||
|
||
#endif |