Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions uuid.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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