From 0c84a43ce25087b7041833685982950a65630d28 Mon Sep 17 00:00:00 2001 From: Jordan Chalupka <9794216+jordan-chalupka@users.noreply.github.com> Date: Thu, 25 Nov 2021 19:32:19 -0500 Subject: [PATCH] adding IsNil method to uuid (#95) * adding IsZero method to uuid * rename isZero to IsNil --- uuid.go | 5 +++++ uuid_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/uuid.go b/uuid.go index 54431ab..f314b84 100644 --- a/uuid.go +++ b/uuid.go @@ -151,6 +151,11 @@ var ( NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8")) ) +// IsNil returns if the UUID is equal to the nil UUID +func (u UUID) IsNil() bool { + return u == Nil +} + // Version returns the algorithm version used to generate the UUID. func (u UUID) Version() byte { return u[6] >> 4 diff --git a/uuid_test.go b/uuid_test.go index 28842c4..2bbbb9d 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -29,6 +29,7 @@ import ( ) func TestUUID(t *testing.T) { + t.Run("IsNil", testUUIDIsNil) t.Run("Bytes", testUUIDBytes) t.Run("String", testUUIDString) t.Run("Version", testUUIDVersion) @@ -38,6 +39,15 @@ func TestUUID(t *testing.T) { t.Run("Format", testUUIDFormat) } +func testUUIDIsNil(t *testing.T) { + u := UUID{} + got := u.IsNil() + want := true + if got != want { + t.Errorf("%v.IsNil() = %t, want %t", u, got, want) + } +} + func testUUIDBytes(t *testing.T) { got := codecTestUUID.Bytes() want := codecTestData