-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adds case(of:) Validation #2172
Conversation
Signed-off-by: Mohammad <porooshani@gmail.com>
Signed-off-by: Mohammad <porooshani@gmail.com>
@tanner0101 I can't find any circleci config files. What's happening?! |
@mohpor CircleCI is triggering on Vapor 4 because Vapor 3 still uses CircleCI. It's an issue between the two testing setups. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 to this change, thank you.
} | ||
|
||
public var failureDescription: String? { | ||
var message = "value {\(rawValue)} cannot be represented as \(E.self)." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the enum seems like an implementation detail to me. This failure description should be similar to the .in
validator and say something like "value is not foo, bar, or baz"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. It's better that way. Applicable only to CaseIterable
s. But still.
We are going to need a better error message for non-CaseIterable
s.
Signed-off-by: Mohammad <porooshani@gmail.com>
@mohpor if you rebase your branch off latest |
Done. |
Signed-off-by: Mohammad <porooshani@gmail.com>
Signed-off-by: Mohammad <porooshani@gmail.com>
Signed-off-by: Mohammad <porooshani@gmail.com>
* Adds a generic EndpointCache<T> class * Review fixups * Changed internal to private * Changed internal to private * Renamed the error * add EndpointCache tests * add CacheControl convienience init * rename badJSON error case Co-authored-by: Tanner <me@tanner.xyz>
Signed-off-by: Mohammad <porooshani@gmail.com>
Signed-off-by: Mohammad <porooshani@gmail.com>
Signed-off-by: Mohammad <porooshani@gmail.com>
Sorry about the mess. Should be squashed. |
No problem, GitHub will squash them for us. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the latest changes! This looks great. Just minor nits left.
if cases.count > 1 { | ||
suffix = " or \(cases.removeLast())" | ||
} | ||
return "is not \(cases.joined(separator: ", "))\(suffix)." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most annoying nit of all time: can we have an oxford comma here? >_<
You should be able to copy makeDescription
from the .in
validator (In.swift
) which supports both successDescription and failureDescription and includes the comma:
func makeDescription(not: Bool) -> String {
let description: String
switch self.items.count {
case 1:
description = self.items[0].description
case 2:
description = "\(self.items[0].description) or \(self.items[1].description)"
default:
let first = self.items[0..<(self.items.count - 1)]
.map { $0.description }.joined(separator: ", ")
let last = self.items[self.items.count - 1].description
description = "\(first), or \(last)"
}
return "is\(not ? " not" : " ") \(description)"
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I was thinking how inefficient is in
's description generation! >_<
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a matter of fact, the in
's description message has an invalid 2-space distance for successful cases.
Signed-off-by: Mohammad <porooshani@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
These changes are now available in 4.0.0-beta.3.22 |
Added Enum validation for
RawRepresentable
enums. Checks to see if a value can be represented as a specific enum, and if enum isCaseIterable
, reports the possible values too.e.g.: