Repository navigation
Add -validate flag generating a Validate() error method - #130
Merged
Merged
Conversation
Validate() returns nil for a declared constant and an error naming the value otherwise, so enum fields can be checked through a common interface instead of the type-specific IsAT() bool. With -typederrors the error wraps enumerrs.ErrValueInvalid, matching TString() and the unmarshal methods. The end-to-end harness now takes extra flags per fixture instead of a single typed-errors boolean. Two fixtures cover declared values, gap values, out-of-range values, calls through an interface, and errors.Is against the sentinel. Based on #102 by peczenyj, a port of #82 by mbyio.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Based on #102 by @peczenyj, itself a port of #82 by @mbyio. Rebuilt on current master.
-validategenerates:With
-typederrorsthe error wrapsenumerrs.ErrValueInvalid, same asTString()and the unmarshal methods. Opt-in, stdlib only, no change to existing output.Tests
testdata/validate.go: contiguous enum. Every declared value returns nil; below, just above, and far out of range each return an error with the exact message; calls through aValidate() errorinterface.testdata/validateTypedErrors.go: enum with gaps. Declared values return nil and do not match the sentinel; gap, zero, negative and out-of-range values matchenumerrs.ErrValueInvalidundererrors.Isand name the value; an unrelated sentinel does not match.Validate()that always returns nil and a builder that ignores-typederrorseach fail the suite.The end-to-end harness now takes extra flags per fixture instead of one typed-errors boolean.