Files
swift-async-algorithms/Sources/AsyncSequenceValidation/Expectation.swift
T
Philippe Hauslerandkperryua 7969001299 Add a detailed proposal-like guide for AsyncSequence validation (#56)
* Add a detailed proposal like guide for MarbleDiagram

* Slight spacing change

Co-authored-by: kperryua <kperry@apple.com>

* Fix some pluralization agreement

Co-authored-by: kperryua <kperry@apple.com>

* Clarify the testing of merge and add a future direction for unordered groups

* rename the diagram system to a more general 'validate' based name

* Spelling fixes

* Grammar fixes for credits

Co-authored-by: kperryua <kperry@apple.com>
2022-02-22 11:03:27 -08:00

73 lines
2.6 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift Async Algorithms open source project
//
// Copyright (c) 2022 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//
extension AsyncSequenceValidationDiagram {
public struct ExpectationResult {
public var expected: [(Clock.Instant, Result<String?, Error>)]
public var actual: [(Clock.Instant, Result<String?, Error>)]
}
public struct ExpectationFailure: CustomStringConvertible {
public enum Kind {
case expectedFinishButGotValue(String)
case expectedMismatch(String, String)
case expectedValueButGotFinished(String)
case expectedFailureButGotValue(Error, String)
case expectedFailureButGotFinish(Error)
case expectedValueButGotFailure(String, Error)
case expectedFinishButGotFailure(Error)
case expectedValue(String)
case expectedFinish
case expectedFailure(Error)
case unexpectedValue(String)
case unexpectedFinish
case unexpectedFailure(Error)
}
public var when: Clock.Instant
public var kind: Kind
var reason: String {
switch kind {
case .expectedFinishButGotValue(let actual):
return "expected finish but got \"\(actual)\""
case .expectedMismatch(let expected, let actual):
return "expected \"\(expected)\" but got \"\(actual)\""
case .expectedValueButGotFinished(let expected):
return "expected \"\(expected)\" but got finish"
case .expectedFailureButGotValue(_, let actual):
return "expected failure but got \"\(actual)\""
case .expectedFailureButGotFinish:
return "expected failure but got finish"
case .expectedValueButGotFailure(let expected, _):
return "expected \"\(expected)\" but got failure"
case .expectedFinishButGotFailure:
return "expected finish but got failure"
case .expectedValue(let expected):
return "expected \"\(expected)\""
case .expectedFinish:
return "expected finish"
case .expectedFailure:
return "expected failure"
case .unexpectedValue(let actual):
return "unexpected \"\(actual)\""
case .unexpectedFinish:
return "unexpected finish"
case .unexpectedFailure:
return "unexpected failure"
}
}
public var description: String {
return reason + " at tick \(when.when.rawValue - 1)"
}
}
}