From 6a2634dcd36dcbb1ef87cba1ad379665850d9b7b Mon Sep 17 00:00:00 2001 From: jordan-chalupka Date: Mon, 22 Nov 2021 20:09:00 -0500 Subject: [PATCH 1/2] adding IsZero method to uuid --- uuid.go | 5 +++++ uuid_test.go | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/uuid.go b/uuid.go index 54431ab..82aec1a 100644 --- a/uuid.go +++ b/uuid.go @@ -151,6 +151,11 @@ var ( NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8")) ) +// IsZero returns if the UUID is equal to the nil UUID +func (u UUID) IsZero() 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..1e73a61 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -29,6 +29,7 @@ import ( ) func TestUUID(t *testing.T) { + t.Run("IsZero", testUUIDIsZero) 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 testUUIDIsZero(t *testing.T) { + u := UUID{} + got := u.IsZero() + want := true + if got != want { + t.Errorf("%v.IsZero() = %t, want %t", u, got, want) + } +} + func testUUIDBytes(t *testing.T) { got := codecTestUUID.Bytes() want := codecTestData From 4758840b8b80765659cd614f60774bb741bd739f Mon Sep 17 00:00:00 2001 From: jordan-chalupka Date: Thu, 25 Nov 2021 14:32:29 -0500 Subject: [PATCH 2/2] rename isZero to IsNil --- uuid.go | 4 ++-- uuid_test.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/uuid.go b/uuid.go index 82aec1a..f314b84 100644 --- a/uuid.go +++ b/uuid.go @@ -151,8 +151,8 @@ var ( NamespaceX500 = Must(FromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8")) ) -// IsZero returns if the UUID is equal to the nil UUID -func (u UUID) IsZero() bool { +// IsNil returns if the UUID is equal to the nil UUID +func (u UUID) IsNil() bool { return u == Nil } diff --git a/uuid_test.go b/uuid_test.go index 1e73a61..2bbbb9d 100644 --- a/uuid_test.go +++ b/uuid_test.go @@ -29,7 +29,7 @@ import ( ) func TestUUID(t *testing.T) { - t.Run("IsZero", testUUIDIsZero) + t.Run("IsNil", testUUIDIsNil) t.Run("Bytes", testUUIDBytes) t.Run("String", testUUIDString) t.Run("Version", testUUIDVersion) @@ -39,12 +39,12 @@ func TestUUID(t *testing.T) { t.Run("Format", testUUIDFormat) } -func testUUIDIsZero(t *testing.T) { +func testUUIDIsNil(t *testing.T) { u := UUID{} - got := u.IsZero() + got := u.IsNil() want := true if got != want { - t.Errorf("%v.IsZero() = %t, want %t", u, got, want) + t.Errorf("%v.IsNil() = %t, want %t", u, got, want) } }