Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.3 kB · 71 lines
Swift
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172//// XCTAssertEndToEndCoding.swift// URLQueryItemCoder//// Created by Kyle Hughes on 2/25/23.//
#if canImport(Combine)import Combineimport XCTest
@testable import URLQueryItemCoder
public func XCTAssertEndToEndCoding<Encoder, Decoder>( encoder: (EncodingStrategies) -> Encoder, decoder: (DecodingStrategies) -> Decoder, encodedWith encodingStrategies: EncodingStrategies = .default, decodedWith decodingStrategies: DecodingStrategies = .default, value: some Codable & Equatable, file: StaticString = #filePath, line: UInt = #line) where Encoder: TopLevelEncoder, Encoder.Output: Equatable, Decoder: TopLevelDecoder, Decoder.Input == Encoder.Output{ do { let encoder = encoder(encodingStrategies) let encodedRepresentation = try encoder.encode(value) let decoder = decoder(decodingStrategies) let decodedRepresentation = try decoder.decode(type(of: value), from: encodedRepresentation) XCTAssertEqual(value, decodedRepresentation, file: file, line: line) } catch { XCTFail(error.localizedDescription, file: file, line: line) }}
public func XCTAssertEndToEndCoding<Encoder, Decoder>( encoder: (EncodingStrategies) -> Encoder, decoder: (DecodingStrategies) -> Decoder, encodedWith encodingStrategies: EncodingStrategies = .default, decodedWith decodingStrategies: DecodingStrategies = .default, value: some Codable & Equatable & FloatingPoint, file: StaticString = #filePath, line: UInt = #line) where Encoder: TopLevelEncoder, Encoder.Output: Equatable, Decoder: TopLevelDecoder, Decoder.Input == Encoder.Output{ do { let encoder = encoder(encodingStrategies) let encodedRepresentation = try encoder.encode(value) let decoder = decoder(decodingStrategies) let decodedRepresentation = try decoder.decode(type(of: value), from: encodedRepresentation) if value.isNaN { XCTAssertEqual(value.isNaN, decodedRepresentation.isNaN) } else { XCTAssertEqual(value, decodedRepresentation, file: file, line: line) } } catch { XCTFail(error.localizedDescription, file: file, line: line) }}#endif