Skip to content

Commit

Permalink
feat: add public matcher function for custom error type invalidLength…
Browse files Browse the repository at this point in the history
…Error (#78)
  • Loading branch information
charlielukman committed Mar 31, 2021
1 parent bfb86fa commit 512b657
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions uuid.go
Expand Up @@ -41,6 +41,12 @@ func (err invalidLengthError) Error() string {
return fmt.Sprintf("invalid UUID length: %d", err.len)
}

// IsInvalidLengthError is matcher function for custom error invalidLengthError
func IsInvalidLengthError(err error) bool {
_, ok := err.(invalidLengthError)
return ok
}

// Parse decodes s into a UUID or returns an error. Both the standard UUID
// forms of xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx and
// urn:uuid:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx are decoded as well as the
Expand Down
7 changes: 7 additions & 0 deletions uuid_test.go
Expand Up @@ -526,6 +526,13 @@ func TestWrongLength(t *testing.T) {
}
}

func TestIsWrongLength(t *testing.T) {
_, err := Parse("12345")
if !IsInvalidLengthError(err) {
t.Errorf("expected error type is invalidLengthError")
}
}

var asString = "f47ac10b-58cc-0372-8567-0e02b2c3d479"
var asBytes = []byte(asString)

Expand Down

0 comments on commit 512b657

Please sign in to comment.