aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Lukman <lukman.charlie@gmail.com>2021-03-31 08:36:51 +0700
committerGitHub <noreply@github.com>2021-03-30 20:36:51 -0500
commit512b657a42880af87e9f0d863aa6dccf3540d4ba (patch)
tree775f232676b6e1b16923f2360016237224b5bedd
parentbfb86fa49a73e4194d93bea18d7acfe3694438ce (diff)
downloadgoogle-uuid-512b657a42880af87e9f0d863aa6dccf3540d4ba.tar.gz
feat: add public matcher function for custom error type invalidLengthError (#78)
-rw-r--r--uuid.go6
-rw-r--r--uuid_test.go7
2 files changed, 13 insertions, 0 deletions
diff --git a/uuid.go b/uuid.go
index 60d26bb..d732ae8 100644
--- a/uuid.go
+++ b/uuid.go
@@ -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
diff --git a/uuid_test.go b/uuid_test.go
index 709e34c..99f0bed 100644
--- a/uuid_test.go
+++ b/uuid_test.go
@@ -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)